deterministic random wallet generationg
This commit is contained in:
@ -11,7 +11,7 @@ use getopts::Options;
|
|||||||
use isatty::stdin_isatty;
|
use isatty::stdin_isatty;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use solana::mint::MintDemo;
|
use solana::mint::MintDemo;
|
||||||
use solana::signature::{KeyPair, KeyPairUtil};
|
use solana::signature::{GenKeys, KeyPair, KeyPairUtil};
|
||||||
use solana::thin_client::ThinClient;
|
use solana::thin_client::ThinClient;
|
||||||
use solana::transaction::Transaction;
|
use solana::transaction::Transaction;
|
||||||
use std::env;
|
use std::env;
|
||||||
@ -93,9 +93,20 @@ fn main() {
|
|||||||
let last_id = acc.get_last_id().wait().unwrap();
|
let last_id = acc.get_last_id().wait().unwrap();
|
||||||
println!("Got last ID {:?}", last_id);
|
println!("Got last ID {:?}", last_id);
|
||||||
|
|
||||||
|
let rnd = GenKeys::new(demo.mint.keypair().public_key_bytes());
|
||||||
|
let tokens_per_user = 1_000;
|
||||||
|
|
||||||
|
let users: Vec<_> = (0..demo.num_accounts)
|
||||||
|
.into_par_iter()
|
||||||
|
.map(|_| {
|
||||||
|
let pkcs8 = rnd.new_key();
|
||||||
|
(pkcs8, tokens_per_user)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
println!("Creating keypairs...");
|
println!("Creating keypairs...");
|
||||||
let txs = demo.users.len() / 2;
|
let txs = users.len() / 2;
|
||||||
let keypairs: Vec<_> = demo.users
|
let keypairs: Vec<_> = users
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|(pkcs8, _)| KeyPair::from_pkcs8(Input::from(&pkcs8)).unwrap())
|
.map(|(pkcs8, _)| KeyPair::from_pkcs8(Input::from(&pkcs8)).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -11,7 +11,7 @@ use solana::accountant::MAX_ENTRY_IDS;
|
|||||||
use solana::entry::{create_entry, next_tick};
|
use solana::entry::{create_entry, next_tick};
|
||||||
use solana::event::Event;
|
use solana::event::Event;
|
||||||
use solana::mint::MintDemo;
|
use solana::mint::MintDemo;
|
||||||
use solana::signature::{KeyPair, KeyPairUtil};
|
use solana::signature::{GenKeys, KeyPair, KeyPairUtil};
|
||||||
use solana::transaction::Transaction;
|
use solana::transaction::Transaction;
|
||||||
use std::io::{stdin, Read};
|
use std::io::{stdin, Read};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
@ -36,12 +36,23 @@ fn main() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
let num_accounts = demo.users.len();
|
let rnd = GenKeys::new(demo.mint.keypair().public_key_bytes());
|
||||||
|
let tokens_per_user = 1_000;
|
||||||
|
|
||||||
|
let users: Vec<_> = (0..demo.num_accounts)
|
||||||
|
.into_iter()
|
||||||
|
.map(|_| {
|
||||||
|
let pkcs8 = rnd.new_key();
|
||||||
|
(pkcs8, tokens_per_user)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let num_accounts = users.len();
|
||||||
let last_id = demo.mint.last_id();
|
let last_id = demo.mint.last_id();
|
||||||
let mint_keypair = demo.mint.keypair();
|
let mint_keypair = demo.mint.keypair();
|
||||||
|
|
||||||
eprintln!("Signing {} transactions...", num_accounts);
|
eprintln!("Signing {} transactions...", num_accounts);
|
||||||
let events: Vec<_> = demo.users
|
let events: Vec<_> = users
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|(pkcs8, tokens)| {
|
.map(|(pkcs8, tokens)| {
|
||||||
let rando = KeyPair::from_pkcs8(Input::from(&pkcs8)).unwrap();
|
let rando = KeyPair::from_pkcs8(Input::from(&pkcs8)).unwrap();
|
||||||
|
@ -3,10 +3,7 @@ extern crate ring;
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate solana;
|
extern crate solana;
|
||||||
|
|
||||||
use rayon::prelude::*;
|
|
||||||
use ring::rand::SystemRandom;
|
|
||||||
use solana::mint::{Mint, MintDemo};
|
use solana::mint::{Mint, MintDemo};
|
||||||
use solana::signature::KeyPair;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -18,16 +15,7 @@ fn main() {
|
|||||||
let mint = Mint::new(tokens);
|
let mint = Mint::new(tokens);
|
||||||
let tokens_per_user = 1_000;
|
let tokens_per_user = 1_000;
|
||||||
let num_accounts = tokens / tokens_per_user;
|
let num_accounts = tokens / tokens_per_user;
|
||||||
let rnd = SystemRandom::new();
|
|
||||||
|
|
||||||
let users: Vec<_> = (0..num_accounts)
|
let demo = MintDemo { mint, num_accounts };
|
||||||
.into_par_iter()
|
|
||||||
.map(|_| {
|
|
||||||
let pkcs8 = KeyPair::generate_pkcs8(&rnd).unwrap().to_vec();
|
|
||||||
(pkcs8, tokens_per_user)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let demo = MintDemo { mint, users };
|
|
||||||
println!("{}", serde_json::to_string(&demo).unwrap());
|
println!("{}", serde_json::to_string(&demo).unwrap());
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ impl Mint {
|
|||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct MintDemo {
|
pub struct MintDemo {
|
||||||
pub mint: Mint,
|
pub mint: Mint,
|
||||||
pub users: Vec<(Vec<u8>, i64)>,
|
pub num_accounts: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -2,8 +2,13 @@
|
|||||||
|
|
||||||
use generic_array::typenum::{U32, U64};
|
use generic_array::typenum::{U32, U64};
|
||||||
use generic_array::GenericArray;
|
use generic_array::GenericArray;
|
||||||
|
use rand::{ChaChaRng, Rng, SeedableRng};
|
||||||
|
use ring::error::Unspecified;
|
||||||
|
use ring::rand::SecureRandom;
|
||||||
use ring::signature::Ed25519KeyPair;
|
use ring::signature::Ed25519KeyPair;
|
||||||
use ring::{rand, signature};
|
use ring::{rand, signature};
|
||||||
|
use std::mem;
|
||||||
|
use std::sync::RwLock;
|
||||||
use untrusted;
|
use untrusted;
|
||||||
|
|
||||||
pub type KeyPair = Ed25519KeyPair;
|
pub type KeyPair = Ed25519KeyPair;
|
||||||
@ -41,3 +46,29 @@ impl SignatureUtil for GenericArray<u8, U64> {
|
|||||||
signature::verify(&signature::ED25519, peer_public_key, msg, sig).is_ok()
|
signature::verify(&signature::ED25519, peer_public_key, msg, sig).is_ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct GenKeys {
|
||||||
|
generator: RwLock<ChaChaRng>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenKeys {
|
||||||
|
pub fn new(seed_values: &[u8]) -> GenKeys {
|
||||||
|
let seed: &[u8] = &seed_values[..];
|
||||||
|
let rng: ChaChaRng = SeedableRng::from_seed(unsafe { mem::transmute(seed) });
|
||||||
|
GenKeys {
|
||||||
|
generator: RwLock::new(rng),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_key(&self) -> Vec<u8> {
|
||||||
|
KeyPair::generate_pkcs8(self).unwrap().to_vec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SecureRandom for GenKeys {
|
||||||
|
fn fill(&self, dest: &mut [u8]) -> Result<(), Unspecified> {
|
||||||
|
let mut rng = self.generator.write().unwrap();
|
||||||
|
rng.fill_bytes(dest);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user