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
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.7.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. 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. 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. 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 - If True, will update and return self.
Returns: coincurve.PrivateKey
multiply(scalar, update=False)
Parameters:
scalar (bytes) - The scalar to multiply.
update - 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)
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. hasher(message) must return 32 bytes.
Returns: bool
add(scalar, update=False)
Parameters:
scalar (bytes) - The scalar to add.
update - If True, will update and return self.
Returns: coincurve.PublicKey
multiply(scalar, update=False)
Parameters:
scalar (bytes) - The scalar to multiply.
update - If True, will update and return self.
Returns: coincurve.PublicKey
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-4.5.1-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 526c75becbbc83c0d55844cc89472211aea18070f676c88d93c837a3c3e6d872 |
|
MD5 | e072890ee074e9bfe1f363cbf2dd354b |
|
BLAKE2b-256 | e613f76e74fdcbee593338d0d95e6a117fe419442d88b9695b9dbe1b507b79eb |
Hashes for coincurve-4.5.1-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 671931a40a76f2ed1f0416fbd21860bfeee0cf2f543f1eabd7fd3fc4d6f2db60 |
|
MD5 | cd92ca12a5f8e13714ffb22f53a7f1e9 |
|
BLAKE2b-256 | 0236c63efbbb02f971a872e74dabd69eb8ee244ace7d845a1858f4d174010d65 |
Hashes for coincurve-4.5.1-pp357-pp357-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5713952f9184e828b1248a74ea73322e5559a3843a58f3ad89173c9c5dbd3880 |
|
MD5 | bed1cc6e0001bd1b6ebbf6d0bf8c4c3e |
|
BLAKE2b-256 | 40eec055099a6dbccce75c9b8698eed7673f6d2f505b2e2914cadda75a864ab7 |
Hashes for coincurve-4.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38bdd9cb93bbb185de131524d5d32fae5c10b86f8d7abacc8edce5875de0aa08 |
|
MD5 | cc77993f148d0273677ababfcdf2207f |
|
BLAKE2b-256 | 413d5fc24d7f2271f0961f98196e4ed140bec96824dd54c612525afdd29c0d02 |
Hashes for coincurve-4.5.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 655370480c3640d9b778847eeddad67d491314ea1ce44dbdfc89be07a912ad79 |
|
MD5 | 9a7b097d0d908818f956a89f562e9481 |
|
BLAKE2b-256 | e972174a28831805d4fa48896d7e4fbd22c6cd18ffbab3dd91e07592b4b9b256 |
Hashes for coincurve-4.5.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ef71d5a2dc60a776f4a85d11e282e302f40d2bcdd20086682f494725d7855ec |
|
MD5 | 23d3d1e3fb08acba87ac954aeeda92fe |
|
BLAKE2b-256 | 3f1761a34c165543ee4619806c1c6caaa707c88f5bf50620dd3066d92c05e368 |
Hashes for coincurve-4.5.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c40614cd6db2716b3cc798843c5d17bf766662933852f3cb006e6db4b495106 |
|
MD5 | 036b0e090046802c33009635017a318e |
|
BLAKE2b-256 | fb4218a57d9009e499379c617d043b630bc92af39416c8f75bdedaa28160adb9 |
Hashes for coincurve-4.5.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1312cd0e436dd21766e27da4ea92811bde0684f6eac70964747b232ceac4d43 |
|
MD5 | 881faedd6db5df510372fe0942dc0c7a |
|
BLAKE2b-256 | c35a920ec45c531bb1f3b188eea03fb09585e1036d77297174872993442f61fb |
Hashes for coincurve-4.5.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddbcf56df4cea97a2afe03bf4ccd8e3d83976e7b6abcd1eafc409bf73eaeb8f6 |
|
MD5 | 02a4435ad0fce84283098447a438e12d |
|
BLAKE2b-256 | 84fa69ff256a707aa4612f7e0590fa7e29f34c32cfefaf93aecfacc34ed3c866 |
Hashes for coincurve-4.5.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b18685fd42c64fd424cdd1ad5c519be0503ae16ddd71ccecd8292d8f633fa99c |
|
MD5 | 3a7ff98fa96775639e17eb25d6a2ab2c |
|
BLAKE2b-256 | 183ae81ae611553dc876c6e229a61a6ff9c8cdb4494bad7e73e78dc1663fd80a |
Hashes for coincurve-4.5.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89ffb10efa31847039f64109f39211644f93c5a73b4bc4f40dbbde28703da646 |
|
MD5 | ce03c0c128963ba968a1ce17f4bd7072 |
|
BLAKE2b-256 | 08e5b79506e7cdcd809aa080af54f7ee582b9f48af9d9674ebfccf8ada69283c |
Hashes for coincurve-4.5.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 642740ed2eaadc245e860891d422c1c42c15e4a326460ca2475b3035a9c886dc |
|
MD5 | e0c2a03d401d1acf12f0ac81639a7cc1 |
|
BLAKE2b-256 | 7d5b7d5b27026e3e9eeea80643c84aa852ba5ff27ab45922bba7f9654fe17a41 |
Hashes for coincurve-4.5.1-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0d40e009d4547b4ed31567637bdcada7222cc4ac2267c3440f26a49513e6dcb |
|
MD5 | 5c4165b8977f7a24fdce39cc13c8d69c |
|
BLAKE2b-256 | 83148e8ba6dbd27c5344446f25f4307bd2174564e91dfc6333bdfcf30f74778b |
Hashes for coincurve-4.5.1-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8832a0e23d409d607c19227887d6daa9f446662c34de39470b527c14850c56af |
|
MD5 | 990bc3a6f1279d2ee9b8fab03b87cdf4 |
|
BLAKE2b-256 | fb66e618c55ac002d9a6a358dc1e9998ab5dd78702b6a1959070e982fc7dfe73 |