From 9f9deb107e5b2784d9d50107702452a6d828e382 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 26 Nov 2024 11:34:43 -0500 Subject: [PATCH] icepick: add config file format --- Cargo.lock | 380 ++++++++++++++++++++++++++-------- crates/icepick/Cargo.toml | 3 + crates/icepick/src/cli/mod.rs | 39 +++- icepick.toml | 3 + 4 files changed, 334 insertions(+), 91 deletions(-) create mode 100644 icepick.toml diff --git a/Cargo.lock b/Cargo.lock index 173343a..f0deac7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -230,6 +230,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.12.3" @@ -242,6 +248,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bincode" version = "1.3.3" @@ -527,6 +539,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -573,6 +591,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -669,6 +699,16 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "derivation-path" version = "0.2.0" @@ -706,13 +746,35 @@ dependencies = [ "subtle", ] +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "elliptic-curve", + "signature 2.2.0", + "spki", +] + [[package]] name = "ed25519" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ - "signature", + "signature 1.6.4", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature 2.2.0", ] [[package]] @@ -722,13 +784,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek 3.2.0", - "ed25519", + "ed25519 1.5.3", "rand 0.7.3", "serde", "sha2 0.9.9", "zeroize", ] +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek 4.1.3", + "ed25519 2.2.3", + "serde", + "sha2 0.10.8", + "subtle", + "zeroize", +] + [[package]] name = "ed25519-dalek-bip32" version = "0.2.0" @@ -736,7 +812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d2be62a4061b872c8c0873ee4fc6f101ce7b889d039f019c5fa2af471a59908" dependencies = [ "derivation-path", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "hmac 0.12.1", "sha2 0.10.8", ] @@ -747,6 +823,25 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -772,6 +867,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da" +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "fiat-crypto" version = "0.2.9" @@ -823,6 +928,7 @@ dependencies = [ "serde", "typenum", "version_check", + "zeroize", ] [[package]] @@ -851,6 +957,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "hashbrown" version = "0.13.2" @@ -929,24 +1046,11 @@ version = "0.1.0" dependencies = [ "clap", "icepick-module", + "keyforkd-client", + "serde", "serde_json", "thiserror 2.0.3", -] - -[[package]] -name = "icepick-coin" -version = "0.1.0" -dependencies = [ - "clap", - "thiserror 2.0.3", -] - -[[package]] -name = "icepick-eth" -version = "0.1.0" -dependencies = [ - "clap", - "icepick-coin", + "toml 0.8.19", ] [[package]] @@ -957,15 +1061,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "icepick-sol" -version = "0.1.0" -dependencies = [ - "clap", - "icepick-coin", - "solana-sdk 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "icepick-solana" version = "0.1.0" @@ -973,7 +1068,7 @@ dependencies = [ "icepick-module", "serde", "serde_json", - "solana-sdk 2.1.1", + "solana-sdk", "thiserror 2.0.3", ] @@ -1048,6 +1143,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "k256" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", +] + [[package]] name = "keccak" version = "0.1.5" @@ -1057,6 +1164,78 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "keyfork-bug" +version = "0.1.0" +source = "registry+https://git.distrust.co/public/_cargo-index.git" +checksum = "fb5eae1e7471415b59f852ccb43b7858f0650a5d158ccbfb1d39088d0881f582" + +[[package]] +name = "keyfork-derive-util" +version = "0.2.1" +source = "registry+https://git.distrust.co/public/_cargo-index.git" +checksum = "12df1b3dbe1ac978fa53d86889156da010e290edb60ec308064906696d6a85b7" +dependencies = [ + "digest 0.10.7", + "ed25519-dalek 2.1.1", + "hmac 0.12.1", + "k256", + "keyfork-bug", + "keyfork-mnemonic", + "ripemd", + "serde", + "sha2 0.10.8", + "thiserror 1.0.69", +] + +[[package]] +name = "keyfork-frame" +version = "0.1.0" +source = "registry+https://git.distrust.co/public/_cargo-index.git" +checksum = "836118d47fd2c754d630207adb6106595262ea33b8e827004c3af6e9ea140959" +dependencies = [ + "sha2 0.10.8", + "thiserror 1.0.69", +] + +[[package]] +name = "keyfork-mnemonic" +version = "0.4.0" +source = "registry+https://git.distrust.co/public/_cargo-index.git" +checksum = "b1ee8bee167c8a5c7c0156bf577d21e83f0d6e3659d98a958408b74edecd84d5" +dependencies = [ + "hmac 0.12.1", + "keyfork-bug", + "pbkdf2 0.12.2", + "sha2 0.10.8", +] + +[[package]] +name = "keyforkd-client" +version = "0.2.1" +source = "registry+https://git.distrust.co/public/_cargo-index.git" +checksum = "f57d9b8b956ca3c79d5f992e9a84f19810b75937c9064ecb35485780e8243a03" +dependencies = [ + "bincode", + "ed25519-dalek 2.1.1", + "k256", + "keyfork-derive-util", + "keyfork-frame", + "keyforkd-models", + "thiserror 1.0.69", +] + +[[package]] +name = "keyforkd-models" +version = "0.2.0" +source = "registry+https://git.distrust.co/public/_cargo-index.git" +checksum = "8fdef2303ad5bff8ca05d0a42df89396905c940fd814f89385e99f8c764af8ac" +dependencies = [ + "keyfork-derive-util", + "serde", + "thiserror 1.0.69", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -1324,12 +1503,32 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac 0.12.1", +] + [[package]] name = "percent-encoding" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.31" @@ -1351,7 +1550,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml", + "toml 0.5.11", ] [[package]] @@ -1539,6 +1738,15 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1566,6 +1774,20 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "semver" version = "1.0.23" @@ -1613,6 +1835,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "serde_with" version = "3.11.0" @@ -1682,6 +1913,15 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -2214,7 +2454,7 @@ dependencies = [ "chrono", "curve25519-dalek 4.1.3", "digest 0.10.7", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "ed25519-dalek-bip32", "generic-array", "getrandom 0.1.16", @@ -2271,55 +2511,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "solana-sdk" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "336579d2332cb16af892b0bbf0afcca14072e19421c3770de27167d4c186e9ab" -dependencies = [ - "bincode", - "bitflags", - "bs58", - "bytemuck", - "bytemuck_derive", - "getrandom 0.1.16", - "hmac 0.12.1", - "itertools 0.12.1", - "js-sys", - "lazy_static", - "log", - "num-derive", - "num-traits", - "num_enum", - "pbkdf2 0.11.0", - "serde", - "serde_bytes", - "serde_derive", - "serde_with", - "sha2 0.10.8", - "siphasher", - "solana-account", - "solana-bn254", - "solana-decode-error", - "solana-derivation-path", - "solana-feature-set", - "solana-inflation", - "solana-instruction", - "solana-native-token", - "solana-packet", - "solana-program", - "solana-program-memory", - "solana-pubkey", - "solana-sanitize", - "solana-sdk-macro", - "solana-secp256k1-recover", - "solana-secp256r1-program", - "solana-serde-varint", - "solana-short-vec", - "thiserror 1.0.69", - "wasm-bindgen", -] - [[package]] name = "solana-sdk-macro" version = "2.1.1" @@ -2407,7 +2598,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea56a4cca29f0785f72aed81ada27d03e0be408cb570f68a8f99665bb8ccd7b5" dependencies = [ "bs58", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "generic-array", "rand 0.8.5", "serde", @@ -2474,6 +2665,16 @@ dependencies = [ "solana-sanitize", ] +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -2606,11 +2807,26 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -2619,6 +2835,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] diff --git a/crates/icepick/Cargo.toml b/crates/icepick/Cargo.toml index c302e86..43ed8a9 100644 --- a/crates/icepick/Cargo.toml +++ b/crates/icepick/Cargo.toml @@ -6,5 +6,8 @@ edition = "2021" [dependencies] clap = { version = "4.5.20", features = ["cargo", "derive", "string"] } icepick-module = { version = "0.1.0", path = "../icepick-module" } +keyforkd-client = { version = "0.2.1", registry = "distrust" } +serde = { workspace = true, features = ["derive"] } serde_json.workspace = true thiserror = "2.0.3" +toml = "0.8.19" diff --git a/crates/icepick/src/cli/mod.rs b/crates/icepick/src/cli/mod.rs index ec16669..a42a061 100644 --- a/crates/icepick/src/cli/mod.rs +++ b/crates/icepick/src/cli/mod.rs @@ -1,14 +1,11 @@ use clap::command; use icepick_module::help::*; +use serde::{Deserialize, Serialize}; use std::{ io::{IsTerminal, Write}, process::{Command, Stdio}, }; -pub fn guessed_bins() -> Vec { - "sol".split_whitespace().map(|s| s.to_owned()).collect() -} - pub fn get_command(bin_name: &str) -> (&str, Vec<&str>) { if std::env::vars().any(|(k, _)| &k == "ICEPICK_USE_CARGO") { ("cargo", vec!["run", "--bin", bin_name, "--"]) @@ -17,10 +14,35 @@ pub fn get_command(bin_name: &str) -> (&str, Vec<&str>) { } } +#[derive(Serialize, Deserialize, Debug)] +struct ModuleConfig { + name: String, + derivation_prefix: String, +} + +#[derive(Serialize, Deserialize, Debug, Default)] +struct Config { + #[serde(rename = "module")] + modules: Vec, +} + pub fn do_cli_thing() { + /* parse config file to get module names */ + let config_file = std::env::vars().find_map(|(k, v)| { + if k == "ICEPICK_CONFIG_FILE" { + return Some(v); + } + None + }); + let config_path = config_file.unwrap_or_else(|| "icepick.toml".to_string()); + let config_content = std::fs::read_to_string(config_path).expect("can't read config file"); + let config: Config = toml::from_str(&config_content).expect("config file had invalid toml"); + let mut commands = vec![]; let mut icepick_command = command!(); - for coin_bin in guessed_bins() { + // NOTE: this needs to be .cloned(), since commands is leaked to be 'static + // and coin_bin otherwise wouldn't live long enough + for coin_bin in config.modules.iter().map(|m| &m.name).cloned() { // try to run the "help" operation on any bins. let bin = format!("icepick-{coin_bin}"); let (command, args) = get_command(&bin); @@ -68,17 +90,14 @@ pub fn do_cli_thing() { if !stdin.is_terminal() { cli_input = serde_json::from_reader(stdin).ok(); } - dbg!(&cli_input); - let blob = cli_input.as_ref().and_then(|json| { - json.get("blob") - }); + let blob = cli_input.as_ref().and_then(|json| json.get("blob")); let matches = icepick_command.get_matches(); if let Some((module, matches)) = matches.subcommand() { if let Some((subcommand, matches)) = matches.subcommand() { if let Some(operation) = commands .iter() - .find(|(name, _)| name == module) + .find(|(name, _)| *name == module) .and_then(|(_, operations)| operations.iter().find(|o| o.name == subcommand)) { let mut args = std::collections::HashMap::<&String, Option<&String>>::with_capacity( diff --git a/icepick.toml b/icepick.toml new file mode 100644 index 0000000..da16332 --- /dev/null +++ b/icepick.toml @@ -0,0 +1,3 @@ +[[module]] +name = "sol" +derivation_prefix = "m/44'/501'"