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.

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

Table of Contents

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, 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)

  • Parameters:

    • message (bytes) - The message to sign.

    • hasher - The hash function to use, can be None. 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, can be None. 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, can be None. 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

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.

Changelog

Important changes are emphasized.

5.0.1

  • Fixed an issue where validate_secret would occasionally erroneously error on user-provided secrets (secrets not generated by Coincurve itself) if there were not exactly 256 bits of entropy. See #5

5.0.0

  • Breaking: Coincurve is now dual-licensed under the terms of MIT and Apache v2.0.

  • Performance improvements from libsecp256k1 master: 1 2 3 4 5 6

  • Improvements to documentation.

4.5.1

  • First public stable release

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-5.0.1.tar.gz (877.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-5.0.1-py2.py3-none-win_amd64.whl (257.3 kB view details)

Uploaded Python 2Python 3Windows x86-64

coincurve-5.0.1-py2.py3-none-win32.whl (272.3 kB view details)

Uploaded Python 2Python 3Windows x86

coincurve-5.0.1-cp36-cp36m-manylinux1_x86_64.whl (525.4 kB view details)

Uploaded CPython 3.6m

coincurve-5.0.1-cp36-cp36m-manylinux1_i686.whl (532.2 kB view details)

Uploaded CPython 3.6m

coincurve-5.0.1-cp36-cp36m-macosx_10_6_intel.whl (157.2 kB view details)

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

coincurve-5.0.1-cp35-cp35m-manylinux1_x86_64.whl (525.4 kB view details)

Uploaded CPython 3.5m

coincurve-5.0.1-cp35-cp35m-manylinux1_i686.whl (532.2 kB view details)

Uploaded CPython 3.5m

coincurve-5.0.1-cp35-cp35m-macosx_10_6_intel.whl (157.2 kB view details)

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

coincurve-5.0.1-cp27-cp27mu-manylinux1_x86_64.whl (528.4 kB view details)

Uploaded CPython 2.7mu

coincurve-5.0.1-cp27-cp27mu-manylinux1_i686.whl (535.3 kB view details)

Uploaded CPython 2.7mu

coincurve-5.0.1-cp27-cp27m-manylinux1_x86_64.whl (528.4 kB view details)

Uploaded CPython 2.7m

coincurve-5.0.1-cp27-cp27m-manylinux1_i686.whl (535.3 kB view details)

Uploaded CPython 2.7m

coincurve-5.0.1-cp27-cp27m-macosx_10_6_intel.whl (157.0 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for coincurve-5.0.1.tar.gz
Algorithm Hash digest
SHA256 21bedb8254eeef8fd64a657ffe96eb62a1c65abaf0fa405ba00874f875edba70
MD5 a3430537da064f8868eb752ed1be998d
BLAKE2b-256 d6c2e55e4e9cf42da8a2a852345c7fe5e41dd18f0c8886fdc58e4305aa03938d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 789caf833219a0f9732f3a5eefcd958a10caf41601b9fdcef6d3fa5dab0b8a5e
MD5 e453453fa1cdc3d83678612ba06dc997
BLAKE2b-256 eea2ecb20cda0d7745ffe1937c2e55b69dfff07a6140fb560a34cc17f5a10223

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 77e99968797ce6998e0d6d5fb77d73c06f3098fe1003afccde08e475af07b0cd
MD5 e677180a65a8810084692f8622b3554d
BLAKE2b-256 1805eaa81f1ec5b3abdbdd6afe1146492754f16740bd0f0a8b3fe26cc93ba485

See more details on using hashes here.

File details

Details for the file coincurve-5.0.1-pp358-pypy3_58-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-5.0.1-pp358-pypy3_58-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b820b51e62819db6312f95825db077948e29988bbda147ef0af8feebfd4d1cc3
MD5 5c2bb80328befe1139d0908c84b08a5a
BLAKE2b-256 137801e9d2e1518f09038a7a07919809b22f49ad702cdc31eb898402660d4493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 582e57469cd10a54c06b8499efc01c090f0d39a25e8744d26d5327fb5bc436c5
MD5 d067117f02b65e4b54ae320f21368ee4
BLAKE2b-256 61b9bdeda20cff7e16e71f8380f93fc93799077ff7998ca800a92287d5a90328

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c081e50e2f04ca53d54119d6a8ac64b43ebd6343bcf7be3de54b1e3071423b23
MD5 4009887c2425ae7f8b9f3174cebca931
BLAKE2b-256 03f1a18b6cc10f81dd82732b8bfe25fc4dfa6b12f1f6849915beaff4631ce92c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 e4b4b23698756ce13db46747ec969c88431e2b98be8dc05e6961b5f73b98d346
MD5 6960a8ddfc0ea3f8b2b11fb125f341ac
BLAKE2b-256 5143d6ad0c9d9bb915879586b17bd0e2ab4b924031e061cead8e1acd23848ffc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 81c74a15d4aef93f66d28eda76b801341f92a073c8e64e33d8cbc3baf6d6b3bd
MD5 07159bb929b8935836f9318156b77ff9
BLAKE2b-256 2dca0e616f5ce13d6981dbd2ff98419ff4eac3a603717435e17c9f67f66d8aa9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4daae03682ca867c5e5fb12eb9b03f2365b1139ab81c3c2686b6c6b7d231898d
MD5 851c4ad78f077c6e978852ea857142c9
BLAKE2b-256 89f8e60bb519220f11ade312ef57ba54e70d3061457d56b9b6c400404a44a572

See more details on using hashes here.

File details

Details for the file coincurve-5.0.1-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for coincurve-5.0.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 2446499fc6d7003559611756bedcb18afd9a1512b3d09a0ef7cced56773c127f
MD5 af19e7a7a85fe00f87ac0304cada372e
BLAKE2b-256 2248a459581a93cb81e725054c960a95e481536c1d25db46e3f61a654c7fa8cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f05bad0ddb07510a6d606ffc77678354b8c4641c42a6aa2a4340ed235ed56633
MD5 2923518174a32c146bb71c688af64911
BLAKE2b-256 583a9ab8db46f9b720ad054f91f592f89f2b4a699cb24a04556c13ca289f2908

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 bb8a7b3e911dc2f06f7d69a325bc4472bb0f895052a65721c287f44a07532746
MD5 4393b358b7fe3b3f9dac225975313623
BLAKE2b-256 49695b78a20262f15606d0551170198da2cfd91c6a95a88b2efbd440c5712633

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6ca1ff4583156fd43c113283914f5c64d01fcc4acbf94296c12527a36b25f0bc
MD5 192d030342dd55ad47b3f9235baa0377
BLAKE2b-256 ec9835fd9271aab761d53ebc9a8e63d0916a86e56c3bbb1d1a8c55b3a8f3829d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 11dda9cfd9f03307f7146604b51b1bc7f058d19669072d5f8cb189a59fc406d3
MD5 2634b72fbf0522136a5ad652d7cd4710
BLAKE2b-256 747affade54760705984293f6723f073ee084cbbb44040cdc97370e1c8c1cc86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.1-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 b99062580beff3fd57ef079f7b71aeb9d9f7216ffb9a73aa46e84f2462027dc7
MD5 0b70204e987f4d5a078da60bb4dec962
BLAKE2b-256 1a3226fee2aaa89ceeb53cebe960f17bee90b413d9f7835e5b38068f300baa5b

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