Skip to main content

Cross-platform Python CFFI bindings for libsecp256k1

Project description

https://img.shields.io/pypi/v/coincurve.svg?style=flat-square https://img.shields.io/travis/ofek/coincurve/master.svg?style=flat-square https://img.shields.io/pypi/pyversions/coincurve.svg?style=flat-square https://img.shields.io/pypi/l/coincurve.svg?style=flat-square

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.

Table of Contents

Features

  • Fastest available implementation (more than 10x faster than OpenSSL)

  • Clean, easy to use API

  • Frequent updates from libsecp256k1 master

  • Linux, macOS, and Windows all have binary packages for both 64 and 32-bit architectures

  • Linux & macOS use GMP for faster computation

  • Deterministic signatures via RFC 6979

  • Non-malleable signatures (lower-S form) by default

  • Secure, non-malleable ECDH implementation

  • Implements a fix for https://bugs.python.org/issue28150 to support Python 3.6+ on macOS

Users

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. 68 <= len(signature) <= 71

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. Note: This prevents malleability by returning sha256(x) instead of the x coordinate directly. See https://github.com/ofek/coincurve/issues/9.

  • 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.

History

Important changes are emphasized.

8.0.0

  • New: Binary wheels for Python 3.7!

  • Changed: Binary wheels on macOS for Python 3.5 now use Homebrew Python for compilation due to new security requirements

  • Make build system support new GitHub & PyPI security requirements

  • Improvements from libsecp256k1 master

7.1.0

  • Pin version of libsecp256k1

  • Improve docs

7.0.0

  • Improvements from libsecp256k1 master

  • Fix build script

6.0.0

View all history

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coincurve-8.0.0.tar.gz (914.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

coincurve-8.0.0-py2.py3-none-win_amd64.whl (265.4 kB view details)

Uploaded Python 2Python 3Windows x86-64

coincurve-8.0.0-py2.py3-none-win32.whl (278.0 kB view details)

Uploaded Python 2Python 3Windows x86

coincurve-8.0.0-cp37-cp37m-manylinux1_x86_64.whl (525.5 kB view details)

Uploaded CPython 3.7m

coincurve-8.0.0-cp37-cp37m-manylinux1_i686.whl (530.8 kB view details)

Uploaded CPython 3.7m

coincurve-8.0.0-cp37-cp37m-macosx_10_6_intel.whl (153.2 kB view details)

Uploaded CPython 3.7mmacOS 10.6+ Intel (x86-64, i386)

coincurve-8.0.0-cp36-cp36m-manylinux1_x86_64.whl (525.5 kB view details)

Uploaded CPython 3.6m

coincurve-8.0.0-cp36-cp36m-manylinux1_i686.whl (530.8 kB view details)

Uploaded CPython 3.6m

coincurve-8.0.0-cp36-cp36m-macosx_10_6_intel.whl (153.2 kB view details)

Uploaded CPython 3.6mmacOS 10.6+ Intel (x86-64, i386)

coincurve-8.0.0-cp35-cp35m-manylinux1_x86_64.whl (525.5 kB view details)

Uploaded CPython 3.5m

coincurve-8.0.0-cp35-cp35m-manylinux1_i686.whl (530.8 kB view details)

Uploaded CPython 3.5m

coincurve-8.0.0-cp35-cp35m-macosx_10_12_x86_64.whl (142.8 kB view details)

Uploaded CPython 3.5mmacOS 10.12+ x86-64

coincurve-8.0.0-cp27-cp27mu-manylinux1_x86_64.whl (529.1 kB view details)

Uploaded CPython 2.7mu

coincurve-8.0.0-cp27-cp27mu-manylinux1_i686.whl (533.9 kB view details)

Uploaded CPython 2.7mu

coincurve-8.0.0-cp27-cp27m-manylinux1_x86_64.whl (529.1 kB view details)

Uploaded CPython 2.7m

coincurve-8.0.0-cp27-cp27m-manylinux1_i686.whl (533.9 kB view details)

Uploaded CPython 2.7m

coincurve-8.0.0-cp27-cp27m-macosx_10_6_intel.whl (153.0 kB view details)

Uploaded CPython 2.7mmacOS 10.6+ Intel (x86-64, i386)

File details

Details for the file coincurve-8.0.0.tar.gz.

File metadata

  • Download URL: coincurve-8.0.0.tar.gz
  • Upload date:
  • Size: 914.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for coincurve-8.0.0.tar.gz
Algorithm Hash digest
SHA256 05f2d8760c8d902a369fb57d28a71ec6f5ef29661abbb9504eebae9c28e92ed5
MD5 80b0b52a160a30be05a09da582cf46c4
BLAKE2b-256 9f424edb5e3abceade4ba8aa1df0f0aec2700a2187282ea6530fd0c7aae23140

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-py2.py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 d5072b0a138194e997125c343e0147c7939b5754ab885ac7b0409d3d13d308af
MD5 71af552799861b7fc85bb678bd1e9d22
BLAKE2b-256 0029e65dc852a266229934fef4db726156b22bb1d8c6c47dff7be6377d319ee0

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-py2.py3-none-win32.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 8b156c59d3a99f68c63a67cd324e07762a2b01a7dd8013ddc2d9f1ad2bd3261d
MD5 adfff5827941539d739dbfd91d5c063c
BLAKE2b-256 1488051af5d0a704142776d45d603bf7146b0eb065fb6da1977932c5726dee08

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 09696838e7cd22b390dbeed9f2b9e340785c0e5db3ed7b6925b7140fce6183ac
MD5 ca821dc79720dab5c9bd02831f33a6ce
BLAKE2b-256 9692832f3dd2e3a5c170ff60baf26f39d0980801636f77e8f9055f0a044c0f97

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp37-cp37m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 3051b251034b6a0fe47d249125c83fecc6f3c9eb2466ac1732bf3df73ae61ccf
MD5 037d6b7c107ae82bb4d8cef0cdd404a6
BLAKE2b-256 a5418798e423770569ce0a5f90efb6771f0244a60893f15183866976ba1696d7

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp37-cp37m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 a6404900c6f7828132bf178d2dd79b0708863e78d3ca1a8b9eb736da9644110a
MD5 42a563e031be4331fbf2631bad74a0e4
BLAKE2b-256 b7b4f6251235ec16d96a72554e7917f479fd55c2c48a253d570d057bddac1ee3

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d1cacef79ce2fdbec0896647b144ac77b0339865f672a3d94e2e00cdefa082a8
MD5 5bf98e160569b749ab34eee3131e4afe
BLAKE2b-256 7fd9d18e54a3a504756bdc46fa8454c9f57b76819048f955a2c6d10911b5604f

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e4f6ce6dd87eb5629e60a13cf72c30f05e6d7cc822f4c5f8b0a4ef0fd133172d
MD5 9b3c9ec8b10d739a96de117f71177e9e
BLAKE2b-256 db846d5398094f9fde3dc3eca05f4ff9c19697f4c98782b9216b4fb25f199901

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 62f2901a7cd1bd2cb4db2d52ce616cc03f67745d12ea0f2df7ef11df1500de61
MD5 d35805c6923a7f603e7f19a0cb29f884
BLAKE2b-256 2a9a5a8b8476df2363c1b6cc853cd717f14a32377076eb1997b4537d3a451a24

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b7e0b0af75121ffb6aee0b27015fc79883bf9a9a23ab980178f46f04e09d6dfb
MD5 153ad6c600110139fe4dc2541be7a009
BLAKE2b-256 bf6502995461728248e863b434148938b51a2e25b130c277783c566fef21a329

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 48c3fd3c08203bd54f70b6ae673c362fd9f7d094c089c39a989f8c928c3b2c60
MD5 489ed7bb370becb711532abe7d567cc5
BLAKE2b-256 dc1e934ac8eb8cd8e30dfb55e806713e5673960a0c4e51cca2bba003315a1804

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp35-cp35m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 432caf3a263309e640c10fd3db4c97c224cc0db295cda06092ff91c80b10deba
MD5 cf58bb2cc33042b6d7a75da1138bea0a
BLAKE2b-256 7ec475ec411ef27aba9f662544d288c7d57b55048f2f63fe2ba4f02962bb8076

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 80dd1aa282d208e87c623a8aa1399b871fa318f06926351569e2c290795d962f
MD5 c2cf79f5d9d35e4fd4422d8e7c158e62
BLAKE2b-256 08b7c79ad0e71f7ea4d885dd7fbe8ee70c47ddb84d8e639c93ad0ae21874975f

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c798b800639e0e3876a04db45e3001cf5dda6f0958ba6383e8dda77654158815
MD5 c98f7f69c0fda25e6f2bcad336aa2b0a
BLAKE2b-256 0a0309848fcb6e734698a4e824491283a5a2ed2cd875a7ff92791c6849f64945

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e57c75cc40421281786f35d380f9337a67f97f0b24760eab3040738a4f35e97a
MD5 d8455defbc87dc36f9670e94121f50ea
BLAKE2b-256 b92b7a96d8e0f4a6645249185cbb3c3079ebfbfe80f1c52d92c7645b2a09ca09

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2df684608a827e2652ff1e4d21c22b82130f37aa321f618606e7a3733f0810c6
MD5 21d09f43c7e15aeff0117c519fd59318
BLAKE2b-256 fb6f875d01ce6e548b7a43468ad38ea2d9edd2ea8502f73c62445604a36b364f

See more details on using hashes here.

File details

Details for the file coincurve-8.0.0-cp27-cp27m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for coincurve-8.0.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 41ab5c9d733b3cc1c93ab3de5e5b15e0327e67ee416a8b289b2012b9fce72ee5
MD5 16e3c135f3f9edb96e72c110f1fba748
BLAKE2b-256 9d687b4ab2b88fa660bcd322c7d314d3fab002751bf02f4410222af69a82d609

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page