Trait commonware_cryptography::Scheme
source · pub trait Scheme:
Send
+ Sync
+ Clone
+ 'static {
// Required methods
fn me(&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;
}
Expand description
Interface that commonware crates rely on for most cryptographic operations.
Required Methods§
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.