pub trait Scheme:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn new<R: Rng + CryptoRng>(rng: &mut R) -> Self;
fn from(private_key: PrivateKey) -> Option<Self>;
fn from_seed(seed: u64) -> Self;
fn private_key(&self) -> PrivateKey;
fn public_key(&self) -> PublicKey;
fn validate(public_key: &PublicKey) -> bool;
fn sign(&mut self, namespace: &[u8], message: &[u8]) -> Signature;
fn verify(
namespace: &[u8],
message: &[u8],
public_key: &PublicKey,
signature: &Signature,
) -> bool;
fn len() -> (usize, usize);
}
Expand description
Interface that commonware crates rely on for most cryptographic operations.
Required Methods§
Sourcefn from(private_key: PrivateKey) -> Option<Self>
fn from(private_key: PrivateKey) -> Option<Self>
Returns a new instance of the scheme from a secret key.
Sourcefn from_seed(seed: u64) -> Self
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.
Sourcefn private_key(&self) -> PrivateKey
fn private_key(&self) -> PrivateKey
Returns the serialized private key of the signer.
Sourcefn public_key(&self) -> PublicKey
fn public_key(&self) -> PublicKey
Returns the serialized public key of the signer.
Sourcefn sign(&mut self, namespace: &[u8], message: &[u8]) -> Signature
fn sign(&mut self, namespace: &[u8], message: &[u8]) -> 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.
To protect against replay attacks, it is required to provide a namespace to prefix any message. This ensures 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).
Sourcefn verify(
namespace: &[u8],
message: &[u8],
public_key: &PublicKey,
signature: &Signature,
) -> bool
fn verify( namespace: &[u8], message: &[u8], public_key: &PublicKey, signature: &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.
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.