mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 20:11:03 +00:00
Introduce AppVerify (#3343)
This trait, which works just like `Verify`, except on AppKey types. I'd like for it all just to be `Verify`, but Rust's trait rules concerning upstream changes mean it can't happen. This is a simple workaround needed for some stuff in Polkadot.
This commit is contained in:
@@ -35,6 +35,7 @@ use rstd::ops::{
|
|||||||
Add, Sub, Mul, Div, Rem, AddAssign, SubAssign, MulAssign, DivAssign,
|
Add, Sub, Mul, Div, Rem, AddAssign, SubAssign, MulAssign, DivAssign,
|
||||||
RemAssign, Shl, Shr
|
RemAssign, Shl, Shr
|
||||||
};
|
};
|
||||||
|
use crate::AppKey;
|
||||||
|
|
||||||
/// A lazy value.
|
/// A lazy value.
|
||||||
pub trait Lazy<T: ?Sized> {
|
pub trait Lazy<T: ?Sized> {
|
||||||
@@ -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<L: Lazy<[u8]>>(&self, msg: L, signer: &Self::Signer) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
S: Verify<Signer=<<T as AppKey>::Public as app_crypto::AppPublic>::Generic> + From<T>,
|
||||||
|
T: app_crypto::Wraps<Inner=S> + app_crypto::AppKey + app_crypto::AppSignature +
|
||||||
|
AsRef<S> + AsMut<S> + From<S>,
|
||||||
|
> AppVerify for T {
|
||||||
|
type Signer = <T as AppKey>::Public;
|
||||||
|
fn verify<L: Lazy<[u8]>>(&self, msg: L, signer: &Self::Signer) -> bool {
|
||||||
|
use app_crypto::IsWrappedBy;
|
||||||
|
let inner: &S = self.as_ref();
|
||||||
|
let inner_pubkey = <Self::Signer as app_crypto::AppPublic>::Generic::from_ref(&signer);
|
||||||
|
Verify::verify(inner, msg, inner_pubkey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Some sort of check on the origin is performed by this object.
|
/// Some sort of check on the origin is performed by this object.
|
||||||
pub trait EnsureOrigin<OuterOrigin> {
|
pub trait EnsureOrigin<OuterOrigin> {
|
||||||
/// A return type.
|
/// A return type.
|
||||||
|
|||||||
Reference in New Issue
Block a user