Overview of coincurve
masterlibsecp256k1, a highly optimized C library used by Bitcoin Core. It is designed for performing cryptographic operations on the secp256k1 elliptic curve.repository·master·Indexed 41 days ago
https://github.com/ofek/coincurveA high-performance Python library providing bindings to the libsecp256k1 C library for secp256k1 elliptic curve operations. It provides classes for PrivateKey, PublicKey, and PublicKeyXOnly to support signing, verification, and key derivation for projects like Bitcoin and Ethereum, including support for Schnorr signatures and Taproot.
libsecp256k1, a highly optimized C library used by Bitcoin Core. It is designed for performing cryptographic operations on the secp256k1 elliptic curve.To build coincurve from source on Debian or Ubuntu, install the following packages using apt-get:
sudo apt-get install -y autoconf automake build-essential libffi-dev libtool pkg-config python3-devTo build coincurve from source on RHEL or CentOS, install the following packages using yum:
sudo yum install -y autoconf automake gcc gcc-c++ libffi-devel libtool make pkgconfig python3-develTo run the performance benchmarks for coincurve, you must have either Hatch or UV installed. Use the following command to execute the benchmark script:
[hatch|uv] run scripts/bench.pyBenchmark Details:
hatch run scripts/bench.py
# OR
uv run scripts/bench.pyIf pre-compiled wheels are unavailable for your platform, you can build from source. You can force a source installation by using the --no-binary flag with pip.
To control the build process, you can use the following environment variables:
COINCURVE_UPSTREAM_REF: Specifies a specific Git reference of libsecp256k1 to use instead of the default.COINCURVE_IGNORE_SYSTEM_LIB: Set to ON to force fetching libsecp256k1 even if a system version is detected.COINCURVE_SECP256K1_STATIC: Set to OFF to build the vendored libsecp256k1 as a shared library.COINCURVE_VENDOR_CFFI: Set to anything other than 1 (the default) to prevent vendoring the _cffi_backend module. Note that if you disable this, you must add cffi as a runtime dependency.pip install coincurve --no-binary coincurveThe easiest way to install coincurve is via PyPI using pip. Binary wheels are available for most platforms, including macOS, Windows, and Linux (both glibc and musl) across multiple CPython versions (3.10 through 3.14, including free-threaded builds).
pip install coincurveTo build coincurve from source on macOS, you need to install Xcode command line tools and several dependencies via Homebrew:
xcode-select --install
brew install autoconf automake libffi libtool pkg-config pythonTo build coincurve from source on Alpine Linux, install the following packages using apk:
sudo apk add autoconf automake build-base libffi-dev libtool pkgconfig python3-devUse der_to_cdata to parse a DER-encoded signature and convert it back into a cdata signature object. This will raise a ValueError if the DER encoding is invalid.
from coincurve.ecdsa import der_to_cdata
cdata_signature = der_to_cdata(der_signature)The reseed method protects against certain possible future side-channel timing attacks by randomizing the context.
seed that is exactly 32 bytes, it will be used.os.urandom(32).If the underlying secp256k1_context_randomize operation fails, a ValueError with the message "secp256k1_context_randomize" is raised.
# Reseed with a specific 32-byte seed
ctx.reseed(b'a_very_secure_32_byte_seed_value')
# Reseed using random bytes (default behavior if no seed is provided)
ctx.reseed()The coincurve package provides high-level interfaces for elliptic curve cryptography (secp256k1). You can import the primary classes for key management and signature verification directly from the top-level package:
Context: For managing cryptographic contexts.PrivateKey: For handling private keys.PublicKey: For handling full public keys.PublicKeyXOnly: For handling X-only public keys.verify_signature: A utility function for verifying signatures.from coincurve import Context, PrivateKey, PublicKey, verify_signatureThe module provides low-level utilities for encoding specific ASN.1 types used in the DER structure.
encode_octet_string(value: bytes) -> bytes: Encodes a value as an OCTET STRING.encode_bit_string(value: bytes, unused_bits: int = 0) -> bytes: Encodes a value as a BIT STRING. The unused_bits parameter (default 0) specifies how many bits at the end of the octet string are not used.