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.
Coincurve replaces secp256k1-py.
New features include:
Cleaner API
Uses newest version of libsecp256k1
Support for Windows
Linux, macOS, and Windows all have binary packages for both 64 and 32-bit architectures
Linux & macOS use GMP for faster computation
Endomorphism optimization is enabled
A global context is used by default, drastically increasing performance
Fixed ECDH
A fix to remove CFFI warnings
Implements a fix for https://bugs.python.org/issue28150 to support Python 3.6+ on macOS
Table of Contents
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 for example the necessary packages are:
build-essential
automake
pkg-config
libtool
libffi-dev
libgmp-dev
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. 71 <= len(signature) <= 72
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.
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.
Changelog
Important changes are emphasized.
5.2.0
Added support for supplying a custom nonce to PrivateKey.sign.
5.1.0
Added PublicKey.combine_keys class method.
Improvements to documentation.
5.0.1
Fixed an issue where validate_secret would occasionally erroneously error on user-provided secrets (secrets not generated by Coincurve itself) if there were not exactly 256 bits of entropy. See #5
5.0.0
4.5.1
First public stable release
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-5.2.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea91d00a02b77af9583125ce99595c3c5300582b627b02b4de785c1388432720 |
|
MD5 | b5b141acc952e693e21833a7cef927cc |
|
BLAKE2b-256 | 064f3803ccc3f84310172f755abcbbe7cd3ddb07478b863c213112321594bdd6 |
Hashes for coincurve-5.2.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d549ee735f606d21908a8bd406852c0ebe63b9ef289654e9053d985477b221bd |
|
MD5 | ce9ce18a33a37b68e78c6561cf457f24 |
|
BLAKE2b-256 | ed494b338ecf452eddebed48b526133290542289e862d6e88d17554b037bf4cc |
Hashes for coincurve-5.2.0-pp358-pypy3_58-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fff730a4ecce9e87961101a902060d143d2cc5abcd489af43013cd61c3c93d0 |
|
MD5 | 8a92310aeadc7660424abfafd1d68edd |
|
BLAKE2b-256 | 138ff03a0b5f7fbf47802a7bec36ecb4faed88739dfa1d7378e166753c0a5028 |
Hashes for coincurve-5.2.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 693ba7d4d02597d5c56e3c8dab42876e723a1d172aa43e8820a0117bb3164c5d |
|
MD5 | 37d524acdc36b602fde9416e512b85ff |
|
BLAKE2b-256 | f7bfb96918bfa63eb2982cab27494200bf17a986f5e081f3b4fa1eb06f3cc509 |
Hashes for coincurve-5.2.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 890ad8a83ce716a5ebf0867a43fe9c7ef9b44f1b71308a6d302ae568b9d24dda |
|
MD5 | 37ec0026076d19195843028725b5142e |
|
BLAKE2b-256 | 799b61e2406b094f48a6989f0dbd1d062117e19b10d941a96d9a8b3c066b5c4a |
Hashes for coincurve-5.2.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ea527dc6c5a286fa32ab49f47500e3aee5b0701bf41974a604e5fb307e56243 |
|
MD5 | 1a3b8a955e9cbb912c178a4912f89cb6 |
|
BLAKE2b-256 | 42aa70afb32031e11f27915031a7516570ffbb7e19f0d97933e266e5317a67de |
Hashes for coincurve-5.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fb027712427c201f904f279ef8a33b7af52ac1238f619d1c27c2b98741f2eba |
|
MD5 | 7705e6e75a50f381d5ca4544a9e3d09e |
|
BLAKE2b-256 | 986a6ff02895f01a4a97a0cc8959d69ff5e7b8fb1c75e582f59afe23523b47bf |
Hashes for coincurve-5.2.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e7af7efa7d6b8dbd506e1fca5bff68649fac000c5ad466441eff138ec97d3c |
|
MD5 | 35182fd8123a5ebbe3961109dfc045f9 |
|
BLAKE2b-256 | 2bbd19695136554194847cbc48e0cf1139a8f5dc40cecc42a05c77799fc7da2d |
Hashes for coincurve-5.2.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e65c65d3b9e9b10645ee1fbc7b5e49c6c446c890d3720d9e2f407750836a145c |
|
MD5 | bc13992ed00a6ebd1d601cd5b13b1420 |
|
BLAKE2b-256 | 15db2eede3e30fca2fcd89cc92f036a7aec63ac51bbbd752431303f879d03bf7 |
Hashes for coincurve-5.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4a41bdbbff1b281ef2c6dd598e8a5c859ae6dfabb268286d684a573485024db |
|
MD5 | 044c604aa63735e97ddd02ddebbd3bb7 |
|
BLAKE2b-256 | e5e277356d418b397e8ec468ebc3529b6005391e54281e9aabac767b8b22e8c9 |
Hashes for coincurve-5.2.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac1495f2d3ec5ee16d6a658a3f99b648b482b67369cb36ca03a298cefd9f8c1b |
|
MD5 | 92769f3eea92768f63b02ed98f225de4 |
|
BLAKE2b-256 | e9d562c2c532bf32a2d35d5572611e34db075176e844f478df685ac00561e91a |
Hashes for coincurve-5.2.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbb5b1b6da217d60ff3fa43c6cbdf76834eac9c8f68c4eafac15748815da889b |
|
MD5 | f5f718c6fa035145baa5800ec091c54c |
|
BLAKE2b-256 | f4513b040a6cc515d52fb607e62d2278f2de935f007946fbe87d26bab2eb3c24 |
Hashes for coincurve-5.2.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7ec2e4b21aeeed2a3a62d043f0f1e7ccb70426572b9901fe8d27374aa9ed4fc |
|
MD5 | 21c3222ae2035be17c552aa663f72505 |
|
BLAKE2b-256 | 3fba163fd7b0b3fc94b35a24b30943c979970af6e1576454ab2c8b4b68f599cc |
Hashes for coincurve-5.2.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ae3b66144d5f27e061bc7c5931e834b72ab7d63be01134df91def497d2bfff7 |
|
MD5 | 2f91247b27b44e9a828f28d0f6337571 |
|
BLAKE2b-256 | dda2368f66779ffe9625608e65591fbcbe6a0b7334f3cd6e7a4e3573cf156449 |