Trait Scheme

Source
pub trait Scheme:
    Clone
    + Send
    + Sync
    + 'static {
    type PrivateKey: Array;
    type PublicKey: Array;
    type Signature: Array;

    // Required methods
    fn new<R: Rng + CryptoRng>(rng: &mut R) -> Self;
    fn from(private_key: Self::PrivateKey) -> Option<Self>;
    fn private_key(&self) -> Self::PrivateKey;
    fn public_key(&self) -> Self::PublicKey;
    fn sign(
        &mut self,
        namespace: Option<&[u8]>,
        message: &[u8],
    ) -> Self::Signature;
    fn verify(
        namespace: Option<&[u8]>,
        message: &[u8],
        public_key: &Self::PublicKey,
        signature: &Self::Signature,
    ) -> bool;

    // Provided method
    fn from_seed(seed: u64) -> Self { ... }
}
Expand description

Interface that commonware crates rely on for most cryptographic operations.

Required Associated Types§

Source

type PrivateKey: Array

Private key used for signing.

Source

type PublicKey: Array

Public key used for verifying signatures.

Source

type Signature: Array

Signature generated by signing a message.

Required Methods§

Source

fn new<R: Rng + CryptoRng>(rng: &mut R) -> Self

Returns a new instance of the scheme.

Source

fn from(private_key: Self::PrivateKey) -> Option<Self>

Returns a new instance of the scheme from a secret key.

Source

fn private_key(&self) -> Self::PrivateKey

Returns the private key of the signer.

Source

fn public_key(&self) -> Self::PublicKey

Returns the public key of the signer.

Source

fn sign(&mut self, namespace: Option<&[u8]>, message: &[u8]) -> Self::Signature

Sign the given message.

The message should not be hashed prior to calling this function. If a particular scheme requires a payload to be hashed before it is signed, it will be done internally.

A namespace should be used to prevent replay attacks. It will be prepended to the message so that a signature meant for one context cannot be used unexpectedly in another (i.e. signing a message on the network layer can’t accidentally spend funds on the execution layer). See union_unique for details.

Source

fn verify( namespace: Option<&[u8]>, message: &[u8], public_key: &Self::PublicKey, signature: &Self::Signature, ) -> bool

Check that a signature is valid for the given message and public key.

The message should not be hashed prior to calling this function. If a particular scheme requires a payload to be hashed before it is signed, it will be done internally.

Because namespace is prepended to message before signing, the namespace provided here must match the namespace provided during signing.

Provided Methods§

Source

fn from_seed(seed: u64) -> Self

Returns a new instance of the scheme from a provided seed.

§Warning

This function is insecure and should only be used for examples and testing.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§