mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
Overhaul crypto (Schnorr/Ristretto, HDKD, BIP39) (#1795)
* Rijig to Ristretto * Rebuild wasm * adds compatibility test with the wasm module * Add Ed25519-BIP39 support * Bump subkey version * Update CLI output * New keys. * Standard phrase/password/path keys. * Subkey uses S-URI for secrets * Move everything to use new HDKD crypto. * Test fixes * Ignore old test vector. * fix the ^^ old test vector. * Fix tests * Test fixes * Cleanups * Fix broken key conversion logic in grandpa CC @rphmeier * Remove legacy Keyring usage * Traitify `Pair` * Replace Ed25519AuthorityId with ed25519::Public * Expunge Ed25519AuthorityId type! * Replace Sr25519AuthorityId with sr25519::Public * Remove dodgy crypto type-punning conversions * Fix some tests * Avoid trait * Deduplicate DeriveJunction string decode * Remove cruft code * Fix test * Minor removals * Build fix * Subkey supports sign and verify * Inspect works for public key URIs * Remove more crypto type-punning * Fix typo * Fix tests
This commit is contained in:
@@ -22,7 +22,7 @@ use network::test::{PassThroughVerifier};
|
||||
use network::config::{ProtocolConfig, Roles};
|
||||
use parking_lot::Mutex;
|
||||
use tokio::runtime::current_thread;
|
||||
use keyring::Keyring;
|
||||
use keyring::AuthorityKeyring;
|
||||
use client::{
|
||||
BlockchainEvents, error::Result,
|
||||
blockchain::Backend as BlockchainBackend,
|
||||
@@ -238,13 +238,13 @@ impl Network<Block> for MessageRouting {
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
struct TestApi {
|
||||
genesis_authorities: Vec<(Ed25519AuthorityId, u64)>,
|
||||
genesis_authorities: Vec<(AuthorityId, u64)>,
|
||||
scheduled_changes: Arc<Mutex<HashMap<Hash, ScheduledChange<BlockNumber>>>>,
|
||||
forced_changes: Arc<Mutex<HashMap<Hash, (BlockNumber, ScheduledChange<BlockNumber>)>>>,
|
||||
}
|
||||
|
||||
impl TestApi {
|
||||
fn new(genesis_authorities: Vec<(Ed25519AuthorityId, u64)>) -> Self {
|
||||
fn new(genesis_authorities: Vec<(AuthorityId, u64)>) -> Self {
|
||||
TestApi {
|
||||
genesis_authorities,
|
||||
scheduled_changes: Arc::new(Mutex::new(HashMap::new())),
|
||||
@@ -282,7 +282,7 @@ impl Core<Block> for RuntimeApi {
|
||||
_: ExecutionContext,
|
||||
_: Option<()>,
|
||||
_: Vec<u8>,
|
||||
) -> Result<NativeOrEncoded<Vec<Ed25519AuthorityId>>> {
|
||||
) -> Result<NativeOrEncoded<Vec<AuthorityId>>> {
|
||||
unimplemented!("Not required for testing!")
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ impl GrandpaApi<Block> for RuntimeApi {
|
||||
_: ExecutionContext,
|
||||
_: Option<()>,
|
||||
_: Vec<u8>,
|
||||
) -> Result<NativeOrEncoded<Vec<(Ed25519AuthorityId, u64)>>> {
|
||||
) -> Result<NativeOrEncoded<Vec<(AuthorityId, u64)>>> {
|
||||
if at == &BlockId::Number(0) {
|
||||
Ok(self.inner.genesis_authorities.clone()).map(NativeOrEncoded::Native)
|
||||
} else {
|
||||
@@ -374,9 +374,9 @@ impl GrandpaApi<Block> for RuntimeApi {
|
||||
const TEST_GOSSIP_DURATION: Duration = Duration::from_millis(500);
|
||||
const TEST_ROUTING_INTERVAL: Duration = Duration::from_millis(50);
|
||||
|
||||
fn make_ids(keys: &[Keyring]) -> Vec<(Ed25519AuthorityId, u64)> {
|
||||
fn make_ids(keys: &[AuthorityKeyring]) -> Vec<(AuthorityId, u64)> {
|
||||
keys.iter()
|
||||
.map(|key| Ed25519AuthorityId(key.to_raw_public()))
|
||||
.map(|key| AuthorityId(key.to_raw_public()))
|
||||
.map(|id| (id, 1))
|
||||
.collect()
|
||||
}
|
||||
@@ -386,7 +386,7 @@ fn make_ids(keys: &[Keyring]) -> Vec<(Ed25519AuthorityId, u64)> {
|
||||
fn run_to_completion_with<F: FnOnce()>(
|
||||
blocks: u64,
|
||||
net: Arc<Mutex<GrandpaTestNet>>,
|
||||
peers: &[Keyring],
|
||||
peers: &[AuthorityKeyring],
|
||||
before_waiting: F,
|
||||
) -> u64 {
|
||||
use parking_lot::RwLock;
|
||||
@@ -462,14 +462,14 @@ fn run_to_completion_with<F: FnOnce()>(
|
||||
highest_finalized
|
||||
}
|
||||
|
||||
fn run_to_completion(blocks: u64, net: Arc<Mutex<GrandpaTestNet>>, peers: &[Keyring]) -> u64 {
|
||||
fn run_to_completion(blocks: u64, net: Arc<Mutex<GrandpaTestNet>>, peers: &[AuthorityKeyring]) -> u64 {
|
||||
run_to_completion_with(blocks, net, peers, || {})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finalize_3_voters_no_observers() {
|
||||
let _ = env_logger::try_init();
|
||||
let peers = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let voters = make_ids(peers);
|
||||
|
||||
let mut net = GrandpaTestNet::new(TestApi::new(voters), 3);
|
||||
@@ -491,7 +491,7 @@ fn finalize_3_voters_no_observers() {
|
||||
|
||||
#[test]
|
||||
fn finalize_3_voters_1_observer() {
|
||||
let peers = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let voters = make_ids(peers);
|
||||
|
||||
let mut net = GrandpaTestNet::new(TestApi::new(voters), 4);
|
||||
@@ -554,24 +554,24 @@ fn finalize_3_voters_1_observer() {
|
||||
fn transition_3_voters_twice_1_observer() {
|
||||
let _ = env_logger::try_init();
|
||||
let peers_a = &[
|
||||
Keyring::Alice,
|
||||
Keyring::Bob,
|
||||
Keyring::Charlie,
|
||||
AuthorityKeyring::Alice,
|
||||
AuthorityKeyring::Bob,
|
||||
AuthorityKeyring::Charlie,
|
||||
];
|
||||
|
||||
let peers_b = &[
|
||||
Keyring::Dave,
|
||||
Keyring::Eve,
|
||||
Keyring::Ferdie,
|
||||
AuthorityKeyring::Dave,
|
||||
AuthorityKeyring::Eve,
|
||||
AuthorityKeyring::Ferdie,
|
||||
];
|
||||
|
||||
let peers_c = &[
|
||||
Keyring::Alice,
|
||||
Keyring::Eve,
|
||||
Keyring::Two,
|
||||
AuthorityKeyring::Alice,
|
||||
AuthorityKeyring::Eve,
|
||||
AuthorityKeyring::Two,
|
||||
];
|
||||
|
||||
let observer = &[Keyring::One];
|
||||
let observer = &[AuthorityKeyring::One];
|
||||
|
||||
let genesis_voters = make_ids(peers_a);
|
||||
|
||||
@@ -719,11 +719,11 @@ fn transition_3_voters_twice_1_observer() {
|
||||
|
||||
#[test]
|
||||
fn justification_is_emitted_when_consensus_data_changes() {
|
||||
let peers = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let mut net = GrandpaTestNet::new(TestApi::new(make_ids(peers)), 3);
|
||||
|
||||
// import block#1 WITH consensus data change
|
||||
let new_authorities = vec![Ed25519AuthorityId::from([42; 32])];
|
||||
let new_authorities = vec![AuthorityId::from_raw([42; 32])];
|
||||
net.peer(0).push_authorities_change_block(new_authorities);
|
||||
net.sync();
|
||||
let net = Arc::new(Mutex::new(net));
|
||||
@@ -736,7 +736,7 @@ fn justification_is_emitted_when_consensus_data_changes() {
|
||||
|
||||
#[test]
|
||||
fn justification_is_generated_periodically() {
|
||||
let peers = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let voters = make_ids(peers);
|
||||
|
||||
let mut net = GrandpaTestNet::new(TestApi::new(voters), 3);
|
||||
@@ -775,8 +775,8 @@ fn consensus_changes_works() {
|
||||
|
||||
#[test]
|
||||
fn sync_justifications_on_change_blocks() {
|
||||
let peers_a = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers_b = &[Keyring::Alice, Keyring::Bob];
|
||||
let peers_a = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let peers_b = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob];
|
||||
let voters = make_ids(peers_b);
|
||||
|
||||
// 4 peers, 3 of them are authorities and participate in grandpa
|
||||
@@ -825,13 +825,13 @@ fn sync_justifications_on_change_blocks() {
|
||||
fn finalizes_multiple_pending_changes_in_order() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let peers_a = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers_b = &[Keyring::Dave, Keyring::Eve, Keyring::Ferdie];
|
||||
let peers_c = &[Keyring::Dave, Keyring::Alice, Keyring::Bob];
|
||||
let peers_a = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let peers_b = &[AuthorityKeyring::Dave, AuthorityKeyring::Eve, AuthorityKeyring::Ferdie];
|
||||
let peers_c = &[AuthorityKeyring::Dave, AuthorityKeyring::Alice, AuthorityKeyring::Bob];
|
||||
|
||||
let all_peers = &[
|
||||
Keyring::Alice, Keyring::Bob, Keyring::Charlie,
|
||||
Keyring::Dave, Keyring::Eve, Keyring::Ferdie,
|
||||
AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie,
|
||||
AuthorityKeyring::Dave, AuthorityKeyring::Eve, AuthorityKeyring::Ferdie,
|
||||
];
|
||||
let genesis_voters = make_ids(peers_a);
|
||||
|
||||
@@ -883,7 +883,7 @@ fn finalizes_multiple_pending_changes_in_order() {
|
||||
|
||||
#[test]
|
||||
fn doesnt_vote_on_the_tip_of_the_chain() {
|
||||
let peers_a = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers_a = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let voters = make_ids(peers_a);
|
||||
let api = TestApi::new(voters);
|
||||
let mut net = GrandpaTestNet::new(api, 3);
|
||||
@@ -907,8 +907,8 @@ fn doesnt_vote_on_the_tip_of_the_chain() {
|
||||
#[test]
|
||||
fn force_change_to_new_set() {
|
||||
// two of these guys are offline.
|
||||
let genesis_authorities = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie, Keyring::One, Keyring::Two];
|
||||
let peers_a = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let genesis_authorities = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie, AuthorityKeyring::One, AuthorityKeyring::Two];
|
||||
let peers_a = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let api = TestApi::new(make_ids(genesis_authorities));
|
||||
|
||||
let voters = make_ids(peers_a);
|
||||
@@ -960,8 +960,8 @@ fn force_change_to_new_set() {
|
||||
|
||||
#[test]
|
||||
fn allows_reimporting_change_blocks() {
|
||||
let peers_a = &[Keyring::Alice, Keyring::Bob, Keyring::Charlie];
|
||||
let peers_b = &[Keyring::Alice, Keyring::Bob];
|
||||
let peers_a = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie];
|
||||
let peers_b = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob];
|
||||
let voters = make_ids(peers_a);
|
||||
let api = TestApi::new(voters);
|
||||
let net = GrandpaTestNet::new(api.clone(), 3);
|
||||
|
||||
Reference in New Issue
Block a user