Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add crypto identifier to RuntimeAppPublic #5965

Merged
merged 5 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions primitives/application-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
};
Expand Down Expand Up @@ -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 {
Expand All @@ -267,6 +267,8 @@ macro_rules! app_crypto_public_common {

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> {
Expand Down
4 changes: 3 additions & 1 deletion primitives/application-crypto/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -115,6 +115,8 @@ pub trait RuntimePublic: Sized {
pub trait RuntimeAppPublic: Sized {
/// An identifier for this application-specific key type.
const ID: KeyTypeId;
/// An identifier for this application-specific crypto type.
rakanalh marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down
2 changes: 1 addition & 1 deletion primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion primitives/runtime/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;

Expand Down