#hdwallet #bip32 #wallet #bitcoin #crypto

hdwallet-bitcoin

Bitcoin BIP-32 key derivation

8 releases

0.4.1 Feb 16, 2023
0.4.0 Feb 15, 2023
0.3.0 Feb 13, 2021
0.2.5 Feb 7, 2020
0.1.1 Mar 3, 2019

#2447 in Magic Beans

Download history 31/week @ 2023-10-29 44/week @ 2023-11-05 22/week @ 2023-11-12 24/week @ 2023-11-19 53/week @ 2023-11-26 39/week @ 2023-12-03 22/week @ 2023-12-10 32/week @ 2023-12-17 33/week @ 2023-12-24 81/week @ 2023-12-31 90/week @ 2024-01-07 56/week @ 2024-01-14 90/week @ 2024-01-21 90/week @ 2024-01-28 69/week @ 2024-02-04 53/week @ 2024-02-11

302 downloads per month
Used in 4 crates

MIT license

57KB
1K SLoC

HD wallet Bitcoin extention.

This crate extend the hdwallet crate, provide Bitcoin key derivation and serialization according to BIP-32. See hdwallet documentation to learn how to derive HD keys. See secp256k1 documentation to learn how to signature.

Examples

use hdwallet::{KeyChain, DefaultKeyChain, ExtendedPrivKey, traits::Serialize};
use hdwallet_bitcoin::{PrivKey as BitcoinPrivKey, Network as BitcoinNetwork};

let mut rng = rand::thread_rng();
let master_key = ExtendedPrivKey::random(&mut rng).expect("master key");
let key_chain = DefaultKeyChain::new(master_key);
let (extended_key, derivation) = key_chain.derive_private_key("m/1H/0".into()).expect("derive ExtendedPrivKey");
let key = BitcoinPrivKey {
    network: BitcoinNetwork::MainNet,
    derivation,
    extended_key,
};
let serialized_key: String = key.serialize();
println!("derive m/1H/0 key: {}", serialized_key);

Dependencies

~13MB
~288K SLoC