From f9a2b77ad08f5c742de30c6a01691e03854c7a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Colas?= Date: Fri, 2 Oct 2020 17:51:13 +0200 Subject: [PATCH 01/11] Add variants for CI --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 8f58bc0c..90ea8547 100644 --- a/Makefile +++ b/Makefile @@ -164,3 +164,6 @@ test: tests/node_packages tests/*.js tests/package.json bin/app.elf tests/node_packages: tests/package.json (cd tests; yarn install --frozen-lockfile) + +listvariants: + @echo VARIANTS COIN AVAX From 699aefc85dbe1c102d3acbe15d8c130be64bfcba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Colas?= Date: Fri, 2 Oct 2020 18:13:22 +0200 Subject: [PATCH 02/11] Add 'Pending Ledger review' banner --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 90ea8547..a063a441 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ include $(BOLOS_SDK)/Makefile.defines APPNAME = "Avalanche" -APP_LOAD_PARAMS= --appFlags 0 --curve secp256k1 --path "44'/9000'" $(COMMON_LOAD_PARAMS) +APP_LOAD_PARAMS= --appFlags 0 --curve secp256k1 --path "44'/9000'" $(COMMON_LOAD_PARAMS) --tlvraw 9F:01 GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2>/dev/null) From 7c65da4b9e4ba38752c0aecb19c265576dfa89f6 Mon Sep 17 00:00:00 2001 From: Edouard Merle Date: Wed, 6 Jan 2021 17:59:54 +0100 Subject: [PATCH 03/11] add missing includes --- src/types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types.h b/src/types.h index a3328b69..f5bcee4e 100644 --- a/src/types.h +++ b/src/types.h @@ -2,6 +2,8 @@ #include "exception.h" #include "os.h" +#include "cx.h" +#include "ux.h" #include "os_io_seproxyhal.h" #include From 3331aaa2e9273685a2cd761a2ceb6c540e1515b1 Mon Sep 17 00:00:00 2001 From: Edouard Merle Date: Wed, 6 Jan 2021 18:00:23 +0100 Subject: [PATCH 04/11] bump version to 0.3.2 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5db46d18..59b8e683 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2 VERSION_TAG ?= $(shell echo "$(GIT_DESCRIBE)" | cut -f1 -d-) APPVERSION_M=0 APPVERSION_N=3 -APPVERSION_P=1 +APPVERSION_P=2 APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) # Only warn about version tags if specified/inferred From 57272f1439f84c1a9559ced26d4b4d85b0d71297 Mon Sep 17 00:00:00 2001 From: TamtamHero <10632523+TamtamHero@users.noreply.github.com> Date: Mon, 22 Feb 2021 19:08:19 +0100 Subject: [PATCH 05/11] Add HAVE_PENDING_REVIEW_FLAG --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ccdec44b..15de4111 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ include $(BOLOS_SDK)/Makefile.defines APPNAME = "Avalanche" APP_LOAD_PARAMS= --appFlags 0 --curve secp256k1 --path "44'/9000'" --path "44'/60'" $(COMMON_LOAD_PARAMS) --tlvraw 9F:01 +DEFINES += HAVE_PENDING_REVIEW_SCREEN GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2>/dev/null) From 401985d3d33ba88c8306efbc4c61e70bd2ad6c8b Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Wed, 3 Mar 2021 15:04:39 +0100 Subject: [PATCH 06/11] Fix background of app icon, which does not work on Nano X --- icons/nano-s.gif | Bin 69 -> 75 bytes icons/nano-x.gif | Bin 71 -> 77 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/icons/nano-s.gif b/icons/nano-s.gif index ddf1085d83b365f5197ca7b549ee6eaa634ff5ac..cc5e607e0df43feb56b395e7d4b7a18851f7c056 100644 GIT binary patch literal 75 zcmZ?wbhEHb6krfwSjfom|Nnmm7*PDl!pOzI#GnHb0Le2j$+YyZJpEQsrs>jwi2P;J VkC!qo6zUT$FT8qcTM#3IH2{_96yg8? literal 69 zcmZ?wbhEHb6krfwXkcUjg8%>jEB<6*R`0Ax87y8r+H diff --git a/icons/nano-x.gif b/icons/nano-x.gif index 64aba373ad265d0d0b8d0f4f710ce3c4fd0e9024..e1fb611b8e50189cc260c698dddeb7966c65ed58 100644 GIT binary patch literal 77 zcmZ?wbhEHb6_GT#!5ilUz&x%!RUd&Q)LZd6Bob Y;^iOBIW2`3To#FCty{)5gO$M=0L7pd<^TWy literal 71 zcmZ?wbhEHb;K|NkrgWMSlDU}Vr?00NK<1Cv}&|I7uvcg|H`^m&oD Zx8mg=%{eWF7hD#JWvyE#HG`GG8USMa8aV&} From 6b35edc44c7aa2fd1dd441f375fd59281378f9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Baptiste=20B=C3=A9drune?= Date: Tue, 20 Apr 2021 12:00:08 +0200 Subject: [PATCH 07/11] Apply markdownlint --- CHANGELOG.md | 1 - CONTRIBUTING.md | 49 ++++++++++--------- README.md | 127 +++++++++++++++++++++++++----------------------- 3 files changed, 91 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56a0efe..c65ac7b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,6 @@ * Support signing of a hash with Ethereum BIP32 paths. * Other miscellaneous bug fixes. - ## 0.3.1 * Support P chain import and export. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f8004770..83d468f3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,71 +1,72 @@ -# Overview +# Contributing + +## Overview This repository contains the Avalanche BOLOS application for the Ledger Nano S and Ledger Nano X and tools for testing the application. While this app is currently under development, we do not recommend using it. This application has been developed against our fork of Avalanche.js. Most instructions assume you have the [Nix](https://nixos.org/nix/) Package Manager, which you can install on any Linux distribution or MacOS. Application and wallet developers who would like to support Ledger can do so with [LedgerJS](https://github.com/obsidiansystems/ledgerjs/tree/avax). -# Installation on the Nano S # +## Installation on the Nano S To install from the source directory, ensure that you have nix installed, run -``` -$ ./nix/install.sh -t s +```shell +./nix/install.sh -t s ``` and accept the prompts on your ledger device. -# Development # +## Development -## Developing on the Ledger Nano S ## +### Developing on the Ledger Nano S -### Incremental Build ### +#### Incremental Build -``` sh -$ nix-shell -A wallet.s --run 'make all' +```shell +nix-shell -A wallet.s --run 'make all' ``` -### Load ### +#### Load -``` sh -$ nix-shell -A wallet.s --run 'make load' +```shell +nix-shell -A wallet.s --run 'make load' ``` -## Developing on the Ledger Nano X ## +### Developing on the Ledger Nano X -### Incremental Build ### +#### Incremental Build -``` sh -$ nix-shell -A wallet.x --run 'make all' +```shell +nix-shell -A wallet.x --run 'make all' ``` -### Load ### +#### Load Ledger Nano X does not currently have a way to load unsigned apps. Testing need to be done through Ledger Live. -# Testing # - +## Testing -## Automated Testing ## +### Automated Testing You can run automated tests through speculos via the ./test.sh script. Just run this: -``` sh -$ nix-shell -A wallet.s --run 'make test' +```shell +nix-shell -A wallet.s --run 'make test' ``` Running the same test suite on a live ledger currently requires that the ledger be configured with the recovery phrase -``` +```text glory promote mansion idle axis finger extra february uncover one trip resource lawn turtle enact monster seven myth punch hobby comfort wild raise skin ``` and then you can (with the ledger connected) run -``` +```shell nix-shell -A wallet.s --run 'make; ./test.sh -h' ``` diff --git a/README.md b/README.md index 22ccb30a..d6544ed3 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,67 @@ -# Overview +# Ledger Avalanche app + +## Overview This repository contains the Avalanche BOLOS application for the Ledger Nano S and Ledger Nano X and tools for testing the application. Most instructions assume you have the [Nix](https://nixos.org/nix/) Package Manager, which you can install on any Linux distribution or MacOS. -# System Requirements +## System Requirements System requirements differ based on if you are using or installing the application. If you are using a Linux machine, you will need to [Prepare your Linux Machine for Ledger Device Communication](#preparing-your-linux-machine-for-ledger-device-communication) for both installing and usaging the application. This application is has been tested against Ledger Nano S firmware 1.6.1. Ledger Nano X has not been tested yet. Please use [Ledger Live](https://www.ledger.com/ledger-live) to manage your Ledger device's firmware. -## For Application Installation +### For Application Installation Installation requirements differ based on installation method: -### Installing with Ledger Live ### +#### Installing with Ledger Live + [Ledger Live](https://www.ledger.com/ledger-live) is the easiest way to install applications on your Ledger device. Please refer to [Ledger Live's system requirements](https://support.ledger.com/hc/en-us/articles/360006395553-Download-and-install-Ledger-Live) for this installation method. This application is still in active development and not yet available in Ledger Live. -### Installing Release Files ### +#### Installing Release Files -#### Supported Operating Systems #### +##### Supported Operating Systems - **Linux**: Supported. Debian distributions such as Ubuntu (18.04+) and NixOS (vXXX+). Other linux distributions may work, but have not been tested. - **Mac**: Supported. This has been tested on Catalina 10.15.5. Other versions may work, but have not been tested. - **Windows**: Not currently supported. -#### Package/Tool Dependency #### +##### Package/Tool Dependency - **libusb and libudev**: On Debian distributions, including Ubuntu, these packages are suffixed with `-dev`. Other distributions may have their own conventions. - - Linux Installation: `sudo apt-get install libusb-1.0.0-dev libudev-dev` - - Mac Installation: N/A (not necessary) + - Linux Installation: `sudo apt-get install libusb-1.0.0-dev libudev-dev` + - Mac Installation: N/A (not necessary) - **Python3**: Use `python3 --version` to check whether you have python3 installed or to confirm an installation was successful. - - Linux Installation: `sudo apt-get install python3-pip # Ubuntu example` - - Mac Installation: Python 3 can be installed on mac with homebrew: `brew install python` + - Linux Installation: `sudo apt-get install python3-pip # Ubuntu example` + - Mac Installation: Python 3 can be installed on mac with homebrew: `brew install python` - **virtualenv**: Use `virtualenv --version` to check whether you have virtualenv installed or to confirm an installation was successful. - - Linux Installation: To install using python3: `pip3 install virtualenv` (this may require `sudo`). - - Mac Installation: To install using python3: `pip3 install virtualenv` (this may require `sudo`). + - Linux Installation: To install using python3: `pip3 install virtualenv` (this may require `sudo`). + - Mac Installation: To install using python3: `pip3 install virtualenv` (this may require `sudo`). -### Installing from Source ### +#### Installing from Source -#### Supported Operating Systems #### +##### Supported Operating Systems - **Linux**: Supported. Debian distributions such as Ubuntu (18.04+) and NixOS (vXXX+). Other linux distributions may work, but have not been tested. - **Mac**: Supported on Catalina (10.15) but note that Catalina requires extra steps in the [Nix installation](https://nixos.org/nix/manual/#sect-macos-installation). - **Windows**: Not currently supported. -#### Package/Tool Dependency #### +##### Package/Tool Dependency - **Nix Package Manager**: Use `nix-env --version` to check whether you have Nix installed or to confirm an installation was successful. We recommend checking which [Nix Installation](https://nixos.org/nix/manual/#chap-installation) is right for you, but for most users the following will will work: - - Linux Installation: `sh <(curl -L https://nixos.org/nix/install) --daemon` - - Mac Installation: `sh <(curl -L https://nixos.org/nix/install) --daemon` + - Linux Installation: `sh <(curl -L https://nixos.org/nix/install) --daemon` + - Mac Installation: `sh <(curl -L https://nixos.org/nix/install) --daemon` -## Preparing Your Linux Machine for Ledger Device Communication +### Preparing Your Linux Machine for Ledger Device Communication On Linux, the "udev" rules must be set up to allow your user to communicate with the ledger device. MacOS devices do not need any configuration to communicate with a Ledger device, so if you are using Mac you can ignore this section. -### NixOS +#### NixOS On NixOS, one can easily do this with by adding the following to configuration.nix: + ``` nix { # ... @@ -66,95 +70,95 @@ On NixOS, one can easily do this with by adding the following to configuration.n } ``` -### Non-NixOS Linux Distros +#### Non-NixOS Linux Distros For non-NixOS Linux distros, LedgerHQ provides a [script](https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/add_udev_rules.sh) for this purpose, in its own [specialized repo](https://github.com/LedgerHQ/udev-rules). Download this script, read it, customize it, and run it as root: -``` -$ wget https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/add_udev_rules.sh -$ chmod +x add_udev_rules.sh +```shell +wget https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/add_udev_rules.sh +chmod +x add_udev_rules.sh ``` **We recommend against running the next command without reviewing the script** and modifying it to match your configuration. -``` -$ sudo ./add_udev_rules.sh +```shell +sudo ./add_udev_rules.sh ``` Subsequently, unplug your ledger hardware wallet, and plug it in again for the changes to take effect. For more details, see [Ledger's documentation](https://support.ledger.com/hc/en-us/articles/115005165269-Fix-connection-issues). -# Ledger App Installation +## Ledger App Installation There are 3 ways you can install this Ledger application: + 1. [Ledger Live](https://www.ledger.com/ledger-live) *(not yet available)*: Ledger Live is the easiest way to install applications on your Ledger device. However, this application is still in active development and not yet available in Ledger Live. 2. [Installing from Release](#installing-the-ledger-application-from-release): This is the recommended installation method until this app is available in Ledger Live. 3. [Installing from Source](#installing-the-ledger-application-from-source): Recommended for development only. *Note: You can only install applications on the Ledger Nano X through Ledger Live.* -## Installing the Ledger Application from Release +### Installing the Ledger Application from Release Please download `nano-s-release.tar.gz` from the latest release on the [releases](https://github.com/obsidiansystems/ledger-app-avalanche/releases) page of this repo, which contains a pre-compiled app or `.hex` file ready to install on the Ledger. The following sections describe how to install it, including acquiring other tools from the Ledger project. -### Installing BOLOS Python Loader +#### Installing BOLOS Python Loader Install `libusb` and `libudev`, with the relevant headers. On Debian-based distros, including Ubuntu, the packages with the headers are suffixed with `-dev`. Other distros will have their own conventions. So, for example, on Ubuntu, you can do this with: -``` -$ sudo apt-get install libusb-1.0.0-dev libudev-dev # Ubuntu example +```shell +sudo apt-get install libusb-1.0.0-dev libudev-dev # Ubuntu example ``` Then, install `pip3`. You must install `pip3` for this and not `pip`. On Ubuntu: -``` -$ sudo apt-get install python3-pip # Ubuntu example +```shell +sudo apt-get install python3-pip # Ubuntu example ``` Now, on any operating system, install `virtualenv` using `pip3`. It is important to use `pip3` and not `pip` for this, as this module requires `python3` support. -``` -$ sudo pip3 install virtualenv # Any OS +```shell +sudo pip3 install virtualenv # Any OS ``` Then create a Python virtual environment (abbreviated *virtualenv*). You could call it anything, but we shall call it "ledger". This will create a directory called "ledger" containing the virtualenv: -``` -$ virtualenv ledger # Any OS +```shell +virtualenv ledger # Any OS ``` Then, you must enter the `virtualenv`. If you do not successfully enter the `virtualenv`, future commands will fail. You can tell you have entered the virtualenv when your prompt is prefixed with `(ledger)`. -``` -$ source ledger/bin/activate +```shell +source ledger/bin/activate ``` Your terminal session -- and only that terminal session -- will now be in the virtual env. To have a new terminal session enter the virtualenv, run the above `source` command only in the same directory in the new terminal session. -### ledgerblue: The Python Module for Ledger Nano S/X +#### ledgerblue: The Python Module for Ledger Nano S/X We can now install `ledgerblue`, which is a Python module designed originally for Ledger Blue, but also is needed for the Ledger Nano S/X. Although we do not yet support Ledger Blue, you must still install the following python package. Within the virtualenv environment -- making sure that `(ledger)` is showing up before your prompt -- use pip to install the `ledgerblue` [Python package](https://pypi.org/project/ledgerblue/). This will install the Ledger Python packages into the virtualenv; they will be available only in a shell where the virtualenv has been activated. -``` -$ pip install ledgerblue +```shell +pip install ledgerblue ``` If you have to use `sudo` or `pip3` here, that is an indication that you have not correctly set up `virtualenv`. It will still work in such a situation, but please research other material on troubleshooting `virtualenv` setup. -### Load the Application onto the Ledger Device +#### Load the Application onto the Ledger Device Next you'll use the installation script to install the application on your Ledger device. The Ledger device must be in the following state: - * Plugged into your computer - * Unlocked (enter your PIN) - * On the home screen (do not have any application open) - * Not asleep (you should not see *vires in numeris* is scrolling across the - screen) +- Plugged into your computer +- Unlocked (enter your PIN) +- On the home screen (do not have any application open) +- Not asleep (you should not see *vires in numeris* is scrolling across the screen) If you are already in an application or the Ledger device is asleep, your installation process will fail. @@ -162,7 +166,7 @@ We recommend staying at your computer and keeping an eye on the Ledger device's Still within the virtualenv, run the `./install.sh` command included in the `nano-s-release.tar.gz` that you downloaded. This `./install.sh` script takes the path to an application directory. The only such directory included in the downloaded `release.tar.gz` will be `app`, so install the app like this, replacing `~/Downloads/` with whatever directory you downloaded the file into: -``` +```shell cd ~/Downloads/ tar xzf nano-s-release.tar.gz cd ledger-app-avalanche-s @@ -171,7 +175,7 @@ cd ledger-app-avalanche-s The first thing that should come up in your terminal is a message that looks like this: -``` +```text Generated random root public key : ``` @@ -181,7 +185,7 @@ You will need to push confirmation buttons on your Ledger device a few times dur If you see the "Generated random root public key" message and then something that looks like this: -``` +```text Traceback (most recent call last): File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main <...more file names...> @@ -192,25 +196,26 @@ the most likely cause is that your `udev` rules are not set up correctly, or you To load a new version of the Avalanche application onto the Ledger device in the future, you can run the command again, and it will automatically remove any previously-loaded version. -## Installing the Ledger Application from Source +### Installing the Ledger Application from Source You can install the Ledger app from source if you have Nix installed. To load the latest version of the Avalanche app: -``` sh -$ git clone https://github.com/obsidiansystems/ledger-app-avalanche.git -$ cd ledger-app-avalanche -$ git checkout master -$ ./nix/install.sh -t s +``` shell +git clone https://github.com/obsidiansystems/ledger-app-avalanche.git +cd ledger-app-avalanche +git checkout master +./nix/install.sh -t s ``` Some notes during app installation: + - 'Starting bats': When building and installing the application from source, the client will run a suite of tests found in the `tests.sh` file. 'bats' stands for "[Bash Automated Testing System](https://github.com/bats-core/bats-core)". These tests may take some time to complete. When they are done, the app installation will proceed. - Unsafe Manager: you will see a prompt to either allow or deny 'unsafe manager' when running `./nix/install.sh s`. 'Unsafe Manager' is any manager which is not Ledger Live. - Permission Denied: If you get a “permission denied” error, your computer is not detecting the Ledger device correctly. Make sure the Ledger is connected properly, that it was plugged in since updating the `udev` rules. You have to accept a few prompts on the Ledger. Then you must select and load the Avalanche app. -### Confirming the Installed Version +#### Confirming the Installed Version To confirm the version of the application installed on your hardware wallet, first make sure the Ledger device is: @@ -226,13 +231,13 @@ Then run the following: If the results of that command match the results of `git rev-parse --short HEAD`, the installation was successful. -# Troubleshooting # +## Troubleshooting -## Application Build Failure ## +### Application Build Failure If you run into issues building the Ledger application using `nix-shell -A wallet.s --run 'make all'`, we recommend trying `nix-shell -A wallet.s --run 'make clean all`. -## Manually Removing Applications from a Ledger Device ## +### Manually Removing Applications from a Ledger Device If an application is not listed in Ledger Live, it can only be uninstalled from the device over the command line similar to how it was installed. From eda22f20e2279af4a949c54ba3dc9cbbca7cc7ad Mon Sep 17 00:00:00 2001 From: TamtamHero <10632523+TamtamHero@users.noreply.github.com> Date: Thu, 29 Apr 2021 10:04:16 +0200 Subject: [PATCH 08/11] Remove Pending Ledger review flag --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3b0fccb8..da1ccd7b 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,7 @@ include $(BOLOS_SDK)/Makefile.defines APPNAME = "Avalanche" -APP_LOAD_PARAMS= --appFlags 0 --curve secp256k1 --path "44'/9000'" --path "44'/60'" $(COMMON_LOAD_PARAMS) --tlvraw 9F:01 -DEFINES += HAVE_PENDING_REVIEW_SCREEN +APP_LOAD_PARAMS= --appFlags 0 --curve secp256k1 --path "44'/9000'" --path "44'/60'" $(COMMON_LOAD_PARAMS) GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2>/dev/null) From 5866395a67c1cfe1e46943ef18f72ca568ec6d54 Mon Sep 17 00:00:00 2001 From: TamtamHero <10632523+TamtamHero@users.noreply.github.com> Date: Thu, 29 Apr 2021 10:04:52 +0200 Subject: [PATCH 09/11] Bump version 0.5.2 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index da1ccd7b..3ae3e101 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2 VERSION_TAG ?= $(shell echo "$(GIT_DESCRIBE)" | cut -f1 -d-) APPVERSION_M=0 APPVERSION_N=5 -APPVERSION_P=1 +APPVERSION_P=2 APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) # Only warn about version tags if specified/inferred From 4833d49749d9b3e2452f241820c6dc8f273a8409 Mon Sep 17 00:00:00 2001 From: Alexandre Esteves Date: Thu, 6 May 2021 23:46:58 +0100 Subject: [PATCH 10/11] Output code identifier in release utils --- release.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/release.nix b/release.nix index 6b579aa7..1b97baa7 100644 --- a/release.nix +++ b/release.nix @@ -7,13 +7,17 @@ in rec { release-nanox = ledger-app.nano.x.release.all; debug-build = (import ./. { debug = true; inherit runTest gitDescribe; }).nano.s.release.all; usbtool = import ./nix/usbtool.nix {}; - hashes = ledger-app.pkgs.writeScript "hashes" '' + release-notes = ledger-app.pkgs.writeScript "release-notes" '' PATH=${ledger-app.pkgs.coreutils}:$PATH MD5=$(md5sum -b ${release-nanos} | awk '{print $1;}') SHA256=$(sha256sum -b ${release-nanos} | awk '{print $1;}') SHA512=$(sha512sum -b ${release-nanos} | awk '{print $1;}') + CODE_IDENTIFIER=$(tar xfO ${release-nanos} ledger-app-avalanche-s/code-identifier.txt) + echo "MD5 | $MD5" echo "SHA256 | $SHA256" echo "SHA512 | $SHA512" + echo + echo "Code Identifier: $CODE_IDENTIFIER" ''; } From 5845df8871a48dad3772cdbe5e1930931fea12d7 Mon Sep 17 00:00:00 2001 From: Evan Richard Date: Thu, 10 Jun 2021 10:18:52 -0400 Subject: [PATCH 11/11] Apply squashed patchfile. --- src/evm_parse.c | 4 ++-- src/to_string.c | 34 +++++++++++++++++++++++++++------- src/to_string.h | 2 +- tests/eth-tests.js | 6 +++--- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/evm_parse.c b/src/evm_parse.c index fb0ff3fe..8e779c61 100644 --- a/src/evm_parse.c +++ b/src/evm_parse.c @@ -84,7 +84,7 @@ static void output_evm_fee_to_string(char *const out, size_t const out_size, out wei_to_gwei_string(out, out_size, in->fee); } static void output_evm_fund_to_string(char *const out, size_t const out_size, output_prompt_t const *const in) { - wei_to_navax_string_256(out, out_size, &in->amount_big); + wei_to_avax_or_navax_string_256(out, out_size, &in->amount_big); } static void output_evm_address_to_string(char *const out, size_t const out_size, output_prompt_t const *const in) { output_hex_to_string(out, out_size, &in->address.val, ETHEREUM_ADDRESS_SIZE); @@ -94,7 +94,7 @@ static void output_evm_bytes32_to_string(char *const out, size_t const out_size, } static void output_evm_prompt_to_string(char *const out, size_t const out_size, output_prompt_t const *const in) { - size_t ix = wei_to_navax_string_256(out, out_size, &in->amount_big); + size_t ix = wei_to_avax_or_navax_string_256(out, out_size, &in->amount_big); static char const to[] = " to "; if (ix + sizeof(to) > out_size) THROW_(EXC_MEMORY_ERROR, "Can't fit ' to ' into prompt value string"); diff --git a/src/to_string.c b/src/to_string.c index 8ea8a61a..31cdb5e2 100644 --- a/src/to_string.c +++ b/src/to_string.c @@ -174,6 +174,8 @@ size_t number_to_string(char *const dest, uint64_t number) { #define DECIMAL_DIGITS 9 #define NANO_AVAX_SCALE 1000000000 #define WEI_GWEI_SCALE 1000000000 +#define WEI_NAVAX_DIGITS 9 +#define WEI_AVAX_DIGITS 18 // Display avax in human readable form size_t subunit_to_unit_string(char *const dest, size_t const buff_size, uint64_t subunits, uint64_t scale) { @@ -253,13 +255,31 @@ size_t wei_to_navax_string(char *const dest, size_t const buff_size, uint64_t co ix += sizeof(unit) - 1; return ix; } -size_t wei_to_navax_string_256(char *const dest, size_t const buff_size, uint256_t const *const wei) { - static char const unit[] = " nAVAX"; - size_t ix = subunit_to_unit_string_256(dest, buff_size, wei, 9); - if (ix + sizeof(unit) > buff_size) THROW_(EXC_MEMORY_ERROR, "Can't fit ' nAVAX' into prompt value string"); - memcpy(&dest[ix], unit, sizeof(unit)); - ix += sizeof(unit) - 1; - return ix; + +size_t wei_to_avax_or_navax_string_256(char *const dest, size_t const buff_size, uint256_t const *const wei) { + const uint8_t AVAX_NAVAX_DISPLAY_THRESHOLD_BE[] = { + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x03, 0x8D, 0x7E, 0xA4, 0xC6, 0x80, 0x00}; // 38D7EA4C68000 = 1000000000000000dec + uint256_t AVAX_NAVAX_DISPLAY_THRESHOLD_256; + readu256BE(AVAX_NAVAX_DISPLAY_THRESHOLD_BE, &AVAX_NAVAX_DISPLAY_THRESHOLD_256); + + if (gte256(wei, &AVAX_NAVAX_DISPLAY_THRESHOLD_256)) { + static char const unit[] = " AVAX"; + size_t ix = subunit_to_unit_string_256(dest, buff_size, wei, WEI_AVAX_DIGITS); + if (ix + sizeof(unit) > buff_size) THROW_(EXC_MEMORY_ERROR, "Can't fit ' AVAX' into prompt value string"); + memcpy(&dest[ix], unit, sizeof(unit)); + ix += sizeof(unit) - 1; + return ix; + } else { + static char const unit[] = " nAVAX"; + size_t ix = subunit_to_unit_string_256(dest, buff_size, wei, WEI_NAVAX_DIGITS); + if (ix + sizeof(unit) > buff_size) THROW_(EXC_MEMORY_ERROR, "Can't fit ' nAVAX' into prompt value string"); + memcpy(&dest[ix], unit, sizeof(unit)); + ix += sizeof(unit) - 1; + return ix; + } } void nano_avax_to_string_indirect64(char *const dest, size_t const buff_size, uint64_t const *const number) { diff --git a/src/to_string.h b/src/to_string.h index f7267476..0897d087 100644 --- a/src/to_string.h +++ b/src/to_string.h @@ -13,7 +13,7 @@ size_t nano_avax_to_string(char *const dest, size_t const buff_size, uint64_t co size_t wei_to_gwei_string(char *const dest, size_t const buff_size, uint64_t const wei); size_t wei_to_gwei_string_256(char *const dest, size_t const buff_size, uint256_t const wei); size_t wei_to_navax_string(char *const dest, size_t const buff_size, uint64_t const wei); -size_t wei_to_navax_string_256(char *const dest, size_t const buff_size, uint256_t const *const wei); +size_t wei_to_avax_or_navax_string_256(char *const dest, size_t const buff_size, uint256_t const *const wei); void bip32_path_to_string(char *const out, size_t const out_size, bip32_path_t const *const path); size_t pkh_to_string(char *const out, size_t const out_size, char const *const hrp, size_t const hrp_size, diff --git a/tests/eth-tests.js b/tests/eth-tests.js index bca58c8b..d731764b 100644 --- a/tests/eth-tests.js +++ b/tests/eth-tests.js @@ -172,7 +172,7 @@ describe("Eth app compatibility tests", async function () { it('can sign a transaction via the ethereum ledgerjs module', async function() { await testSigning(this, 43114, transferPrompts('0x28ee52a8f3d6e5d15f8b131996950d7f296c7952', - '12340000 nAVAX', + '0.01234 AVAX', '9870000 GWEI' ), 'ed01856d6e2edc008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a248740008082a86a8080' @@ -182,7 +182,7 @@ describe("Eth app compatibility tests", async function () { it('can sign a larger transaction via the ethereum ledgerjs module', async function() { await testSigning(this, 43114, transferPrompts('0x28ee52a8f3d6e5d15f8b131996950d7f296c7952', - '238547462614852887054687704548455.429902335 nAVAX', + '238547462614852887054687.704548455429902335 AVAX', '9870000 GWEI'), 'f83801856d6e2edc008252089428ee52a8f3d6e5d15f8b131996950d7f296c79529202bd072a24087400000f0fff0f0fff0f0fff8082a86a8080' ); @@ -274,7 +274,7 @@ describe("Eth app compatibility tests", async function () { await testSigning(this, 43114, transferPrompts('0x28ee52a8f3d6e5d15f8b131996950d7f296c7952', - '12340000 nAVAX', + '0.01234 AVAX', '441000 GWEI'), 'ed018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a248740008082a86a8080' );