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.
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-6.0.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92362edf8b97dedf0328adc1a2f7e0d61b0248215963ad195f2b3458ad54d121 |
|
MD5 | 6636e8d85bc3f128639326788bd4b39d |
|
BLAKE2b-256 | 8461ad9d028dd98ab1403584ca67e3339c1ecb070204f0d1c28a0ec320b90402 |
Hashes for coincurve-6.0.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b247023650d24906c6b3e444cd1fbb0fbbfd3622de6f20a857fc9107564a730d |
|
MD5 | fbd7c4b5ca081ad5d6a1b00c641c1432 |
|
BLAKE2b-256 | 01173b20b4329dae5eb6901904d021a97e026b7183ef743468d9a084af216583 |
Hashes for coincurve-6.0.0-pp358-pypy3_58-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5452ffd4a74a59bd4eb43ee28a2b18aa63c34b427f3802d15595809351cbd644 |
|
MD5 | 652f55bd92041be744766686d767e0bb |
|
BLAKE2b-256 | ad4e48bdfbd409b0e3319c5bd10ee948156d83b7665335f283f881472c674543 |
Hashes for coincurve-6.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffc78fb60bc74ffdd5a425e56c8839f7c869f4d7ab505594c4757d49ea5a0fff |
|
MD5 | 03e2b41b8dff3f96b64de659a77cfaa1 |
|
BLAKE2b-256 | 51750e891ae81704326684f0b05407aa894ccd6cb1851baae31d21ce7ea34236 |
Hashes for coincurve-6.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc0d86d3003abfef55ea79c5654c26ae841f1261be94d10f216c9c3c11ea767 |
|
MD5 | 80951ca214fa361bb5775ba0297b5914 |
|
BLAKE2b-256 | 8c7b5d41b290a7556a724437c0c4727337d72d1500cdadf18050bd593d22b1f1 |
Hashes for coincurve-6.0.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf443c2f2db980c37a747d2347298a49de8228ae736c0b049c5390f6503b71d8 |
|
MD5 | fd5f610264eb3d1370fca95fc8ed0fc3 |
|
BLAKE2b-256 | 1b5b818b12223b81cdcfac4a4300f5e8cba7ec690641bf6c904d274bb40b3cbc |
Hashes for coincurve-6.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca62108ae0544c74aa2263ad92462fbe231ba5c524bb8ae1505b8d9e7039b7e3 |
|
MD5 | 972edd6cadb008908d2f36b0813a909c |
|
BLAKE2b-256 | 08258ea675b79578a90847558ea97a28725f0b07503acb56b91a3d91c3d003cd |
Hashes for coincurve-6.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54250b15650d749f0b9abcfe289eb5655f601f226fccbe8ecbdcadfc9235ab11 |
|
MD5 | 4a25cc56b077fb65bd92e281a94ec0ed |
|
BLAKE2b-256 | 6e7b123b80b188def3869a15dc058913d4cc5e6ac82d9b3a07ac2b9c04de3c29 |
Hashes for coincurve-6.0.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d076abba642f95173730f4bc011dd514b3a727858db52666bb4625d7acbd9373 |
|
MD5 | 97f900914a9f96fb31f9fd00b375caba |
|
BLAKE2b-256 | bf0345fc216b065a11c142b96a857c40c39265b3c8a7d736d45d7fed5fc5edb6 |
Hashes for coincurve-6.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f378583a8f15fcb343c6dc7f5520bb02e80bfdb9360a8f21ea035ec37e7114d |
|
MD5 | e208493c8fa74184780d532e8e8afc21 |
|
BLAKE2b-256 | b36506fad5f4405508193e35c1e922e8464307a36749f7cc6a8e70f27b1cc12a |
Hashes for coincurve-6.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdbbfc20a5bf53c9433499481a3da7083ebcda7de0b5af88fb0021faad8dd0e9 |
|
MD5 | c4a65ec261169d3ccecf5b4728020b5a |
|
BLAKE2b-256 | b9ce606721f7725cd1207962ca956dd3b2835feeefe6035dae7d0a860b006c2a |
Hashes for coincurve-6.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d722f95e5fb9554ebc7c3db7f67f2fbd00d5e9af29c4ccf4b0923881d0069a3 |
|
MD5 | a0c38fecdfca83be50e50fb595d01052 |
|
BLAKE2b-256 | 61366eb25df70dd7cc39a1c030d447fdc3df86c6d75b11dc23a90d7af040822d |
Hashes for coincurve-6.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1492f954120b0612805d5e2d9f6ec6f2b1ede0ea575f4a8e17c14892cb3f3014 |
|
MD5 | a911f83bd2edfbaffd09802f2995dcac |
|
BLAKE2b-256 | c7c934555347ae424ad684599123fb1a00e4909632292a47507e7c1c7ebebb0f |
Hashes for coincurve-6.0.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cc3b5e70fced891a8851ffa00ab8ad9319297509195b1f07eae17bc7cd276a1 |
|
MD5 | a52dc0015997a338dd5dfca9dd5e1892 |
|
BLAKE2b-256 | 960251f5acdf0c711323d41dc40267ab060663a5b9e524fe703fd76775411594 |