12 releases (6 breaking)

0.12.0 Jul 27, 2024
0.11.1 Jun 9, 2024
0.8.7 Aug 23, 2023
0.8.3 Mar 15, 2023
0.2.2 Apr 4, 2021

#10 in #bip-32

Download history 45381/week @ 2024-07-21 42564/week @ 2024-07-28 43983/week @ 2024-08-04 48865/week @ 2024-08-11 45708/week @ 2024-08-18 44451/week @ 2024-08-25 46559/week @ 2024-09-01 46898/week @ 2024-09-08 44801/week @ 2024-09-15 45194/week @ 2024-09-22 50178/week @ 2024-09-29 57675/week @ 2024-10-06 53385/week @ 2024-10-13 54601/week @ 2024-10-20 46641/week @ 2024-10-27 41424/week @ 2024-11-03

198,506 downloads per month
Used in 298 crates (10 directly)

MIT/Apache

120KB
2.5K SLoC

coins-bip32

This is an implementation of BIP32. It uses k256 and re-exports several of its traits and types.

It can be used to build wallets and applications for Bitcoin and Ethereum.

Building

$ cargo build
$ cargo build --target wasm32-unknown-unknown

Run tests (make sure to run with all feature combinations):

$ cargo test

Run bench marks

$ cargo bench
$ cargo bench --no-default-features

lib.rs:

This crate provides a basic implementation of BIP32, BIP49, and BIP84. It can be easily adapted to support other networks, using the paramaterizable encoder.

Typically, users will want to use the MainnetEncoder, DerivedXPub, DerivedXPriv types, which are available at the crate root. If key derivations are unknown, use the XPub and XPriv objects instead. These may be deserialized using a network-specific Encoder from the enc module.

Useful traits will need to be imported from the enc or model modules. We also provide a prelude module with everything you need to get started.

Warnings:

  • This crate is NOT designed to be used in adversarial environments.
  • This crate has NOT had a comprehensive security review.

Usage

use coins_bip32::prelude::*;

let digest = coins_core::Hash256::default();

let xpriv_str = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi".to_owned();

let xpriv: XPriv = xpriv_str.parse().unwrap();

let child_xpriv = xpriv.derive_child(33)?;
let (sig, _recovery_id): (Signature, RecoveryId) = child_xpriv.sign_digest(digest.clone());

// Signing key types are associated with verifying key types. You can always derive a pubkey
let child_xpub = child_xpriv.verify_key();
child_xpub.verify_digest(digest.clone(), &sig)?;

MainnetEncoder::xpub_to_base58(&child_xpub)?;

Dependencies

~5MB
~88K SLoC