wip adding bitcoin keys to side nodes
This commit is contained in:
@@ -17,7 +17,7 @@ pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn load_from_file(side_dir: PathBuf) -> Ed25519KeyPair {
|
pub(crate) fn load_from_file(side_dir: &PathBuf) -> Ed25519KeyPair {
|
||||||
let key_path = crate::utils::side_paths(side_dir.clone()).0;
|
let key_path = crate::utils::side_paths(side_dir.clone()).0;
|
||||||
|
|
||||||
let data = fs::read_to_string(key_path).expect("couldn't read bft-crdt key file");
|
let data = fs::read_to_string(key_path).expect("couldn't read bft-crdt key file");
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use bitcoin::secp256k1::{rand, Keypair, Secp256k1};
|
use bitcoin::secp256k1::{rand, Keypair, Secp256k1, SecretKey};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::Write,
|
io::Write,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
||||||
@@ -13,6 +14,7 @@ pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
|||||||
|
|
||||||
let pub_str = public_key.to_string();
|
let pub_str = public_key.to_string();
|
||||||
let priv_str = secret_key.display_secret().to_string();
|
let priv_str = secret_key.display_secret().to_string();
|
||||||
|
println!("private key: {priv_str}");
|
||||||
let out = format!("{pub_str}/{priv_str}");
|
let out = format!("{pub_str}/{priv_str}");
|
||||||
println!("out: {out}");
|
println!("out: {out}");
|
||||||
file.write(out.as_bytes())?;
|
file.write(out.as_bytes())?;
|
||||||
@@ -20,16 +22,15 @@ pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn load_from_file(side_dir: PathBuf) -> bitcoin::secp256k1::Keypair {
|
pub(crate) fn load_from_file(side_dir: &PathBuf) -> bitcoin::secp256k1::Keypair {
|
||||||
let key_path = crate::utils::side_paths(side_dir.clone()).0;
|
let bitcoin_key_path = crate::utils::side_paths(side_dir.clone()).1; // TODO: this tuple stinks
|
||||||
|
|
||||||
let data = fs::read_to_string(key_path).expect("couldn't read bitcoin key file");
|
let data = fs::read_to_string(bitcoin_key_path).expect("couldn't read bitcoin key file");
|
||||||
println!("data: {:?}", data);
|
println!("bitcoin keys: {:?}", data);
|
||||||
|
|
||||||
let secret_key_data = data.split("/").collect::<Vec<&str>>()[1];
|
let secret_key_data = data.split("/").collect::<Vec<&str>>()[1];
|
||||||
|
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let secret_key = bitcoin::secp256k1::SecretKey::from_slice(secret_key_data.as_bytes()).unwrap();
|
let secret_key =
|
||||||
|
SecretKey::from_str(secret_key_data).expect("couldn't load secret key from file");
|
||||||
Keypair::from_secret_key(&secp, &secret_key)
|
Keypair::from_secret_key(&secp, &secret_key)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ pub async fn run() {
|
|||||||
async fn setup(name: &String) -> SideNode {
|
async fn setup(name: &String) -> SideNode {
|
||||||
// First, load up the keys and create a bft-crdt
|
// First, load up the keys and create a bft-crdt
|
||||||
let side_dir = utils::home(name);
|
let side_dir = utils::home(name);
|
||||||
let bft_crdt_keys = bft_crdt_keys::load_from_file(side_dir);
|
let bft_crdt_keys = bft_crdt_keys::load_from_file(&side_dir);
|
||||||
|
let bitcoin_keys = bitcoin_keys::load_from_file(&side_dir);
|
||||||
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);
|
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);
|
||||||
|
|
||||||
// Channels for internal communication, and a tokio task for stdin input
|
// Channels for internal communication, and a tokio task for stdin input
|
||||||
@@ -54,6 +55,7 @@ async fn setup(name: &String) -> SideNode {
|
|||||||
let node = SideNode::new(
|
let node = SideNode::new(
|
||||||
crdt,
|
crdt,
|
||||||
bft_crdt_keys,
|
bft_crdt_keys,
|
||||||
|
bitcoin_keys,
|
||||||
incoming_receiver,
|
incoming_receiver,
|
||||||
stdin_receiver,
|
stdin_receiver,
|
||||||
handle,
|
handle,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::{crdt::TransactionList, utils, websocket::WebSocketClient};
|
|||||||
pub struct SideNode {
|
pub struct SideNode {
|
||||||
crdt: BaseCrdt<TransactionList>,
|
crdt: BaseCrdt<TransactionList>,
|
||||||
bft_crdt_keys: fastcrypto::ed25519::Ed25519KeyPair,
|
bft_crdt_keys: fastcrypto::ed25519::Ed25519KeyPair,
|
||||||
|
bitcoin_keys: bitcoin::secp256k1::Keypair,
|
||||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||||
handle: ezsockets::Client<WebSocketClient>,
|
handle: ezsockets::Client<WebSocketClient>,
|
||||||
@@ -15,14 +16,16 @@ pub struct SideNode {
|
|||||||
impl SideNode {
|
impl SideNode {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
crdt: BaseCrdt<TransactionList>,
|
crdt: BaseCrdt<TransactionList>,
|
||||||
keys: Ed25519KeyPair,
|
bft_crdt_keys: Ed25519KeyPair,
|
||||||
|
bitcoin_keys: bitcoin::secp256k1::Keypair,
|
||||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||||
handle: ezsockets::Client<WebSocketClient>,
|
handle: ezsockets::Client<WebSocketClient>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let node = Self {
|
let node = Self {
|
||||||
crdt,
|
crdt,
|
||||||
bft_crdt_keys: keys,
|
bft_crdt_keys,
|
||||||
|
bitcoin_keys,
|
||||||
incoming_receiver,
|
incoming_receiver,
|
||||||
stdin_receiver,
|
stdin_receiver,
|
||||||
handle,
|
handle,
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ async fn test_distribute_via_websockets() {
|
|||||||
async fn setup(_: &str) -> SideNode {
|
async fn setup(_: &str) -> SideNode {
|
||||||
// First, load up the keys and create a bft-crdt
|
// First, load up the keys and create a bft-crdt
|
||||||
let keys = make_keypair();
|
let keys = make_keypair();
|
||||||
|
let bitcoin_keys = bitcoin::secp256k1::Keypair::new();
|
||||||
let crdt = BaseCrdt::<TransactionList>::new(&keys);
|
let crdt = BaseCrdt::<TransactionList>::new(&keys);
|
||||||
|
|
||||||
// Channels for internal communication, and a tokio task for stdin input
|
// Channels for internal communication, and a tokio task for stdin input
|
||||||
|
|||||||
Reference in New Issue
Block a user