aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2022-01-09 20:48:49 +0100
committerNicholas Rodrigues Lordello <[email protected]>2022-01-09 20:48:49 +0100
commit7988f75774317d3ab0fdc513df12ccc77ef0d315 (patch)
treeddfe932803cde7289d553b46691455d491dfe1ae /src
parenta51adad4672c443ebeb6c427ab37ba6c5694ecd8 (diff)
expose derive_index
Diffstat (limited to 'src')
-rw-r--r--src/cmd.rs9
-rw-r--r--src/hdk.rs6
2 files changed, 10 insertions, 5 deletions
diff --git a/src/cmd.rs b/src/cmd.rs
index e3df2eb..918ac84 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -44,11 +44,10 @@ impl AccountOptions {
/// Returns the private key for the specified account options.
pub fn private_key(&self) -> Result<PrivateKey> {
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)
+ match &self.hd_path {
+ None => hdk::derive_index(seed, self.account_index),
+ Some(hd_path) => hdk::derive(seed, &hd_path.parse()?),
+ }
}
}
diff --git a/src/hdk.rs b/src/hdk.rs
index bf1b33a..830b7c3 100644
--- a/src/hdk.rs
+++ b/src/hdk.rs
@@ -12,6 +12,12 @@ use sha2::Sha512;
/// A value indicating a path component is hardened.
const HARDENED: u32 = 0x8000_0000;
+/// Creates a new extended private key for an account index using the standard
+/// Ethereum HD path.
+pub fn derive_index(seed: impl AsRef<[u8]>, account_index: usize) -> Result<PrivateKey> {
+ derive(seed, &format!("m/44'/60'/0'/0/{}", account_index).parse()?)
+}
+
/// 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)