Registry / security / secp256k1

secp256k1

JSON →
library0.14.0pypypi✓ verified 84d ago

Python FFI (Foreign Function Interface) bindings to libsecp256k1, the optimized C library used by Bitcoin for elliptic curve cryptography. Version 0.14.0 wraps libsecp256k1 with secure memory handling (by default) and provides low-level primitives for EC operations, signing, verification, and public key recovery. Release cadence is irregular; maintained by the same author for over a decade.

pip install secp256k1
INSTALL
IMPORT
SIG · SECP256K1
S
secp256k1
securitypythonv0.14.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

secp256k1
import secp256k1
Top-level package; no submodule needed for basic usage.

Creates a PrivateKey, signs a message, then verifies using the public key.

import secp256k1 # Verify a message (example) msg = b"message" # Generate a random private key (should be securely generated in practice) private_key = secp256k1.PrivateKey() signature = private_key.ecdsa_sign(msg, raw=True) # Verify public_key = private_key.pubkey verified = public_key.ecdsa_verify(msg, signature, raw=True) print("Valid?", verified)
Debug
Known issues
gotchaThe PrivateKey constructor does **not** automatically use secure memory unless compiled with libsecp256k1's 'secp256k1_context_create' (default). However, setting `flags=secp256k1.FLAG_SIGN` alone does not enable memory protection. Use `secp256k1.PrivateKey(secp256k1.PrivateKey.random(), raw=True)` for secure key generation.
fix
Read the 'About memory safety' section in the README; prefer keys generated via `PrivateKey.random()`.
affects: all
gotchaThe term 'serialize' and 'deserialize' are spelled with 'z' not 's'. Common to mis-type 'serialise'.
fix
Use `private_key.serialize()` (z) and `private_key.deserialize()` (z).
affects: all
deprecatedThe `secp256k1.All()` and `secp256k1.ALL_FLAGS` constants have been removed in 0.14.0. Use `secp256k1.FLAG_SIGN | secp256k1.FLAG_VERIFY` instead.
fix
Replace `All()` with `secp256k1.FLAG_SIGN | secp256k1.FLAG_VERIFY`.
affects: 0.14.0
Errors
Common errors & fixes
AttributeError: module 'secp256k1' has no attribute 'All'
The All() constant was removed in 0.14.0.
fix
Use `secp256k1.FLAG_SIGN | secp256k1.FLAG_VERIFY`.
OSError: libsecp256k1.so.0: cannot open shared object file: No such file or directory
The libsecp256k1 shared library is not installed on the system or not in LD_LIBRARY_PATH.
fix
Install libsecp256k1 via your system package manager (e.g., `apt install libsecp256k1-0`) or build from source with `pip install --no-binary :all: secp256k1` to compile statically.
ValueError: Invalid secret key
The private key bytes do not satisfy the curve order (e.g., zero or >= n).
fix
Ensure the private key is a 32-byte value less than the secp256k1 curve order (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141). Use `secp256k1.PrivateKey(random_bytes)` where random_bytes is 32 cryptographically random bytes.
Upgrade
Version history
0.14.0latest on PyPI · released Jan 29, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
secp256k1 — pip install secp256k1 · libregistry