diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index 9c6954db28..7370a5074f 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -35,6 +35,7 @@ use rstd::ops::{ Add, Sub, Mul, Div, Rem, AddAssign, SubAssign, MulAssign, DivAssign, RemAssign, Shl, Shr }; +use crate::AppKey; /// A lazy value. pub trait Lazy { @@ -70,6 +71,28 @@ impl Verify for primitives::sr25519::Signature { } } +/// Means of signature verification of an application key. +pub trait AppVerify { + /// Type of the signer. + type Signer; + /// Verify a signature. Return `true` if signature is valid for the value. + fn verify>(&self, msg: L, signer: &Self::Signer) -> bool; +} + +impl< + S: Verify::Public as app_crypto::AppPublic>::Generic> + From, + T: app_crypto::Wraps + app_crypto::AppKey + app_crypto::AppSignature + + AsRef + AsMut + From, +> AppVerify for T { + type Signer = ::Public; + fn verify>(&self, msg: L, signer: &Self::Signer) -> bool { + use app_crypto::IsWrappedBy; + let inner: &S = self.as_ref(); + let inner_pubkey = ::Generic::from_ref(&signer); + Verify::verify(inner, msg, inner_pubkey) + } +} + /// Some sort of check on the origin is performed by this object. pub trait EnsureOrigin { /// A return type.