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:
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
To retain backward compatibility with secp256k1-py, use coincurve==2.1.1 specifically! Anything after that has a modified (cleaner :) API and only supports newest versions of Python.
Installation
Coincurve is distributed on PyPI and is available on Linux/macOS and Windows and supports Python 2.7/3.5+ and PyPy2.7-v5.7.1/PyPy3.5-v5.7.1+.
$ pip install coincurve
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)
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 Distributions
Built Distributions
Hashes for coincurve-4.1.3-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a50916573ca617ff085554de85206ff08ee65103b8c020e55517939db7553e |
|
MD5 | efecf33c1d2d43187bab6a3b452a70cc |
|
BLAKE2b-256 | 1210d5cb4739694a3767ec214552548d75aa873946f882d9b6be564447c6b36b |
Hashes for coincurve-4.1.3-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68c96faa4f52e479d9b153edf6c2aee9e4c34e5a00ca63f8044b2d81e33f44dd |
|
MD5 | 7eeb72294065fbf340e255c75ee12eca |
|
BLAKE2b-256 | b5a586c0fb90883106bc74490fbcf4ab36f5254bbca74319a9b1d12140e5f277 |
Hashes for coincurve-4.1.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b685cee9a583c546a81bcbbc681604d4a6ef0ae228265f37d9c0646ac3078302 |
|
MD5 | 63190691582df5aff37c4a7815f099bb |
|
BLAKE2b-256 | 374ff545036c068b042910716b85433bfae819fc1c1f38652541e91946c394bf |
Hashes for coincurve-4.1.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cbe54adcf996b151ab84216a4cc13e3b31c6021bc484d2c526b85606d726f1f |
|
MD5 | f2044984d4e12b34a2bb2bd4d896c2a6 |
|
BLAKE2b-256 | 669cc8143b57fa4ec4256a79aad4873bc0aa0314da3490312a85480672e91767 |
Hashes for coincurve-4.1.3-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c59032f514b684c3711eab753146bf195f4af65889c8f766c527cb3ab0a21fb |
|
MD5 | 544c9e729def60a62936ebb79e19b08d |
|
BLAKE2b-256 | e3369e0124a9ed47bedbd61bd1860e8e267546354a600dbc1b0fdd7ebe04082f |
Hashes for coincurve-4.1.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb86899cfd4d0cf5b3d7027a125d776ac83698e9beee248eb818cbe545537292 |
|
MD5 | 9e18598057a9d6aeebeedbbb5bd44d7b |
|
BLAKE2b-256 | 9ac5f444cda5b0506cfecfbecd3dedde61f052170fa4b94d2141451d3eb209e3 |
Hashes for coincurve-4.1.3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75372f73a57c149dd313383daefe7eacb2ce9809f32de1ea6b9776fc99a53e30 |
|
MD5 | 556a6407f2cf291fc6a1d265d03e8f7a |
|
BLAKE2b-256 | 17f6314b98cdcd648ebb71e83fca2595091fc55e860de111f4360c92c6edf5b0 |
Hashes for coincurve-4.1.3-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bf9fa3caa552af63bf90f8ddee3b474b51c969022df52c58a60045efd73907c |
|
MD5 | 481fe3cde76648cff4ce0daeafa0191d |
|
BLAKE2b-256 | b634896b262b2143f59b3d39793ddf95777af9f9d5f8a0cf7dade4622bc5257e |
Hashes for coincurve-4.1.3-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50884f13251f908df0a053fe6037cc9757c687d43ad9b21294b8db7311b9cc6c |
|
MD5 | 1b57943b668d05c95495f09c2385fecb |
|
BLAKE2b-256 | cdf7c21314e7857c6354df97febdf6b37eadb38b9444dac0e80ed6487057da52 |
Hashes for coincurve-4.1.3-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53d0cb11d77aa603eecb0dd9bef746d5e7cd93753ae48e122f3c6d3f35ee15d8 |
|
MD5 | fcaf34d01fb159f61576355ced1e6e92 |
|
BLAKE2b-256 | 342e533d9bfb2e8359883bb47c483737c0c07dc649ee688df9efae62be57e4c3 |
Hashes for coincurve-4.1.3-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 555035afa51089af4476ee284434d90a71a051c5f7ecb22444b6f838b836499e |
|
MD5 | c9cf5c6e293de3a1424e6f523b5f19e4 |
|
BLAKE2b-256 | 044739d9ee978fac64703cde48b4a37cd87a2cb2047ab246bbcae82578b2f74a |
Hashes for coincurve-4.1.3-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36797d096f3a593fea474e60b9f9d2fb782e0aaec3d9aa217367ab54f6d1e1f1 |
|
MD5 | 995c765c049c8b9fda8728d62f7a5373 |
|
BLAKE2b-256 | f1999f8b8019ca325f8531bc605d3385a5c048298914a70ab293fe3ec1252b5b |
Hashes for coincurve-4.1.3-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0be3d3011c443a28532c995a77575e97f89b7f2e0bb12d50c0f7233e01eb55b8 |
|
MD5 | bc7236c3f2fd418e823b7fcf03ae2459 |
|
BLAKE2b-256 | 4e1f9ac31f90489d53ec8427ed70a1fcb8b2d3bf2fb165debccb5aadcd160d43 |