sr25519
Sign and verify with sr25519 Schnorr signatures over ristretto255.
Warning
Experimental: sr25519 is defined by schnorrkel and Substrate, not by an IETF or NIST standard.
from oxcrypto.signature.sr25519 import SR25519
private_key = SR25519.SR25519.generate()
signature = private_key.sign(b"message", context=b"substrate")
public_key = private_key.public_key()
assert public_key.verify(signature, b"message", context=b"substrate")sr25519 is the Schnorr signature scheme over ristretto255 used by Substrate
and Polkadot. Messages are hashed with a Merlin transcript bound to a signing
context, which sign and verify take as a required keyword argument.
Substrate uses b"substrate". Signatures are 64 bytes and are randomized, so
signing the same message twice gives different signatures.
| Method | Encoding |
|---|---|
load_private_bytes(data) | 32-byte seed, expanded in Ed25519 mode as Substrate and polkadot-js do, or a 64-byte schnorrkel secret key (scalar and nonce seed) |
PrivateKey.to_bytes() | 64-byte schnorrkel secret key; the seed is not kept after expansion |
load_public_bytes(data) / PublicKey.to_bytes() | 32-byte compressed ristretto255 point |
There is no PKCS#8 or SPKI encoding because sr25519 has no registered OID.
| Standard | None. sr25519 is defined by the schnorrkel crate and the Polkadot specification, not by the IETF |
| Crate | schnorrkel 0.11.5 on curve25519-dalek 4, stable |
| Audit | No published audit of schnorrkel |
| MSRV | Not declared by the crate; builds with the project MSRV 1.88 |
| Experimental | Yes (non-IETF) |
| Test vectors | No published vectors exist. The key vector is the SecretKey::from_ed25519_bytes example in schnorrkel's documentation; the seed and signature vectors were produced with schnorrkel 0.11.5 |
curve25519-dalek is written to run secret-dependent arithmetic in constant
time; oxcrypto has not verified this independently.
Zeroization
Note
Read from the schnorrkel 0.11.5 source; oxcrypto has not verified it
independently. Short-lived copies and Python bytes are not wiped.
- State the key object keeps: the
Keypairdrop handler zeroizes theSecretKey(scalar and nonce seed).MiniSecretKeyseeds are zeroized on drop, and the per-signature nonce is zeroized after signing. - Short-lived copies during a call that are not wiped: the SHA-512 output and
the scalar and nonce arrays in
MiniSecretKey::expand_ed25519, and copies thatSecretKey::to_bytesreturns. - Python
bytespassed in or returned are not wiped.