pub trait Signature: for<'a> TryFrom<&'a [u8], Error = CryptoMaterialError> + Sized + Debug + Clone + Eq + Hash + Sealed {
    type VerifyingKeyMaterial: VerifyingKey<SignatureMaterial = Self>;
    type SigningKeyMaterial: SigningKey<SignatureMaterial = Self>;

    // Required methods
    fn verify<T>(
        &self,
        message: &T,
        public_key: &Self::VerifyingKeyMaterial
    ) -> Result<(), Error>
       where T: CryptoHash + Serialize;
    fn verify_arbitrary_msg(
        &self,
        message: &[u8],
        public_key: &Self::VerifyingKeyMaterial
    ) -> Result<(), Error>;
    fn to_bytes(&self) -> Vec<u8, Global> ;

    // Provided method
    fn batch_verify<T>(
        message: &T,
        keys_and_signatures: Vec<(Self::VerifyingKeyMaterial, Self), Global>
    ) -> Result<(), Error>
       where T: CryptoHash + Serialize { ... }
}
Expand description

A type family for signature material that knows which public key type is needed to verify it, and given such a public key, knows how to verify.

This trait simply requires an association to some type of the PublicKey family of which we are the SignatureMaterial.

This trait has a requirement on a pub(crate) marker trait meant to specifically limit its implementations to the present crate.

It should be possible to write a generic signature function that checks signature material passed as &[u8] and only returns Ok when that material de-serializes to a signature of the expected concrete scheme. This would be done as an extension trait of Signature.

Required Associated Types§

type VerifyingKeyMaterial: VerifyingKey<SignatureMaterial = Self>

The associated verifying key type for this signature.

type SigningKeyMaterial: SigningKey<SignatureMaterial = Self>

The associated signing key type for this signature

Required Methods§

fn verify<T>( &self, message: &T, public_key: &Self::VerifyingKeyMaterial ) -> Result<(), Error>where T: CryptoHash + Serialize,

Verification for a struct we unabmiguously know how to serialize and that we have a domain separation prefix for.

fn verify_arbitrary_msg( &self, message: &[u8], public_key: &Self::VerifyingKeyMaterial ) -> Result<(), Error>

Native verification function.

fn to_bytes(&self) -> Vec<u8, Global>

Convert the signature into a byte representation.

Provided Methods§

fn batch_verify<T>( message: &T, keys_and_signatures: Vec<(Self::VerifyingKeyMaterial, Self), Global> ) -> Result<(), Error>where T: CryptoHash + Serialize,

The implementer can override a batch verification implementation that by default iterates over each signature. More efficient implementations exist and should be implemented for many schemes.

Implementors§