Added deterministic keypair generation.

- The Account Manager has a new subcommand, allowing generation of deterministic keys given a particular validator index.
 - Split functionality in generate_deterministic_keypair function
 - Fixed up READMEs to reflect new functionality & correct naming.
This commit is contained in:
Luke Anderson
2019-04-08 15:02:11 +10:00
parent a46f676f89
commit 177a351462
8 changed files with 69 additions and 15 deletions

View File

@@ -18,13 +18,17 @@ pub fn generate_deterministic_keypairs(validator_count: usize) -> Vec<Keypair> {
let keypairs: Vec<Keypair> = (0..validator_count)
.collect::<Vec<usize>>()
.par_iter()
.map(|&i| {
let secret = int_to_bytes48(i as u64 + 1000);
let sk = SecretKey::from_bytes(&secret).unwrap();
let pk = PublicKey::from_secret_key(&sk);
Keypair { sk, pk }
})
.map(|&i| generate_deterministic_keypair(i))
.collect();
keypairs
}
/// Generates a single deterministic keypair, where the secret key is `validator_index`.
///
/// This is used for testing only, and not to be used in production!
pub fn generate_deterministic_keypair(validator_index: usize) -> Keypair {
let secret = int_to_bytes48(validator_index as u64 + 1000);
let sk = SecretKey::from_bytes(&secret).unwrap();
let pk = PublicKey::from_secret_key(&sk);
Keypair { sk, pk }
}

View File

@@ -16,6 +16,7 @@ mod testing_transfer_builder;
mod testing_voluntary_exit_builder;
pub use generate_deterministic_keypairs::generate_deterministic_keypairs;
pub use generate_deterministic_keypairs::generate_deterministic_keypair;
pub use keypairs_file::KeypairsFile;
pub use rand::{prng::XorShiftRng, SeedableRng};
pub use serde_utils::{fork_from_hex_str, u8_from_hex_str};