Cross-platform Python CFFI bindings for libsecp256k1
Project description
This library provides well-tested Python CFFI bindings for libsecp256k1, the heavily optimized C library used by Bitcoin Core for operations on elliptic curve secp256k1.
Table of Contents
Features
Fastest available implementation (more than 10x faster than OpenSSL)
Clean, easy to use API
Frequent updates from libsecp256k1 master
Linux, macOS, and Windows all have binary packages for both 64 and 32-bit architectures
Linux & macOS use GMP for faster computation
Deterministic signatures via RFC 6979
Non-malleable signatures (lower-S form) by default
Secure, non-malleable ECDH implementation
Implements a fix for https://bugs.python.org/issue28150 to support Python 3.6+ on macOS
Users
and many more
Installation
Coincurve is distributed on PyPI and is available on Linux/macOS and Windows and supports Python 2.7/3.5+ and PyPy3.5-v5.8.1+.
$ pip install coincurve
If you are on a system that doesn’t have a precompiled binary wheel (e.g. FreeBSD) then pip will fetch source to build yourself. You must have the necessary packages.
On Debian/Ubuntu the necessary system packages are:
build-essential
automake
pkg-config
libtool
libffi-dev
python3-dev (or python-dev for Python 2)
libgmp-dev (optional)
On macOS the necessary Homebrew packages are:
automake
pkg-config
libtool
libffi
gmp (optional)
API
Coincurve provides a simple API.
coincurve.verify_signature
verify_signature(signature, message, public_key, hasher=sha256, context=GLOBAL_CONTEXT)
Verifies some message was signed by the owner of a public key.
Parameters:
signature (bytes) - The signature to verify.
message (bytes) - The message that was supposedly signed.
public_key (bytes) - A public key in compressed or uncompressed form.
hasher - The hash function to use, can be None. hasher(message) must return 32 bytes.
context (coincurve.Context)
Returns: bool
coincurve.PrivateKey
All instances have a public_key of type coincurve.PublicKey
PrivateKey(secret=None, context=GLOBAL_CONTEXT)
Parameters:
secret (bytes) - The secret to use.
context (coincurve.Context)
Methods:
classmethod from_hex(hexed, context=GLOBAL_CONTEXT)
classmethod from_int(num, context=GLOBAL_CONTEXT)
classmethod from_pem(pem, context=GLOBAL_CONTEXT)
classmethod from_der(der, context=GLOBAL_CONTEXT)
sign(message, hasher=sha256, custom_nonce=None)
Parameters:
message (bytes) - The message to sign.
hasher - The hash function to use, can be None. hasher(message) must return 32 bytes.
custom_nonce - A tuple of arity 2 in the form of (nonce_fn, nonce_data). Refer to: secp256k1.h
Returns: bytes. 68 <= len(signature) <= 71
sign_recoverable(message, hasher=sha256)
Parameters:
message (bytes) - The message to sign.
hasher - The hash function to use, can be None. hasher(message) must return 32 bytes.
Returns: bytes
ecdh(public_key)
Computes a Diffie-Hellman secret in constant time. Note: This prevents malleability by returning sha256(x) instead of the x coordinate directly. See https://github.com/ofek/coincurve/issues/9.
Parameters:
public_key (bytes) - Another party’s public key in compressed or uncompressed form.
Returns: bytes
add(scalar, update=False)
Parameters:
scalar (bytes) - The scalar to add.
update (bool) - If True, will update and return self.
Returns: coincurve.PrivateKey
multiply(scalar, update=False)
Parameters:
scalar (bytes) - The scalar to multiply.
update (bool) - If True, will update and return self.
Returns: coincurve.PrivateKey
to_hex()
to_int()
to_pem()
to_der()
coincurve.PublicKey
PublicKey(data, context=GLOBAL_CONTEXT)
Parameters:
data (bytes) - The public key in compressed or uncompressed form.
context (coincurve.Context)
Methods:
classmethod from_secret(secret, context=GLOBAL_CONTEXT)
classmethod from_valid_secret(secret, context=GLOBAL_CONTEXT)
classmethod from_point(x, y, context=GLOBAL_CONTEXT)
classmethod from_signature_and_message(serialized_sig, message, hasher=sha256, context=GLOBAL_CONTEXT)
classmethod combine_keys(public_keys, context=GLOBAL_CONTEXT)
Parameters:
public_keys (list) - A list of coincurve.PublicKey to add.
context (coincurve.Context)
Returns: coincurve.PublicKey
format(compressed=True)
Parameters:
compressed (bool)
Returns: The public key serialized to bytes.
point()
Returns: (x, y)
verify(signature, message, hasher=sha256)
Verifies some message was signed by the owner of this public key.
Parameters:
signature (bytes) - The signature to verify.
message (bytes) - The message that was supposedly signed.
hasher - The hash function to use, can be None. hasher(message) must return 32 bytes.
Returns: bool
add(scalar, update=False)
Parameters:
scalar (bytes) - The scalar to add.
update (bool) - If True, will update and return self.
Returns: coincurve.PublicKey
multiply(scalar, update=False)
Parameters:
scalar (bytes) - The scalar to multiply.
update (bool) - If True, will update and return self.
Returns: coincurve.PublicKey
combine(public_keys, update=False)
Parameters:
public_keys (list) - A list of coincurve.PublicKey to add.
update (bool) - If True, will update and return self.
Returns: coincurve.PublicKey
License
Coincurve is distributed under the terms of both
at your option.
Credits
Contributors of libsecp256k1.
Contributors of secp256k1-py. While Coincurve is nearly a complete rewrite, much of the build system provided by ulope remains.
History
Important changes are emphasized.
12.0.0
New: Binary wheels on Linux for PyPy3.6 v7.1.1-beta!
New: Binary wheels on macOS for Python 3.8.0-alpha.3!
New: Binary wheels on Linux are now also built with the new manylinux2010 spec for 64-bit platforms!
Improvements from libsecp256k1 master
11.0.0
Fix some linking scenarios by placing bundled libsecp256k1 dir first in path
Allow override of system libsecp256k1 with environment variable
Add benchmarks
Use Codecov to track coverage
Use black for code formatting
10.0.0
Support tox for testing
Compatibility with latest libsecp256k1 ECDH API
Make libgmp optional when building from source
9.0.0
Fixed wheels for macOS
Breaking: Drop support for 32-bit macOS
8.0.2
No longer package tests
8.0.0
New: Binary wheels for Python 3.7!
Changed: Binary wheels on macOS for Python 3.5 now use Homebrew Python for compilation due to new security requirements
Make build system support new GitHub & PyPI security requirements
Improvements from libsecp256k1 master
View all history
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for coincurve-12.0.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea0b7150053a8c46d0f2096ec75a6f7cdcbd4afd1abafa0caa28f3cdd34e3987 |
|
MD5 | 44c688f5353cc4771d994556335e4230 |
|
BLAKE2b-256 | e364ff2969cf6ad5381eee37ead6620bb9296151c9f520c202d56899552c8826 |
Hashes for coincurve-12.0.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01b1dad52c718c694dec1881bcda28358cd672c2a800c791b293ac60ce378e4d |
|
MD5 | 91d1f3421144ce83c2cbf191d579418f |
|
BLAKE2b-256 | b8975e1e178166e7807df66a143c27f1b76ece337451c6e08ee89ea3fcae3ac4 |
Hashes for coincurve-12.0.0-pp371-pypy3_71-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1300fc144e28cb825deeaa44cb0475455437b9aa7dbcafcf46ed083a10670f8 |
|
MD5 | 781f48682b57e14f8892cfb29a3d342a |
|
BLAKE2b-256 | caa4af34c6084b607ed9041dfabcdb4106aa9148f0250b9f214e7915b14deaaa |
Hashes for coincurve-12.0.0-cp38-cp38m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16697fd18874ca3d7a0b452f022a2604cab08af0b8326dda83da868e85ee6ecc |
|
MD5 | e2e9e4a03efa363702db021c7e794675 |
|
BLAKE2b-256 | e19ede3475c181aedf1cefeef50a758c41fe6d4bc89e78633376869e68137b26 |
Hashes for coincurve-12.0.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c118b85ee107d9be1e34645f94be505882bcf2616bd09ddf4ef2d207f9f5e82f |
|
MD5 | 47d093f8869562b4f74a78c3b23641d2 |
|
BLAKE2b-256 | e3a35eb8b4ac1be7506ad6b9845f3995ce9acf7ca58428e649a2d5685cec4c65 |
Hashes for coincurve-12.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 174d7fe9c886abf77131724d4eb1816ca99c6a876b02ea4382a8fc638c5c5659 |
|
MD5 | dccd2fb0c2d2c2f1778862943055551d |
|
BLAKE2b-256 | bfb785c33c1d0a13b32f4051af61648cb71f8cd4e31c2b4c812e10bac3d51398 |
Hashes for coincurve-12.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e04c83d3d977df6caad688a66b98eb87d3b0d70a4a698c7339abc5bc818aba1 |
|
MD5 | 9466386399bea822770f67c26fe4fd34 |
|
BLAKE2b-256 | 67fe4b15bc01b7b737793265ef413f3443325a1d34193b36a4e4ef74e96f7c00 |
Hashes for coincurve-12.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e851630985a0f0b099d1ed3bdf2c50a68b4aa4c2dc31fa53a1a6a7dbb76ee554 |
|
MD5 | 53aa65e0c19fa0f65be86ceb8d63e9f2 |
|
BLAKE2b-256 | 92ef955357aec25562705d79c174cbf94b092720c1fd9d101f2e6761c6811a05 |
Hashes for coincurve-12.0.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e76172a97e693e96f165435640f7a5e55f1c3005e602b25d10875ee0c3014b57 |
|
MD5 | be4f0d4b1fea7e5cea1ad2494a83f5d4 |
|
BLAKE2b-256 | a5590bfd2cb24566d9109aaadeaf7d2fae615b287e744027c54d76d09ae439d6 |
Hashes for coincurve-12.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42bf66b273220eaf5cc20fe868bc544931c76a09716121b8f93b4ba639b9c1ff |
|
MD5 | 36bfe178a383534427e8de670f0d0154 |
|
BLAKE2b-256 | 5cca966b9aa55b70a4ba10232641d357f97eb2774c8541c43c05442f23bbe307 |
Hashes for coincurve-12.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a4f721937a1bced6381130a34c9b5da2e7041973f2aa5e78bb64889d8663658 |
|
MD5 | 95d75014e187704bd173c92c94bd4aac |
|
BLAKE2b-256 | 10dffa1c7c075ad13a2e9c9b989d5437edbe90bc54a0ded799bf54eb895cddb6 |
Hashes for coincurve-12.0.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e6685a2bd59bbbfe7d21fcca036f045b88ada209b257c5f4edb976379d9ba8a |
|
MD5 | ff898603dfa75498d5a1bf06a685d99f |
|
BLAKE2b-256 | 97be2962d5b1ea2c6dc2aaf728778a4bb7137e826525c66cae51a5d344cbc2d0 |
Hashes for coincurve-12.0.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f63cbc4b7cb0b70845bb1f9f4b714822bd3a1a68db4a90f325f7cce1daed77 |
|
MD5 | 556ddc7b4a490b9a698bb9f1d16b7840 |
|
BLAKE2b-256 | 7510e01b1195ce91eab4671ceca880bd99856f20ddcf30ea6dfd5c5d525b43e4 |
Hashes for coincurve-12.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 750476ff4eddb44902dbbb3b311ecfb62071327e38dbe0c833bee435e4007f57 |
|
MD5 | e0f56b8d1d0c73886e494855173be216 |
|
BLAKE2b-256 | 0ecf0e9d48bdccc76b747e7e9e2b8f14f3387176c9bad66fdb9e24e0211a7227 |
Hashes for coincurve-12.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8e29373eb53214e7f3e9bbc819bc2b700bf1e599f357157737fe12e97938dbe |
|
MD5 | fcb87500bb706c8228079e74b19c7b8a |
|
BLAKE2b-256 | d8a7501560241a6d3add93c39cf309a6693e2c467f6cfa57416053aaf6c025e4 |
Hashes for coincurve-12.0.0-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ddb162249cbf54952b424aa3a0c97549893597c9d4529589bd9a89969151042 |
|
MD5 | b6b4712a34e7f0369824aed27d2101ce |
|
BLAKE2b-256 | e5e5fcf37a984c48d3ea697975afe684b848770680f756a49ca96e814ecabb9a |
Hashes for coincurve-12.0.0-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 023a32800b76fbbc070d79fb028910789a5cb52813bbd809ae134965ceec26fc |
|
MD5 | ee29dc6ab75ba7413d39859396cd8add |
|
BLAKE2b-256 | deb604c1f7b68d0a048e8a6243fff1853264f92b559d2a5ca4019292cee56f68 |
Hashes for coincurve-12.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5885e4d7c05707db460a2cdec3ca08bf7dec185514eb7fa0417ea2c7e686804e |
|
MD5 | 532c7951baf7f9740caac748f2ff71b7 |
|
BLAKE2b-256 | 7d788563a1094b8492b3854cece165b55439d5066b73bed88bc636c8eee035d8 |
Hashes for coincurve-12.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f79d168089756058953593e06f8c3f3aa044d07fe440c142753e58895a0077a2 |
|
MD5 | f4827cf18350706402eb38e6f752e70f |
|
BLAKE2b-256 | 9a94bdd14db9e9a2ec6a352b30ffdec4e34b905f90c508dc7077abdc5bcbb632 |
Hashes for coincurve-12.0.0-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bce55e69056d5c4b645e0dfad57c8d9c46de851b8b2d11c6a539655221d04dba |
|
MD5 | d0762b6345fb222de7286e6e25447d9f |
|
BLAKE2b-256 | 9052c88b57ffc68233463558f681fe60fc8e425f7120f2c57994e18d6214d365 |
Hashes for coincurve-12.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eeaa5dc061c9341fc4802421e036a705edfe6487b71d41b3045f6532cc13c8f |
|
MD5 | 31ad1547174dd1ff73887943f5fb0885 |
|
BLAKE2b-256 | 97282009f24bb7558c0b25a57f14e4400206e15bbc95b17f5cf56506df6c701a |
Hashes for coincurve-12.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d5cf56de0adebcf7f2395b279868b19fee17a98b7de2c8c38f4b15b3b0805b5 |
|
MD5 | 5c50dcab9c467dd88705afbf7f002479 |
|
BLAKE2b-256 | 9b7b7d49ce403c3c087bf3735d01594325dbec7a09a058accd27c77e4cfbe351 |
Hashes for coincurve-12.0.0-cp27-cp27m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e01c7b9c705ea377ac18c7ec6a1cebd545204e844209c985e23059bf5de58ca9 |
|
MD5 | 6d33cfccb672aa12f8f0560593554e74 |
|
BLAKE2b-256 | ea1a20a8a9da170e37014e255f155f5cbdb0c2c540440534063f01132fbb0be9 |