pub struct Schnorr<H: Hashable> {
pub hasher: Box<dyn Hasher<Message<H>>>,
pub domain_param: H::D,
}Expand description
Schnorr signer context for the Mina signature algorithm
For details about the signature algorithm please see the
schnorr documentation
Fields§
§hasher: Box<dyn Hasher<Message<H>>>The hasher instance used to hash messages
domain_param: H::DThe domain parameter used for hashing
Implementations§
Source§impl<H: 'static + Hashable> Schnorr<H>
impl<H: 'static + Hashable> Schnorr<H>
Sourcepub fn derive_nonce_chunked(&self, kp: &Keypair, input: &H) -> ScalarField
pub fn derive_nonce_chunked(&self, kp: &Keypair, input: &H) -> ScalarField
Chunked nonce derivation for zkApp transactions.
This function implements the deterministic nonce derivation algorithm used
by Message.Chunked in the OCaml implementation. Use this for zkApp
transactions that need to be compatible with o1js.
§Compatibility
This implementation corresponds to Message.Chunked.derive in the OCaml
implementation (src/lib/crypto/signature_lib/schnorr.ml).
It is also compatible with the TypeScript o1js implementation: https://github.com/o1-labs/o1js/blob/main/src/mina-signer/src/signature.ts
The private key conversion replicates the “Field.project” method with unpack from the OCaml implementation, which performs modular reduction when the scalar field value is larger than the base field modulus.
§Algorithm
The nonce derivation follows this process:
- Create
ROInputfrom:message || public_key_x || public_key_y || private_key || network_id - Pack the
ROInputinto fields using Mina’s field packing - Convert packed fields to bits (255 bits per field)
- Convert bits to bytes for
BLAKE2binput - Hash with BLAKE2b-256
- Drop the top 2 bits to create a valid scalar field element
§Parameters
kp- The keypair containing both public and private keysinput- The message to be signed
§Returns
A deterministic nonce as a scalar field element.
§Test Vectors
For test vectors demonstrating this function’s usage, see the
sign_fields_test in tests/signer.rs which
uses NonceMode::Chunked.
§Security
This function generates a cryptographically secure, deterministic nonce that:
- Depends on the private key, public key, message, and network context
- Ensures no two different messages share the same nonce (with the same key)
- Is compatible with existing Mina protocol implementations
§Panics
Panics if the BLAKE2b variable-output hasher cannot be created with
a 32-byte output size (should not happen).
Sourcefn derive_nonce_legacy(&self, kp: &Keypair, input: &H) -> ScalarField
fn derive_nonce_legacy(&self, kp: &Keypair, input: &H) -> ScalarField
Legacy nonce derivation for user commands (payments, delegations).
This function implements the deterministic nonce derivation algorithm used
by Message.Legacy in the OCaml implementation. Use this for legacy Mina
transactions (user commands) such as payments and delegations.
§Compatibility
This implementation corresponds to Message.Legacy.derive in the OCaml
implementation (src/lib/crypto/signature_lib/schnorr.ml).
§Parameters
kp- The keypair containing both public and private keysinput- The message to be signed
§Returns
A deterministic nonce as a scalar field element.
§Usage
Use this method for legacy Mina transactions (user commands) such as
payments and delegations. For zkApp transactions, use
derive_nonce_chunked instead.
§Differences from derive_nonce_chunked
This method differs from derive_nonce_chunked in several ways:
- Uses direct byte serialization (
roi.to_bytes()) instead of field packing - Appends private key as scalar field element instead of base field element
- Uses full network ID bytes instead of packed single byte
- Does not perform bit-level manipulation for
BLAKE2binput
§Security
This function generates a cryptographically secure, deterministic nonce that depends on the private key, public key, message, and network context.
Sourcefn message_hash(
&mut self,
pub_key: &PubKey,
rx: BaseField,
input: &H,
) -> ScalarField
fn message_hash( &mut self, pub_key: &PubKey, rx: BaseField, input: &H, ) -> ScalarField
This function uses a cryptographic hash function (based on a sponge construction) to convert the message to be signed (and some other information) into a uniformly and randomly distributed scalar field element. It uses Mina’s variant of the Poseidon SNARK-friendly cryptographic hash function. Details: https://github.com/o1-labs/cryptography-rfcs/blob/httpsnapps-notary-signatures/mina/001-poseidon-sponge.md
Trait Implementations§
Auto Trait Implementations§
impl<H> Freeze for Schnorr<H>where
<H as Hashable>::D: Freeze,
impl<H> !RefUnwindSafe for Schnorr<H>
impl<H> !Send for Schnorr<H>
impl<H> !Sync for Schnorr<H>
impl<H> Unpin for Schnorr<H>where
<H as Hashable>::D: Unpin,
impl<H> UnsafeUnpin for Schnorr<H>where
<H as Hashable>::D: UnsafeUnpin,
impl<H> !UnwindSafe for Schnorr<H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.