Py-ed25519-zebra-bindings

1.3.0 · active · verified Thu Apr 16

Python bindings for the `ed25519-zebra` Rust crate, providing high-performance cryptographic operations for Ed25519 digital signatures. It's currently at version 1.3.0 and has a moderate release cadence, driven by updates to the underlying Rust dependencies and Python version support, ensuring compatibility and performance.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to generate an Ed25519 keypair, sign a message with the secret key, and then verify the signature using the public key. It also shows how to convert keys to and from byte representations and derive the public key from a secret key.

from ed25519_zebra import generate_keypair, sign, verify, PublicKey, SecretKey, ed_public_from_secret

# Generate a new keypair
secret_key, public_key = generate_keypair()
print(f"Secret Key: {secret_key.to_bytes().hex()}")
print(f"Public Key: {public_key.to_bytes().hex()}")

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

# Sign the message
signature = sign(secret_key, message)
print(f"Signature: {signature.to_bytes().hex()}")

# Verify the signature
is_valid = verify(public_key, signature, message)
print(f"Signature valid: {is_valid}")

# Example of converting bytes to key objects
public_key_bytes = public_key.to_bytes()
secret_key_bytes = secret_key.to_bytes()

reconstructed_public_key = PublicKey.from_bytes(public_key_bytes)
reconstructed_secret_key = SecretKey.from_bytes(secret_key_bytes)

print(f"Reconstructed Public Key Matches: {reconstructed_public_key == public_key}")
print(f"Reconstructed Secret Key Matches: {reconstructed_secret_key == secret_key}")

# Derived public key from secret (available from v1.1.0+)
derived_public_key = ed_public_from_secret(secret_key)
print(f"Derived Public Key from Secret Matches: {derived_public_key == public_key}")

view raw JSON →