diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2020-11-30 19:11:36 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2020-11-30 19:11:36 +0100 |
| commit | a699b6b4fe6f0e2567f7298fd8174e779f1bd43d (patch) | |
| tree | e79f3927acc133cd05e06e22b1c95c776effe991 /src/cmd.rs | |
| parent | 678d45e7ae09510796d27a80ecd894f6a1ad8279 (diff) | |
hd wallet impl
Diffstat (limited to 'src/cmd.rs')
| -rw-r--r-- | src/cmd.rs | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -1 +1,29 @@ +//! Module containing subcommands. + +pub mod address; pub mod new; + +use crate::{account::PrivateKey, hdk, mnemonic::Mnemonic}; +use anyhow::Result; +use structopt::StructOpt; + +/// Shared account options. +#[derive(Debug, StructOpt)] +struct AccountOptions { + /// The BIP-0039 mnemonic phrase for seeding the HD wallet. + #[structopt(short, long, env)] + mnemonic: Mnemonic, + + /// The BIP-44 account index for deriving a private from the mnemonic seed + /// phrase. + #[structopt(long, env, default_value = "0")] + account_index: usize, +} + +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) + } +} |
