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
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. 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.
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
7.1.0
Pin version of libsecp256k1
Improve docs
7.0.0
Improvements from libsecp256k1 master
Fix build script
6.0.0
Resolved #6. You can choose to use this or remain on 5.2.0. This will only be a temporary change. See https://github.com/ofek/coincurve/commit/3e93480b3e38c6b9beb0bc2de83bc3630fc74c46
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-8.0.2-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 356844cfd400c4ce772d6ecab4bcda81d0e34f14cecd540410089006ac9557b8 |
|
MD5 | 3685b1c6604d5061c11eeda6ced5cf3d |
|
BLAKE2b-256 | 9f33970851ea35e08b4391b5693079ec0e928f345688a77631c0ce83e2bff36c |
Hashes for coincurve-8.0.2-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63fc5a5ef41883b1747dae4a38e8b79b4f7238f89b3f64d0fba001d979a53d14 |
|
MD5 | 325644e7c963f6494ae15d66b993f5e5 |
|
BLAKE2b-256 | d3597a1bd37f2ba14e18d7992682514e0d2feb736df8cd157190445828ecdbc1 |
Hashes for coincurve-8.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23239fef98fff158f2e0b53be5cf75f9b3d320062bc1cfdc3b45f95c7da8595c |
|
MD5 | 2ebde9672dc8e67fd3c1faabc924bfbf |
|
BLAKE2b-256 | 2a1836cc625b023b55a3f78cd7b8c40292851c09b709a4e738edb702d6280438 |
Hashes for coincurve-8.0.2-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aae207488afb82a1a3b76a0ecc53678b44e5a381c3e9f335dd6bbe5d180632d |
|
MD5 | cf0b2a5a82524845875d4da40b387314 |
|
BLAKE2b-256 | 020ce71c1bac86fd85cd8abef45af512bf93c43e665e6dead0acb764649905d1 |
Hashes for coincurve-8.0.2-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c3320bfc4d73a3ee3d4ffd4739d90995da1a26a3ac2ef8bf7c4f0a936e6ea57 |
|
MD5 | 43f75fd287fc448b161f1cb6cb59a833 |
|
BLAKE2b-256 | 376e0197d62eb3a3c209ae91654c58dd7ba788cc14e0634276bd4a76a329d81e |
Hashes for coincurve-8.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8da73a884d566d12016c4bfe24bd9c40439f81b8aef4c9c624c57a9a0fd0267f |
|
MD5 | dbba79c0a4544b96d8c501d6e0a88d6b |
|
BLAKE2b-256 | 920f9c7dd6a51fd366f2b0529ff82649cf6a2d3ae5a9681b19a894c59d8a2296 |
Hashes for coincurve-8.0.2-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4df71fe8ebb3a2d7ecb5b3fcd6a7f2202ee36adbadee9502b4c222b9ef48c492 |
|
MD5 | 478c626b36cefb05ebc67b13adabf094 |
|
BLAKE2b-256 | ce48eb7e4c505e36bc6443db5f7c9f789f2eb1a2af47e403fe108b1a4a8a4475 |
Hashes for coincurve-8.0.2-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aea80bbabc2b5bf705246a7f616293b7f0939251468fa4cf84fba9ebb45f32e9 |
|
MD5 | 67e5fc076b9b7b22f217782897bd62a1 |
|
BLAKE2b-256 | 70fb2466e1bcc9c30045629c9bd98908439c036fc6c7409476123b9c92c4f9c1 |
Hashes for coincurve-8.0.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27df00e25e31ca52d42a51af878aeb48b0af18dc5cbd35ebde31d330f6bf6f33 |
|
MD5 | 567956273fd011083c57d9e17ee46efc |
|
BLAKE2b-256 | 674ae62a5240562561420945ba7fe9f8bad023a6ef402a3f1f1084480cd2a05d |
Hashes for coincurve-8.0.2-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01af511c2eda407599a1c28ff0e8ef07be0f7b9ce1fa1eba43d7865f91d304b9 |
|
MD5 | acc26d582d58047b3f9c8360ae7dedf5 |
|
BLAKE2b-256 | 807d4d8a7eb297e9a7ee3f0bc8f4c62d8396c0c4266a02035fedc2ebd93cd173 |
Hashes for coincurve-8.0.2-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09bddfe22590a75648f10b6db8a4beccb064f8ec935b9a59ccc65018699d7a7b |
|
MD5 | acd47ea84837dad2d1b630e56775c782 |
|
BLAKE2b-256 | a058cd9577e703e0325047426f6f4a513c59937b9a87d9143803200e09ef1ccf |
Hashes for coincurve-8.0.2-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1aa846eee501c1608f7a68ab892c66e659cfcad24dfcfe8e5d4721d4bfdc302 |
|
MD5 | 6373ae60e3f3de3f43a3142a2e88d021 |
|
BLAKE2b-256 | 6f3f71fe98984f2fdc7ee52d33551929b4a52653a38a681a980685e85513bfe7 |
Hashes for coincurve-8.0.2-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df5c964ee2024545a8e119f196529cc2458de39a7685cd11de2d577138fcb84d |
|
MD5 | 6c983d4ab3309e7906ecee4064be0d9d |
|
BLAKE2b-256 | c19b4ab7685b6bb9058a17c360c0fb916df72f91e14586ad86995c7922e65cd8 |
Hashes for coincurve-8.0.2-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb7165d2cf063f89dd8418cc7f42b93f4d93e736b5bb8140c4752fb9817c8853 |
|
MD5 | 4d3cc790580685b4fce7b2df932e06de |
|
BLAKE2b-256 | 840fe339e959fe3e7d6c0ac6ad46580042b6d9e2f88b2eae29d6105fb64a5d73 |
Hashes for coincurve-8.0.2-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 860dda3aeaf5454457283dafcc695944078316208775af8f302a1971cc84b184 |
|
MD5 | db840b03e1462f67335cb25b52eef801 |
|
BLAKE2b-256 | 53b92e81a9c8d610ab438cb7a2d69a5fa50a049be5dc2c9850a9ccef9bc20d34 |
Hashes for coincurve-8.0.2-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 578918b56ed8990c3dc6fd447ddbdc4708f597e4e00e17ba3cfc25932bd846c0 |
|
MD5 | b32bbb60ab9fec02dc6496b5e049c9be |
|
BLAKE2b-256 | 7d30ad8fd30a16c23278fffd3d396681b94bf0069904d2ffaaa48784573e49bf |