#[cfg(feature = "full_crypto")]
use sp_core::crypto::Pair;
use codec::Codec;
use sp_core::crypto::{CryptoType, CryptoTypeId, IsWrappedBy, KeyTypeId, Public};
use sp_std::{fmt::Debug, vec::Vec};
pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone {
type UntypedGeneric: IsWrappedBy<Self>;
type Public: AppPublic;
#[cfg(feature = "full_crypto")]
type Pair: AppPair;
type Signature: AppSignature;
const ID: KeyTypeId;
const CRYPTO_ID: CryptoTypeId;
}
#[cfg(any(feature = "std", feature = "full_crypto"))]
pub trait MaybeHash: sp_std::hash::Hash {}
#[cfg(any(feature = "std", feature = "full_crypto"))]
impl<T: sp_std::hash::Hash> MaybeHash for T {}
#[cfg(all(not(feature = "std"), not(feature = "full_crypto")))]
pub trait MaybeHash {}
#[cfg(all(not(feature = "std"), not(feature = "full_crypto")))]
impl<T> MaybeHash for T {}
#[cfg(all(not(feature = "std"), feature = "full_crypto"))]
pub trait MaybeDebugHash: sp_std::hash::Hash {}
#[cfg(all(not(feature = "std"), feature = "full_crypto"))]
impl<T: sp_std::hash::Hash> MaybeDebugHash for T {}
pub trait AppPublic:
AppKey + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec
{
type Generic: IsWrappedBy<Self>
+ Public
+ Ord
+ PartialOrd
+ Eq
+ PartialEq
+ Debug
+ MaybeHash
+ codec::Codec;
}
#[cfg(feature = "full_crypto")]
pub trait AppPair: AppKey + Pair<Public = <Self as AppKey>::Public> {
type Generic: IsWrappedBy<Self>
+ Pair<Public = <<Self as AppKey>::Public as AppPublic>::Generic>;
}
pub trait AppSignature: AppKey + Eq + PartialEq + Debug + MaybeHash {
type Generic: IsWrappedBy<Self> + Eq + PartialEq + Debug + MaybeHash;
}
pub trait RuntimePublic: Sized {
type Signature: Codec + Debug + MaybeHash + Eq + PartialEq + Clone;
fn all(key_type: KeyTypeId) -> crate::Vec<Self>;
fn generate_pair(key_type: KeyTypeId, seed: Option<Vec<u8>>) -> Self;
fn sign<M: AsRef<[u8]>>(&self, key_type: KeyTypeId, msg: &M) -> Option<Self::Signature>;
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool;
fn to_raw_vec(&self) -> Vec<u8>;
}
pub trait RuntimeAppPublic: Sized {
const ID: KeyTypeId;
const CRYPTO_ID: CryptoTypeId;
type Signature: Codec + Debug + MaybeHash + Eq + PartialEq + Clone + scale_info::TypeInfo;
fn all() -> crate::Vec<Self>;
fn generate_pair(seed: Option<Vec<u8>>) -> Self;
fn sign<M: AsRef<[u8]>>(&self, msg: &M) -> Option<Self::Signature>;
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool;
fn to_raw_vec(&self) -> Vec<u8>;
}
pub trait BoundToRuntimeAppPublic {
type Public: RuntimeAppPublic;
}