mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
Refactor key management (#3296)
* Add Call type to extensible transactions. Cleanup some naming * Merge Resource and BlockExhausted into just Exhausted * Fix * Another fix * Call * Some fixes * Fix srml tests. * Fix all tests. * Refactor crypto so each application of it has its own type. * Introduce new AuthorityProvider API into Aura This will eventually allow for dynamic determination of authority keys and avoid having to set them directly on CLI. * Introduce authority determinator for Babe. Experiment with modular consensus API. * Work in progress to introduce KeyTypeId and avoid polluting API with validator IDs * Finish up drafting imonline * Rework offchain workers API. * Rework API implementation. * Make it compile for wasm, simplify app_crypto. * Fix compilation of im-online. * Fix compilation of im-online. * Fix more compilation errors. * Make it compile. * Fixing tests. * Rewrite `keystore` * Fix session tests * Bring back `TryFrom`'s' * Fix `srml-grandpa` * Fix `srml-aura` * Fix consensus babe * More fixes * Make service generate keys from dev_seed * Build fixes * Remove offchain tests * More fixes and cleanups * Fixes finality grandpa * Fix `consensus-aura` * Fix cli * Fix `node-cli` * Fix chain_spec builder * Fix doc tests * Add authority getter for grandpa. * Test fix * Fixes * Make keystore accessible from the runtime * Move app crypto to its own crate * Update `Cargo.lock` * Make the crypto stuff usable from the runtime * Adds some runtime crypto tests * Use last finalized block for grandpa authority * Fix warning * Adds `SessionKeys` runtime api * Remove `FinalityPair` and `ConsensusPair` * Minor governance tweaks to get it inline with docs. * Make the governance be up to date with the docs. * Build fixes. * Generate the inital session keys * Failing keystore is a hard error * Make babe work again * Fix grandpa * Fix tests * Disable `keystore` in consensus critical stuff * Build fix. * ImOnline supports multiple authorities at once. * Update core/application-crypto/src/ed25519.rs * Merge branch 'master' into gav-in-progress * Remove unneeded code for now. * Some `session` testing * Support querying the public keys * Cleanup offchain * Remove warnings * More cleanup * Apply suggestions from code review Co-Authored-By: Benjamin Kampmann <ben.kampmann@googlemail.com> * More cleanups * JSONRPC API for setting keys. Also, rename traits::KeyStore* -> traits::BareCryptoStore* * Bad merge * Fix integration tests * Fix test build * Test fix * Fixes * Warnings * Another warning * Bump version.
This commit is contained in:
@@ -25,7 +25,9 @@ pub mod system;
|
||||
use rstd::{prelude::*, marker::PhantomData};
|
||||
use codec::{Encode, Decode, Input, Error};
|
||||
|
||||
use primitives::Blake2Hasher;
|
||||
use primitives::{Blake2Hasher, OpaqueMetadata};
|
||||
use app_crypto::{ed25519, sr25519, RuntimeAppPublic};
|
||||
pub use app_crypto;
|
||||
use trie_db::{TrieMut, Trie};
|
||||
use substrate_trie::PrefixedMemoryDB;
|
||||
use substrate_trie::trie_types::{TrieDB, TrieDBMut};
|
||||
@@ -44,7 +46,6 @@ use sr_primitives::{
|
||||
};
|
||||
use runtime_version::RuntimeVersion;
|
||||
pub use primitives::hash::H256;
|
||||
use primitives::{sr25519, OpaqueMetadata};
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use runtime_version::NativeVersion;
|
||||
use runtime_support::{impl_outer_origin, parameter_types};
|
||||
@@ -53,7 +54,7 @@ use cfg_if::cfg_if;
|
||||
|
||||
// Ensure Babe and Aura use the same crypto to simplify things a bit.
|
||||
pub use babe_primitives::AuthorityId;
|
||||
pub type AuraId = AuthorityId;
|
||||
pub type AuraId = aura_primitives::sr25519::AuthorityId;
|
||||
|
||||
// Inlucde the WASM binary
|
||||
#[cfg(feature = "std")]
|
||||
@@ -139,7 +140,7 @@ impl BlindCheckable for Extrinsic {
|
||||
}
|
||||
|
||||
impl ExtrinsicT for Extrinsic {
|
||||
type Call = ();
|
||||
type Call = Extrinsic;
|
||||
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
if let Extrinsic::IncludeData(_) = *self {
|
||||
@@ -149,8 +150,8 @@ impl ExtrinsicT for Extrinsic {
|
||||
}
|
||||
}
|
||||
|
||||
fn new_unsigned(_call: Self::Call) -> Option<Self> {
|
||||
None
|
||||
fn new_unsigned(call: Self::Call) -> Option<Self> {
|
||||
Some(call)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +268,14 @@ cfg_if! {
|
||||
/// Returns if no block was initialized.
|
||||
#[skip_initialize_block]
|
||||
fn without_initialize_block() -> bool;
|
||||
/// Test that `ed25519` crypto works in the runtime.
|
||||
///
|
||||
/// Returns the signature generated for the message `ed25519` and the public key.
|
||||
fn test_ed25519_crypto() -> (ed25519::AppSignature, ed25519::AppPublic);
|
||||
/// Test that `sr25519` crypto works in the runtime.
|
||||
///
|
||||
/// Returns the signature generated for the message `sr25519`.
|
||||
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -300,6 +309,14 @@ cfg_if! {
|
||||
/// Returns if no block was initialized.
|
||||
#[skip_initialize_block]
|
||||
fn without_initialize_block() -> bool;
|
||||
/// Test that `ed25519` crypto works in the runtime.
|
||||
///
|
||||
/// Returns the signature generated for the message `ed25519` and the public key.
|
||||
fn test_ed25519_crypto() -> (ed25519::AppSignature, ed25519::AppPublic);
|
||||
/// Test that `sr25519` crypto works in the runtime.
|
||||
///
|
||||
/// Returns the signature generated for the message `sr25519`.
|
||||
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,6 +357,7 @@ parameter_types! {
|
||||
|
||||
impl srml_system::Trait for Runtime {
|
||||
type Origin = Origin;
|
||||
type Call = Extrinsic;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -545,11 +563,24 @@ cfg_if! {
|
||||
fn take_block_number() -> Option<u64> {
|
||||
system::take_block_number()
|
||||
}
|
||||
|
||||
fn test_ed25519_crypto() -> (ed25519::AppSignature, ed25519::AppPublic) {
|
||||
test_ed25519_crypto()
|
||||
}
|
||||
|
||||
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic) {
|
||||
test_sr25519_crypto()
|
||||
}
|
||||
}
|
||||
|
||||
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
|
||||
fn slot_duration() -> u64 { 1000 }
|
||||
fn authorities() -> Vec<AuraId> { system::authorities() }
|
||||
fn authorities() -> Vec<AuraId> {
|
||||
system::authorities().into_iter().map(|a| {
|
||||
let authority: sr25519::Public = a.into();
|
||||
AuraId::from(authority)
|
||||
}).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl babe_primitives::BabeApi<Block> for Runtime {
|
||||
@@ -736,11 +767,24 @@ cfg_if! {
|
||||
fn take_block_number() -> Option<u64> {
|
||||
system::take_block_number()
|
||||
}
|
||||
|
||||
fn test_ed25519_crypto() -> (ed25519::AppSignature, ed25519::AppPublic) {
|
||||
test_ed25519_crypto()
|
||||
}
|
||||
|
||||
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic) {
|
||||
test_sr25519_crypto()
|
||||
}
|
||||
}
|
||||
|
||||
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
|
||||
fn slot_duration() -> u64 { 1000 }
|
||||
fn authorities() -> Vec<AuraId> { system::authorities() }
|
||||
fn authorities() -> Vec<AuraId> {
|
||||
system::authorities().into_iter().map(|a| {
|
||||
let authority: sr25519::Public = a.into();
|
||||
AuraId::from(authority)
|
||||
}).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl babe_primitives::BabeApi<Block> for Runtime {
|
||||
@@ -776,6 +820,36 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
fn test_ed25519_crypto() -> (ed25519::AppSignature, ed25519::AppPublic) {
|
||||
let public0 = ed25519::AppPublic::generate_pair(None);
|
||||
let public1 = ed25519::AppPublic::generate_pair(None);
|
||||
let public2 = ed25519::AppPublic::generate_pair(None);
|
||||
|
||||
let all = ed25519::AppPublic::all();
|
||||
assert!(all.contains(&public0));
|
||||
assert!(all.contains(&public1));
|
||||
assert!(all.contains(&public2));
|
||||
|
||||
let signature = public0.sign(&"ed25519").expect("Generates a valid `ed25519` signature.");
|
||||
assert!(public0.verify(&"ed25519", &signature));
|
||||
(signature, public0)
|
||||
}
|
||||
|
||||
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic) {
|
||||
let public0 = sr25519::AppPublic::generate_pair(None);
|
||||
let public1 = sr25519::AppPublic::generate_pair(None);
|
||||
let public2 = sr25519::AppPublic::generate_pair(None);
|
||||
|
||||
let all = sr25519::AppPublic::all();
|
||||
assert!(all.contains(&public0));
|
||||
assert!(all.contains(&public1));
|
||||
assert!(all.contains(&public2));
|
||||
|
||||
let signature = public0.sign(&"sr25519").expect("Generates a valid `sr25519` signature.");
|
||||
assert!(public0.verify(&"sr25519", &signature));
|
||||
(signature, public0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use substrate_test_runtime_client::{
|
||||
|
||||
@@ -274,8 +274,7 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyResult {
|
||||
}
|
||||
|
||||
fn execute_new_authorities_backend(new_authorities: &[AuthorityId]) -> ApplyResult {
|
||||
let new_authorities: Vec<AuthorityId> = new_authorities.iter().cloned().collect();
|
||||
<NewAuthorities>::put(new_authorities);
|
||||
NewAuthorities::put(new_authorities.to_vec());
|
||||
Ok(ApplyOutcome::Success)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user