diff --git a/Cargo.lock b/Cargo.lock index 6fe7a1a70..4efae8448 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1448,7 +1448,6 @@ dependencies = [ name = "glcli" version = "0.1.0" dependencies = [ - "bip39", "clap", "dirs", "env_logger 0.11.5", diff --git a/libs/gl-cli/Cargo.toml b/libs/gl-cli/Cargo.toml index 8f2e6e55d..8f7c46623 100644 --- a/libs/gl-cli/Cargo.toml +++ b/libs/gl-cli/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bip39 = "2.0.0" clap = { version = "4.5.4", features = ["derive"] } dirs = "5.0.1" env_logger = "0.11.3" diff --git a/libs/gl-cli/src/main.rs b/libs/gl-cli/src/main.rs index 36bc6a33e..bc6501e5d 100644 --- a/libs/gl-cli/src/main.rs +++ b/libs/gl-cli/src/main.rs @@ -57,10 +57,10 @@ async fn run(cli: Cli) -> Result<()> { env_logger::init(); } - let data_dir = match cli.data_dir { - Some(d) => util::DataDir(PathBuf::from_str(&d).unwrap()), - None => util::DataDir::default(), - }; + let data_dir = cli + .data_dir + .map(|d| util::DataDir(PathBuf::from_str(&d).expect("is not a valid path"))) + .unwrap_or_default(); Ok(match cli.cmd { Commands::Scheduler(cmd) => { diff --git a/libs/gl-cli/src/scheduler.rs b/libs/gl-cli/src/scheduler.rs index cae309edf..e8b8b113a 100644 --- a/libs/gl-cli/src/scheduler.rs +++ b/libs/gl-cli/src/scheduler.rs @@ -92,10 +92,10 @@ async fn register_handler>( } None => { // Generate a new seed and save it. - let seed = util::generate_seed()?; + let seed = util::generate_seed(); util::write_seed(&seed_path, &seed)?; println!("Seed saved to {}", seed_path.display()); - seed + seed.to_vec() } }; diff --git a/libs/gl-cli/src/signer.rs b/libs/gl-cli/src/signer.rs index dcfeb695c..d103ec33f 100644 --- a/libs/gl-cli/src/signer.rs +++ b/libs/gl-cli/src/signer.rs @@ -2,7 +2,7 @@ use crate::error::{Error, Result}; use crate::util; use clap::Subcommand; use core::fmt::Debug; -use gl_client::{credentials, signer::Signer}; +use gl_client::signer::Signer; use lightning_signer::bitcoin::Network; use std::path::Path; use tokio::{join, signal}; diff --git a/libs/gl-cli/src/util.rs b/libs/gl-cli/src/util.rs index b1b060583..6d11c24b8 100644 --- a/libs/gl-cli/src/util.rs +++ b/libs/gl-cli/src/util.rs @@ -1,4 +1,3 @@ -use bip39::{self, Language, Mnemonic}; use dirs; use gl_client::bitcoin::secp256k1::rand::{self, RngCore}; use gl_client::credentials; @@ -16,15 +15,11 @@ pub const DEFAULT_GREENLIGHT_DIR: &str = "greenlight"; // -- Seed section -pub fn generate_seed() -> Result> { - let mut entropy = [0u8; 32]; +pub fn generate_seed() -> [u8; 32] { + let mut seed = [0u8; 32]; let mut rng = rand::thread_rng(); - rng.fill_bytes(&mut entropy); - - let mnemonic = Mnemonic::from_entropy_in(Language::English, &entropy)?; - - // Return the first 32 bytes of the seed generated from the mnemonic - Ok(mnemonic.to_seed("")[0..32].to_vec()) + rng.fill_bytes(&mut seed); + seed } pub fn read_seed(file_path: impl AsRef) -> Option> { @@ -39,6 +34,7 @@ pub fn write_seed(file_path: impl AsRef, seed: impl AsRef<[u8]>) -> Result let mut file = File::create(file_path)?; file.write_all(seed.as_ref())?; + file.sync_all()?; Ok(()) } @@ -48,6 +44,7 @@ pub fn write_seed(file_path: impl AsRef, seed: impl AsRef<[u8]>) -> Result pub fn write_credentials(file_path: impl AsRef, creds: impl AsRef<[u8]>) -> Result<()> { let mut file = File::create(&file_path)?; file.write_all(creds.as_ref())?; + file.sync_all()?; Ok(()) } @@ -82,8 +79,6 @@ impl AsRef for DataDir { #[derive(thiserror::Error, core::fmt::Debug)] pub enum UtilsError { - #[error(transparent)] - SeedError(#[from] bip39::Error), #[error(transparent)] IoError(#[from] std::io::Error), }