https://github.com/bitcoindevkit/rust-hwi
Rust wrapper for the Bitcoin Core Hardware Wallet Interface
https://github.com/bitcoindevkit/rust-hwi
Last synced: about 1 year ago
JSON representation
Rust wrapper for the Bitcoin Core Hardware Wallet Interface
- Host: GitHub
- URL: https://github.com/bitcoindevkit/rust-hwi
- Owner: bitcoindevkit
- License: other
- Created: 2020-03-10T17:33:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-02T13:29:06.000Z (about 1 year ago)
- Last Synced: 2025-04-12T03:38:11.419Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 261 KB
- Stars: 33
- Watchers: 8
- Forks: 28
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# rust-hwi
Rust wrapper for the [Bitcoin Hardware Wallet Interface](https://github.com/bitcoin-core/HWI/) library.
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](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`.