Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bp-wg/bitcoin_hwi


https://github.com/bp-wg/bitcoin_hwi

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# rust-hwi

**NB: This is a temporary fork of https://github.com/bitcoindevkit/rust-hwi. The plan is the full rewrite from scratch not to depend and not to work with the command-line python `hwi` utility and use `libusb` directly from rust - with improved data types and error reporting.**

Here is the copy of the original README:

Rust wrapper for [HWI](https://github.com/bitcoin-core/HWI/).

Crate Info
API Docs
Rustc Version 1.41+
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.48.0`. To build with the MSRV you will need to pin some dependencies:
```bash
cargo update -p serde_json --precise 1.0.99
cargo update -p serde --precise 1.0.156
cargo update -p once_cell --precise 1.14.0
cargo update -p quote --precise 1.0.30
cargo update -p proc-macro2 --precise 1.0.65
```

## Prerequisites

Python 3 is required. The libraries and [udev rules](https://github.com/bitcoin-core/HWI/blob/master/hwilib/udev/README.md) for each device must also be installed. Some libraries will need to be installed

For Ubuntu/Debian:
```bash
sudo apt install libusb-1.0-0-dev libudev-dev python3-dev
```

For Centos:
```bash
sudo yum -y install python3-devel libusbx-devel systemd-devel
```

For macOS:
```bash
brew install libusb
```

## Install

- Clone the repo
```bash
git clone https://github.com/bitcoindevkit/rust-hwi.git && cd rust-hwi
```

- Create a virtualenv:

```bash
virtualenv -p python3 venv
source venv/bin/activate
```

- Install all the dependencies using pip:

```bash
pip install -r requirements.txt
```

## Usage

```rust
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:
- [Coldcard simulator](https://github.com/Coldcard/firmware)
- [Trezor simulator](https://docs.trezor.io/trezor-firmware/core/emulator/index.html)
- [Ledger simulator](https://github.com/LedgerHQ/speculos)

**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`.