diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/account.rs | 5 | ||||
| -rw-r--r-- | src/cmd.rs | 5 | ||||
| -rw-r--r-- | src/cmd/address.rs | 2 | ||||
| -rw-r--r-- | src/cmd/export.rs | 19 | ||||
| -rw-r--r-- | src/cmd/new.rs | 2 | ||||
| -rw-r--r-- | src/cmd/sign.rs | 5 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/mnemonic.rs | 4 |
8 files changed, 36 insertions, 8 deletions
diff --git a/src/account.rs b/src/account.rs index 338913f..cbe0148 100644 --- a/src/account.rs +++ b/src/account.rs @@ -37,6 +37,11 @@ impl PrivateKey { Address::from_slice(&hash[12..]) } + /// Returns the private key's 32 byte secret. + pub fn secret(&self) -> [u8; 32] { + *self.0.as_ref() + } + /// Generate a signature for the specified message. pub fn sign(&self, message: [u8; 32]) -> Signature { let message = Message::from_slice(&message).expect("invalid message"); @@ -1,6 +1,7 @@ //! Module containing subcommands. pub mod address; +pub mod export; pub mod new; pub mod sign; @@ -8,7 +9,9 @@ use crate::{account::PrivateKey, hdk, mnemonic::Mnemonic}; use anyhow::Result; use structopt::StructOpt; -/// Shared account options. +// Shared account options. +// NOTE: This is intentionally not a doc-comment as it would hijack the sub- +// command's description. #[derive(Debug, StructOpt)] struct AccountOptions { /// The BIP-0039 mnemonic phrase for seeding the HD wallet. diff --git a/src/cmd/address.rs b/src/cmd/address.rs index b0322b2..199de69 100644 --- a/src/cmd/address.rs +++ b/src/cmd/address.rs @@ -6,7 +6,7 @@ use anyhow::Result; use structopt::StructOpt; #[derive(Debug, StructOpt)] -#[structopt(about = "print account public address")] +#[structopt(about = "Print account public address")] pub struct Options { #[structopt(flatten)] account: AccountOptions, diff --git a/src/cmd/export.rs b/src/cmd/export.rs new file mode 100644 index 0000000..1e78098 --- /dev/null +++ b/src/cmd/export.rs @@ -0,0 +1,19 @@ +//! Module implementing the `export` subcommand for displaying an account's +//! private key. + +use crate::cmd::AccountOptions; +use anyhow::Result; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +#[structopt(about = "Export a private key")] +pub struct Options { + #[structopt(flatten)] + account: AccountOptions, +} + +pub fn run(options: Options) -> Result<()> { + let key = options.account.private_key()?; + println!("0x{}", hex::encode(key.secret())); + Ok(()) +} diff --git a/src/cmd/new.rs b/src/cmd/new.rs index 699b825..95af22a 100644 --- a/src/cmd/new.rs +++ b/src/cmd/new.rs @@ -6,7 +6,7 @@ use anyhow::Result; use structopt::StructOpt; #[derive(Debug, StructOpt)] -#[structopt(about = "generate a new HD wallet mnemonic")] +#[structopt(about = "Generate a new HD wallet mnemonic")] pub struct Options { /// The number of words for the mnemonic phrase. #[structopt(short = "n", long, default_value = "12")] diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs index 59095ae..bf88849 100644 --- a/src/cmd/sign.rs +++ b/src/cmd/sign.rs @@ -1,5 +1,4 @@ -//! Module implementing the `address` subcommand for displaying the public -//! address for corresponding account. +//! Module implementing the `sign` subcommand for generating ECDSA signatures. use crate::{cmd::AccountOptions, hash}; use anyhow::{Context as _, Result}; @@ -7,7 +6,7 @@ use std::convert::TryInto; use structopt::StructOpt; #[derive(Debug, StructOpt)] -#[structopt(about = "print account public address")] +#[structopt(about = "Sign a message")] pub struct Options { #[structopt(flatten)] account: AccountOptions, diff --git a/src/main.rs b/src/main.rs index 7122b40..b390021 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use structopt::StructOpt; )] enum Options { Address(address::Options), + Export(export::Options), New(new::Options), Sign(sign::Options), } @@ -23,6 +24,7 @@ enum Options { fn main() { if let Err(err) = match Options::from_args() { Options::Address(options) => address::run(options), + Options::Export(options) => export::run(options), Options::New(options) => new::run(options), Options::Sign(options) => sign::run(options), } { diff --git a/src/mnemonic.rs b/src/mnemonic.rs index 836ceee..ff0718c 100644 --- a/src/mnemonic.rs +++ b/src/mnemonic.rs @@ -25,7 +25,7 @@ pub struct Mnemonic { /// A buffer containing the mnemonic's binary representation and hash used /// for checksums. buf: [u8; 64], - /// The length of the seed bytes without the 32-byte hash. + /// The length of the seed bytes without the 32 byte hash. len: usize, } @@ -172,7 +172,7 @@ impl FromStr for Mnemonic { } } -/// A 64-byte seed derived from a BIP-0039 mnemonic. +/// A 64 byte seed derived from a BIP-0039 mnemonic. #[derive(Clone, Debug, Eq, PartialEq)] pub struct Seed([u8; 64]); |
