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.svg?branch=master&style=flat-square https://img.shields.io/pypi/pyversions/coincurve.svg?style=flat-square https://img.shields.io/badge/license-MIT-blue.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

Installation

Coincurve is distributed on PyPI and is available on Linux/macOS and Windows and supports Python 2.7/3.5+ and PyPy2.7-v5.7.1/PyPy3.5-v5.7.1+.

$ pip install coincurve

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


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

coincurve-4.3.0-py2.py3-none-win_amd64.whl (258.9 kB view details)

Uploaded Python 2Python 3Windows x86-64

coincurve-4.3.0-py2.py3-none-win32.whl (274.1 kB view details)

Uploaded Python 2Python 3Windows x86

coincurve-4.3.0-pp357-pp357-manylinux1_x86_64.whl (208.5 kB view details)

Uploaded PyPy

coincurve-4.3.0-cp36-cp36m-manylinux1_x86_64.whl (526.2 kB view details)

Uploaded CPython 3.6m

coincurve-4.3.0-cp36-cp36m-manylinux1_i686.whl (532.9 kB view details)

Uploaded CPython 3.6m

coincurve-4.3.0-cp36-cp36m-macosx_10_6_intel.whl (154.6 kB view details)

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

coincurve-4.3.0-cp35-cp35m-manylinux1_x86_64.whl (526.2 kB view details)

Uploaded CPython 3.5m

coincurve-4.3.0-cp35-cp35m-manylinux1_i686.whl (532.9 kB view details)

Uploaded CPython 3.5m

coincurve-4.3.0-cp35-cp35m-macosx_10_6_intel.whl (154.6 kB view details)

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

coincurve-4.3.0-cp27-cp27mu-manylinux1_x86_64.whl (529.7 kB view details)

Uploaded CPython 2.7mu

coincurve-4.3.0-cp27-cp27mu-manylinux1_i686.whl (535.7 kB view details)

Uploaded CPython 2.7mu

coincurve-4.3.0-cp27-cp27m-manylinux1_x86_64.whl (529.7 kB view details)

Uploaded CPython 2.7m

coincurve-4.3.0-cp27-cp27m-manylinux1_i686.whl (535.7 kB view details)

Uploaded CPython 2.7m

coincurve-4.3.0-cp27-cp27m-macosx_10_6_intel.whl (154.5 kB view details)

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

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a4b2a1e3974e4331050b5d14cae9e59ca6056b8c1727ec1b37915d235c041d0d
MD5 efd1e80524df261299895dc2c7545de9
BLAKE2b-256 f567a41d745efc24e1a29554fca843a7f3756e69e4c3710e0ed52e6b5177bed7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 8fc849d1789700930653105598e29955080425b7aa43005ce2404f1c3d4c5b5b
MD5 95461618009088087b1786c8009015f0
BLAKE2b-256 6894a15d946acbfbec8635795d76787b416e7a701d40415e23d3f5fbe782e7db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-pp357-pp357-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 78379fa8a3a3d408bd142f59b5b2d78ee48fd2f75d33cc9ce8ee612cce676eff
MD5 ecff00d0c873efe2025de60db684588f
BLAKE2b-256 6644de6d0618c663f0c0e2e67df70ef2559542298e2c5eb8661eeca62f086491

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5b680491b0574d8a7d9c8712055ea838783dc014fffed80b3560b1f1fb399196
MD5 0a93eca056514d98ed8684b2eb1a204f
BLAKE2b-256 df583ba38be1354e17c0216fbe3d251539b74485da887f41c1aae0716f03c7c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b1c86d6e7d6bb076e351df739fbdd367b546fac88fcd18d20cf63d3ec40c9181
MD5 784e8d7308c070080e59bb46a327d75d
BLAKE2b-256 98fc62dabf4dde56141bc41900eb21fb2a0e960212dbf07269fee4a5f1d1eafe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 29d272ee8f35ec2b44bd39d8b8a138d7f9bd957bd8f51b31456b86f9b064af9b
MD5 f4281c7e88f27948c2ee3dd88b877ded
BLAKE2b-256 18a2aa258bb8b989ba2338f1a0320e3dc459119df641cad07a18836ece32cbc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b764c453a4b517b966571fe80faece23b1ca9875eb01578c18976c0e8f5f3dd2
MD5 fbe80f918cd17a775bd57cd427aed957
BLAKE2b-256 e442e59470df4ba4b115b81e318863f4289f224930339ee9772b0ba0deaf7ebd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4e8a877aed0490ab6427b8c3884e5c6ea5debc4fdf608f17f53b34bdd4f1def1
MD5 021a3254acfa0c2df98ea93a648e9cd2
BLAKE2b-256 d0452c63dd522591ae68db8a3171a751cc06c0f2065e516b436dde02ce9a3cff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 9228dbee2bb4e12ad6e8b106c4d274443e39e736e15a20e8135565161161099d
MD5 7f9c6ecbd944f74790b855ef595a2fac
BLAKE2b-256 22350522522c0a2ed26e73902fa873a3c3e0b3f5be1478396abde3131fae5d65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 163fefbee203324610afd4ee435bf9b7365dc40bd12dcfd113e8e5678fdb02f4
MD5 ca8bb022cc0378c3b09d908be5e086ed
BLAKE2b-256 b3150980ba654f992f8ea0c3a2148e01a0db1fe20f8378611370cbbdffa9d407

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 de784037408f3539052347495fb1399f5ccf8a8945be620d6350ac1385a6de39
MD5 eaeae5c34ee7d48abc82e5baa23cee74
BLAKE2b-256 8c894fc4de2cfac3196f1516935ac84ace3c3a190d755399c4ee82213f40b9ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 386dc2bb633004fb28e7e894303d46f9ac8c265ee40ff3083a60168d4848f193
MD5 31c58b9fe9fe4af25ce38475e4cce368
BLAKE2b-256 ccd4284caec8238f22e2a85d15e20a734ac9aeb524fdbe18c913bbf1a26032f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5dec48e552ffcda56c4f856601790a2ee3771b243befecf8227c06853a389bb0
MD5 d4084c5eb97052f7a60e70fc9a215038
BLAKE2b-256 61c57daf0b67e00c7925bc190da2bec55523f7b5d1f54e27c8cfd7053eaaa2c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coincurve-4.3.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 dafbe06c3fd4f8e5ea6a92576ddffbbe4e9a4adad1c2dc59d59aefc47ac633c3
MD5 6fc68290d97aba261b3736e1670ddd58
BLAKE2b-256 2925abd1db4f34db42fbb92f009063355ad23e85012ad15e719f30cfc8acc818

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