mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Remove unused key types sr25 and ed25 (#3659)
* Remove unused key types sr25 and ed25. * Restore in specific files to fix build. * Fix runtime tests * Fix keystore test * Revert typo * Move keytypes to primitives/src/testing.rs * More missed items. * Getting close now. * Fix example in documentation. * Update core/application-crypto/src/ed25519.rs * Update core/application-crypto/src/sr25519.rs * Bump impl version.
This commit is contained in:
committed by
Gavin Wood
parent
c25d7386cf
commit
210290f8ca
@@ -21,7 +21,7 @@ use crate::{RuntimePublic, KeyTypeId};
|
||||
pub use primitives::ed25519::*;
|
||||
|
||||
mod app {
|
||||
use crate::key_types::ED25519;
|
||||
use primitives::testing::ED25519;
|
||||
crate::app_crypto!(super, ED25519);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,14 @@ impl RuntimePublic for Public {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sr_primitives::{generic::BlockId, traits::ProvideRuntimeApi};
|
||||
use primitives::{testing::KeyStore, crypto::Pair, traits::BareCryptoStore as _};
|
||||
use primitives::{
|
||||
testing::{
|
||||
KeyStore,
|
||||
ED25519,
|
||||
},
|
||||
crypto::Pair,
|
||||
traits::BareCryptoStore as _,
|
||||
};
|
||||
use test_client::{
|
||||
TestClientBuilder, DefaultTestClientBuilderExt, TestClientBuilderExt,
|
||||
runtime::{TestAPI, app_crypto::ed25519::{AppPair, AppPublic}},
|
||||
@@ -67,7 +74,7 @@ mod tests {
|
||||
.test_ed25519_crypto(&BlockId::Number(0))
|
||||
.expect("Tests `ed25519` crypto.");
|
||||
|
||||
let key_pair = keystore.read().ed25519_key_pair(crate::key_types::ED25519, &public.as_ref())
|
||||
let key_pair = keystore.read().ed25519_key_pair(ED25519, &public.as_ref())
|
||||
.expect("There should be at a `ed25519` key in the keystore for the given public key.");
|
||||
|
||||
assert!(AppPair::verify(&signature, "ed25519", &AppPublic::from(key_pair.public())));
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::{RuntimePublic, KeyTypeId};
|
||||
pub use primitives::sr25519::*;
|
||||
|
||||
mod app {
|
||||
use crate::key_types::SR25519;
|
||||
use primitives::testing::SR25519;
|
||||
crate::app_crypto!(super, SR25519);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,14 @@ impl RuntimePublic for Public {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sr_primitives::{generic::BlockId, traits::ProvideRuntimeApi};
|
||||
use primitives::{testing::KeyStore, crypto::Pair, traits::BareCryptoStore as _};
|
||||
use primitives::{
|
||||
testing::{
|
||||
KeyStore,
|
||||
SR25519,
|
||||
},
|
||||
crypto::Pair,
|
||||
traits::BareCryptoStore as _,
|
||||
};
|
||||
use test_client::{
|
||||
TestClientBuilder, DefaultTestClientBuilderExt, TestClientBuilderExt,
|
||||
runtime::{TestAPI, app_crypto::sr25519::{AppPair, AppPublic}},
|
||||
@@ -67,7 +74,7 @@ mod tests {
|
||||
.test_sr25519_crypto(&BlockId::Number(0))
|
||||
.expect("Tests `sr25519` crypto.");
|
||||
|
||||
let key_pair = keystore.read().sr25519_key_pair(crate::key_types::SR25519, public.as_ref())
|
||||
let key_pair = keystore.read().sr25519_key_pair(SR25519, public.as_ref())
|
||||
.expect("There should be at a `sr25519` key in the keystore for the given public key.");
|
||||
|
||||
assert!(AppPair::verify(&signature, "sr25519", &AppPublic::from(key_pair.public())));
|
||||
|
||||
@@ -318,7 +318,7 @@ impl BareCryptoStore for Store {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempdir::TempDir;
|
||||
use primitives::crypto::{Ss58Codec, key_types};
|
||||
use primitives::{testing::{SR25519}, crypto::{Ss58Codec}};
|
||||
|
||||
#[test]
|
||||
fn basic_store() {
|
||||
@@ -410,14 +410,14 @@ mod tests {
|
||||
let key_pair = sr25519::AppPair::from_string(secret_uri, None).expect("Generates key pair");
|
||||
|
||||
store.write().insert_unknown(
|
||||
key_types::SR25519,
|
||||
SR25519,
|
||||
secret_uri,
|
||||
key_pair.public().as_ref(),
|
||||
).expect("Inserts unknown key");
|
||||
|
||||
let store_key_pair = store.read().key_pair_by_type::<sr25519::AppPair>(
|
||||
&key_pair.public(),
|
||||
key_types::SR25519,
|
||||
SR25519,
|
||||
).expect("Gets key pair from keystore");
|
||||
|
||||
assert_eq!(key_pair.public(), store_key_pair.public());
|
||||
|
||||
@@ -780,10 +780,6 @@ impl<'a> TryFrom<&'a str> for KeyTypeId {
|
||||
pub mod key_types {
|
||||
use super::KeyTypeId;
|
||||
|
||||
/// Key type for generic S/R 25519 key.
|
||||
pub const SR25519: KeyTypeId = KeyTypeId(*b"sr25");
|
||||
/// Key type for generic Ed25519 key.
|
||||
pub const ED25519: KeyTypeId = KeyTypeId(*b"ed25");
|
||||
/// Key type for Babe module, build-in.
|
||||
pub const BABE: KeyTypeId = KeyTypeId(*b"babe");
|
||||
/// Key type for Grandpa module, build-in.
|
||||
|
||||
@@ -17,7 +17,14 @@
|
||||
//! Types that should only be used for testing!
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use crate::{ed25519, sr25519, crypto::{Public, Pair, KeyTypeId}};
|
||||
use crate::{ed25519, sr25519, crypto::{Public, Pair}};
|
||||
use crate::crypto::KeyTypeId; // No idea why this import had to move from
|
||||
// the previous line, but now the compiler is happy
|
||||
|
||||
/// Key type for generic Ed25519 key.
|
||||
pub const ED25519: KeyTypeId = KeyTypeId(*b"ed25");
|
||||
/// Key type for generic Sr 25519 key.
|
||||
pub const SR25519: KeyTypeId = KeyTypeId(*b"sr25");
|
||||
|
||||
/// A keystore implementation usable in tests.
|
||||
#[cfg(feature = "std")]
|
||||
@@ -126,18 +133,20 @@ impl crate::traits::BareCryptoStore for KeyStore {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{sr25519, crypto::key_types, traits::BareCryptoStore};
|
||||
use crate::{sr25519, traits::BareCryptoStore};
|
||||
use crate::testing::{ED25519, SR25519};
|
||||
|
||||
|
||||
#[test]
|
||||
fn store_key_and_extract() {
|
||||
let store = KeyStore::new();
|
||||
|
||||
let public = store.write()
|
||||
.ed25519_generate_new(key_types::ED25519, None)
|
||||
.ed25519_generate_new(ED25519, None)
|
||||
.expect("Genrates key");
|
||||
|
||||
let store_key_pair = store.read()
|
||||
.ed25519_key_pair(key_types::ED25519, &public)
|
||||
.ed25519_key_pair(ED25519, &public)
|
||||
.expect("Key should exists in store");
|
||||
|
||||
assert_eq!(public, store_key_pair.public());
|
||||
@@ -151,13 +160,13 @@ mod tests {
|
||||
let key_pair = sr25519::Pair::from_string(secret_uri, None).expect("Generates key pair");
|
||||
|
||||
store.write().insert_unknown(
|
||||
key_types::SR25519,
|
||||
SR25519,
|
||||
secret_uri,
|
||||
key_pair.public().as_ref(),
|
||||
).expect("Inserts unknown key");
|
||||
|
||||
let store_key_pair = store.read().sr25519_key_pair(
|
||||
key_types::SR25519,
|
||||
SR25519,
|
||||
&key_pair.public(),
|
||||
).expect("Gets key pair from keystore");
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ use transaction_pool::{
|
||||
};
|
||||
use futures::Stream;
|
||||
use primitives::{
|
||||
H256, blake2_256, hexdisplay::HexDisplay, traits::BareCryptoStore, testing::KeyStore,
|
||||
ed25519, crypto::{key_types, Pair},
|
||||
H256, blake2_256, hexdisplay::HexDisplay, traits::BareCryptoStore,
|
||||
testing::{ED25519, SR25519, KeyStore}, ed25519, crypto::Pair
|
||||
};
|
||||
use test_client::{
|
||||
self, AccountKeyring, runtime::{Extrinsic, Transfer, SessionKeys}, DefaultTestClientBuilderExt,
|
||||
@@ -198,13 +198,13 @@ fn should_insert_key() {
|
||||
let suri = "//Alice";
|
||||
let key_pair = ed25519::Pair::from_string(suri, None).expect("Generates keypair");
|
||||
p.insert_key(
|
||||
String::from_utf8(key_types::ED25519.0.to_vec()).expect("Keytype is a valid string"),
|
||||
String::from_utf8(ED25519.0.to_vec()).expect("Keytype is a valid string"),
|
||||
suri.to_string(),
|
||||
key_pair.public().0.to_vec().into(),
|
||||
).expect("Insert key");
|
||||
|
||||
let store_key_pair = keystore.read()
|
||||
.ed25519_key_pair(key_types::ED25519, &key_pair.public()).expect("Key exists in store");
|
||||
.ed25519_key_pair(ED25519, &key_pair.public()).expect("Key exists in store");
|
||||
|
||||
assert_eq!(key_pair.public(), store_key_pair.public());
|
||||
}
|
||||
@@ -227,12 +227,12 @@ fn should_rotate_keys() {
|
||||
.expect("SessionKeys decode successfully");
|
||||
|
||||
let ed25519_key_pair = keystore.read().ed25519_key_pair(
|
||||
key_types::ED25519,
|
||||
ED25519,
|
||||
&session_keys.ed25519.clone().into(),
|
||||
).expect("ed25519 key exists in store");
|
||||
|
||||
let sr25519_key_pair = keystore.read().sr25519_key_pair(
|
||||
key_types::SR25519,
|
||||
SR25519,
|
||||
&session_keys.sr25519.clone().into(),
|
||||
).expect("sr25519 key exists in store");
|
||||
|
||||
|
||||
@@ -1180,13 +1180,14 @@ macro_rules! count {
|
||||
/// just the bytes of the key.
|
||||
///
|
||||
/// ```rust
|
||||
/// use sr_primitives::{impl_opaque_keys, key_types, KeyTypeId, app_crypto::{sr25519, ed25519}};
|
||||
/// use sr_primitives::{impl_opaque_keys, KeyTypeId, app_crypto::{sr25519, ed25519}};
|
||||
/// use primitives::testing::{SR25519, ED25519};
|
||||
///
|
||||
/// impl_opaque_keys! {
|
||||
/// pub struct Keys {
|
||||
/// #[id(key_types::ED25519)]
|
||||
/// #[id(ED25519)]
|
||||
/// pub ed25519: ed25519::AppPublic,
|
||||
/// #[id(key_types::SR25519)]
|
||||
/// #[id(SR25519)]
|
||||
/// pub sr25519: sr25519::AppPublic,
|
||||
/// }
|
||||
/// }
|
||||
|
||||
@@ -25,7 +25,14 @@ pub mod system;
|
||||
use rstd::{prelude::*, marker::PhantomData};
|
||||
use codec::{Encode, Decode, Input, Error};
|
||||
|
||||
use primitives::{Blake2Hasher, OpaqueMetadata};
|
||||
use primitives::{
|
||||
Blake2Hasher,
|
||||
OpaqueMetadata,
|
||||
testing::{
|
||||
ED25519,
|
||||
SR25519,
|
||||
}
|
||||
};
|
||||
use app_crypto::{ed25519, sr25519, RuntimeAppPublic};
|
||||
pub use app_crypto;
|
||||
use trie_db::{TrieMut, Trie};
|
||||
@@ -47,7 +54,7 @@ use sr_primitives::{
|
||||
},
|
||||
};
|
||||
use runtime_version::RuntimeVersion;
|
||||
pub use primitives::{hash::H256, crypto::key_types};
|
||||
pub use primitives::{hash::H256};
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use runtime_version::NativeVersion;
|
||||
use runtime_support::{impl_outer_origin, parameter_types};
|
||||
@@ -446,9 +453,9 @@ fn code_using_trie() -> u64 {
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
#[id(key_types::ED25519)]
|
||||
#[id(ED25519)]
|
||||
pub ed25519: ed25519::AppPublic,
|
||||
#[id(key_types::SR25519)]
|
||||
#[id(SR25519)]
|
||||
pub sr25519: sr25519::AppPublic,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 160,
|
||||
impl_version: 160,
|
||||
impl_version: 161,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user