Getting ready to create Bitcoin keys
This commit is contained in:
113
Cargo.lock
generated
113
Cargo.lock
generated
@@ -225,6 +225,12 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||
|
||||
[[package]]
|
||||
name = "async-channel"
|
||||
version = "1.9.0"
|
||||
@@ -302,6 +308,16 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf"
|
||||
|
||||
[[package]]
|
||||
name = "base58ck"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f"
|
||||
dependencies = [
|
||||
"bitcoin-internals",
|
||||
"bitcoin_hashes 0.14.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
@@ -332,6 +348,12 @@ version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445"
|
||||
|
||||
[[package]]
|
||||
name = "bech32"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
|
||||
|
||||
[[package]]
|
||||
name = "bft-crdt-derive"
|
||||
version = "0.1.0"
|
||||
@@ -370,12 +392,50 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin"
|
||||
version = "0.32.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6"
|
||||
dependencies = [
|
||||
"base58ck",
|
||||
"bech32 0.11.0",
|
||||
"bitcoin-internals",
|
||||
"bitcoin-io",
|
||||
"bitcoin-units",
|
||||
"bitcoin_hashes 0.14.0",
|
||||
"hex-conservative",
|
||||
"hex_lit",
|
||||
"secp256k1 0.29.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin-internals"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2"
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin-io"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56"
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin-private"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57"
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin-units"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb54da0b28892f3c52203a7191534033e051b6f4b52bc15480681b57b7e036f5"
|
||||
dependencies = [
|
||||
"bitcoin-internals",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin_hashes"
|
||||
version = "0.12.0"
|
||||
@@ -385,6 +445,16 @@ dependencies = [
|
||||
"bitcoin-private",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitcoin_hashes"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
|
||||
dependencies = [
|
||||
"bitcoin-io",
|
||||
"hex-conservative",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
@@ -1016,7 +1086,7 @@ dependencies = [
|
||||
"ark-serialize",
|
||||
"auto_ops",
|
||||
"base64ct",
|
||||
"bech32",
|
||||
"bech32 0.9.1",
|
||||
"bincode",
|
||||
"blake2",
|
||||
"blst",
|
||||
@@ -1042,7 +1112,7 @@ dependencies = [
|
||||
"rfc6979",
|
||||
"rsa",
|
||||
"schemars",
|
||||
"secp256k1",
|
||||
"secp256k1 0.27.0",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with 2.3.3",
|
||||
@@ -1299,12 +1369,27 @@ version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "hex-conservative"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hex-literal"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46"
|
||||
|
||||
[[package]]
|
||||
name = "hex_lit"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"
|
||||
|
||||
[[package]]
|
||||
name = "hkdf"
|
||||
version = "0.12.4"
|
||||
@@ -2114,9 +2199,19 @@ version = "0.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f"
|
||||
dependencies = [
|
||||
"bitcoin_hashes",
|
||||
"bitcoin_hashes 0.12.0",
|
||||
"rand 0.8.5",
|
||||
"secp256k1-sys",
|
||||
"secp256k1-sys 0.8.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "secp256k1"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3"
|
||||
dependencies = [
|
||||
"bitcoin_hashes 0.12.0",
|
||||
"secp256k1-sys 0.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2128,6 +2223,15 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "secp256k1-sys"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.23"
|
||||
@@ -2318,6 +2422,7 @@ dependencies = [
|
||||
"async-trait",
|
||||
"bft-crdt-derive",
|
||||
"bft-json-crdt",
|
||||
"bitcoin",
|
||||
"clap 4.5.4",
|
||||
"dirs",
|
||||
"ezsockets",
|
||||
|
||||
@@ -9,6 +9,7 @@ edition = "2021"
|
||||
async-trait = "0.1.52"
|
||||
bft-json-crdt = { path = "../crates/bft-json-crdt" }
|
||||
bft-crdt-derive = { path = "../crates/bft-json-crdt/bft-crdt-derive" }
|
||||
bitcoin = "0.32.2"
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
dirs = "5.0.1"
|
||||
ezsockets = { version = "*", features = ["client"] }
|
||||
|
||||
@@ -53,6 +53,24 @@ mod tests {
|
||||
(SideNodeConfig { name: name.clone() }, name)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_bitcoin_keys() {
|
||||
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 _ = init(PathBuf::from_str(&side_dir).unwrap(), config);
|
||||
assert!(key_file_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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_side_node_directory() {
|
||||
let (config, name) = side_node_config();
|
||||
@@ -67,13 +85,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_key_file() {
|
||||
fn creates_bft_crdt_key_file() {
|
||||
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::KEY_FILE);
|
||||
key_file_path.push(utils::BFT_CRDT_KEY_FILE);
|
||||
|
||||
let _ = init(PathBuf::from_str(&side_dir).unwrap(), config);
|
||||
assert!(key_file_path.exists());
|
||||
|
||||
@@ -5,7 +5,6 @@ pub(crate) fn input(stdin_sender: std::sync::mpsc::Sender<String>) {
|
||||
let stdin = std::io::stdin();
|
||||
let lines = stdin.lock().lines();
|
||||
for line in lines {
|
||||
println!("We're in stdin_input");
|
||||
let line = line.unwrap();
|
||||
stdin_sender.send(line).unwrap();
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ use std::path::PathBuf;
|
||||
use bft_json_crdt::json_crdt::SignedOp;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
pub(crate) const KEY_FILE: &str = "keys.pem";
|
||||
pub(crate) const BFT_CRDT_KEY_FILE: &str = "keys.pem";
|
||||
pub(crate) const CONFIG_FILE: &str = "config.toml";
|
||||
|
||||
/// Returns the path to the key file and config for this host OS.
|
||||
pub(crate) fn side_paths(prefix: PathBuf) -> (PathBuf, PathBuf) {
|
||||
let mut key_path = prefix.clone();
|
||||
key_path.push(KEY_FILE);
|
||||
key_path.push(BFT_CRDT_KEY_FILE);
|
||||
|
||||
let mut config_path = prefix.clone();
|
||||
config_path.push(CONFIG_FILE);
|
||||
|
||||
@@ -47,9 +47,7 @@ impl ezsockets::ClientExt for WebSocketClient {
|
||||
let object_sha = utils::shappy(incoming.clone());
|
||||
println!("deserialized: {}", object_sha);
|
||||
if string_sha != object_sha {
|
||||
println!("SHA mismatch: {string_sha} != {object_sha}");
|
||||
println!("text: {text}");
|
||||
println!("incoming: {incoming:?}");
|
||||
panic!("sha mismatch: {string_sha} != {object_sha}, bft-crdt has failed");
|
||||
}
|
||||
self.incoming_sender.send(incoming).await?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user