GithubHelp home page GithubHelp logo

isabella232 / ledger-crypto Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zondax/ledger-crypto

0.0 0.0 0.0 1018 KB

License: Apache License 2.0

JavaScript 25.71% C++ 9.36% Python 1.24% C 51.43% Rust 0.24% Makefile 4.12% HTML 0.33% CMake 3.99% Vue 3.39% GDB 0.19%

ledger-crypto's Introduction

Ledger Crypto.com Chain app

stability-wip License CircleCI

This app is still work in progress!

This project contains the Crypto.com Chain app for Ledger Nano S and X.

  • Ledger Nano S/X BOLOS app
  • Specs / Documentation
  • C++ unit tests
  • Rust unit tests
  • Zemu tests

ATTENTION

Please note that:

  • Crypto.com Chain is ONLY running as Testnet now
  • This project has NOT been fully audited yet
  • Do not use in production and Do not use it with your real funds
  • Do not use a Ledger device with funds for development purposes.
  • Have a separate and marked device that is used ONLY for development and testing

Tip:

  • In releases, you will find a precompiled test app. If you are just curious, you can run zxtool.sh and avoid building.

Download and install

Once the app is approved by Ledger, it will be available in their app store (Ledger Live). You can get builds generated by CircleCI from the release tab. THESE ARE UNVETTED DEVELOPMENT RELEASES

Download a release from here (https://github.com/Zondax/ledger-crypto/releases). You only need zxtool.sh

If the file is not executable, run

chmod +x ./zxtool.sh

then run:

./zxtool.sh load

Development

Preconditions

  • Be sure you checkout submodules too:

    git submodule update --init --recursive
    
  • We only officially support Ubuntu. Install the following packages:

    sudo apt update && sudo apt-get -y install build-essential git wget cmake \
    libssl-dev libgmp-dev autoconf libtool libusb-1.0-0-dev libudev-dev
    

    Experimental support for MacOS (Catalina 10.15.4)

    brew install hidapi

  • Install Docker CE

  • You will need python 3 and then run

    • make deps

Warning: Some IDEs may not use the same python interpreter or virtual enviroment as the one you used when running pip. If you see conan is not found, check that you installed the package in the same interpreter as the one that launches cmake.

  • This project requires Ledger firmware 1.6
    • The current repository keeps track of Ledger's SDK but it is possible to override it by changing the git submodule.

If you want to run integration tests (zemu)

  • Install node > v13.0. We typically recommend using n
  • Install yarn. For instance: npm install -g yarn

How to build ?

We like clion or vscode but let's have some reproducible command line steps

  • Building the app itself

    If you installed the what is described above, just run:

    make

Running tests

  • Running rust tests (x64)

    If you installed the what is described above, just run:

    make rust_test
  • Running C/C++ tests (x64)

    If you installed the what is described above, just run:

    make cpp_test
  • Running device emulation+integration tests!!

     Use Zemu! Explained below!

How to test with Zemu?

What is Zemu?? Great you asked!! As part of this project, we are making public a beta version of our internal testing+emulation framework for Ledger apps.

Npm Package here: https://www.npmjs.com/package/@zondax/zemu

Repo here: https://github.com/Zondax/zemu

Let's go! First install everything:

At this moment, if you change the app you will need to run make before running the test again.

make zemu_install

Then you can run JS tests:

make zemu_test

To run a single specific test:

At the moment, the recommendation is to run from the IDE. Remember to run make if you change the app.

How to debug a Ledger app?

You can use vscode or clion to debug the app. We recommend using CLion but we provide a vscode (unsupported) configuration too.

Preconditions

If you are using CLion, you need to a configuration file in your home directory: $HOME/.gdbinit with the following content:

set auto-load local-gdbinit on
add-auto-load-safe-path /

Warnings

There are a few things to take into account when enabling Ledger App debugging:

  • Once you enable the local .gdbinit that is located in your project workspace. You will break local Rust debugging in your host. The reason is that debugging unit tests will use the same .gdbinit configuration that sets the environment to ARM. We are looking at some possible fixes. For now, if you want to debug unit tests instead of the ledger app, you need to comment out the lines in .gdbinit

Debugging

  1. Build your app

    make
  2. Define your debug scenario

    Open tests/zemu/tools/debug.mjs and look for the line:

    /// TIP you can use zemu commands here to take the app ...

    You can adjust this code to get the emulator to trigger a breakpoint in your app:

    • send clicks
    • send APDUs, etc
  3. Launch the emulator in debug mode

    If you didnt install Zemu yet (previous section), then run make zemu_install

    make zemu_debug

    The emulator will launch and immediately stop. You should see a black window

  4. Configure Clion debugger

    Your configuration should look similar to this:

    image

    Check that the path mappings are correct

  5. Start CLion debugger

    You will hit a breakpoint in main. Add breakpoints in other places and continue.

    Enjoy :)

Using a real device

How to prepare your DEVELOPMENT! device:

You can use an emulated device for development. This is only required if you are using a physical device

Please do not use a Ledger device with funds for development purposes.

Have a separate and marked device that is used ONLY for development and testing

There are a few additional steps that increase reproducibility and simplify development:

1 - Ensure your device works in your OS

2 - Set a test mnemonic

Many of our integration tests expect the device to be configured with a known test mnemonic.

  • Plug your device while pressing the right button

  • Your device will show "Recovery" in the screen

  • Double click

  • Run make dev_init. This will take about 2 minutes. The device will be initialized to:

    PIN: 5555
    Mnemonic: equip will roof matter pink blind book anxiety banner elbow sun young
    

3. Add a development certificate

  • Plug your device while pressing the right button

  • Your device will show "Recovery" in the screen

  • Click both buttons at the same time

  • Enter your pin if necessary

  • Run make dev_ca. The device will receive a development certificate to avoid constant manual confirmations.

Building the Ledger App

Loading into your development device

The Makefile will build the firmware in a docker container and leave the binary in the correct directory.

  • Build

    make                # Builds the app
    
  • Upload to a device

    The following command will upload the application to the ledger:

    Warning: The application will be deleted before uploading.

    make load          # Builds and loads the app to the device
    

APDU Specifications

ledger-crypto's People

Contributors

calvinaco avatar dependabot[bot] avatar jleni 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.