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 PyPy3.5-v5.7.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. 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 Distribution
Built Distributions
Hashes for coincurve-4.4.1-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ce48ac9d9bf71d425a6c3a18040ee91949f172ba0aeef60cbcd03399dd28730 |
|
MD5 | bad23f348f35d14e74d5971d044eb6e7 |
|
BLAKE2b-256 | 460b2b459fe591b9d7af50a41ba92538231b9183df21e4148996194e132284b9 |
Hashes for coincurve-4.4.1-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c5d7c4ed87a2496c060c03ecff822253c4413997667e659116bbdbdf8620f34 |
|
MD5 | 42300462a927b6373e47acf19945dd2f |
|
BLAKE2b-256 | e117bdac5dd2e8f124f957a7f665eb5b8ad68a48c679ec97ed69e5744d700750 |
Hashes for coincurve-4.4.1-pp357-pp357-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d56c0740072dae3de4dc900e93d9afdec68e3e87a2bd02b185bf00da96e6d1cb |
|
MD5 | 771f1445475ec6222849b6fc5d6d8550 |
|
BLAKE2b-256 | 719b9e6812a10660838cedf4f3d0ba4d4429d0c6ceb31c9826c43b1e303df882 |
Hashes for coincurve-4.4.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d225f0d73f05e1aa0319d98c8c68e1c4e94e44837a8322e490e5785017c35c90 |
|
MD5 | f2c9529c94b5ec6ec49a07e65f78ada5 |
|
BLAKE2b-256 | 1e3354ba749e06f161ff6b2f7651f74b96010ac335e10efde6453f8b9f6053fa |
Hashes for coincurve-4.4.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a9dc747816d0c98dea6bf10567e1e5a827b734c7c5615f96b031c48168308b9 |
|
MD5 | da4c8fc3e9d2e457cf812ce4e8dbe9db |
|
BLAKE2b-256 | 492221256505403390bf36271e5072a3dd9a7109adedf6a7eb7c1ce38a0966fa |
Hashes for coincurve-4.4.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53ad178059de8461cc404a2e0a4ad237235f55ce39507ed7d8ebd3046cb4aa27 |
|
MD5 | 222cf4e9dc637a5f6c140dea18d262c0 |
|
BLAKE2b-256 | 33b9511032feb2eef1357b79495abbca911f4a82f0b4e7c550841b95e5f87865 |
Hashes for coincurve-4.4.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20710c5d7132087b8e61895492f1e479f2f3ff88f14c60a58d1424f3df651e1e |
|
MD5 | 25f22df3ae5c3eac6fa85a7c10ec0068 |
|
BLAKE2b-256 | d7fa57ca9e6d9f579688af1c9b7d1409e8f9f2330dfda3db478b5a53ed4f4ee9 |
Hashes for coincurve-4.4.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34f9758d865ba6ed36eb1bc28ffb7a0327dc0c7b71dd93d8114b2d555c0bb344 |
|
MD5 | 763fcff6a48cbca5f457e26becaf871c |
|
BLAKE2b-256 | 82eb20447f2ae102ba18feade48049f7a88090837324970066fe6027995adc21 |
Hashes for coincurve-4.4.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9176f86a6767adb1c55961a04beff8559683dba81fbfb626ec8fd16f327aefbd |
|
MD5 | 6708d252cd96139438a0ad2d530e8709 |
|
BLAKE2b-256 | cfe737a3f9bc3c9c4751ce62b978e440153c4ef52c19e3f41ada3c885b393789 |
Hashes for coincurve-4.4.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d552ac01789ec54465d8a38ec36dc400175ea4c8aabe79d4b0dd7421f61594af |
|
MD5 | 2776fb7ecf9987f2a2f3c8d8700b7111 |
|
BLAKE2b-256 | f3e8bb19505c7a43dde5dc797f5baba2224dc1031ef563904865bfbf709d1c89 |
Hashes for coincurve-4.4.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6243ddf9c7dc00f6392aca2f40d9d64bb7a9ba2fa8f617a5eb4245f3e4bd6bbf |
|
MD5 | 1b21dfd58196ca5a6b8bb99a40c4df7f |
|
BLAKE2b-256 | a594ed3c63036f26bb87c72ac2447ae5dccbab83d9a3b89f63a401aee4a3b179 |
Hashes for coincurve-4.4.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ec70677b24dfdae70877251d3086135c0947ee9c0e3c7e3d3cd0636b4b0f758 |
|
MD5 | 815a33a68b76df2ff7be11e6e31dc601 |
|
BLAKE2b-256 | d99d2d90add9f9bb1b0db8654ef32819e3abd53344264db8c796863254805081 |
Hashes for coincurve-4.4.1-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29c163b6f8a502793f38313dec9b0702ab5f6ed2c1ad19b39e01f2b3fcd7d08f |
|
MD5 | cb0a26e551249bb3a226fd97e4fa0f19 |
|
BLAKE2b-256 | 9557e305c14ded6e852c33197e8740fa7472d9ad011a5c3d07f8b51a7a4db966 |
Hashes for coincurve-4.4.1-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a28ad7266df0b60124afab7d614e8b0eb3d521489de0cb3e53f97cb1a1db729 |
|
MD5 | bb5ccd45ebbcc1e79099f074beef2707 |
|
BLAKE2b-256 | 58039cb40f8b12d43ce4df3ff25b78d17c9caeee684822b431f628c8daf9aa82 |