ECPy: Pure Python Elliptic Curve Library

1.2.5 · maintenance · verified Thu Apr 16

ECPy is a pure Python Elliptic Curve library providing implementations of ECDSA, EDDSA (Ed25519), ECSchnorr, and Borromean signatures, alongside fundamental Point operations. The library is currently at version 1.2.5, with its last release in October 2020. While its documentation historically noted a 'beta stage' status, the current lack of recent development suggests it is in maintenance mode rather than active feature development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core functionality of ECPy by performing an ECDSA signature and verification. It initializes a secp256k1 elliptic curve, creates a public/private key pair, signs a simple message, and then verifies the signature.

from ecpy.curves import Curve, Point
from ecpy.keys import ECPublicKey, ECPrivateKey
from ecpy.ecdsa import ECDSA

# Get a predefined elliptic curve (secp256k1 is commonly used)
cv = Curve.get_curve('secp256k1')

# Define public and private keys (example values, in a real scenario these would be generated securely)
# Private key (scalar 'd')
pv_scalar = 0xfb26a4e75eec75544c0f44e937dcf5ee6355c7176600b9688c667e5c283b43c5
pv_key = ECPrivateKey(pv_scalar, cv)

# Public key (Point 'Q' = d * G, where G is the generator point of the curve)
# For secp256k1, the generator is part of the curve definition. 
# The public key point is derived from the private scalar.
Q_x = 0x65d5b8bf9ab1801c9f168d4815994ad35f1dcb6ae6c7a1a303966b677b813b00
Q_y = 0xe6b865e529b8ecbf71cf966e900477d49ced5846d7662dd2dd11ccd55c0aff7f
pu_key_point = Point(Q_x, Q_y, cv)
pu_key = ECPublicKey(pu_key_point)

# Create an ECDSA signer instance
signer = ECDSA()

# Message to be signed (must be bytes)
message = b'This is a test message to be signed.'

# Sign the message
sig = signer.sign(message, pv_key)

# Verify the signature
is_valid = signer.verify(message, sig, pu_key)

print(f"Message: {message.decode()}")
print(f"Private Key (scalar): {hex(pv_scalar)}")
print(f"Public Key (Point): ({hex(pu_key_point.x)}, {hex(pu_key_point.y)})")
print(f"Signature: {sig.hex()}")
print(f"Signature Valid: {is_valid}")

assert is_valid, "Signature verification failed!"
print("Signature successfully verified.")

view raw JSON →