Ed25519
provide.foundation.crypto.ed25519
¶
Ed25519 digital signature implementation.
Ed25519 is the recommended algorithm for new applications: fast, small keys, deterministic signatures, and modern cryptography.
Examples:
>>> signer = Ed25519Signer.generate()
>>> signature = signer.sign(b"message")
>>> verifier = Ed25519Verifier(signer.public_key)
>>> assert verifier.verify(b"message", signature)
Classes¶
Ed25519Signer
¶
Ed25519 digital signature signer.
Stateful signer that holds private key and provides signing operations. Ed25519 is the recommended choice for new applications: fast, small keys, deterministic signatures.
Examples:
Generate new keypair: >>> signer = Ed25519Signer.generate() >>> signature = signer.sign(b"message") >>> public_key = signer.public_key
Load existing key: >>> signer = Ed25519Signer(private_key=existing_32_byte_seed) >>> signature = signer.sign(b"message")
Attributes¶
public_key
cached
property
¶
Functions¶
__attrs_post_init__
¶
Initialize private key object from bytes.
Source code in provide/foundation/crypto/ed25519.py
export_private_key
¶
Export 32-byte private key seed.
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
32-byte Ed25519 private key seed |
Warning
Private keys should be stored securely. Consider encryption.
Source code in provide/foundation/crypto/ed25519.py
generate
classmethod
¶
Generate new signer with random Ed25519 keypair.
Returns:
| Name | Type | Description |
|---|---|---|
Ed25519Signer |
Self
|
Signer with newly generated keypair |
Source code in provide/foundation/crypto/ed25519.py
sign
¶
Sign data with Ed25519 private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Data to sign |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
64-byte Ed25519 signature |
Raises:
| Type | Description |
|---|---|
CryptoSignatureError
|
If signature generation fails |
Source code in provide/foundation/crypto/ed25519.py
Ed25519Verifier
¶
Ed25519 signature verifier.
Stateful verifier that holds public key and provides verification operations.
Examples:
>>> signer = Ed25519Signer.generate()
>>> verifier = Ed25519Verifier(signer.public_key)
>>> signature = signer.sign(b"message")
>>> assert verifier.verify(b"message", signature)
Functions¶
__attrs_post_init__
¶
Initialize public key object from bytes.
Source code in provide/foundation/crypto/ed25519.py
verify
¶
Verify Ed25519 signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Data that was signed |
required |
signature
|
bytes
|
64-byte Ed25519 signature |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if signature is valid, False otherwise |