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 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)
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 Distributions
Built Distributions
Hashes for coincurve-4.2.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90e4d7c01f84155621a22673725515de3f4724ebf46a7fcfa6cc2c7da793da39 |
|
MD5 | d552ed2fd60da62d45ef95cc640bfa1e |
|
BLAKE2b-256 | 34b321214636411070ec6648162b5d2b551d588716bd818af6c84e1b023521d0 |
Hashes for coincurve-4.2.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51fa73efcea74abaabd06e9da2022ae667651a5b4db3b54362cfce7c52325a57 |
|
MD5 | 5621a8f896b2b8161532839b0f5354f5 |
|
BLAKE2b-256 | 43533490469d788ac30a575480ebf8218372c98e2b87142e4b84ea78faf17a0f |
Hashes for coincurve-4.2.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f178ee5d983da6395f05ceb7fc5a4d7eae10b53119a9b50d19b441d43378a6eb |
|
MD5 | cb45a97664fedb15c2a6bc598d9b302c |
|
BLAKE2b-256 | d2cd7eb52b3f4086a3fb56b95a2d1f3843a8ebc2f57c47f5a01eef7bcd2dab66 |
Hashes for coincurve-4.2.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36c8a41c09061de3db33205c36cc7892a90a6b247b2d688e92b5770a444d78c4 |
|
MD5 | 8799b6dcaa1e4774e86348f3f0d7917a |
|
BLAKE2b-256 | ce57cc7107b3c76c82a03b88cf3c348297337a29c84bb3e3f75ed30700ffb80a |
Hashes for coincurve-4.2.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7fda9ff2dce8aafdea27e6b802c3cad4fde6879afd1dbb3a2fd42879973e433 |
|
MD5 | d120440632d6900e25bed0730c079b28 |
|
BLAKE2b-256 | 59698380535023ebc8a0e6ed00036ce1f16e94316a483b21ca3f03120b87f66a |
Hashes for coincurve-4.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 234cf8f1b7c29cb82d0c092034fc3d0b2081b35dc2e5762f2a6ad89ddd3cf9f0 |
|
MD5 | cf9f510822517b349183d181ac9cb613 |
|
BLAKE2b-256 | 56cf83b037c422b201adb18ee26cf10e7f5d4596b0a16b5efff2229e4a571772 |
Hashes for coincurve-4.2.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c98304f02bfc0694267ba8b7dd820ab794544c193372ddd9617e1cc09fa0bcae |
|
MD5 | cdb02a274e696b25d5eb2edf8c830f09 |
|
BLAKE2b-256 | e789ab87ffd86b9a266e58e6e502cfa41f2f97d432b53af079929a9838fc60e8 |
Hashes for coincurve-4.2.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37cb663476210c3959e05b5c2e294cd82f39c0f2b28015af3afa65ad5c635c56 |
|
MD5 | afd3ed14d19f9e3427f5923e47c5753d |
|
BLAKE2b-256 | 7c54da0e95370e32bbffbc866e2a13ee731dbda77b8d35f1051d702454a153ff |
Hashes for coincurve-4.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5554554cd1409cf05e89d12e90cdc0f4688b0d2874224ebd98c2bc4afc979921 |
|
MD5 | 15dfa83cf79100a98c96a509930226c9 |
|
BLAKE2b-256 | 5759790cc54e91b1225e1aafd0e18da9b7733105b935cfdd87f28ae203941da9 |
Hashes for coincurve-4.2.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2257981b177fe8e27729aa4285de6687a7a36988bec26ef5891d91181fb17776 |
|
MD5 | c236ea90594c7779f9b2d848b67a11c7 |
|
BLAKE2b-256 | f24c6f2d1c781e3f1bb5239a28d5703c6099e2d98f30114b6e9a328edb3bed85 |
Hashes for coincurve-4.2.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f453749a20afdb4ade34ccc899c131f069cd7a591d430f15f7a5e7db989c9907 |
|
MD5 | e9d44351efbfc1106d79793dd594658d |
|
BLAKE2b-256 | 8b5b28e68fefb2a49b4ed713a1527213c82302b2580b64605ce2935de81dce43 |
Hashes for coincurve-4.2.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5339beae436d454371dcbbf704d3395f7173ad91694becf0f586f0d1656c404e |
|
MD5 | 66d3d3746b6d3605a10aa90bbde91b69 |
|
BLAKE2b-256 | 021b55af6af60a1733a280954070cb23abf2b61024c17d158171cc942916ca7d |
Hashes for coincurve-4.2.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77842f427028334695686d89c11d54cd787fa6ea49fec844bce384fcf6aba975 |
|
MD5 | 7a2e39388eba1c8f851ba8a6e0b873ee |
|
BLAKE2b-256 | 245993f3c91097b28e70966d82bd21119a9c0c6af9ddd4f67221c330897a0e0a |