#ledger #ledger-nano #apdu #cryptocurrency

coins-ledger

Ledger Nano X/S connection and communication management library

21 releases (10 breaking)

0.12.0 Jul 27, 2024
0.10.1 Feb 1, 2024
0.9.2 Dec 2, 2023
0.9.1 Nov 27, 2023
0.1.0 Jan 4, 2021

#9 in #ledger-nano

Download history 6112/week @ 2024-07-22 5068/week @ 2024-07-29 9431/week @ 2024-08-05 7379/week @ 2024-08-12 5842/week @ 2024-08-19 8234/week @ 2024-08-26 9916/week @ 2024-09-02 6005/week @ 2024-09-09 5787/week @ 2024-09-16 6262/week @ 2024-09-23 7713/week @ 2024-09-30 7619/week @ 2024-10-07 7806/week @ 2024-10-14 6522/week @ 2024-10-21 6238/week @ 2024-10-28 7168/week @ 2024-11-04

28,445 downloads per month
Used in 13 crates (5 directly)

MIT/Apache

73KB
797 lines

coins-ledger

Communication library between Rust and Ledger Nano S/X devices

Building

Windows is not yet supported.

Native

  • Install dependencies
    • OSX
      • TODO
      • please file an issue if you know. I don't have a macbook :)
  • Build with native transport
    • cargo build

WASM

  • Install wasm-pack
  • MUST pass --disable-default-features
  • MUST select feature AT MOST ONE of browser and node
  • Build with node WASM bindings to @ledgerhq/hw-transport-node-hid
    • wasm-pack build --scope summa-tx --target nodejs -- --features=node --no-default-features
    • Runtime environment MUST be able to import @ledgerhq/hw-transport-node-hid
  • Build with browser WASM bindings to @ledgerhq/hw-transport-u2f
    • wasm-pack build --scope summa-tx --target bundler -- --features=broswer --no-default-features
    • Runtime environment MUST be able to import @ledgerhq/hw-transport-u2f

Features

The node and browser features are mutually exclusive. You must specify exactly one, as well as the --no-default-features flag.

When building for non-wasm architectures, a native HID transport is compiled in. When building wasm via wasm-pack, you must specify whether you want the node or browser wasm transport.

Testing

  • run the unit tests
    • $ cargo test -- --lib
  • run the integration tests
    • Plug in a Ledger Nano S or X device
    • Unlock the device
    • Open the Ethereum application on the device
    • $ cargo test

License Notes

This repo was forked from Zondax's repo at commit 7d40af96. Their code is reproduced here under the terms of the Apache 2 License. Files containing elements from their code maintain their original Apache 2 license notice at the bottom of the file.

Further work by Summa is available under the GNU LGPLv3 license.

These changes are as follows:

  • Remove bip44 crates
  • Significant refactoring to all other crates
  • Crates have been moved to be modules of a single crate
  • Refactor APDUErrorCodes
  • Refactor APDUCommand to move towards no_std support. They hold &'a [u8] instead of vectors
  • Refactor APDUAnswer to move towards no_std support and avoid unnecessary copies. It is now a thin wrapper around a &[u8]
  • Change exchange functions to accept a mutable buffer. The caller must allocate space for the response packet
  • wasm_bindgen bindings for JS ledger transports
  • Conditional compilation based abstraction of transport type
    • Native HID if not wasm32
    • Feature flags for browser or node if wasm32
  • Break out integration tests
  • Strip print logs

Dependencies

~0.4–8.5MB
~77K SLoC