diff options
| -rw-r--r-- | Cargo.lock | 149 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/cmd.rs | 14 | ||||
| -rw-r--r-- | src/cmd/address.rs | 6 | ||||
| -rw-r--r-- | src/cmd/export.rs | 6 | ||||
| -rw-r--r-- | src/cmd/hash.rs | 6 | ||||
| -rw-r--r-- | src/cmd/hex.rs | 12 | ||||
| -rw-r--r-- | src/cmd/new.rs | 8 | ||||
| -rw-r--r-- | src/cmd/public_key.rs | 6 | ||||
| -rw-r--r-- | src/cmd/sign.rs | 24 | ||||
| -rw-r--r-- | src/main.rs | 22 |
11 files changed, 134 insertions, 121 deletions
@@ -3,15 +3,6 @@ version = 3 [[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] name = "anyhow" version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -29,6 +20,12 @@ dependencies = [ ] [[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -57,17 +54,32 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.34.0" +version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "12e8611f9ae4e068fa3e56931fded356ff745e70987ff76924a6e0ab1c8ef2e3" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_derive" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -117,10 +129,17 @@ dependencies = [ ] [[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] name = "hdwallet" version = "0.2.0" dependencies = [ "anyhow", + "clap", "ethnum", "hex", "hex-literal", @@ -132,18 +151,14 @@ dependencies = [ "serde_json", "sha2", "sha3", - "structopt", "unicode-normalization", ] [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -176,6 +191,16 @@ dependencies = [ ] [[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] name = "itoa" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -206,6 +231,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" [[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + +[[package]] name = "pbkdf2" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -334,33 +374,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "structopt" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" @@ -380,15 +396,21 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.11.0" +name = "termcolor" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ - "unicode-width", + "winapi-util", ] [[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" + +[[package]] name = "tinyvec" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -419,30 +441,12 @@ dependencies = [ ] [[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - -[[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -465,6 +469,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -11,6 +11,7 @@ license = "GPL-3.0-or-later" [dependencies] anyhow = "1" +clap = { version = "3", features = ["derive", "env"] } ethnum = "1" hex = "0.4" hmac = { version = "0.12", features = ["std"] } @@ -20,7 +21,6 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" sha2 = "0.10" sha3 = "0.10" -structopt = "0.3" unicode-normalization = "0.1" [dev-dependencies] @@ -9,34 +9,34 @@ pub mod public_key; pub mod sign; use anyhow::Result; +use clap::Parser; use hdwallet::{account::PrivateKey, hdk, mnemonic::Mnemonic}; use std::{ fs, io::{self, Read as _}, path::Path, }; -use structopt::StructOpt; /// Shared account options. -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] struct AccountOptions { /// The BIP-0039 mnemonic phrase for seeding the HD wallet. - #[structopt(short, long, env)] + #[clap(short, long, env, hide_env_values = true)] mnemonic: Mnemonic, /// The password to use with the mnemonic phrase for salting the seed used /// for the HD wallet. - #[structopt(long, env, default_value)] + #[clap(long, env, hide_env_values = true, default_value_t)] password: String, /// The BIP-44 account index for deriving a private from the mnemonic seed /// phrase. The derived key will use the path "m/44'/60'/0'/0/{index}". - #[structopt(long, env, default_value = "0")] + #[clap(long, env, default_value_t = 0)] account_index: usize, /// Manually specified HD path for deriving the account key. This option can /// not be used in conjunction with the "--account-index" option. - #[structopt(long, env, conflicts_with = "account-index")] + #[clap(long, env, conflicts_with = "account-index")] hd_path: Option<String>, } @@ -58,7 +58,7 @@ fn permissive_hex(s: &str) -> Result<Box<[u8]>> { let hex_string = trimmed.strip_prefix("0x").unwrap_or(&trimmed); let bytes = ::hex::decode(&hex_string)?; // NOTE: Use a boxed slice instead of a `Vec` as the former has special - // scemantics with `structopt`. + // scemantics with `clap`. Ok(bytes.into_boxed_slice()) } diff --git a/src/cmd/address.rs b/src/cmd/address.rs index 91476d3..28ed8fd 100644 --- a/src/cmd/address.rs +++ b/src/cmd/address.rs @@ -3,11 +3,11 @@ use crate::cmd::AccountOptions; use anyhow::Result; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Options { - #[structopt(flatten)] + #[clap(flatten)] account: AccountOptions, } diff --git a/src/cmd/export.rs b/src/cmd/export.rs index 957cd0e..df11d08 100644 --- a/src/cmd/export.rs +++ b/src/cmd/export.rs @@ -3,11 +3,11 @@ use crate::cmd::AccountOptions; use anyhow::Result; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Options { - #[structopt(flatten)] + #[clap(flatten)] account: AccountOptions, } diff --git a/src/cmd/hash.rs b/src/cmd/hash.rs index 4a650ff..4c8a9b8 100644 --- a/src/cmd/hash.rs +++ b/src/cmd/hash.rs @@ -2,14 +2,14 @@ use crate::cmd; use anyhow::Result; +use clap::Parser; use hdwallet::hash; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Options { /// Path to the data to hash. Use `-` for standard in. - #[structopt(name = "DATA", default_value = "-")] + #[clap(name = "DATA", default_value = "-")] data: PathBuf, } diff --git a/src/cmd/hex.rs b/src/cmd/hex.rs index 48eb02f..143bc43 100644 --- a/src/cmd/hex.rs +++ b/src/cmd/hex.rs @@ -6,32 +6,32 @@ use crate::cmd; use anyhow::Result; +use clap::Parser; use std::{ io::{self, Write}, path::PathBuf, str, }; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Options { - #[structopt(subcommand)] + #[clap(subcommand)] op: Op, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] enum Op { /// Encode binary data as a hexadecimal string. Encode { /// Path to the data to encode. Use `-` for standard in. - #[structopt(name = "DATA", default_value = "-")] + #[clap(name = "DATA", default_value = "-")] data: PathBuf, }, /// Decode a hexadecimal string as binary data. Decode { /// Path to the data to decode. Use `-` for standard in. - #[structopt(name = "DATA", default_value = "-")] + #[clap(name = "DATA", default_value = "-")] data: PathBuf, }, } diff --git a/src/cmd/new.rs b/src/cmd/new.rs index 002e5d0..db89958 100644 --- a/src/cmd/new.rs +++ b/src/cmd/new.rs @@ -2,17 +2,17 @@ //! hierarchical deterministic wallet. use anyhow::Result; +use clap::Parser; use hdwallet::mnemonic::{Language, Mnemonic}; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Options { /// The number of words for the mnemonic phrase. - #[structopt(short = "n", long, default_value = "12")] + #[clap(short = 'n', long, default_value_t = 12)] length: usize, /// The language to generate the mnemonic for. - #[structopt(short, long, default_value)] + #[clap(short, long, default_value_t)] language: Language, } diff --git a/src/cmd/public_key.rs b/src/cmd/public_key.rs index 31e5d0a..360255b 100644 --- a/src/cmd/public_key.rs +++ b/src/cmd/public_key.rs @@ -3,11 +3,11 @@ use crate::cmd::AccountOptions; use anyhow::Result; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Options { - #[structopt(flatten)] + #[clap(flatten)] account: AccountOptions, } diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs index f292f0d..f0a7c89 100644 --- a/src/cmd/sign.rs +++ b/src/cmd/sign.rs @@ -2,40 +2,40 @@ use crate::cmd::{self, AccountOptions}; use anyhow::{ensure, Context as _, Result}; +use clap::Parser; use hdwallet::{ hash, transaction::{LegacyTransaction, Transaction}, typeddata::TypedData, }; use std::{convert::TryInto, path::PathBuf}; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Options { - #[structopt(subcommand)] + #[clap(subcommand)] input: Input, - #[structopt(flatten)] + #[clap(flatten)] account: AccountOptions, } -#[derive(Debug, StructOpt)] -#[structopt(rename_all = "lowercase")] +#[derive(Debug, Parser)] +#[clap(rename_all = "lowercase")] enum Input { /// Sign an Ethereum transaction. Transaction { /// Path to transaction to sign in JSON format. - #[structopt(name = "TRANSACTION")] + #[clap(name = "TRANSACTION")] transaction: PathBuf, /// Only output the transaction signature instead of the RLP-encoded /// signed transaction. - #[structopt(long)] + #[clap(long)] signature_only: bool, /// Force allowing legacy transactions without a chain ID for relay /// protection. Use this care! - #[structopt(long)] + #[clap(long)] allow_missing_relay_protection: bool, }, @@ -44,21 +44,21 @@ enum Input { /// Path to the message to sign in the "eth_sign" scheme. This message /// will be prefixed with "\x19Ethereum Signed Message:\n" and its /// length before hashing and singing. - #[structopt(name = "MESSAGE")] + #[clap(name = "MESSAGE")] message: PathBuf, }, /// Sign EIP-712 typed data. TypedData { /// Path to the EIP-712 typed data in JSON format. - #[structopt(name = "TYPEDDATA")] + #[clap(name = "TYPEDDATA")] typed_data: PathBuf, }, /// Sign a raw data. Raw { /// The 32 byte message to sign specified as a hexadecimal string. - #[structopt(name = "BYTES", parse(try_from_str = permissive_hex_digest))] + #[clap(name = "BYTES", parse(try_from_str = permissive_hex_digest))] message: [u8; 32], }, } diff --git a/src/main.rs b/src/main.rs index 211cfb1..2c80f57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,33 +1,33 @@ mod cmd; +use clap::Parser; use std::process; -use structopt::StructOpt; #[allow(clippy::large_enum_variant)] -#[derive(Debug, StructOpt)] -#[structopt( +#[derive(Debug, Parser)] +#[clap( name = "hdwallet", about = "Hierarchical deterministic wallet for Ethereum" )] enum Options { - #[structopt(about = "Print account public address")] + #[clap(about = "Print account public address")] Address(cmd::address::Options), - #[structopt(about = "Export a private key")] + #[clap(about = "Export a private key")] Export(cmd::export::Options), - #[structopt(about = "Keccak256 hash data")] + #[clap(about = "Keccak256 hash data")] Hash(cmd::hash::Options), - #[structopt(about = "Hex encoding and decoding")] + #[clap(about = "Hex encoding and decoding")] Hex(cmd::hex::Options), - #[structopt(about = "Generate a new HD wallet mnemonic")] + #[clap(about = "Generate a new HD wallet mnemonic")] New(cmd::new::Options), - #[structopt(about = "Export the public key for an account")] + #[clap(about = "Export the public key for an account")] PublicKey(cmd::public_key::Options), - #[structopt(about = "Sign a message")] + #[clap(about = "Sign a message")] Sign(cmd::sign::Options), } fn main() { - if let Err(err) = match Options::from_args() { + if let Err(err) = match Options::parse() { Options::Address(options) => cmd::address::run(options), Options::Export(options) => cmd::export::run(options), Options::Hash(options) => cmd::hash::run(options), |
