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)
Parameters:
message (bytes) - The message to sign.
hasher - The hash function to use, can be None. hasher(message) must return 32 bytes.
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.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.1.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb3c86e902f319c377fc5d9c32e37dc3cc3d6cf5d07478c99fea6e45b58cea76 |
|
MD5 | a682ec933660f8c2baca92aa816e7e61 |
|
BLAKE2b-256 | 2c7d9d1bb7325c34d982abdd673d87cd4736d6dc1bb9e557890398b36d2080d4 |
Hashes for coincurve-5.1.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766cb8af7a372527abb584692b0ebadf945deca2f76416f3553014a4c1afc2c1 |
|
MD5 | 61b896afafe319c7bed0c0fb86615bd3 |
|
BLAKE2b-256 | a44e4b9e913d859a4651b447397320130067ef4275a9657cf5afbdcfd0a800c0 |
Hashes for coincurve-5.1.0-pp358-pypy3_58-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1212d13c9e8827fe9df1694de37d83b83bf3d39a03a08af7c6f2b667f5fcee2b |
|
MD5 | bea9753fc2f988a12e0b8083a48dff7d |
|
BLAKE2b-256 | 486a3e1841975a8156fab622552c8e8023bdc47292705e19113580e7cc87e5d5 |
Hashes for coincurve-5.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5d84c70e2d08aef7590cd814cce10c8e35c43da104329e581fb6473ab66df97 |
|
MD5 | 4023b7035b3ee89ab4cd19cf89cad675 |
|
BLAKE2b-256 | 948d6c9a9ccb0060c51c06de4b18017d2cfebb40e79d4c74bae9b4e8e4579813 |
Hashes for coincurve-5.1.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15a3f97b09812df0eb678e3525c454fdec66261c3cc1d2b1b14e3a3d0a4e0bda |
|
MD5 | e6b7e88cd30cfc66af91d9f441b8158b |
|
BLAKE2b-256 | 82e3adaf8a159b4da0b1423d34482bb905c4bbd745a00c0f7ac0687874508f74 |
Hashes for coincurve-5.1.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0223c5181fe73f92e48f4d10281e6828add6a15e5c24cca205ed611343808967 |
|
MD5 | 6768e1fb80d84ac3d01008db3ea07eaa |
|
BLAKE2b-256 | e722a5dd838b70994fdbc1f75e4ec11248711a53618917970566d17583ac137f |
Hashes for coincurve-5.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35e8231985718fc9189d689c58acf57f5fdd35716ac144e72e863c0151b8a9d6 |
|
MD5 | 915c25bc1432e10e1c42a7cdf6954e4a |
|
BLAKE2b-256 | e858726fc870eba39107dc9a858eb8c912e8867eab540b54cd878e4361268761 |
Hashes for coincurve-5.1.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd67d86a54d63273d5ec5485d9de8b76b242269d382696730b2f708ab5cd1fd7 |
|
MD5 | 1dea0d7160feefa40b56884cf3f3f72e |
|
BLAKE2b-256 | 66649fc50f0e3f18df161035d38fd05640ed3586747910e15eeaff9637d1ec16 |
Hashes for coincurve-5.1.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ef83e5197956594b237d892337c936e57c8b856d2a361ce4d324dc13b615191 |
|
MD5 | bedc486bfb01a833865dc29d2586fe0e |
|
BLAKE2b-256 | 9a8ed9f100c08c6bfaf99f95619d8c2ab663391c8a208b652d30294a43a74410 |
Hashes for coincurve-5.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc0d9690c66d1db97d34f07cb377a4bd55af617bc1cd6999825cc46cc094085e |
|
MD5 | 10f5c842ba1bc1df762f9824d4da15dc |
|
BLAKE2b-256 | 78f5545924c2afbff351287b8428e5b6ffbabd7b9bf014a44b271f5d7dbfafe0 |
Hashes for coincurve-5.1.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a13b3730390949c54502f0c2d0d5ea7735042a44f5474522118866149e658741 |
|
MD5 | ba1593eac497d34c93e0fe280dc359d0 |
|
BLAKE2b-256 | 1b8e8b9f24621de3ed13cf933ea1e34d063b69c92f8936fcbac6d47f171c84a7 |
Hashes for coincurve-5.1.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bb787e83fa2e057bd182f936640797cab8e247f1f27f03f8dfdad725d08f349 |
|
MD5 | da1714c01a1f6bd56b18ff1d126e95a4 |
|
BLAKE2b-256 | 5c35c0fd2ded9992c53bdf63ff79ab79c1de213ce31d4f813a7e8139777d725a |
Hashes for coincurve-5.1.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 096715cca8aa45e96493ab78b46a60dfee76eae750482e43a7164aaf9dc6d1bb |
|
MD5 | 8f10ed5772f799c3a4e17adffb76e07c |
|
BLAKE2b-256 | 3be3f0655074abf833dd0bb176cd4dccfbd7fdf613f831ae96dba133ee79afd9 |
Hashes for coincurve-5.1.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c258a1d54e193b0c9553f79b40742ebb3e9a189d6135193b417005acee36446 |
|
MD5 | 4b35488f4192623cf33be5c9a83d638e |
|
BLAKE2b-256 | e9994254c4bc7a2a3b8386ebacbacbd2081b9604757fe15f8dc7394119f8442c |