mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 11:38:01 +00:00
Application Crypto cleanup (#13746)
* Adjust application crypto docs * Blanket implementation for 'RuntimeAppPublic' trait * Blanket implementation for 'BoundToRuntimeAppPublic' for 'RuntimeAppPublic' * Relax type bounds * Docs fix * restore MaybeHash * Commit suggestion Co-authored-by: Anton <anton.kalyaev@gmail.com> --------- Co-authored-by: Anton <anton.kalyaev@gmail.com>
This commit is contained in:
@@ -48,14 +48,15 @@ mod traits;
|
||||
|
||||
pub use traits::*;
|
||||
|
||||
/// Declares Public, Pair, Signature types which are functionally equivalent to `$pair`, but are new
|
||||
/// Application-specific types whose identifier is `$key_type`.
|
||||
/// Declares `Public`, `Pair` and `Signature` types which are functionally equivalent
|
||||
/// to the corresponding types defined by `$module` but are new application-specific
|
||||
/// types whose identifier is `$key_type`.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
|
||||
/// // Declare a new set of crypto types using Ed25519 logic that identifies as `KeyTypeId`
|
||||
/// # use sp_application_crypto::{app_crypto, ed25519, KeyTypeId};
|
||||
/// // Declare a new set of crypto types using ed25519 logic that identifies as `KeyTypeId`
|
||||
/// // of value `b"fuba"`.
|
||||
/// app_crypto!(ed25519, KeyTypeId(*b"_uba"));
|
||||
/// app_crypto!(ed25519, KeyTypeId(*b"fuba"));
|
||||
/// ```
|
||||
#[cfg(feature = "full_crypto")]
|
||||
#[macro_export]
|
||||
@@ -78,14 +79,15 @@ macro_rules! app_crypto {
|
||||
};
|
||||
}
|
||||
|
||||
/// Declares Public, Pair, Signature types which are functionally equivalent to `$pair`, but are new
|
||||
/// Application-specific types whose identifier is `$key_type`.
|
||||
/// Declares `Public`, `Pair` and `Signature` types which are functionally equivalent
|
||||
/// to the corresponding types defined by `$module` but that are new application-specific
|
||||
/// types whose identifier is `$key_type`.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
|
||||
/// // Declare a new set of crypto types using Ed25519 logic that identifies as `KeyTypeId`
|
||||
/// # use sp_application_crypto::{app_crypto, ed25519, KeyTypeId};
|
||||
/// // Declare a new set of crypto types using ed25519 logic that identifies as `KeyTypeId`
|
||||
/// // of value `b"fuba"`.
|
||||
/// app_crypto!(ed25519, KeyTypeId(*b"_uba"));
|
||||
/// app_crypto!(ed25519, KeyTypeId(*b"fuba"));
|
||||
/// ```
|
||||
#[cfg(not(feature = "full_crypto"))]
|
||||
#[macro_export]
|
||||
@@ -107,8 +109,8 @@ macro_rules! app_crypto {
|
||||
};
|
||||
}
|
||||
|
||||
/// Declares Pair type which is functionally equivalent to `$pair`, but is new
|
||||
/// Application-specific type whose identifier is `$key_type`.
|
||||
/// Declares `Pair` type which is functionally equivalent to `$pair`, but is
|
||||
/// new application-specific type whose identifier is `$key_type`.
|
||||
#[macro_export]
|
||||
macro_rules! app_crypto_pair {
|
||||
($pair:ty, $key_type:expr, $crypto_type:expr) => {
|
||||
@@ -208,10 +210,10 @@ macro_rules! app_crypto_pair_functions_if_std {
|
||||
($pair:ty) => {};
|
||||
}
|
||||
|
||||
/// Declares Public type which is functionally equivalent to `$public`, but is new
|
||||
/// Application-specific type whose identifier is `$key_type`.
|
||||
/// can only be used together with `full_crypto` feature
|
||||
/// For full functionality, app_crypto_public_common! must be called too.
|
||||
/// Declares `Public` type which is functionally equivalent to `$public` but is
|
||||
/// new application-specific type whose identifier is `$key_type`.
|
||||
/// For full functionality, `app_crypto_public_common!` must be called too.
|
||||
/// Can only be used with `full_crypto` feature.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! app_crypto_public_full_crypto {
|
||||
@@ -244,10 +246,10 @@ macro_rules! app_crypto_public_full_crypto {
|
||||
};
|
||||
}
|
||||
|
||||
/// Declares Public type which is functionally equivalent to `$public`, but is new
|
||||
/// Application-specific type whose identifier is `$key_type`.
|
||||
/// can only be used without `full_crypto` feature
|
||||
/// For full functionality, app_crypto_public_common! must be called too.
|
||||
/// Declares `Public` type which is functionally equivalent to `$public` but is
|
||||
/// new application-specific type whose identifier is `$key_type`.
|
||||
/// For full functionality, `app_crypto_public_common!` must be called too.
|
||||
/// Can only be used without `full_crypto` feature.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! app_crypto_public_not_full_crypto {
|
||||
@@ -276,9 +278,9 @@ macro_rules! app_crypto_public_not_full_crypto {
|
||||
};
|
||||
}
|
||||
|
||||
/// Declares Public type which is functionally equivalent to `$public`, but is new
|
||||
/// Application-specific type whose identifier is `$key_type`.
|
||||
/// For full functionality, app_crypto_public_(not)_full_crypto! must be called too.
|
||||
/// Declares `Public` type which is functionally equivalent to `$public` but is
|
||||
/// new application-specific type whose identifier is `$key_type`.
|
||||
/// For full functionality, `app_crypto_public_(not)_full_crypto!` must be called too.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! app_crypto_public_common {
|
||||
@@ -307,40 +309,6 @@ macro_rules! app_crypto_public_common {
|
||||
type Generic = $public;
|
||||
}
|
||||
|
||||
impl $crate::RuntimeAppPublic for Public
|
||||
where
|
||||
$public: $crate::RuntimePublic<Signature = $sig>,
|
||||
{
|
||||
const ID: $crate::KeyTypeId = $key_type;
|
||||
const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type;
|
||||
|
||||
type Signature = Signature;
|
||||
|
||||
fn all() -> $crate::Vec<Self> {
|
||||
<$public as $crate::RuntimePublic>::all($key_type)
|
||||
.into_iter()
|
||||
.map(Self)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn generate_pair(seed: Option<$crate::Vec<u8>>) -> Self {
|
||||
Self(<$public as $crate::RuntimePublic>::generate_pair($key_type, seed))
|
||||
}
|
||||
|
||||
fn sign<M: AsRef<[u8]>>(&self, msg: &M) -> Option<Self::Signature> {
|
||||
<$public as $crate::RuntimePublic>::sign(self.as_ref(), $key_type, msg)
|
||||
.map(Signature)
|
||||
}
|
||||
|
||||
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
|
||||
<$public as $crate::RuntimePublic>::verify(self.as_ref(), msg, &signature.as_ref())
|
||||
}
|
||||
|
||||
fn to_raw_vec(&self) -> $crate::Vec<u8> {
|
||||
<$public as $crate::RuntimePublic>::to_raw_vec(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a [u8]> for Public {
|
||||
type Error = ();
|
||||
|
||||
@@ -407,8 +375,8 @@ macro_rules! app_crypto_public_common_if_std {
|
||||
|
||||
/// Declares Signature type which is functionally equivalent to `$sig`, but is new
|
||||
/// Application-specific type whose identifier is `$key_type`.
|
||||
/// can only be used together with `full_crypto` feature
|
||||
/// For full functionality, app_crypto_public_common! must be called too.
|
||||
/// Can only be used with `full_crypto` feature
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! app_crypto_signature_full_crypto {
|
||||
@@ -439,10 +407,10 @@ macro_rules! app_crypto_signature_full_crypto {
|
||||
};
|
||||
}
|
||||
|
||||
/// Declares Signature type which is functionally equivalent to `$sig`, but is new
|
||||
/// Application-specific type whose identifier is `$key_type`.
|
||||
/// can only be used without `full_crypto` feature
|
||||
/// For full functionality, app_crypto_public_common! must be called too.
|
||||
/// Declares `Signature` type which is functionally equivalent to `$sig`, but is new
|
||||
/// application-specific type whose identifier is `$key_type`.
|
||||
/// For full functionality, `app_crypto_signature_common` must be called too.
|
||||
/// Can only be used without `full_crypto` feature.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! app_crypto_signature_not_full_crypto {
|
||||
@@ -452,8 +420,8 @@ macro_rules! app_crypto_signature_not_full_crypto {
|
||||
#[derive(Clone, Eq, PartialEq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::scale_info::TypeInfo,
|
||||
$crate::RuntimeDebug,
|
||||
$crate::scale_info::TypeInfo,
|
||||
)]
|
||||
pub struct Signature($sig);
|
||||
}
|
||||
@@ -469,9 +437,9 @@ macro_rules! app_crypto_signature_not_full_crypto {
|
||||
};
|
||||
}
|
||||
|
||||
/// Declares Signature type which is functionally equivalent to `$sig`, but is new
|
||||
/// Application-specific type whose identifier is `$key_type`.
|
||||
/// For full functionality, app_crypto_public_(not)_full_crypto! must be called too.
|
||||
/// Declares `Signature` type which is functionally equivalent to `$sig`, but is new
|
||||
/// application-specific type whose identifier is `$key_type`.
|
||||
/// For full functionality, app_crypto_signature_(not)_full_crypto! must be called too.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! app_crypto_signature_common {
|
||||
|
||||
Reference in New Issue
Block a user