Skip to content

Rust boilerplate application for Ledger Nano S+/X, Stax and Flex

License

Notifications You must be signed in to change notification settings

LedgerHQ/app-boilerplate-rust

Repository files navigation

Ledger Rust Boilerplate Application

Rule enforcer Build and tests

This is a boilerplate application written in Rust which can be forked to start a new project for the Ledger Nano X, S+, Stax and Flex devices.

⚠️ Nano S is not supported

  • Implements standard features (display address, transaction signature...),
  • Has functional tests using Ragger,
  • Has CI workflows mandatory for app deployment in the Ledger store.

Links

Quick start guide

With VS Code

You can quickly setup a development environment on any platform (macOS, Linux or Windows) to build and test your application with Ledger's VS Code extension.

By using Ledger's own developer tools Docker image, the extension allows you to build your apps with the latest SDK, test them on Speculos and load them on any supported device.

  • Install and run Docker.
  • Make sure you have an X11 server running :
    • On Ubuntu Linux, it should be running by default.
    • On macOS, install and launch XQuartz (make sure to go to XQuartz > Preferences > Security and check "Allow client connections").
    • On Windows, install and launch VcXsrv (make sure to configure it to disable access control).
  • Install VScode and add Ledger's extension.
  • Open a terminal and clone app-boilerplate-rust with git clone [email protected]:LedgerHQ/app-boilerplate-rust.git.
  • Open the app-boilerplate-rust folder with VSCode.
  • Use Ledger extension's sidebar menu or open the tasks menu with ctrl + shift + b (command + shift + b on a Mac) to conveniently execute actions :
    • Build the app for the device model of your choice with Build.
    • Test your binary on the Speculos emulator with Run with emulator.
    • You can also run functional tests, load the app on a physical device, and more.

ℹ️ The terminal tab of VSCode will show you what commands the extension runs behind the scene.

With a terminal

Prerequisites

If you do not wish to use the VS Code extension, you can follow the following steps to setup a development environment on Linux, Windows or MacOS.

  • The ledger-app-dev-tools Docker image contains all the required tools and libraries to build, test and load an application on a device. You can download it from the ghcr.io docker repository:
sudo docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
  • Make sure you have an X11 server running :
    • On Ubuntu Linux, it should be running by default.
    • On macOS, install and launch XQuartz (make sure to go to XQuartz > Preferences > Security and check "Allow client connections").
    • On Windows, install and launch VcXsrv (make sure to configure it to disable access control).
  • You can then enter into this development environment by executing the following command from the directory of the application (git repository):
    • Linux (Ubuntu):
    sudo docker run --rm -ti --privileged -v "/dev/bus/usb:/dev/bus/usb" -v "$(realpath .):/app" --publish 5001:5001 --publish 9999:9999 -e DISPLAY=$DISPLAY -v '/tmp/.X11-unix:/tmp/.X11-unix' ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
    • macOS:
    sudo docker run  --rm -ti --privileged -v "$(pwd -P):/app" --publish 5001:5001 --publish 9999:9999 -e DISPLAY='host.docker.internal:0' -v '/tmp/.X11-unix:/tmp/.X11-unix' ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
    • Windows (with PowerShell):
    docker run --rm -ti --privileged -v "$(Get-Location):/app" -e DISPLAY='host.docker.internal:0' --publish 5001:5001 --publish 9999:9999 ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest

The application's code will be available from inside the docker container, you can proceed to the following compilation steps to build your app.

Building

You can build the boilerplate with the following command executed in the root directory of the app.

cargo ledger build nanox

This command will build the app for the Nano X, but you can use any supported device (nanox, nanosplus, stax, flex)

Testing

Ragger functional tests

This boilerplate app comes with functional tests implemented with Ledger's Ragger test framework.

  • Install the tests requirements
pip install -r tests/requirements.txt 
  • Run the functional tests :
pytest tests/ --tb=short -v --device {nanosp | nanox | stax | flex}

Emulator

You can also run the app directly on the Speculos emulator from the Docker container

Nano S+ or X

speculos --apdu-port 9999 --api-port 5001 --display headless --model nanosp target/nanosplus/release/app-boilerplate-rust

⚠️ UI is displayed on localhost:5001

Stax or Flex

speculos --apdu-port 9999 --api-port 5001 --model stax target/stax/release/app-boilerplate-rust

⚠️ UI is displayed by your X server

You can then send APDU using ledgercomm (pip install ledgercomm):

ledgercomm-send file test.apdu

Loading on device

⚠️ Loading the built application on a device shall be performed out of the Docker container, by using ledgerctl:

pip3 install ledgerwallet

ℹ️ Your device must be connected, unlocked and the screen showing the dashboard (not inside an application).

For instance, for Flex:

ledgerctl install -f target/flex/release/app_flex.json

Continuous Integration

The following workflows are executed in GitHub Actions :

  • Ledger guidelines enforcer which verifies that an app is compliant with Ledger guidelines. The successful completion of this reusable workflow is a mandatory step for an app to be available on the Ledger application store. More information on the guidelines can be found in the repository ledger-app-workflow
  • Compilation of the application for all supported devices in the ledger-app-builder docker image
  • End-to-end tests with the Speculos emulator and ragger (see tests/)
  • Various lint checks :
    • Source code lint checks with cargo fmt
    • Python functional test code lint checks with pylint and mypy

About

Rust boilerplate application for Ledger Nano S+/X, Stax and Flex

Resources

License

Stars

Watchers

Forks

Packages

No packages published