aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2021-08-21 07:35:13 +0000
committerNicholas Rodrigues Lordello <[email protected]>2021-08-21 07:35:13 +0000
commitf608cce748d80d46f49ba25999e4334fd959b070 (patch)
tree9fc73440b321933cfd6e6ead10ee18d93bc99c89 /src
parentc05487949a5cb9808945b5bdd174e14fdd7e51ea (diff)
Refactor into lib+bin and start adding e2e tests
Diffstat (limited to 'src')
-rw-r--r--src/account.rs3
-rw-r--r--src/cmd.rs2
-rw-r--r--src/cmd/hash.rs3
-rw-r--r--src/cmd/new.rs2
-rw-r--r--src/cmd/sign.rs6
-rw-r--r--src/hdk.rs4
-rw-r--r--src/lib.rs17
-rw-r--r--src/main.rs10
-rw-r--r--src/mnemonic.rs4
9 files changed, 34 insertions, 17 deletions
diff --git a/src/account.rs b/src/account.rs
index eda93bf..db80e17 100644
--- a/src/account.rs
+++ b/src/account.rs
@@ -9,8 +9,9 @@ pub use self::{
};
use crate::hash;
use anyhow::Result;
+pub use secp256k1::PublicKey;
use secp256k1::{
- key::{PublicKey, SecretKey, ONE_KEY},
+ key::{SecretKey, ONE_KEY},
Message, Secp256k1,
};
use std::{
diff --git a/src/cmd.rs b/src/cmd.rs
index c976d54..e3df2eb 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -8,8 +8,8 @@ pub mod new;
pub mod public_key;
pub mod sign;
-use crate::{account::PrivateKey, hdk, mnemonic::Mnemonic};
use anyhow::Result;
+use hdwallet::{account::PrivateKey, hdk, mnemonic::Mnemonic};
use std::{
fs,
io::{self, Read as _},
diff --git a/src/cmd/hash.rs b/src/cmd/hash.rs
index aade76b..4a650ff 100644
--- a/src/cmd/hash.rs
+++ b/src/cmd/hash.rs
@@ -1,7 +1,8 @@
//! Module implementing the `hash` subcommand for `keccak256` hashing data.
-use crate::{cmd, hash};
+use crate::cmd;
use anyhow::Result;
+use hdwallet::hash;
use std::path::PathBuf;
use structopt::StructOpt;
diff --git a/src/cmd/new.rs b/src/cmd/new.rs
index d247213..002e5d0 100644
--- a/src/cmd/new.rs
+++ b/src/cmd/new.rs
@@ -1,8 +1,8 @@
//! Module implementing the `new` subcommand for generating a mnemonic for a new
//! hierarchical deterministic wallet.
-use crate::mnemonic::{Language, Mnemonic};
use anyhow::Result;
+use hdwallet::mnemonic::{Language, Mnemonic};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs
index 85aec8b..290b1a3 100644
--- a/src/cmd/sign.rs
+++ b/src/cmd/sign.rs
@@ -1,11 +1,11 @@
//! Module implementing the `sign` subcommand for generating ECDSA signatures.
-use crate::{
- cmd::{self, AccountOptions},
+use crate::cmd::{self, AccountOptions};
+use anyhow::{ensure, Context as _, Result};
+use hdwallet::{
hash,
transaction::{LegacyTransaction, Transaction},
};
-use anyhow::{ensure, Context as _, Result};
use std::{convert::TryInto, path::PathBuf};
use structopt::StructOpt;
diff --git a/src/hdk.rs b/src/hdk.rs
index 3c2af45..7e065b6 100644
--- a/src/hdk.rs
+++ b/src/hdk.rs
@@ -17,6 +17,10 @@ const HARDENED: u32 = 0x8000_0000;
/// Creates a new extended private key from a seed.
pub fn derive(seed: impl AsRef<[u8]>, path: &Path) -> Result<PrivateKey> {
+ derive_slice(seed.as_ref(), path)
+}
+
+fn derive_slice(seed: &[u8], path: &Path) -> Result<PrivateKey> {
let mut extended_key = {
let mut hmac = Hmac::<Sha512>::new_from_slice(b"Bitcoin seed")?;
hmac.update(seed.as_ref());
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..62474bd
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,17 @@
+//! Ethereum hierarchically deterministic wallet.
+//!
+//! This crate implements generating and parsing BIP-0039 mnemonic phrases, as
+//! well as BIP-0032 private key derivation, and various utilities for using
+//! these derived keys for signing various messages relative to Ethereum.
+
+pub mod account;
+pub mod hash;
+pub mod hdk;
+pub mod mnemonic;
+mod rand;
+mod serialization;
+pub mod transaction;
+pub mod typeddata;
+
+#[cfg(test)]
+mod ganache;
diff --git a/src/main.rs b/src/main.rs
index dcba758..211cfb1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,14 +1,4 @@
-mod account;
mod cmd;
-mod hash;
-mod hdk;
-mod mnemonic;
-mod rand;
-mod serialization;
-mod transaction;
-
-#[cfg(test)]
-mod ganache;
use std::process;
use structopt::StructOpt;
diff --git a/src/mnemonic.rs b/src/mnemonic.rs
index 5121e40..1d553f0 100644
--- a/src/mnemonic.rs
+++ b/src/mnemonic.rs
@@ -59,6 +59,10 @@ impl Mnemonic {
/// Parses a mnemonic from a phrase.
pub fn from_phrase(mnemonic: impl AsRef<str>) -> Result<Self> {
+ Self::from_phrase_str(mnemonic.as_ref())
+ }
+
+ fn from_phrase_str(mnemonic: &str) -> Result<Self> {
let (language, words) = Language::split(mnemonic.as_ref())?;
let len = mnemonic_to_byte_length(words.len())?;