4 releases (2 breaking)

0.3.0 Jan 22, 2021
0.2.1 Jun 28, 2019
0.2.0 Mar 11, 2019
0.1.0 Feb 20, 2019

#5 in #bip44

Download history 855/week @ 2024-09-01 932/week @ 2024-09-08 788/week @ 2024-09-15 1003/week @ 2024-09-22 1396/week @ 2024-09-29 771/week @ 2024-10-06 993/week @ 2024-10-13 740/week @ 2024-10-20 995/week @ 2024-10-27 1074/week @ 2024-11-03 748/week @ 2024-11-10 702/week @ 2024-11-17 836/week @ 2024-11-24 1257/week @ 2024-12-01 638/week @ 2024-12-08 1220/week @ 2024-12-15

3,992 downloads per month
Used in 6 crates

GPL-3.0 license

17KB
223 lines

tiny-hderive

A library for deriving secp256k1 secret keys from BIP39 seeds, using BIP32 crypto and BIP44 path formats.

use tiny_hderive::bip32::ExtendedPrivKey;

// Seed should be generated from your BIP39 phrase first!
let seed: &[u8] = &[42; 64];
let ext = ExtendedPrivKey::derive(seed, "m/44'/60'/0'/0/0").unwrap();

// Byte array of the secp256k1 secret key that can be used with Bitcoin or Ethereum.
assert_eq!(&ext.secret(), b"\x98\x84\xbf\x56\x24\xfa\xdd\x7f\xb2\x80\x4c\xfb\x0c\xb6\xf7\x1f\x28\x9e\x21\x1f\xcf\x0d\xe8\x36\xa3\x84\x17\x57\xda\xd9\x70\xd0");

// Deriving child keys from base one is also possible
use tiny_hderive::bip44::ChildNumber;
use std::str::FromStr;

let base_ext = ExtendedPrivKey::derive(seed, "m/44'/60'/0'/0").unwrap();
// child_ext is a key which is derived from this path: m/44'/60'/0'/0/0
let child_ext = base_ext.child(ChildNumber::from_str("0").unwrap()).unwrap();

assert_eq!(ext, child_ext);

lib.rs:

tiny-hderive

A library for deriving secp256k1 secret keys from BIP39 seeds, using BIP32 crypto and BIP44 path formats.

use tiny_hderive::bip32::ExtendedPrivKey;

// Seed should be generated from your BIP39 phrase first!
let seed: &[u8] = &[42; 64];
let ext = ExtendedPrivKey::derive(seed, "m/44'/60'/0'/0/0").unwrap();

// Byte array of the secp256k1 secret key that can be used with Bitcoin or Ethereum.
assert_eq!(&ext.secret(), b"\x98\x84\xbf\x56\x24\xfa\xdd\x7f\xb2\x80\x4c\xfb\x0c\xb6\xf7\x1f\x28\x9e\x21\x1f\xcf\x0d\xe8\x36\xa3\x84\x17\x57\xda\xd9\x70\xd0");

Dependencies

~2–2.7MB
~49K SLoC