keyfork-derive-key: slim dependencies and formats
This commit is contained in:
parent
0119e58d2d
commit
55ff62052b
|
@ -876,17 +876,10 @@ dependencies = [
|
|||
name = "keyfork-derive-key"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"clap",
|
||||
"ed25519-dalek",
|
||||
"keyfork-derive-util",
|
||||
"keyfork-frame",
|
||||
"keyfork-slip10-test-data",
|
||||
"keyforkd",
|
||||
"keyforkd-client",
|
||||
"tempdir",
|
||||
"smex",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -6,16 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bincode = { version = "1.3.3", default-features = false }
|
||||
clap = { version = "4.4.2", default-features = false, features = ["std", "usage", "help", "derive"] }
|
||||
keyfork-derive-util = { version = "0.1.0", path = "../keyfork-derive-util" }
|
||||
keyfork-frame = { version = "0.1.0", path = "../keyfork-frame", default-features = false }
|
||||
keyforkd-client = { version = "0.1.0", path = "../keyforkd-client" }
|
||||
smex = { version = "0.1.0", path = "../smex" }
|
||||
thiserror = "1.0.48"
|
||||
|
||||
[dev-dependencies]
|
||||
ed25519-dalek = "2.0.0"
|
||||
keyfork-slip10-test-data = { path = "../keyfork-slip10-test-data" }
|
||||
keyforkd = { path = "../keyforkd", default-features = false }
|
||||
tempdir = "0.3.7"
|
||||
tokio = { version = "1.32.0", features = ["rt", "rt-multi-thread"] }
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
use clap::Parser;
|
||||
use keyfork_derive_util::{
|
||||
request::{DerivationAlgorithm, DerivationRequest, DerivationResponse},
|
||||
DerivationPath,
|
||||
};
|
||||
use keyforkd_client::{Client, Result};
|
||||
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
pub struct Command {
|
||||
#[arg(long)]
|
||||
pub path: DerivationPath,
|
||||
|
||||
#[arg(long)]
|
||||
pub algorithm: DerivationAlgorithm,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn handle(&self) -> Result<DerivationResponse> {
|
||||
let mut client = Client::discover_socket()?;
|
||||
let request = DerivationRequest::new(self.algorithm.clone(), &self.path);
|
||||
client.request(&request)
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
pub mod cli;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("The first argument to the command should be a derivation path")]
|
||||
Args,
|
||||
|
||||
#[error("The given path was incorrectly formatted: {0}")]
|
||||
ArgsFormat(#[from] keyfork_derive_util::path::Error),
|
||||
|
||||
#[error("Unable to perform key derivation request: {0}")]
|
||||
KeyforkdClient(#[from] keyforkd_client::Error),
|
||||
}
|
||||
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
|
@ -1,10 +1,44 @@
|
|||
use clap::Parser;
|
||||
use std::{env, str::FromStr};
|
||||
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
use keyfork_derive_key::*;
|
||||
use keyfork_derive_util::{
|
||||
request::{DerivationAlgorithm, DerivationError, DerivationRequest},
|
||||
DerivationPath,
|
||||
};
|
||||
use keyforkd_client::Client;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = cli::Command::parse();
|
||||
args.handle()?;
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Could not parse the given algorithm {0:?}: {1}")]
|
||||
AlgoFormat(String, DerivationError),
|
||||
|
||||
#[error("Could not parse the given path: {0}")]
|
||||
PathFormat(#[from] keyfork_derive_util::path::Error),
|
||||
|
||||
#[error("Unable to perform key derivation request: {0}")]
|
||||
KeyforkdClient(#[from] keyforkd_client::Error),
|
||||
}
|
||||
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
fn validate(algo: &str, path: &str) -> Result<(DerivationAlgorithm, DerivationPath)> {
|
||||
let algo =
|
||||
DerivationAlgorithm::from_str(algo).map_err(|e| Error::AlgoFormat(algo.to_string(), e))?;
|
||||
let path = DerivationPath::from_str(path)?;
|
||||
Ok((algo, path))
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut args = env::args();
|
||||
let program_name = args.next().expect("program name");
|
||||
let args = args.collect::<Vec<_>>();
|
||||
let (algo, path) = match args.as_slice() {
|
||||
[algo, path] => validate(algo, path)?,
|
||||
_ => panic!("Usage: {program_name} algorithm path"),
|
||||
};
|
||||
|
||||
let mut client = Client::discover_socket()?;
|
||||
let request = DerivationRequest::new(algo, &path);
|
||||
let response = client.request(&request)?;
|
||||
println!("{}", smex::encode(&response.data));
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue