5 releases

0.6.1 Jan 17, 2025
0.6.0 Dec 5, 2024
0.5.1 Oct 17, 2024
0.5.0 Oct 15, 2024

#633 in Filesystem

Download history 122/week @ 2025-01-11 166/week @ 2025-01-18 86/week @ 2025-01-25 250/week @ 2025-02-01 119/week @ 2025-02-08 350/week @ 2025-02-15 203/week @ 2025-02-22 319/week @ 2025-03-01 126/week @ 2025-03-08 110/week @ 2025-03-15 373/week @ 2025-03-22 281/week @ 2025-03-29 219/week @ 2025-04-05 197/week @ 2025-04-12 302/week @ 2025-04-19 341/week @ 2025-04-26

1,070 downloads per month
Used in 4 crates

MIT/Apache

61KB
730 lines

License Docs Crates io Discord

HD wallets derivation

This crate supports the following HD derivations:

  • SLIP10 (compatible with BIP32), see Slip10
  • Non-standard Edwards derivation for ed25519 curve

To perform HD derivation, use HdWallet trait.

Example: SLIP10 derivation

Derive a master key from the seed, and then derive a child key m/1H/10:

use hd_wallet::{slip10, curves::Secp256k1};

let seed = b"16-64 bytes of high entropy".as_slice();
let master_key = slip10::derive_master_key::<Secp256k1>(seed)?;
let master_key_pair = hd_wallet::ExtendedKeyPair::from(master_key);

let child_key_pair = slip10::derive_child_key_pair_with_path(
    &master_key_pair,
    [1 + hd_wallet::H, 10],
);

Example: via HdWallet trait

HdWallet trait generalizes HD derivation algorithm, you can use it with generics:

use hd_wallet::{Slip10, curves::Secp256r1};

fn derive_using_generic_algo<E: generic_ec::Curve, Hd: hd_wallet::HdWallet<E>>(
    master_key: hd_wallet::ExtendedKeyPair<E>,
) -> hd_wallet::ExtendedKeyPair<E>
{
    Hd::derive_child_key_pair_with_path(
        &master_key,
        [1 + hd_wallet::H, 10],
    )
}

// Use it with any HD derivation:
let seed = b"16-64 bytes of high entropy".as_slice();
let master_key = hd_wallet::slip10::derive_master_key(seed)?;
let master_key_pair = hd_wallet::ExtendedKeyPair::from(master_key);
let child_key = derive_using_generic_algo::<Secp256r1, Slip10>(master_key_pair);

Features

  • curve-secp256k1, curve-secp256r1, curve-ed25519, curve-stark add curve implementation into the crate curves module
  • all-curves adds all curves listed above
  • slip10, edwards, stark add slip10, edwards, and stark HD derivations respectively
  • serde adds serde::{Serialize, Deserialize} traits implementation to the types in the library

Join us in Discord!

Feel free to reach out to us in Discord!

Dependencies

~1.5–3.5MB
~72K SLoC