diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2020-12-01 18:54:35 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2020-12-01 18:54:35 +0100 |
| commit | e00c34041a67b3e59de4aaf0c8efe24823a1e5f3 (patch) | |
| tree | 3a25a1cd301d2076e99c12e2c04a354c24c1404b /src/cmd.rs | |
| parent | a699b6b4fe6f0e2567f7298fd8174e779f1bd43d (diff) | |
added ability to sign
Diffstat (limited to 'src/cmd.rs')
| -rw-r--r-- | src/cmd.rs | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -2,6 +2,7 @@ pub mod address; pub mod new; +pub mod sign; use crate::{account::PrivateKey, hdk, mnemonic::Mnemonic}; use anyhow::Result; @@ -14,16 +15,30 @@ struct AccountOptions { #[structopt(short, long, env)] mnemonic: Mnemonic, + /// The password to use with the mnemonic phrase for salting the seed used + /// for the HD wallet. + #[structopt(long, env, default_value)] + password: String, + /// The BIP-44 account index for deriving a private from the mnemonic seed - /// phrase. + /// phrase. The derived key will use the path "m/44'/60'/0'/0/{index}". #[structopt(long, env, default_value = "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")] + hd_path: Option<String>, } impl AccountOptions { /// Returns the private key for the specified account options. pub fn private_key(&self) -> Result<PrivateKey> { - let path = format!("m/44'/60'/0'/0/{}", self.account_index).parse()?; - hdk::derive(&self.mnemonic, &path) + let seed = self.mnemonic.seed(&self.password); + let path = match &self.hd_path { + None => format!("m/44'/60'/0'/0/{}", self.account_index).parse(), + Some(hd_path) => hd_path.parse(), + }?; + hdk::derive(seed, &path) } } |
