diff --git a/primitives/application-crypto/src/lib.rs b/primitives/application-crypto/src/lib.rs index 8bad474ede81e..b69b8b6877f79 100644 --- a/primitives/application-crypto/src/lib.rs +++ b/primitives/application-crypto/src/lib.rs @@ -25,7 +25,7 @@ pub use sp_core::{self, crypto::{CryptoType, CryptoTypePublicPair, Public, Deriv #[doc(hidden)] #[cfg(feature = "full_crypto")] pub use sp_core::crypto::{SecretStringError, DeriveJunction, Ss58Codec, Pair}; -pub use sp_core::crypto::{KeyTypeId, key_types}; +pub use sp_core::crypto::{KeyTypeId, CryptoTypeId, key_types}; #[doc(hidden)] pub use codec; @@ -55,7 +55,7 @@ pub use traits::*; macro_rules! app_crypto { ($module:ident, $key_type:expr) => { $crate::app_crypto_public_full_crypto!($module::Public, $key_type); - $crate::app_crypto_public_common!($module::Public, $module::Signature, $key_type); + $crate::app_crypto_public_common!($module::Public, $module::Signature, $key_type, $module::CRYPTO_ID); $crate::app_crypto_signature_full_crypto!($module::Signature, $key_type); $crate::app_crypto_signature_common!($module::Signature, $key_type); $crate::app_crypto_pair!($module::Pair, $key_type); @@ -76,7 +76,7 @@ macro_rules! app_crypto { macro_rules! app_crypto { ($module:ident, $key_type:expr) => { $crate::app_crypto_public_not_full_crypto!($module::Public, $key_type); - $crate::app_crypto_public_common!($module::Public, $module::Signature, $key_type); + $crate::app_crypto_public_common!($module::Public, $module::Signature, $key_type, $module::CRYPTO_ID); $crate::app_crypto_signature_not_full_crypto!($module::Signature, $key_type); $crate::app_crypto_signature_common!($module::Signature, $key_type); }; @@ -246,7 +246,7 @@ macro_rules! app_crypto_public_not_full_crypto { #[doc(hidden)] #[macro_export] macro_rules! app_crypto_public_common { - ($public:ty, $sig:ty, $key_type:expr) => { + ($public:ty, $sig:ty, $key_type:expr, $crypto_type:expr) => { $crate::app_crypto_public_common_if_std!(); impl AsRef<[u8]> for Public { @@ -267,6 +267,8 @@ macro_rules! app_crypto_public_common { impl $crate::RuntimeAppPublic for Public where $public: $crate::RuntimePublic { const ID: $crate::KeyTypeId = $key_type; + const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type; + type Signature = Signature; fn all() -> $crate::Vec { diff --git a/primitives/application-crypto/src/traits.rs b/primitives/application-crypto/src/traits.rs index 2af039a88df4c..2983b143df1ec 100644 --- a/primitives/application-crypto/src/traits.rs +++ b/primitives/application-crypto/src/traits.rs @@ -18,7 +18,7 @@ use sp_core::crypto::Pair; use codec::Codec; -use sp_core::crypto::{KeyTypeId, CryptoType, IsWrappedBy, Public}; +use sp_core::crypto::{KeyTypeId, CryptoType, CryptoTypeId, IsWrappedBy, Public}; use sp_std::{fmt::Debug, vec::Vec}; /// An application-specific key. @@ -115,6 +115,8 @@ pub trait RuntimePublic: Sized { pub trait RuntimeAppPublic: Sized { /// An identifier for this application-specific key type. const ID: KeyTypeId; + /// The identifier of the crypto type of this application-specific key type. + const CRYPTO_ID: CryptoTypeId; /// The signature that will be generated when signing with the corresponding private key. type Signature: Codec + Debug + MaybeHash + Eq + PartialEq + Clone; diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index a5b3e71edcde3..b55edbd88d7f1 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -62,7 +62,7 @@ pub use crate::runtime_string::*; pub use generic::{DigestItem, Digest}; /// Re-export this since it's part of the API of this crate. -pub use sp_core::{TypeId, crypto::{key_types, KeyTypeId, CryptoType, AccountId32}}; +pub use sp_core::{TypeId, crypto::{key_types, KeyTypeId, CryptoType, CryptoTypeId, AccountId32}}; pub use sp_application_crypto::{RuntimeAppPublic, BoundToRuntimeAppPublic}; /// Re-export `RuntimeDebug`, to avoid dependency clutter. diff --git a/primitives/runtime/src/testing.rs b/primitives/runtime/src/testing.rs index 40b4e23e3fa0a..333f78f515106 100644 --- a/primitives/runtime/src/testing.rs +++ b/primitives/runtime/src/testing.rs @@ -24,7 +24,7 @@ use crate::traits::{ SignedExtension, Dispatchable, DispatchInfoOf, }; use crate::traits::ValidateUnsigned; -use crate::{generic, KeyTypeId, ApplyExtrinsicResult}; +use crate::{generic, KeyTypeId, CryptoTypeId, ApplyExtrinsicResult}; pub use sp_core::{H256, sr25519}; use sp_core::{crypto::{CryptoType, Dummy, key_types, Public}, U256}; use crate::transaction_validity::{TransactionValidity, TransactionValidityError, TransactionSource}; @@ -86,6 +86,7 @@ impl UintAuthorityId { impl sp_application_crypto::RuntimeAppPublic for UintAuthorityId { const ID: KeyTypeId = key_types::DUMMY; + const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"dumm"); type Signature = TestSignature;