15 releases (9 breaking)

0.10.0 Sep 13, 2024
0.9.0 Jun 4, 2024
0.8.0 Mar 24, 2024
0.7.0 Jul 18, 2023
0.1.2 Mar 15, 2020

#9 in #hardware-wallet

Download history 105/week @ 2024-08-05 193/week @ 2024-08-12 214/week @ 2024-08-19 101/week @ 2024-08-26 169/week @ 2024-09-02 258/week @ 2024-09-09 28/week @ 2024-09-16 101/week @ 2024-09-23 40/week @ 2024-09-30 73/week @ 2024-10-07 26/week @ 2024-10-14 89/week @ 2024-10-21 13/week @ 2024-10-28 40/week @ 2024-11-04 4/week @ 2024-11-11 77/week @ 2024-11-18

134 downloads per month
Used in 5 crates (4 directly)

MIT license

52KB
1K SLoC

rust-hwi

Rust wrapper for the Bitcoin Hardware Wallet Interface library.

Crate Info API Docs Rustc Version 1.63+ Chat on Discord

This library internally uses PyO3 to call HWI's functions. It is not a re-implementation of HWI in native Rust.

MSRV

The MSRV for this project is 1.63.0.

Prerequisites

Python 3 is required. The libraries and udev rules for each device must also be installed. Some libraries will need to be installed

For Ubuntu/Debian:

sudo apt install libusb-1.0-0-dev libudev-dev python3-dev

For Centos:

sudo yum -y install python3-devel libusbx-devel systemd-devel

For macOS:

brew install libusb

Install

  • Clone the repo
git clone https://github.com/bitcoindevkit/rust-hwi.git && cd rust-hwi
  • Create a virtualenv:
virtualenv -p python3 venv
source venv/bin/activate
  • Install all the dependencies using pip:
pip install -r requirements.txt

Usage

use bitcoin::Network;
use bitcoin::bip32::DerivationPath;
use hwi::error::Error;
use hwi::HWIClient;
use std::str::FromStr;

fn main() -> Result<(), Error> {
    let mut devices = HWIClient::enumerate()?;
    if devices.is_empty() {
        panic!("No devices found!");
    }
    let first_device = devices.remove(0)?;
    let client = HWIClient::get_client(&first_device, true, Network::Bitcoin.into())?;
    let derivation_path = DerivationPath::from_str("m/44'/1'/0'/0/0").unwrap();
    let s = client.sign_message("I love BDK wallet", &derivation_path)?;
    println!("{:?}", s.signature);
    Ok(())
}

Testing

To run the tests, you need to have a hardware wallet plugged in. If you don't have a HW for testing, you can try:

Don't use a device with funds for testing!

Either use a testing device with no funds, or use a simulator.

You can run the tests with cargo test.

Dependencies

~11–18MB
~220K SLoC