Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #75 from LedgerHQ/develop
Browse files Browse the repository at this point in the history
Align master with p1
  • Loading branch information
sgliner-ledger authored Oct 18, 2023
2 parents 2cd7b7a + 62cf404 commit fe5a6b2
Show file tree
Hide file tree
Showing 410 changed files with 2,427 additions and 550 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build_and_functional_tests_baking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and run functional baking tests using ragger through reusable workflow

# This workflow will build the app and then run functional tests using the Ragger framework upon Speculos emulation.
# It calls a reusable workflow developed by Ledger's internal developer team to build the application and upload the
# resulting binaries.
# It then calls another reusable workflow to run the Ragger tests on the compiled application binary.
#
# While this workflow is optional, having functional testing on your application is mandatory and this workflow and
# tooling environment is meant to be easy to use and adapt after forking your application

on:
workflow_dispatch:
push:
branches:
- master
- main
- develop
pull_request:

jobs:
build_application:
name: Build application using the reusable workflow
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
upload_app_binaries_artifact: "compiled_app_binaries"
flags: "APP=tezos_baking"

ragger_tests:
name: Run ragger tests using the reusable workflow
needs: build_application
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_ragger_tests.yml@v1
with:
download_app_binaries_artifact: "compiled_app_binaries"
test_dir: test/python/tests_baking

35 changes: 35 additions & 0 deletions .github/workflows/build_and_functional_tests_wallet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and run functional wallet tests using ragger through reusable workflow

# This workflow will build the app and then run functional tests using the Ragger framework upon Speculos emulation.
# It calls a reusable workflow developed by Ledger's internal developer team to build the application and upload the
# resulting binaries.
# It then calls another reusable workflow to run the Ragger tests on the compiled application binary.
#
# While this workflow is optional, having functional testing on your application is mandatory and this workflow and
# tooling environment is meant to be easy to use and adapt after forking your application

on:
workflow_dispatch:
push:
branches:
- master
- main
- develop
pull_request:

jobs:
build_application:
name: Build application using the reusable workflow
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
upload_app_binaries_artifact: "compiled_app_binaries"
flags: "APP=tezos_wallet"

ragger_tests:
name: Run ragger tests using the reusable workflow
needs: build_application
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_ragger_tests.yml@v1
with:
download_app_binaries_artifact: "compiled_app_binaries"
test_dir: test/python/tests_wallet

39 changes: 0 additions & 39 deletions .github/workflows/ci-workflow.yml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/guidelines_enforcer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Ensure compliance with Ledger guidelines

# This workflow is mandatory in all applications
# It calls a reusable workflow guidelines_enforcer developed by Ledger's internal developer team.
# The successful completion of the 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:
# LedgerHQ/ledger-app-workflows/

on:
workflow_dispatch:
push:
branches:
- master
- main
- develop
pull_request:

jobs:
guidelines_enforcer:
name: Call Ledger guidelines_enforcer
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_guidelines_enforcer.yml@v1
16 changes: 16 additions & 0 deletions .github/workflows/swap-ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Swap functional tests

on:
workflow_dispatch:
push:
branches:
- master
- develop
pull_request:

jobs:
job_functional_tests:
uses: LedgerHQ/app-exchange/.github/workflows/reusable_swap_functional_tests.yml@develop
with:
branch_for_tezos: ${{ github.ref }}
test_filter: '"XLM or xlm or Tezos or tezos"'
52 changes: 38 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2

VERSION_TAG ?= $(shell echo "$(GIT_DESCRIBE)" | cut -f1 -d-)
APPVERSION_M=2
APPVERSION_N=3
APPVERSION_P=2
APPVERSION_N=4
APPVERSION_P=5
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

# Only warn about version tags if specified/inferred
Expand All @@ -46,6 +46,8 @@ endif

ifeq ($(TARGET_NAME),TARGET_NANOS)
ICONNAME=icons/nano-s-tezos.gif
else ifeq ($(TARGET_NAME),TARGET_STAX)
ICONNAME=icons/stax_tezos.gif
else
ICONNAME=icons/nano-x-tezos.gif
endif
Expand All @@ -66,14 +68,14 @@ show-app:
############

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF HAVE_UX_FLOW
DEFINES += HAVE_SPRINTF
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
DEFINES += HAVE_LEGACY_PID
DEFINES += VERSION=\"$(APPVERSION)\" APPVERSION_M=$(APPVERSION_M)
DEFINES += COMMIT=\"$(COMMIT)\" APPVERSION_N=$(APPVERSION_N) APPVERSION_P=$(APPVERSION_P)
# DEFINES += _Static_assert\(...\)=

ifeq ($(TARGET_NAME),TARGET_NANOX)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000
DEFINES += HAVE_BLE_APDU # basic ledger apdu transport over BLE

Expand All @@ -84,14 +86,25 @@ ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
else
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_GLO096
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
endif

ifeq ($(TARGET_NAME),TARGET_STAX)
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
else
DEFINES += HAVE_BAGL HAVE_UX_FLOW
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_GLO096
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
endif
endif

DEFINES += UNUSED\(x\)=\(void\)x

# Enabling debug PRINTF
DEBUG ?= 0
ifneq ($(DEBUG),0)
Expand Down Expand Up @@ -130,9 +143,9 @@ endif
CC := $(CLANGPATH)clang

ifeq ($(APP),tezos_wallet)
CFLAGS += -O3 -Os -Wall -Wextra
CFLAGS += -O3 -Os -Wall -Wextra -Wno-incompatible-pointer-types-discards-qualifiers
else ifeq ($(APP),tezos_baking)
CFLAGS += -DBAKING_APP -O3 -Os -Wall -Wextra
CFLAGS += -DBAKING_APP -O3 -Os -Wall -Wextra -Wno-incompatible-pointer-types-discards-qualifiers
else
ifeq ($(filter clean,$(MAKECMDGOALS)),)
$(error Unsupported APP - use tezos_wallet, tezos_baking)
Expand All @@ -150,7 +163,11 @@ include $(BOLOS_SDK)/Makefile.glyphs

### computed variables
APP_SOURCE_PATH += src
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl lib_ux
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl

ifneq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_ux
endif

### U2F support (wallet app only)
ifeq ($(APP), tezos_wallet)
Expand All @@ -162,6 +179,13 @@ DEFINES += U2F_PROXY_MAGIC=\"XTZ\"
DEFINES += HAVE_IO_U2F HAVE_U2F
endif

### webusb support (wallet app only)
ifeq ($(APP), tezos_wallet)
#WEBUSB_URL = www.ledgerwallet.com
#DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g")
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
endif

load: all
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

Expand All @@ -182,4 +206,4 @@ endif
# Generate delegates from baker list
src/delegates.h: tools/gen-delegates.sh tools/BakersRegistryCoreUnfilteredData.json
bash ./tools/gen-delegates.sh ./tools/BakersRegistryCoreUnfilteredData.json
$(DEP_DIR)/to_string.d: src/delegates.h
$(DEP_DIR)/to_string.d $(DEP_DIR)/app/to_string.d: src/delegates.h
Binary file added glyphs/tezos.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/stax_tezos.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 13 additions & 8 deletions src/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <stdint.h>
#include <string.h>

size_t provide_pubkey(uint8_t *const io_buffer, cx_ecfp_public_key_t const *const pubkey) {
size_t provide_pubkey(uint8_t* const io_buffer, cx_ecfp_public_key_t const* const pubkey) {
check_null(io_buffer);
check_null(pubkey);
size_t tx = 0;
Expand All @@ -22,17 +22,20 @@ size_t provide_pubkey(uint8_t *const io_buffer, cx_ecfp_public_key_t const *cons
return finalize_successful_send(tx);
}

size_t handle_apdu_error(uint8_t __attribute__((unused)) instruction) {
size_t handle_apdu_error(uint8_t __attribute__((unused)) instruction,
volatile uint32_t* __attribute__((unused)) flags) {
THROW(EXC_INVALID_INS);
}

size_t handle_apdu_version(uint8_t __attribute__((unused)) instruction) {
size_t handle_apdu_version(uint8_t __attribute__((unused)) instruction,
volatile uint32_t* __attribute__((unused)) flags) {
memcpy(G_io_apdu_buffer, &version, sizeof(version_t));
size_t tx = sizeof(version_t);
return finalize_successful_send(tx);
}

size_t handle_apdu_git(uint8_t __attribute__((unused)) instruction) {
size_t handle_apdu_git(uint8_t __attribute__((unused)) instruction,
volatile uint32_t* __attribute__((unused)) flags) {
static const char commit[] = COMMIT;
memcpy(G_io_apdu_buffer, commit, sizeof(commit));
size_t tx = sizeof(commit);
Expand All @@ -41,9 +44,10 @@ size_t handle_apdu_git(uint8_t __attribute__((unused)) instruction) {

#define CLA 0x80

__attribute__((noreturn)) void main_loop(apdu_handler const *const handlers,
__attribute__((noreturn)) void main_loop(apdu_handler const* const handlers,
size_t const handlers_size) {
volatile size_t rx = io_exchange(CHANNEL_APDU, 0);
volatile uint32_t flags = 0;
while (true) {
BEGIN_TRY {
TRY {
Expand Down Expand Up @@ -71,8 +75,9 @@ __attribute__((noreturn)) void main_loop(apdu_handler const *const handlers,
apdu_handler const cb =
instruction >= handlers_size ? handle_apdu_error : handlers[instruction];

size_t const tx = cb(instruction);
rx = io_exchange(CHANNEL_APDU, tx);
size_t const tx = cb(instruction, &flags);
rx = io_exchange(CHANNEL_APDU | flags, tx);
flags = 0;
}
CATCH(ASYNC_EXCEPTION) {
rx = io_exchange(CHANNEL_APDU | IO_ASYNCH_REPLY, 0);
Expand All @@ -89,7 +94,7 @@ __attribute__((noreturn)) void main_loop(apdu_handler const *const handlers,
switch (sw) {
default:
sw = 0x6800 | (e & 0x7FF);
// FALL THROUGH
__attribute__((fallthrough));
case 0x6000 ... 0x6FFF:
case 0x9000 ... 0x9FFF: {
PRINTF("Line number: %d", sw & 0x0FFF);
Expand Down
10 changes: 5 additions & 5 deletions src/apdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define INS_HMAC 0x0E
#define INS_SIGN_WITH_HASH 0x0F

__attribute__((noreturn)) void main_loop(apdu_handler const *const handlers,
__attribute__((noreturn)) void main_loop(apdu_handler const* const handlers,
size_t const handlers_size);

static inline size_t finalize_successful_send(size_t tx) {
Expand Down Expand Up @@ -69,8 +69,8 @@ static inline void require_permissioned_comm(void) {
}
}

size_t provide_pubkey(uint8_t *const io_buffer, cx_ecfp_public_key_t const *const pubkey);
size_t provide_pubkey(uint8_t* const io_buffer, cx_ecfp_public_key_t const* const pubkey);

size_t handle_apdu_error(uint8_t instruction);
size_t handle_apdu_version(uint8_t instruction);
size_t handle_apdu_git(uint8_t instruction);
size_t handle_apdu_error(uint8_t instruction, volatile uint32_t* flags);
size_t handle_apdu_version(uint8_t instruction, volatile uint32_t* flags);
size_t handle_apdu_git(uint8_t instruction, volatile uint32_t* flags);
Loading

0 comments on commit fe5a6b2

Please sign in to comment.