Skip to content

Commit

Permalink
Merge pull request #19 from steel97/stax-flex
Browse files Browse the repository at this point in the history
Stax/flex support
  • Loading branch information
kushti authored Oct 30, 2024
2 parents d709571 + fd44e8b commit 709af7b
Show file tree
Hide file tree
Showing 45 changed files with 1,228 additions and 461 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ on: [push, pull_request]

jobs:
job_build_nano_debug:
name: Build application for NanoS, X and S+
name: Build application for NanoS+, X, Stax, Flex
runs-on: ubuntu-latest
strategy:
matrix:
include:
- SDK: "$NANOS_SDK"
artifact: ergo-app-debug-nanos
- SDK: "$NANOX_SDK"
artifact: ergo-app-debug-nanox
- SDK: "$NANOSP_SDK"
artifact: ergo-app-debug-nanosp
- SDK: "$STAX_SDK"
artifact: ergo-app-debug-stax
- SDK: "$FLEX_SDK"
artifact: ergo-app-debug-flex

container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest
Expand Down Expand Up @@ -102,6 +104,11 @@ jobs:
job_scan_build:
name: Clang Static Analyzer
runs-on: ubuntu-latest
strategy:
matrix:
include:
- SDK: "$NANOSP_SDK"
- SDK: "$STAX_SDK"

container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest
Expand All @@ -112,6 +119,7 @@ jobs:

- name: Build with Clang Static Analyzer
run: |
export BOLOS_SDK=${{ matrix.SDK }}
make clean
scan-build --use-cc=clang -analyze-headers -enable-checker security -enable-checker unix -enable-checker valist -o scan-build --status-bugs make default
Expand All @@ -128,12 +136,10 @@ jobs:
strategy:
matrix:
include:
- model: nanos
SDK: "2.1"
# - model: nanox
# SDK: "2.0.2"
# - model: nanosp
# SDK: "1.0.4"
- model: nanox
- model: nanosp
#- model: stax
#- model: flex

needs: job_build_nano_debug
runs-on: ubuntu-latest
Expand Down Expand Up @@ -161,13 +167,13 @@ jobs:
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -qy nodejs
export SEED=`cat tests/seed.txt`
nohup bash -c "python /speculos/speculos.py bin/app.elf --apdu-port 9999 --api-port 5000 --display headless --model=${{ matrix.model }} --sdk=${{ matrix.SDK }} --seed \"${SEED}\"" > speculos.log 2<&1 &
nohup bash -c "python /speculos/speculos.py bin/app.elf --apdu-port 9999 --api-port 5000 --display headless --model=${{ matrix.model }} --seed \"${SEED}\"" > speculos.log 2<&1 &
cd tests && npm install
until `nc -w5 -z -v 127.0.0.1 9999`; do sleep 1; done;
npm --model=${{matrix.model}} --port=5000 run test
- name: Upload Speculos log
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: speculos-${{matrix.model}}-log
path: speculos.log
2 changes: 1 addition & 1 deletion .github/workflows/lint-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v4

- name: Lint
uses: DoozyX/clang-format-lint-action@v0.12
uses: DoozyX/clang-format-lint-action@v0.18.2
with:
source: './src'
extensions: 'h,c'
Expand Down
14 changes: 8 additions & 6 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
{
"env": {
"BOLOS_SDK": "~/.ledger/nanos-sdk",
"BOLOS_SDK": "~/.ledger/nanosplus-sdk",
"ARM_GCC": "~/.ledger/gcc-arm-none-eabi-13.2-2023.10"
},
"configurations": [
{
"name": "Nano S",
"name": "Nano S+",
"includePath": [
"${workspaceFolder}/src",
"${workspaceFolder}/build/nanos/gen_src",
"${workspaceFolder}/build/stax/gen_src",
"${env:ARM_GCC}/arm-none-eabi/include/*",
"${env:ARM_GCC}/lib/gcc/arm-none-eabi/13.2.1/include/*",
"${env:BOLOS_SDK}/include/*",
"${env:BOLOS_SDK}/lib_ux/include/*",
"${env:BOLOS_SDK}/lib_nbgl/include/*",
"${env:BOLOS_SDK}/lib_cxng/include/*",
"${env:BOLOS_SDK}/lib_standard_app/*"
],
"defines": [
"TARGET_NANOS",
"TARGET_NANOS2",
"OS_IO_SEPROXYHAL",
"HAVE_BAGL",
"HAVE_NBGL",
"HAVE_SE_TOUCH",
"HAVE_ECC",
"HAVE_ECC_WEIERSTRASS",
"HAVE_SECP_CURVES",
Expand Down Expand Up @@ -50,7 +52,7 @@
"PRINTF=screen_printf",
"_DEFAULT_SOURCE"
],
"compilerPath": "${env:ARM_GCC}/bin/arm-none-eabi-gcc",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-arm",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.6] - 2024-06-10

- Added Stax/Flex
- Removed Nano S

## [0.0.5] - 2024-06-10

- Updated to the latest Ledger SDK
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ APPNAME = "Ergo"
# Application version
APPVERSION_M = 0
APPVERSION_N = 0
APPVERSION_P = 5
APPVERSION_P = 6
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

# Application source files
APP_SOURCE_PATH += src

# Application icons following guidelines:
# https://developers.ledger.com/docs/embedded-app/design-requirements/#device-icon
ICON_NANOS = icons/app_16px.gif
ICON_NANOX = icons/app_14px.gif
ICON_NANOSP = icons/app_14px.gif
#ICON_STAX = icons/app_32px.gif
ICON_STAX = icons/app_32px.gif
ICON_FLEX = icons/app_40px.gif

# Application allowed derivation curves.
# Possibles curves are: secp256k1, secp256r1, ed25519 and bls12381g1
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ledger Ergo Application

This is a Ergo application for the Ledger Nano S/X.
This is a Ergo application for the Ledger Nano S+/X/Stax/Flex.

## Prerequisite

Expand All @@ -15,7 +15,7 @@ BOLOS_ENV=/opt/bolos-devenv
and do the same with `BOLOS_SDK` environment variable

```
BOLOS_SDK=/opt/bolos-sdk/nanos-secure-sdk
BOLOS_SDK=/opt/bolos-sdk/nanosplus-secure-sdk
```

## Compilation
Expand All @@ -42,7 +42,7 @@ the process outputs HTML and LaTeX documentations in `doc/html` and `doc/latex`
The flow processed in [GitHub Actions](https://github.com/features/actions) is the following:

- Code formatting with [clang-format](http://clang.llvm.org/docs/ClangFormat.html)
- Compilation of the application for Ledger Nano S in [ledger-app-builder](https://github.com/LedgerHQ/ledger-app-builder)
- Compilation of the application for Ledger Nano S+ in [ledger-app-builder](https://github.com/LedgerHQ/ledger-app-builder)
- Unit tests of C functions with [cmocka](https://cmocka.org/) (see [unit-tests/](unit-tests/))
- End-to-end tests with [Speculos](https://github.com/LedgerHQ/speculos) emulator (see [tests/](tests/))
- Code coverage with [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html)/[lcov](http://ltp.sourceforge.net/coverage/lcov.php) and upload to [codecov.io](https://about.codecov.io)
Expand Down
File renamed without changes
Binary file added glyphs/app_logo_64px.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/app_32px.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/app_40px.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ledger_app.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[app]
build_directory = "./"
sdk = "C"
devices = ["nanos", "nanox", "nanos+"]
devices = ["nanox", "nanos+", "stax", "flex"]

[tests]
unit_directory = "./unit-tests/"
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef HAVE_BAGL

#include <os.h>
#include <ux.h>
#include <glyphs.h>
Expand Down Expand Up @@ -48,4 +50,6 @@ int ui_display_access_token(uint32_t app_access_token, attest_input_ctx_t* conte
ui_display_screens(&screen);

return 0;
}
}

#endif
57 changes: 57 additions & 0 deletions src/commands/attestinput/ainpt_ui_nbgl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifdef HAVE_NBGL

#include <os.h>
#include <nbgl_use_case.h>
#include <string.h>
#include <glyphs.h>

#include "ainpt_ui.h"
#include "ainpt_response.h"
#include "../../context.h"
#include "../../common/macros_ext.h"
#include "../../helpers/response.h"
#include "../../ui/ui_application_id.h"
#include "../../ui/ui_menu.h"
#include "../../ui/ui_main.h"
#include "../../ui/display.h"

#define APPLICATION_ID_SUBLEN APPLICATION_ID_STR_LEN + 13
static char sub_message[APPLICATION_ID_SUBLEN];

void ui_action_attest_input(bool approved) {
set_flow_response(approved);
}

int ui_display_access_token(uint32_t app_access_token, attest_input_ctx_t* context) {
context->ui.app_token_value = app_access_token;

if (app_access_token != 0) {
ui_application_id_screen(app_access_token, context->ui.app_token);
memset(sub_message, 0, APPLICATION_ID_SUBLEN);
snprintf(sub_message, APPLICATION_ID_SUBLEN, "Application: 0x%08x", app_access_token);
}

nbgl_useCaseChoice(&VALIDATE_ICON,
"Confirm Attest Input",
sub_message,
"Confirm",
"Reject",
ui_action_attest_input);
bool approved = io_ui_process();

if (approved) {
app_set_connected_app_id(context->ui.app_token_value);
context->state = ATTEST_INPUT_STATE_APPROVED;
send_response_attested_input_session_id(context->session);

} else {
app_set_current_command(CMD_NONE);
res_deny();

ui_menu_main();
}

return 0;
}

#endif
9 changes: 8 additions & 1 deletion src/commands/deriveaddress/da_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <stdbool.h> // bool
#include "da_context.h"
#include "../../constants.h"
#include "../../context.h"
#include "../../helpers/response.h"

/**
* Display account on the device and ask confirmation to export.
Expand All @@ -16,4 +18,9 @@ int ui_display_address(derive_address_ctx_t* ctx,
uint32_t app_access_token,
uint32_t* bip32_path,
uint8_t bip32_path_len,
uint8_t raw_address[static P2PK_ADDRESS_LEN]);
uint8_t raw_address[static P2PK_ADDRESS_LEN]);

static inline int send_error(uint16_t err) {
app_set_current_command(CMD_NONE);
return res_error(err);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef HAVE_BAGL

#include <os.h>
#include <ux.h>
#include <glyphs.h>
Expand Down Expand Up @@ -49,11 +51,6 @@ static NOINLINE void ui_action_derive_address(bool approved, void* context) {
ui_menu_main();
}

static inline int send_error(uint16_t err) {
app_set_current_command(CMD_NONE);
return res_error(err);
}

// Display
int ui_display_address(derive_address_ctx_t* ctx,
bool send,
Expand Down Expand Up @@ -117,3 +114,5 @@ int ui_display_address(derive_address_ctx_t* ctx,

return 0;
}

#endif
Loading

0 comments on commit 709af7b

Please sign in to comment.