No longer serialize as JSON-encoded pkcs8
That's supposed to be an ASCII format, but we're not making use of it. We can switch back to that some day, but if we do, it shouldn't be JSON-encoded.
This commit is contained in:
@ -9,7 +9,7 @@ use solana::cluster_info::FULLNODE_PORT_RANGE;
|
|||||||
use solana::fullnode::Config;
|
use solana::fullnode::Config;
|
||||||
use solana::logger;
|
use solana::logger;
|
||||||
use solana::netutil::{get_ip_addr, get_public_ip_addr, parse_port_or_addr};
|
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::io;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
@ -65,11 +65,11 @@ fn main() {
|
|||||||
path.extend(&[".config", "solana", "id.json"]);
|
path.extend(&[".config", "solana", "id.json"]);
|
||||||
path.to_str().unwrap()
|
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
|
// we need all the receiving sockets to be bound within the expected
|
||||||
// port range that we open on aws
|
// 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();
|
let stdout = io::stdout();
|
||||||
serde_json::to_writer(stdout, &config).expect("serialize");
|
serde_json::to_writer(stdout, &config).expect("serialize");
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ fn main() -> Result<(), Box<error::Error>> {
|
|||||||
// Parse the input mint configuration
|
// Parse the input mint configuration
|
||||||
let num_tokens = value_t_or_exit!(matches, "num_tokens", u64);
|
let num_tokens = value_t_or_exit!(matches, "num_tokens", u64);
|
||||||
let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap();
|
let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap();
|
||||||
let pkcs8: Vec<u8> = serde_json::from_reader(&file)?;
|
let keypair_bytes: Vec<u8> = serde_json::from_reader(&file)?;
|
||||||
let mint = Mint::new_with_pkcs8(num_tokens, pkcs8, leader_keypair.pubkey(), 1);
|
let mint = Mint::new_with_keypair_bytes(num_tokens, keypair_bytes, leader_keypair.pubkey(), 1);
|
||||||
|
|
||||||
// Write the ledger entries
|
// Write the ledger entries
|
||||||
let ledger_path = matches.value_of("ledger").unwrap();
|
let ledger_path = matches.value_of("ledger").unwrap();
|
||||||
|
@ -107,18 +107,22 @@ pub struct Fullnode {
|
|||||||
/// Fullnode configuration to be stored in file
|
/// Fullnode configuration to be stored in file
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub node_info: NodeInfo,
|
pub node_info: NodeInfo,
|
||||||
pkcs8: Vec<u8>,
|
keypair_bytes: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new(bind_addr: &SocketAddr, pkcs8: Vec<u8>) -> Self {
|
pub fn new(bind_addr: &SocketAddr, keypair_bytes: Vec<u8>) -> Self {
|
||||||
let keypair = Keypair::from_bytes(&pkcs8).expect("from_pkcs8 in fullnode::Config new");
|
let keypair =
|
||||||
|
Keypair::from_bytes(&keypair_bytes).expect("from_bytes in fullnode::Config new");
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let node_info = NodeInfo::new_with_pubkey_socketaddr(pubkey, bind_addr);
|
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 {
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/mint.rs
18
src/mint.rs
@ -9,7 +9,7 @@ use transaction::Transaction;
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Mint {
|
pub struct Mint {
|
||||||
pub pkcs8: Vec<u8>,
|
pub keypair_bytes: Vec<u8>,
|
||||||
pubkey: Pubkey,
|
pubkey: Pubkey,
|
||||||
pub tokens: u64,
|
pub tokens: u64,
|
||||||
pub bootstrap_leader_id: Pubkey,
|
pub bootstrap_leader_id: Pubkey,
|
||||||
@ -17,16 +17,16 @@ pub struct Mint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Mint {
|
impl Mint {
|
||||||
pub fn new_with_pkcs8(
|
pub fn new_with_keypair_bytes(
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
pkcs8: Vec<u8>,
|
keypair_bytes: Vec<u8>,
|
||||||
bootstrap_leader_id: Pubkey,
|
bootstrap_leader_id: Pubkey,
|
||||||
bootstrap_leader_tokens: u64,
|
bootstrap_leader_tokens: u64,
|
||||||
) -> Self {
|
) -> 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();
|
let pubkey = keypair.pubkey();
|
||||||
Mint {
|
Mint {
|
||||||
pkcs8,
|
keypair_bytes,
|
||||||
pubkey,
|
pubkey,
|
||||||
tokens,
|
tokens,
|
||||||
bootstrap_leader_id,
|
bootstrap_leader_id,
|
||||||
@ -39,8 +39,8 @@ impl Mint {
|
|||||||
bootstrap_leader: Pubkey,
|
bootstrap_leader: Pubkey,
|
||||||
bootstrap_leader_tokens: u64,
|
bootstrap_leader_tokens: u64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let pkcs8 = Keypair::new().to_bytes().to_vec();
|
let bytes = Keypair::new().to_bytes().to_vec();
|
||||||
Self::new_with_pkcs8(tokens, pkcs8, bootstrap_leader, bootstrap_leader_tokens)
|
Self::new_with_keypair_bytes(tokens, bytes, bootstrap_leader, bootstrap_leader_tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(tokens: u64) -> Self {
|
pub fn new(tokens: u64) -> Self {
|
||||||
@ -48,7 +48,7 @@ impl Mint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn seed(&self) -> Hash {
|
pub fn seed(&self) -> Hash {
|
||||||
hash(&self.pkcs8)
|
hash(&self.keypair_bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_id(&self) -> Hash {
|
pub fn last_id(&self) -> Hash {
|
||||||
@ -56,7 +56,7 @@ impl Mint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn keypair(&self) -> Keypair {
|
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 {
|
pub fn pubkey(&self) -> Pubkey {
|
||||||
|
@ -93,15 +93,10 @@ impl GenKeys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_pkcs8(path: &str) -> Result<Vec<u8>, Box<error::Error>> {
|
|
||||||
let file = File::open(path.to_string())?;
|
|
||||||
let pkcs8: Vec<u8> = serde_json::from_reader(file)?;
|
|
||||||
Ok(pkcs8)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_keypair(path: &str) -> Result<Keypair, Box<error::Error>> {
|
pub fn read_keypair(path: &str) -> Result<Keypair, Box<error::Error>> {
|
||||||
let pkcs8 = read_pkcs8(path)?;
|
let file = File::open(path.to_string())?;
|
||||||
let keypair = Keypair::from_bytes(&pkcs8).unwrap();
|
let bytes: Vec<u8> = serde_json::from_reader(file)?;
|
||||||
|
let keypair = Keypair::from_bytes(&bytes).unwrap();
|
||||||
Ok(keypair)
|
Ok(keypair)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -691,8 +691,8 @@ pub fn request_airdrop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_keypair_file(outfile: String) -> Result<String, Box<error::Error>> {
|
pub fn gen_keypair_file(outfile: String) -> Result<String, Box<error::Error>> {
|
||||||
let pkcs8_bytes = Keypair::new().to_bytes();
|
let keypair_bytes = Keypair::new().to_bytes();
|
||||||
let serialized = serde_json::to_string(&pkcs8_bytes.to_vec())?;
|
let serialized = serde_json::to_string(&keypair_bytes.to_vec())?;
|
||||||
|
|
||||||
if outfile != "-" {
|
if outfile != "-" {
|
||||||
if let Some(outdir) = Path::new(&outfile).parent() {
|
if let Some(outdir) = Path::new(&outfile).parent() {
|
||||||
@ -794,7 +794,7 @@ mod tests {
|
|||||||
use leader_scheduler::LeaderScheduler;
|
use leader_scheduler::LeaderScheduler;
|
||||||
use ledger::create_tmp_genesis;
|
use ledger::create_tmp_genesis;
|
||||||
use serde_json::Value;
|
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::fs::remove_dir_all;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
@ -1229,8 +1229,10 @@ mod tests {
|
|||||||
let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap();
|
let serialized_keypair = gen_keypair_file(outfile.to_string()).unwrap();
|
||||||
let keypair_vec: Vec<u8> = serde_json::from_str(&serialized_keypair).unwrap();
|
let keypair_vec: Vec<u8> = serde_json::from_str(&serialized_keypair).unwrap();
|
||||||
assert!(Path::new(&outfile).exists());
|
assert!(Path::new(&outfile).exists());
|
||||||
assert_eq!(keypair_vec, read_pkcs8(&outfile).unwrap());
|
assert_eq!(
|
||||||
assert!(read_keypair(&outfile).is_ok());
|
read_keypair(&outfile).unwrap().to_bytes().to_vec(),
|
||||||
|
keypair_vec
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_keypair(&outfile).unwrap().pubkey().as_ref().len(),
|
read_keypair(&outfile).unwrap().pubkey().as_ref().len(),
|
||||||
mem::size_of::<Pubkey>()
|
mem::size_of::<Pubkey>()
|
||||||
|
Reference in New Issue
Block a user