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: CryptoHash + Serialize>(
        &self,
        message: &T,
        public_key: &Self::VerifyingKeyMaterial
    ) -> Result<()>;
    fn verify_arbitrary_msg(
        &self,
        message: &[u8],
        public_key: &Self::VerifyingKeyMaterial
    ) -> Result<()>;
    fn to_bytes(&self) -> Vec<u8> ;

    // Provided method
    fn batch_verify<T: CryptoHash + Serialize>(
        message: &T,
        keys_and_signatures: Vec<(Self::VerifyingKeyMaterial, Self)>
    ) -> Result<()> { ... }
}
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§

source

type VerifyingKeyMaterial: VerifyingKey<SignatureMaterial = Self>

The associated verifying key type for this signature.

source

type SigningKeyMaterial: SigningKey<SignatureMaterial = Self>

The associated signing key type for this signature

Required Methods§

source

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

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

source

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

Native verification function.

source

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

Convert the signature into a byte representation.

Provided Methods§

source

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

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§