Trait Signer

Source
pub trait Signer:
    Specification
    + Clone
    + Send
    + Sync
    + 'static {
    type PrivateKey: Array;

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

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

Implementation that can sign a message with a PrivateKey.

Required Associated Types§

Source

type PrivateKey: Array

Private key used for signing.

Required Methods§

Source

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

Returns a new instance of the scheme.

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

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§