Bitcoin keys now being produced per-node
This commit is contained in:
@@ -2,16 +2,19 @@ use std::path::PathBuf;
|
||||
|
||||
use config::SideNodeConfig;
|
||||
|
||||
use crate::{keys, utils};
|
||||
use crate::{bitcoin_keys, keys, utils};
|
||||
|
||||
pub(crate) mod config;
|
||||
|
||||
pub(crate) fn init(home: PathBuf, config: SideNodeConfig) -> Result<(), std::io::Error> {
|
||||
ensure_side_directory_exists(&home)?;
|
||||
let (key_path, config_path) = utils::side_paths(home.clone());
|
||||
let (bft_crdt_key_path, bitcoin_key_path, config_path) = utils::side_paths(home.clone());
|
||||
|
||||
println!("Writing key to: {:?}", key_path);
|
||||
keys::write(key_path)?;
|
||||
println!("Writing bft crdt key to: {:?}", bft_crdt_key_path);
|
||||
keys::write(&bft_crdt_key_path)?;
|
||||
|
||||
println!("Writing bitcoin key to: {:?}", bitcoin_key_path);
|
||||
bitcoin_keys::write(&bitcoin_key_path)?;
|
||||
|
||||
println!("Writing config to: {:?}", config_path);
|
||||
config::write_toml(&config, &config_path).expect("unable to write config file");
|
||||
@@ -20,7 +23,7 @@ pub(crate) fn init(home: PathBuf, config: SideNodeConfig) -> Result<(), std::io:
|
||||
}
|
||||
|
||||
/// Ensures that the directory at side_dir exists, so we have a place
|
||||
/// to store our key file and config file.
|
||||
/// to store our key files and config file.
|
||||
fn ensure_side_directory_exists(side_dir: &PathBuf) -> Result<(), std::io::Error> {
|
||||
if side_dir.exists() {
|
||||
return Ok(());
|
||||
@@ -58,17 +61,17 @@ mod tests {
|
||||
let (config, name) = side_node_config();
|
||||
let side_dir = format!("/tmp/side/{name}");
|
||||
|
||||
let mut key_file_path = PathBuf::new();
|
||||
key_file_path.push(side_dir.clone());
|
||||
key_file_path.push(utils::BFT_CRDT_KEY_FILE);
|
||||
let mut bitcoin_keys_path = PathBuf::new();
|
||||
bitcoin_keys_path.push(side_dir.clone());
|
||||
bitcoin_keys_path.push(utils::BITCOIN_KEY_FILE);
|
||||
|
||||
let _ = init(PathBuf::from_str(&side_dir).unwrap(), config);
|
||||
assert!(key_file_path.exists());
|
||||
assert!(bitcoin_keys_path.exists());
|
||||
|
||||
// check that the pem is readable
|
||||
let data = fs::read_to_string(key_file_path).expect("couldn't read key file");
|
||||
let keys = Ed25519KeyPair::decode_base64(&data).expect("couldn't load keypair from file");
|
||||
assert_eq!(keys.public().as_bytes().len(), 32);
|
||||
// let data = fs::read_to_string(bitcoin_keys_path).expect("couldn't read key file");
|
||||
// let keys = Ed25519KeyPair::decode_base64(&data).expect("couldn't load keypair from file");
|
||||
// assert_eq!(keys.public().as_bytes().len(), 32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user