GithubHelp home page GithubHelp logo

jirijakes / rust-hwi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitcoindevkit/rust-hwi

0.0 0.0 0.0 246 KB

Rust wrapper for the Bitcoin Core Hardware Wallet Interface

License: Other

Rust 100.00%

rust-hwi's Introduction

rust-hwi

Rust wrapper for the Bitcoin Hardware Wallet Interface library.

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:

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

rust-hwi's People

Contributors

danielabrozzoni avatar wszdexdrf avatar yukibtc avatar tcharding avatar notmandatory avatar eunoia1729 avatar afilini avatar anishagg17 avatar jirijakes avatar josediegorobles avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.