{"id":2893,"library":"coincurve","title":"Coincurve: secp256k1 Elliptic Curve Operations","description":"Coincurve is a Python library providing fast and secure bindings for libsecp256k1, the highly optimized C library used by Bitcoin Core for elliptic curve cryptography operations. It offers a clean, easy-to-use API for tasks like key generation, signing, and verification. The current version is 21.0.0, and it maintains frequent updates to libsecp256k1.","status":"active","version":"21.0.0","language":"python","source_language":"en","source_url":"https://github.com/ofek/coincurve","tags":["cryptography","secp256k1","elliptic curve","bitcoin","ethereum"],"install":[{"cmd":"pip install coincurve","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"For generating private keys and signing messages.","symbol":"PrivateKey","correct":"from coincurve import PrivateKey"},{"note":"For handling public keys and verifying signatures.","symbol":"PublicKey","correct":"from coincurve import PublicKey"},{"note":"The function is available directly under the top-level `coincurve` module, not a submodule like `ecdsa`.","wrong":"from coincurve.ecdsa import verify_signature","symbol":"verify_signature","correct":"from coincurve import verify_signature"}],"quickstart":{"code":"import os\nfrom coincurve import PrivateKey, verify_signature\nimport hashlib\n\n# 1. Generate a new private key (or use an existing one)\nprivate_key = PrivateKey()\n\n# Get the corresponding public key\npublic_key = private_key.public_key.format(compressed=True)\nprint(f\"Public Key (compressed): {public_key.hex()}\")\n\n# 2. Define a message to sign (must be hashed to 32 bytes for signing)\nmessage_str = \"Hello, Coincurve!\"\nmessage_hash = hashlib.sha256(message_str.encode('utf-8')).digest()\nprint(f\"Message hash: {message_hash.hex()}\")\n\n# 3. Sign the message\nsignature = private_key.sign(message_hash)\nprint(f\"Signature (DER-encoded): {signature.hex()}\")\n\n# 4. Verify the signature using the public key and message hash\nis_valid = verify_signature(signature, message_hash, public_key)\n\nif is_valid:\n    print(\"Signature is valid!\")\nelse:\n    print(\"Signature is INVALID.\")\n\n# Example of direct verification via PublicKey object (also works)\n# is_valid_direct = private_key.public_key.verify(signature, message_hash)\n# print(f\"Signature is valid (direct Public Key method): {is_valid_direct}\")","lang":"python","description":"This quickstart demonstrates how to generate a secp256k1 private key, derive its public key, sign a hashed message, and verify the signature using `coincurve`. Note that `private_key.sign()` produces a DER-encoded signature expected by `verify_signature`."},"warnings":[{"fix":"Upgrade Python to 3.9 or newer. Alternatively, pin `coincurve<21.0.0` if Python upgrade is not feasible.","message":"Python 3.8 support was dropped in `coincurve` version 21.0.0. Users on Python 3.8 or older must upgrade their Python environment or use an earlier `coincurve` version.","severity":"breaking","affected_versions":">=21.0.0"},{"fix":"Ensure CMake is installed and discoverable in your build environment. For standard `pip install`, no explicit action is usually required.","message":"CMake is a build dependency starting from `coincurve` version 20.0.0. While `pip` typically handles this for standard installations by fetching `cmake` from PyPI, redistributors or users building from source in custom environments will need to ensure CMake is available.","severity":"breaking","affected_versions":">=20.0.0"},{"fix":"Upgrade to a 64-bit Windows environment or pin `coincurve<20.0.0`.","message":"Binary wheels for Windows 32-bit are no longer built as of `coincurve` version 20.0.0. Users on Windows 32-bit systems will need to compile from source (which requires appropriate build tools and dependencies) or use an older version.","severity":"breaking","affected_versions":">=20.0.0"},{"fix":"Use `PrivateKey.sign()` when verifying with `coincurve.verify_signature()`. If you need recoverable signatures, verify them using `PublicKey.verify()` if applicable, or recover the public key first and then verify (more complex).","message":"The `PrivateKey.sign_recoverable()` method produces a 65-byte compact signature, which is NOT compatible with the module-level `coincurve.verify_signature()` function that expects a DER-encoded signature (produced by `PrivateKey.sign()`). Attempting to verify a recoverable signature with `verify_signature()` will raise a `ValueError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pin your `coincurve` dependency to `coincurve==20.0.0` or `coincurve!=21.0.0` until a patched version is released. Or, consider updating to a newer working version if available.","message":"A packaging issue in `coincurve==21.0.0` (specifically a missing LICENSE file in the `cffi` distribution during build) can lead to installation failures when `coincurve` is a dependency of another package. This was observed with `ccxt`.","severity":"gotcha","affected_versions":"21.0.0"}],"env_vars":null,"search_vec":"'21.0.0':53 'api':40 'bind':15 'bitcoin':25,65 'c':21 'clean':35 'coincurv':1,6 'core':26 'cryptographi':30,61 'current':50 'curv':4,29,64 'easi':37 'easy-to-us':36 'ellipt':3,28,63 'ethereum':66 'fast':12 'frequent':57 'generat':45 'high':19 'key':44 'librari':10,22 'libsecp256k1':17,60 'like':43 'maintain':56 'offer':33 'oper':5,31 'optim':20 'provid':11 'python':9 'secp256k1':2,62 'secur':14 'sign':46 'task':42 'updat':58 'use':23,39 'verif':48 'version':51","created_at":"2026-04-11T09:12:08.278601+00:00","updated_at":"2026-04-16T03:04:08.183361+00:00","problems":[{"fix":"Pin `coincurve` to an older, stable version like `20.0.0` using `pip install coincurve==20.0.0` to avoid the buggy version.","cause":"This specific error occurs with `coincurve==21.0.0` due to a packaging bug where the build process expects a LICENSE file from the `cffi` distribution, but it is not found in the expected location during installation.","error":"RuntimeError: Expected exactly one LICENSE file in cffi distribution, got 0."},{"fix":"Install the necessary system dependencies before running `pip install coincurve`. For Debian/Ubuntu, use `sudo apt-get install -y autoconf automake build-essential libffi-dev libtool pkg-config python3-dev`. For other operating systems, consult the `coincurve` documentation for equivalent packages.","cause":"`coincurve` relies on C extensions (specifically `libsecp256k1`) which require system-level development tools and libraries to be installed on your system to compile from source, especially if pre-built wheels are not available for your specific platform or Python version.","error":"ERROR: Could not build wheels for coincurve, which is required to install pyproject.toml-based projects"},{"fix":"Ensure `coincurve` is installed in your current Python environment by running `pip install coincurve`. If problems persist, verify you are using the correct Python interpreter or try reinstalling with `pip install --no-cache-dir coincurve` after ensuring all system build dependencies are met.","cause":"This error typically indicates that the `coincurve` package was not installed correctly in the active Python environment, or the Python interpreter running the code cannot find the installed package. This can happen due to different Python environments (e.g., system Python vs. virtual environment) or an incomplete installation.","error":"ImportError: No module named 'coincurve'"},{"fix":"This is often a symptom of the 'Could not build wheels' error. Ensure all necessary system build dependencies (like `build-essential`, `libffi-dev`, `python3-dev`) are installed on your system, then try reinstalling `coincurve` using `pip install coincurve --no-cache-dir --force-reinstall`.","cause":"This error means that the `_libsecp256k1` C extension, which is a core component of `coincurve`, could not be found or loaded. This usually points to a failed or incomplete build of the `coincurve` package, often due to missing system-level dependencies during installation.","error":"ModuleNotFoundError: No module named 'coincurve._libsecp256k1'"},{"fix":"Use `coincurve`'s dedicated serialization or deserialization functions to convert byte strings into the appropriate CFFI `cdata` types. For example, to handle recoverable signatures, use `coincurve.ecdsa.deserialize_recoverable(signature_bytes)` before passing it to other functions.","cause":"This error occurs when you are attempting to pass a raw Python `bytes` object directly to a `coincurve` function that expects a CFFI `cdata` pointer type, particularly when working with operations like deserializing or converting signatures.","error":"TypeError: initializer for ctype 'secp256k1_ecdsa_recoverable_signature *' must be a cdata pointer, not bytes"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"21.0.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://ofek.dev/coincurve/","github":"https://github.com/ofek/coincurve","docs":null,"changelog":"https://ofek.dev/coincurve/history/","pypi":"https://pypi.org/project/coincurve/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}