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.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18c9528c7674665fc2f9bdf31c0ae1bda22c0b76f96d682869fe71d225400a05 |
|
MD5 | 826b7fef27a364fb6fe0c15e35d037b3 |
|
BLAKE2b-256 | cadf2b3a9af20c8393da871fb633787a0ebd86260a43e71b15d6943947eac743 |
Hashes for coincurve-4.4.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8efbfe26fb548cd3c35a6e6f64e526d01d03b4fd118f29fdf500d70d93d3258 |
|
MD5 | 40596958ee96768fe9c5a2c4a6a77a8f |
|
BLAKE2b-256 | 6ab4d490bb7718b3b322a9abc14eae7d0e6965cd3f580afd3ac14a82890ffb6d |
Hashes for coincurve-4.4.0-pp357-pp357-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 742d860b04a95ca22d821f39d255a38729f87427218a98815a102ec87c00f00c |
|
MD5 | 11823291a524b7e6a08682b1c8b3729e |
|
BLAKE2b-256 | 17ae236a02ec144e06124ddc0c9ec0370b971de626ed9110232ebac3d5283799 |
Hashes for coincurve-4.4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a1a51edb4b95dc70143bb085ab1479bcb86c146f8be811609e83202e2fc07f1 |
|
MD5 | 796772a5bd9aada8baf2182b81418224 |
|
BLAKE2b-256 | ebb540047cd7dfc4d79b0b8a57b7e3990a0066e0dd7dfaf5fd4f9ff5fb587455 |
Hashes for coincurve-4.4.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a376967d5b16af9ade1ae12e77b0dae75996978738c01aba67672cf2df9fd956 |
|
MD5 | 697560e522b3e1d1bba7d28b741cc4b2 |
|
BLAKE2b-256 | 85920e5f8bd303ad7c5378b7cb2ba8d1212476898c36818b5e74fdd1771b8254 |
Hashes for coincurve-4.4.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00c967bf601425ed4b2a4245842516bcea4eeb4bbeb4b733707e4fad23e9dd17 |
|
MD5 | 24941161d567c1b72291549165b103a4 |
|
BLAKE2b-256 | 700c9915a2da1b675ceb3ab1f65911f5edc3283b13f8f43ac18cf794b192eb45 |
Hashes for coincurve-4.4.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f50bed53b54a62eef99935b23065fa7bbda1a45aeb2c4aca8e85ac188b6d0f2 |
|
MD5 | 277e9bbc3f9fb162c1080aba7657c452 |
|
BLAKE2b-256 | 05ad5eb2640220d819a0b67d841f39cb84915a9cfe4854dac9e5c9501c219d14 |
Hashes for coincurve-4.4.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e4c08b006b2a67136a586cbc762963ae48fb5370d7405815bb745336c1ed038 |
|
MD5 | bb5ccfd702910661382535ca8237e635 |
|
BLAKE2b-256 | f64ef213c418cf109b16e0c9dddc3e38238d0f5bfeac6a06a146562b7ce4f840 |
Hashes for coincurve-4.4.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed5b6def7eefd02f9425fddc747f0ae9d873c16590ff76a1b1eaabe9bc996fc3 |
|
MD5 | b92eb37d03f887de1f9b0b0bcd855328 |
|
BLAKE2b-256 | badcb7b07204fc71c0cdc3402b6b6c847370d73283ce7de58f4dd14663d7329b |
Hashes for coincurve-4.4.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68171cbae1937ab5eb2e53a2dde1d329ebb99a431b5221c57cf44b135d8340d2 |
|
MD5 | 3f5ca5416b1b99ae728717bf730f184a |
|
BLAKE2b-256 | 796b73473a65f96acb41e22ff84394e92b5f50e0c061d08a1ff3d3ddb3265e56 |
Hashes for coincurve-4.4.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd506d8cb477c07a58d224f35108dc8de36ffa1b37cadccd5abd5b064d42583a |
|
MD5 | 2495d646a05250865ef5ec76f48d2e8b |
|
BLAKE2b-256 | dd383f772f4e12f3e2a6c30275633f5cdd73524f65dbcac8ea40f42e0059dfe0 |
Hashes for coincurve-4.4.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a1162c0ca1d51e2aaa04d87cc296c1bd0c3e7eb21c9bfa07384c172a98eb9d4 |
|
MD5 | d43f89204f553938970b448ac034419f |
|
BLAKE2b-256 | 8a58dc45b1b6aaa9afe9f27729a71d1d9067671a19b586f24b2a91567b52a139 |
Hashes for coincurve-4.4.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 171b0113d943b368326e0fdd21c874597de5cfcdc8200b7a7e35c8f85903279a |
|
MD5 | bc34cfd75c77c93de168337326cdb9a0 |
|
BLAKE2b-256 | ab3d5f96ee49e576f05d22937dc52232bc1f081e80c1e96638ef288880c2963e |
Hashes for coincurve-4.4.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78ad04476156e3e6ed6b6bb133f683bad98b4c5d93bcdb7bd7c5683f76d76ce3 |
|
MD5 | 829fe20f6d39a2e436b4cacfd68db1e5 |
|
BLAKE2b-256 | d09c2739866df1defff8d0335eaa049c2155f151d12067b9e7e82c3e2a76b217 |