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§
Sourcetype PrivateKey: Array
type PrivateKey: Array
Private key used for signing.
Required Methods§
Sourcefn from(private_key: Self::PrivateKey) -> Option<Self>
fn from(private_key: Self::PrivateKey) -> Option<Self>
Returns a new instance of the scheme from a secret key.
Sourcefn private_key(&self) -> Self::PrivateKey
fn private_key(&self) -> Self::PrivateKey
Returns the private key of the signer.
Sourcefn public_key(&self) -> Self::PublicKey
fn public_key(&self) -> Self::PublicKey
Returns the public key of the signer.
Sourcefn sign(&mut self, namespace: Option<&[u8]>, message: &[u8]) -> Self::Signature
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.
Sourcefn verify(
namespace: Option<&[u8]>,
message: &[u8],
public_key: &Self::PublicKey,
signature: &Self::Signature,
) -> bool
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§
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.