Code Monkey home page Code Monkey logo

bitbox-api-rs's Introduction

BitBox02 Rust and TypeScript library

This repo contains both a BitBox02 client library for Rust and for TypeScript. The latter is produced from the Rust code using Rust WASM.

Rust

See README-rust.md.

TypeScript

The NPM package's README is located at README-npm.md.

The version of NPM package is defined in NPM_VERSION.

To build the TypeScript library, follow these steps:

Install wasm-pack using:

cargo install wasm-pack

If not yet installed, install clang so libsecp256k1 can be cross compiled, e.g. on Ubuntu:

sudo apt-get install clang

Also install the jq tool:

sudo apt-get install jq

The Rust library can be compiled to WASM package including TypeScript definitions using:

make wasm

The output of this compilation will be in ./pkg, which is a NPM package ready to be used.

M1 Macs

The default system clang installation currently cannot build wasm32 targets on M1 Macs. Therefore a new clang compiler and archiver needs to be installed via:

brew install llvm

In order to use that new clang compiler and archiver specify it when runing make wasm:

AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang make wasm

Sandbox

A demo React project showcasing the TypeScript API. See sandbox.

Command to update the BitBox02 protobuf message files

Normally, Prost protobuf files are generated in build.rs during each compilation. This has a number of downsides:

  • The generated .rs file is not committed and depends on the particular version of prost-build that is used, as well as on the system installation of the protoc compiler.
  • As a consequence, re-building older version of this library might become tricky if the particular versions of these tools are not easy to install in the future.
  • Downstream projects need to install protoc in order to build this library, on dev-machines, in CI scripts, etc.

By pre-generating the file and making it a regular committed source file, these problems fall away.

As a maintainer/developer of this library, to update the protobuf messages, follow these steps:

Clone the BitBox02 firmware repo:

Make sure you have protoc installed:

On Ubuntu:

sudo apt-get install protobuf-compiler

On MacOS:

brew install protobuf

Install rust-script:

cargo install rust-script

Then:

rm -rf messages/*.proto
cp /path/to/bitbox02-firmware/messages/*.proto messages/
rm messages/backup.proto
make build-protos

This will generate/update src/shiftcrypto.bitbox02.rs.

bitbox-api-rs's People

Contributors

benma avatar asi345 avatar shonsirsha avatar edouardparis avatar tomasvrba avatar nicolals avatar jstrnbrg avatar

Stargazers

Michael D. Schmitt avatar 22388o⚡️  avatar Stadicus avatar tcme avatar  avatar

Watchers

Niklas avatar tcme avatar  avatar  Douglas Bakkum avatar  avatar  avatar

bitbox-api-rs's Issues

Bug in error messages in sandbox UI

The error message does not fit into the message box in BitBox sandbox UI, it exceeds the screen borders. Therefore they can not be fully read. Attaching a screenshot for this below:
Screenshot 2023-10-18 at 13 58 10

Blockchain data

I am currently developing an app in which I am integrating BitBox. I am wondering how I can best access the Bitcoin balances and transaction details on the blockchain of my users in order to display the data to them.
What options are there and which would you recommend?

Usage with webpack (create-react-app)

I tried to use the library in a React app and added the required WebPack config but I still get an error when using it (wasm.bitbox02ConnectWebHID is not a function). The WASM file is copied to the static/media folder during build.

Am I missing something?

Use separate versions for the Rust and NPM packages

wasm-pack produces the NPM package from Rust, adopting the version from Cargo.toml.

Both libraries should have their own versions and changelogs, as it is likely that sometimes one is changed but not other. Already happened with v0.1.6 where a Rust type was made public that did not affect the NPM lib.

Idea for solution: add a NPM-VERSION file that contains the version for NPM, use jq to patch the package.json using this version using in make wasm.

deploy the demo sandbox

It could be very useful if devs and users could visit a live deployment of the sandbox webapp without having to compile it.

Ideally it is deployed automatically when things are merged master.

Deploying using GitHub Pages for this repo could be best.

BTC Sign Message

I just saw that the btcSignMessage call is missing. Do you plan to add it?

consider splitting NPM package into a separate repo

This repo contains both the Rust package and the NPM package. To accomplish this, we are swimming against the tide quite heavily:

  • hack about separate READMEs for NPM, the GitHub page and Rust: #36
  • hack about having separate versions for each: #57
  • we would add prefixes to the version tags going foward (rust-x.y.z etc).

Now that we have all of this we could roll with it, but by now I got the feeling that we should have just done it in separate repos, where the NPM repo just includes the Rust package as a dependency. Then all the above workarounds become unnecessary.

The workarounds above incurs a mental overhead to anyone looking at this repo - separate repos would be straight forward to understand and work with.

Potential downside: development of new features could be a bit more difficult as one would have to use a dev-version of the Rust package in the NPM repo to develop a feature in both repos at once.

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.