diff --git a/src/bin/fullnode-config.rs b/src/bin/fullnode-config.rs index 9bd6961914..803faf08a2 100644 --- a/src/bin/fullnode-config.rs +++ b/src/bin/fullnode-config.rs @@ -9,7 +9,7 @@ use solana::cluster_info::FULLNODE_PORT_RANGE; use solana::fullnode::Config; use solana::logger; use solana::netutil::{get_ip_addr, get_public_ip_addr, parse_port_or_addr}; -use solana::signature::read_pkcs8; +use solana::signature::read_keypair; use std::io; use std::net::SocketAddr; @@ -65,11 +65,11 @@ fn main() { path.extend(&[".config", "solana", "id.json"]); path.to_str().unwrap() }; - let pkcs8 = read_pkcs8(id_path).expect("client keypair"); + let keypair = read_keypair(id_path).expect("client keypair"); // we need all the receiving sockets to be bound within the expected // port range that we open on aws - let config = Config::new(&bind_addr, pkcs8); + let config = Config::new(&bind_addr, keypair.to_bytes().to_vec()); let stdout = io::stdout(); serde_json::to_writer(stdout, &config).expect("serialize"); } diff --git a/src/bin/genesis.rs b/src/bin/genesis.rs index 4817274328..c4e8fef39d 100644 --- a/src/bin/genesis.rs +++ b/src/bin/genesis.rs @@ -60,8 +60,8 @@ fn main() -> Result<(), Box> { // Parse the input mint configuration let num_tokens = value_t_or_exit!(matches, "num_tokens", u64); let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap(); - let pkcs8: Vec = serde_json::from_reader(&file)?; - let mint = Mint::new_with_pkcs8(num_tokens, pkcs8, leader_keypair.pubkey(), 1); + let keypair_bytes: Vec = serde_json::from_reader(&file)?; + let mint = Mint::new_with_keypair_bytes(num_tokens, keypair_bytes, leader_keypair.pubkey(), 1); // Write the ledger entries let ledger_path = matches.value_of("ledger").unwrap(); diff --git a/src/fullnode.rs b/src/fullnode.rs index 9076d8d344..7e29a25a1f 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -107,18 +107,22 @@ pub struct Fullnode { /// Fullnode configuration to be stored in file pub struct Config { pub node_info: NodeInfo, - pkcs8: Vec, + keypair_bytes: Vec, } impl Config { - pub fn new(bind_addr: &SocketAddr, pkcs8: Vec) -> Self { - let keypair = Keypair::from_bytes(&pkcs8).expect("from_pkcs8 in fullnode::Config new"); + pub fn new(bind_addr: &SocketAddr, keypair_bytes: Vec) -> Self { + let keypair = + Keypair::from_bytes(&keypair_bytes).expect("from_bytes in fullnode::Config new"); let pubkey = keypair.pubkey(); let node_info = NodeInfo::new_with_pubkey_socketaddr(pubkey, bind_addr); - Config { node_info, pkcs8 } + Config { + node_info, + keypair_bytes, + } } pub fn keypair(&self) -> Keypair { - Keypair::from_bytes(&self.pkcs8).expect("from_pkcs8 in fullnode::Config keypair") + Keypair::from_bytes(&self.keypair_bytes).expect("from_bytes in fullnode::Config keypair") } } diff --git a/src/mint.rs b/src/mint.rs index fb413afcda..9870de3499 100644 --- a/src/mint.rs +++ b/src/mint.rs @@ -9,7 +9,7 @@ use transaction::Transaction; #[derive(Serialize, Deserialize, Debug)] pub struct Mint { - pub pkcs8: Vec, + pub keypair_bytes: Vec, pubkey: Pubkey, pub tokens: u64, pub bootstrap_leader_id: Pubkey, @@ -17,16 +17,16 @@ pub struct Mint { } impl Mint { - pub fn new_with_pkcs8( + pub fn new_with_keypair_bytes( tokens: u64, - pkcs8: Vec, + keypair_bytes: Vec, bootstrap_leader_id: Pubkey, bootstrap_leader_tokens: u64, ) -> Self { - let keypair = Keypair::from_bytes(&pkcs8).expect("from_pkcs8 in mint pub fn new"); + let keypair = Keypair::from_bytes(&keypair_bytes).expect("from_bytes in mint pub fn new"); let pubkey = keypair.pubkey(); Mint { - pkcs8, + keypair_bytes, pubkey, tokens, bootstrap_leader_id, @@ -39,8 +39,8 @@ impl Mint { bootstrap_leader: Pubkey, bootstrap_leader_tokens: u64, ) -> Self { - let pkcs8 = Keypair::new().to_bytes().to_vec(); - Self::new_with_pkcs8(tokens, pkcs8, bootstrap_leader, bootstrap_leader_tokens) + let bytes = Keypair::new().to_bytes().to_vec(); + Self::new_with_keypair_bytes(tokens, bytes, bootstrap_leader, bootstrap_leader_tokens) } pub fn new(tokens: u64) -> Self { @@ -48,7 +48,7 @@ impl Mint { } pub fn seed(&self) -> Hash { - hash(&self.pkcs8) + hash(&self.keypair_bytes) } pub fn last_id(&self) -> Hash { @@ -56,7 +56,7 @@ impl Mint { } pub fn keypair(&self) -> Keypair { - Keypair::from_bytes(&self.pkcs8).expect("from_pkcs8 in mint pub fn keypair") + Keypair::from_bytes(&self.keypair_bytes).expect("from_bytes in mint pub fn keypair") } pub fn pubkey(&self) -> Pubkey { diff --git a/src/signature.rs b/src/signature.rs index 59a2e0d2d5..21f1c1895e 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -93,15 +93,10 @@ impl GenKeys { } } -pub fn read_pkcs8(path: &str) -> Result, Box> { - let file = File::open(path.to_string())?; - let pkcs8: Vec = serde_json::from_reader(file)?; - Ok(pkcs8) -} - pub fn read_keypair(path: &str) -> Result> { - let pkcs8 = read_pkcs8(path)?; - let keypair = Keypair::from_bytes(&pkcs8).unwrap(); + let file = File::open(path.to_string())?; + let bytes: Vec = serde_json::from_reader(file)?; + let keypair = Keypair::from_bytes(&bytes).unwrap(); Ok(keypair) } diff --git a/src/wallet.rs b/src/wallet.rs index 97316e46bf..5060e62fa9 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -691,8 +691,8 @@ pub fn request_airdrop( } pub fn gen_keypair_file(outfile: String) -> Result> { - let pkcs8_bytes = Keypair::new().to_bytes(); - let serialized = serde_json::to_string(&pkcs8_bytes.to_vec())?; + let keypair_bytes = Keypair::new().to_bytes(); + let serialized = serde_json::to_string(&keypair_bytes.to_vec())?; if outfile != "-" { if let Some(outdir) = Path::new(&outfile).parent() { @@ -794,7 +794,7 @@ mod tests { use leader_scheduler::LeaderScheduler; use ledger::create_tmp_genesis; use serde_json::Value; - use signature::{read_keypair, read_pkcs8, Keypair, KeypairUtil}; + use signature::{read_keypair, Keypair, KeypairUtil}; use std::fs::remove_dir_all; use std::sync::mpsc::channel; use std::sync::{Arc, RwLock}; @@ -1229,8 +1229,10 @@ mod tests { let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap(); let keypair_vec: Vec = serde_json::from_str(&serialized_keypair).unwrap(); assert!(Path::new(&outfile).exists()); - assert_eq!(keypair_vec, read_pkcs8(&outfile).unwrap()); - assert!(read_keypair(&outfile).is_ok()); + assert_eq!( + read_keypair(&outfile).unwrap().to_bytes().to_vec(), + keypair_vec + ); assert_eq!( read_keypair(&outfile).unwrap().pubkey().as_ref().len(), mem::size_of::()