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
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. 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.
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.
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
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-7.0.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b8f320fdd0cd3be09c97d5ab0d005301fb5d49ba36580af083303e99865cef |
|
MD5 | 8db62632aec98ad11c2204d06dc23c9e |
|
BLAKE2b-256 | 3eb61bb292fcc23eafed53aefb0802b03cedd35ed65cc46ac25687a91ae32fd4 |
Hashes for coincurve-7.0.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7f198c168891d69c59f705ae98686bea2b153179d8ec25655192ddac8311a69 |
|
MD5 | 75c1966ef734214d7fcb4e3d5cbc2063 |
|
BLAKE2b-256 | 85183a8ae449092aa5ef3729ed68b0322e9ef198da7a2d18752f8244aa9d3c36 |
Hashes for coincurve-7.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f8e97bfb859b820b560751cbcdb74ccef818f1e56547e63d564b284f117615c |
|
MD5 | 4e8800af0ef4a7bf3fb24822fc28e117 |
|
BLAKE2b-256 | bbea11fe674eadc8aea3d241c6b2950843db1ee15a0a15284c64cd59ab58abc4 |
Hashes for coincurve-7.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4267063ec7273880a681191fa14adf212d8139005e748b76a838ec7821807a9f |
|
MD5 | 5040d051e5fbdb506ce6cc42734e66fe |
|
BLAKE2b-256 | 67da70bb2019adf8abc80a52ef0cc6a238898c22cae2e593921a8d4f6a3df247 |
Hashes for coincurve-7.0.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 392e7c3da64d949eb7499c3da7ba6fb5ea0cdf018789511c9ae6b5dc68189f70 |
|
MD5 | 513e5f845b1cb9546a0217d3dbc41d20 |
|
BLAKE2b-256 | 61b39c69c6df7095f0ee4e9c83e4d4c2267b00475dbc2178fcc02a5b035e6780 |
Hashes for coincurve-7.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcb8f59d81163c14750ca7483c8cb6f818c60c4627d488c1e590a6d89d0b580b |
|
MD5 | ee7fcf17117b3e43cee09a614ad3ba94 |
|
BLAKE2b-256 | 15f111880d258732c2e964106174789fc98f4e9da754322977c417c90125f82e |
Hashes for coincurve-7.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8143ce87c0f56ef63c4bf97601ff30feda4a3e556b10985b290f2bda989706d |
|
MD5 | 6751562aa1d87fff0bc0117b6f410045 |
|
BLAKE2b-256 | 1f4e828fe80a53ee1f73c8e7f75d307a5f996f54bf484a98f2206539fa96e74f |
Hashes for coincurve-7.0.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 642001f2cc7396a67685a4e5e81638195337578f47c1bc85dcfea67326f8b6b4 |
|
MD5 | a3b962965a2c412cb0c5b2d85cf54e75 |
|
BLAKE2b-256 | a68de10d2cea0c19c0ca95b69cc92163d8170e0027cb7b6572aba6f315b989eb |
Hashes for coincurve-7.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c29f66deecfa65dbb626f8311d9e184aecc32313482c191c0f5c3eda00f0da38 |
|
MD5 | b5aed5c0290d9d5442dcbfed0e328eaa |
|
BLAKE2b-256 | 754e061a5f2d80b04f75b739c635d395c23629a697543b89165a8823aaa254a9 |
Hashes for coincurve-7.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 075e766c378be192a7d9c3350521de1c62020651ad16233bcf4a093a5a6e1507 |
|
MD5 | 1efcfedc1bcdbd6661c48d7f8c824140 |
|
BLAKE2b-256 | 02b412aeb84114b34e8411d9be2a5380cf65310752a5194422e6280e09521c42 |
Hashes for coincurve-7.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19f74466d511ad419cfdbf7ba588cfdd7050a92703c5f5c5cb5bb6af6b78a726 |
|
MD5 | 5cf2e06764883682a6bd3232f846bfb0 |
|
BLAKE2b-256 | dfcbfc1a725e78433375df49fe4a32257a0e9ffbc6aeacd6438acbfadb79dbb6 |
Hashes for coincurve-7.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fc995920964800fef7af27ad778bb574466c437d68a03cf5139d479a1c99d8c |
|
MD5 | d4567d5c8a1888b497d9c79a67a7f747 |
|
BLAKE2b-256 | 9f93e798e8928ca9bafe6ee75980a127ffdb9450497df44535ec7b0c447796ca |
Hashes for coincurve-7.0.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dedb4e601a7fbfb871fb27c88fc681eeb7efcb69ebc8e6bbd256de401ad60ac5 |
|
MD5 | 7b368ac714fccd99fa775d5a1d7d7f38 |
|
BLAKE2b-256 | 3f4974672659a0ebfcadee13e9464cce1e3dcdf6ecc40f635704f7a3101aca64 |