Skip to Content
oxcrypto

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.

MethodEncoding
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.

StandardNone. sr25519 is defined by the schnorrkel crate and the Polkadot specification, not by the IETF
Crateschnorrkel 0.11.5 on curve25519-dalek 4, stable
AuditNo published audit of schnorrkel
MSRVNot declared by the crate; builds with the project MSRV 1.88
ExperimentalYes (non-IETF)
Test vectorsNo 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 Keypair drop handler zeroizes the SecretKey (scalar and nonce seed). MiniSecretKey seeds 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 that SecretKey::to_bytes returns.
  • Python bytes passed in or returned are not wiped.

On this page