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.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.0.tar.gz (877.1 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.0-py2.py3-none-win_amd64.whl (257.0 kB view details)

Uploaded Python 2Python 3Windows x86-64

coincurve-5.0.0-py2.py3-none-win32.whl (271.9 kB view details)

Uploaded Python 2Python 3Windows x86

coincurve-5.0.0-pp357-pp357-manylinux1_x86_64.whl (208.0 kB view details)

Uploaded PyPy

coincurve-5.0.0-cp36-cp36m-manylinux1_x86_64.whl (525.0 kB view details)

Uploaded CPython 3.6m

coincurve-5.0.0-cp36-cp36m-manylinux1_i686.whl (531.9 kB view details)

Uploaded CPython 3.6m

coincurve-5.0.0-cp36-cp36m-macosx_10_6_intel.whl (156.8 kB view details)

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

coincurve-5.0.0-cp35-cp35m-manylinux1_x86_64.whl (525.0 kB view details)

Uploaded CPython 3.5m

coincurve-5.0.0-cp35-cp35m-manylinux1_i686.whl (531.9 kB view details)

Uploaded CPython 3.5m

coincurve-5.0.0-cp35-cp35m-macosx_10_6_intel.whl (156.8 kB view details)

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

coincurve-5.0.0-cp27-cp27mu-manylinux1_x86_64.whl (528.1 kB view details)

Uploaded CPython 2.7mu

coincurve-5.0.0-cp27-cp27mu-manylinux1_i686.whl (535.0 kB view details)

Uploaded CPython 2.7mu

coincurve-5.0.0-cp27-cp27m-manylinux1_x86_64.whl (528.1 kB view details)

Uploaded CPython 2.7m

coincurve-5.0.0-cp27-cp27m-manylinux1_i686.whl (535.0 kB view details)

Uploaded CPython 2.7m

coincurve-5.0.0-cp27-cp27m-macosx_10_6_intel.whl (156.7 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for coincurve-5.0.0.tar.gz
Algorithm Hash digest
SHA256 230e246220dac653c31041920d49eee7e4be2abe54c6ba0861a04d730bece112
MD5 4afea169ef4a09f443aa5d5f844893e3
BLAKE2b-256 bb454f50bc68714706715f9debb0d30a443e62b114d3f573e74237b7209f2a25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 98b21fbace06cb5323d5a452df2968f0b35fac8ee5e617a5b45571ad3d10b5c2
MD5 94d5c48bb1a892cf47d8a59798e1d7f7
BLAKE2b-256 650ef325abe5df52c80ab7ac537e778beb76aa0f0edf0bbf86d141e11d7de12b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 2d29f18745a0d7ccf4ce1dfe5eabeb2822e28a19d76328ca2c032805329198c3
MD5 6302b15f1a744f8df625099b6ae96516
BLAKE2b-256 c12a378a146fc4499460e2cb1bc73f1f944568e635aa446890bb1a68a55ff90d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-pp358-pypy3_58-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2237c30384a1e83bb923d750e515b67f79aba7071eca65eac5107f71188515ab
MD5 ee18c679d20502564d9e3cd6ad58c2b7
BLAKE2b-256 06a8f85a6fc9d1790dc2bce87f4f2bcfb79c0dc6913c3300f4b460e574dd26b8

See more details on using hashes here.

File details

Details for the file coincurve-5.0.0-pp357-pp357-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for coincurve-5.0.0-pp357-pp357-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e2cb0cd7bf412b4c615aef61ba68a478cdba95a24ec08af03ab1fa7de2d1834c
MD5 7a200f8b5d13a818e07d4844f2a14503
BLAKE2b-256 d50439071d6f9c5daddadcaa5fd8209a0384c5af206efa5a7e6229051f857c83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 990be35a7103a3e6068c3a0c75507014f83d268023e20276fd105102215868fe
MD5 6eb9883195c0af241332f39831b11671
BLAKE2b-256 14e6410d59413307a0dcc689a4e3b71832a784bb8b0a2c95569e3cd0253a85e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 d2e5651b2ad6a5ef7e868dc0bd8743c485cea6c4a5f47be1bcb9cef8fc1f285e
MD5 37e85336a27cc5b949b1bacaa58799f0
BLAKE2b-256 89ff4336d142eceac22d7eb74b5b2b4f1712f405cdced3584089a35c7ec0fc7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 5ab97b73d2291cc10bfebc81a72b3ed5f2b60fc961d17c2f29d0487810b39ac0
MD5 6c2d11db84409fd4b3bb5d80186f35c9
BLAKE2b-256 f0bd596d24b7c12d49150c69e920a829319749c42f89648cbbfb402ef447fbac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b04fc03c2ee05f00d095abfa86462d377646788a72d255d696668a6ed3f5b15c
MD5 d153f45849248db10a22a29e6472f946
BLAKE2b-256 6c7eaf80be82300f2c778e957456ae3cf308be7639f37b53dd48f7795484d670

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 448b9377af7cc748468cda4a25a66d465d3beadab1576468526cb2134d7a446f
MD5 d516dbe2f78df016e05c808b45284bd1
BLAKE2b-256 c7927bf988bf869534b4699dc23695bd3b286f734214b83455596258f3cd92cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 cc5fa73e782492c3ba7c8cf54f1ea6da1710cda5462f5e8f1574ba4fb32bda6f
MD5 343a0a0a9fba8602debbcf3259f289e8
BLAKE2b-256 e908d2f04ce4d12e6b435ef69b027f14a30bf664fbaae8a380eab661b900bf24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b0667c3ea6f3869ef2e466817a5a4260e5913685dbf92b1fd52a42f4f510b176
MD5 2efd4e407ca932d4bf58c383134bb082
BLAKE2b-256 e02044be4c6f2b5dfa88ad2d012af8f366279e291ef7a83c6153e9dd1cd6e209

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 3d22fc151713ad2beb8690642662f1b09e125eadffcacf61d094c882e01f431d
MD5 c3b3e8fc07da950e5e3b4052d2b94597
BLAKE2b-256 d02dab3fcd03d69c678c470e1dadcbbd12ce679e44ca676490be6c348183582c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ef7e0a04828c27fe5e558220b283b80a782a6662954db2b08d6913bc91a5f2a4
MD5 0d7c0a714dc977b52b7021061960f641
BLAKE2b-256 5e7f9c8cfdad9e2dbe45057946ff76c9d44865029259c703f0ac876fb481ff3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 deaa31fdf39d49d231f05b20543f4ea5570fca52ada7a6682f0b24efa4751977
MD5 c76c73e6b355e4fd502ee9280c3fe5aa
BLAKE2b-256 9d3f04ac15455a086d4e81f6584d3714cff7e998f4c040aca012615fae09c669

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-5.0.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 25c7b2e36cf8de3e261c9035ac39e2a36ba5c21257c6a9cffaec488fac791fc6
MD5 9aaba892793b6a06f2b895fcc844aaae
BLAKE2b-256 5778eb2775dc075d2626f275f7fb75faf97a701e3974ba9ce39c500f9dd55661

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