diff --git a/Makefile b/Makefile index 6d77880..193dea8 100755 --- a/Makefile +++ b/Makefile @@ -85,37 +85,23 @@ ifeq ($(TARGET_NAME),TARGET_NANOS) DISABLE_STANDARD_BAGL_UX_FLOW = 1 endif -# vendor/ledger-nanopb -DEFINES += PB_FIELD_32BIT=1 - # vendor/printf DEFINES += PRINTF_DISABLE_SUPPORT_FLOAT PRINTF_DISABLE_SUPPORT_EXPONENTIAL PRINTF_DISABLE_SUPPORT_PTRDIFF_T DEFINES += PRINTF_FTOA_BUFFER_SIZE=0 -# endif # U2F DEFINES += HAVE_U2F HAVE_IO_U2F DEFINES += U2F_PROXY_MAGIC=\"BOIL\" -# nanopb -CFLAGS += -Og -Iproto -CFLAGS += -I. - -# printf -# CFLAGS += -Ivendor/printf/ - -# enable color from inside a script -CFLAGS += -fcolor-diagnostics -LDFLAGS += -Og -flto=thin - # Allow usage of function from lib_standard_app/crypto_helpers.c APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/crypto_helpers.c +INCLUDES_PATH += ${BOLOS_SDK}/lib_standard_app include vendor/nanopb/extra/nanopb.mk DEFINES += PB_NO_ERRMSG=1 SOURCE_FILES += $(NANOPB_CORE) -CFLAGS += "-I$(NANOPB_DIR)" +CFLAGS += "-I$(NANOPB_DIR)" -I. PB_FILES = $(wildcard proto/*.proto) C_PB_FILES = $(patsubst %.proto,%.pb.c,$(PB_FILES)) @@ -130,8 +116,6 @@ $(C_PB_FILES): %.pb.c: $(PB_FILES) $(PYTHON_PB_FILES): %_pb2.py: $(PB_FILES) $(PROTOC) $(PROTOC_OPTS) --python_out=. $*.proto - - .PHONY: c_pb python_pb clean_python_pb c_pb: $(C_PB_FILES) python_pb: $(PYTHON_PB_FILES) diff --git a/README.md b/README.md index c4e32bd..9135e3c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Hedera Ledger App -Hedera™ Hashgraph BOLOS application for Ledger Nano S, Nano S Plus, and Nano X. +Hedera™ Hashgraph BOLOS application for Ledger devices. ## Development diff --git a/src/get_app_configuration.c b/src/get_app_configuration.c index ab71ce1..d2a0308 100644 --- a/src/get_app_configuration.c +++ b/src/get_app_configuration.c @@ -1,6 +1,6 @@ #include -#include "io.h" +#include "app_io.h" #include "os.h" #include "ux.h" diff --git a/src/get_public_key.h b/src/get_public_key.h index 354a2c3..56ce76c 100644 --- a/src/get_public_key.h +++ b/src/get_public_key.h @@ -4,10 +4,10 @@ #include #include -#include "globals.h" +#include "app_globals.h" #include "handlers.h" #include "hedera.h" -#include "io.h" +#include "app_io.h" #include "ui_common.h" #include "utils.h" @@ -17,7 +17,7 @@ typedef struct get_public_key_context_s { // Lines on the UI Screen char ui_approve_l2[DISPLAY_SIZE + 1]; - uint8_t raw_pubkey[65]; + uint8_t raw_pubkey[RAW_PUBKEY_SIZE]; // Public Key Compare uint8_t display_index; diff --git a/src/hedera.c b/src/hedera.c index 618c876..fb4c730 100644 --- a/src/hedera.c +++ b/src/hedera.c @@ -4,8 +4,7 @@ #include #include -#include "globals.h" -#include "lib_standard_app/crypto_helpers.h" +#include "crypto_helpers.h" #include "utils.h" static void hedera_set_path(uint32_t index, uint32_t path[static 5]) { @@ -16,7 +15,7 @@ static void hedera_set_path(uint32_t index, uint32_t path[static 5]) { path[4] = PATH_FOUR; } -bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static 65]) { +bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]) { static uint32_t path[5]; hedera_set_path(index, path); diff --git a/src/hedera.h b/src/hedera.h index ae7d1ed..730fbb1 100644 --- a/src/hedera.h +++ b/src/hedera.h @@ -2,8 +2,9 @@ #include #include +#include "app_globals.h" -bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static 65]); +bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]); bool hedera_sign(uint32_t index, const uint8_t* tx, uint8_t tx_len, /* out */ uint8_t* result); diff --git a/src/hedera_format.c b/src/hedera_format.c index 7102173..9d94c1b 100644 --- a/src/hedera_format.c +++ b/src/hedera_format.c @@ -132,8 +132,7 @@ static void set_title(const char *title) { static void set_senders_title(const char *title) { #if defined(TARGET_NANOS) set_title(title); -#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ - defined(TARGET_STAX) || defined(TARGET_FLEX) +#else // st_ctx.senders_title --> st_ctx.title (NANOS) hedera_safe_printf(st_ctx.senders_title, "%s", title); #endif @@ -142,8 +141,7 @@ static void set_senders_title(const char *title) { static void set_recipients_title(const char *title) { #if defined(TARGET_NANOS) set_title(title); -#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ - defined(TARGET_STAX) || defined(TARGET_FLEX) +#else // st_ctx.recipients_title --> st_ctx.title (NANOS) hedera_safe_printf(st_ctx.recipients_title, "%s", title); #endif @@ -152,8 +150,7 @@ static void set_recipients_title(const char *title) { static void set_amount_title(const char *title) { #if defined(TARGET_NANOS) set_title(title); -#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ - defined(TARGET_STAX) || defined(TARGET_FLEX) +#else // st_ctx.senders_title --> st_ctx.title (NANOS) hedera_safe_printf(st_ctx.amount_title, "%s", title); #endif diff --git a/src/hedera_format.h b/src/hedera_format.h index 12c4b68..5484315 100644 --- a/src/hedera_format.h +++ b/src/hedera_format.h @@ -1,6 +1,6 @@ #pragma once -#include "globals.h" -#include "io.h" +#include "app_globals.h" +#include "app_io.h" #include "sign_transaction.h" void reformat_key(void); diff --git a/src/main.c b/src/main.c index fdcd7e1..4218c53 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -#include "globals.h" +#include "app_globals.h" #include "glyphs.h" #include "handlers.h" #include "os.h" @@ -16,8 +16,7 @@ // Things are marked volatile throughout the app to prevent unintended compiler // reording of instructions (since the try-catch system is a macro) -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) ux_state_t G_ux; bolos_ux_params_t G_ux_params; #endif @@ -150,7 +149,6 @@ __attribute__((section(".boot"))) int main() { USB_power(0); USB_power(1); - PRINTF("TEST 1\n"); // Shows the main menu ui_idle(); diff --git a/src/sign_transaction.c b/src/sign_transaction.c index fb3b314..9139235 100644 --- a/src/sign_transaction.c +++ b/src/sign_transaction.c @@ -67,8 +67,7 @@ void handle_transaction_body() { #if defined(TARGET_NANOS) MEMCLEAR(st_ctx.full); MEMCLEAR(st_ctx.partial); -#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ - defined(TARGET_STAX) || defined(TARGET_FLEX) +#else MEMCLEAR(st_ctx.amount_title); MEMCLEAR(st_ctx.senders_title); MEMCLEAR(st_ctx.operator); @@ -91,8 +90,7 @@ void handle_transaction_body() { // with Key #X? reformat_key(); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) // All flows except Verify if (!is_verify_account()) reformat_operator(); #endif @@ -103,8 +101,7 @@ void handle_transaction_body() { st_ctx.type = Create; reformat_summary("Create Account"); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_stake_target(); reformat_collect_rewards(); reformat_amount_balance(); @@ -115,8 +112,7 @@ void handle_transaction_body() { st_ctx.type = Update; reformat_summary("Update Account"); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_stake_target(); reformat_collect_rewards(); reformat_updated_account(); @@ -127,8 +123,7 @@ void handle_transaction_body() { st_ctx.type = Associate; reformat_summary("Associate Token"); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_token_associate(); #endif break; @@ -137,8 +132,7 @@ void handle_transaction_body() { st_ctx.type = Dissociate; reformat_summary("Dissociate Token"); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_token_dissociate(); #endif break; @@ -147,8 +141,7 @@ void handle_transaction_body() { st_ctx.type = TokenBurn; reformat_summary("Burn Token"); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_token_burn(); reformat_amount_burn(); #endif @@ -158,8 +151,7 @@ void handle_transaction_body() { st_ctx.type = TokenMint; reformat_summary("Mint Token"); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_token_mint(); reformat_amount_mint(); #endif @@ -172,8 +164,7 @@ void handle_transaction_body() { st_ctx.type = Verify; reformat_summary("Verify Account"); -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_verify_account(); #endif @@ -192,8 +183,7 @@ void handle_transaction_body() { st_ctx.transfer_to_index = 0; } -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_sender_account(); reformat_recipient_account(); reformat_amount_transfer(); @@ -213,8 +203,7 @@ void handle_transaction_body() { st_ctx.transfer_to_index = 0; } -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) reformat_token_sender_account(); reformat_token_recipient_account(); reformat_token_transfer(); @@ -232,8 +221,7 @@ void handle_transaction_body() { break; } -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ - defined(TARGET_FLEX) +#if !defined(TARGET_NANOS) // All flows except Verify if (!is_verify_account()) { reformat_fee(); diff --git a/src/sign_transaction.h b/src/sign_transaction.h index 4675a3c..869f64b 100644 --- a/src/sign_transaction.h +++ b/src/sign_transaction.h @@ -11,7 +11,7 @@ #include "handlers.h" #include "hedera.h" #include "hedera_format.h" -#include "io.h" +#include "app_io.h" #include "transaction_body.pb.h" #include "ui_common.h" #include "utils.h" @@ -101,8 +101,7 @@ typedef struct sign_tx_context_s { char recipients_title[TITLE_SIZE]; // alias for title char amount_title[TITLE_SIZE]; // alias for title }; -#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ - defined(TARGET_STAX) || defined(TARGET_FLEX) +#else char senders_title[DISPLAY_SIZE + 1]; char recipients_title[DISPLAY_SIZE + 1]; char amount_title[DISPLAY_SIZE + 1]; @@ -134,8 +133,7 @@ typedef struct sign_tx_context_s { #if defined(TARGET_NANOS) uint8_t display_index; // 1 -> Number Screens uint8_t display_count; // Number Screens -#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ - defined(TARGET_STAX) || defined(TARGET_FLEX) +#else // Transaction Operator char operator[DISPLAY_SIZE * 2 + 1]; diff --git a/src/ui/globals.h b/src/ui/app_globals.h similarity index 97% rename from src/ui/globals.h rename to src/ui/app_globals.h index 750f433..2861579 100644 --- a/src/ui/globals.h +++ b/src/ui/app_globals.h @@ -5,6 +5,7 @@ #define BIP32_PATH 5 #define DISPLAY_SIZE 18 // characters @ 11pt sys font +#define RAW_PUBKEY_SIZE 65 #define MAX_TX_SIZE 512 #define FULL_ADDRESS_LENGTH 54 #define ACCOUNT_ID_SIZE 19 * 3 + 2 + 1 diff --git a/src/ui/io.h b/src/ui/app_io.h similarity index 85% rename from src/ui/io.h rename to src/ui/app_io.h index 8c073f0..9216513 100644 --- a/src/ui/io.h +++ b/src/ui/app_io.h @@ -1,7 +1,7 @@ #pragma once #include "debug.h" -#include "globals.h" +#include "app_globals.h" #include "os.h" #include "os_io_seproxyhal.h" diff --git a/src/ui/io.c b/src/ui/io.c index e8208f5..805ccfa 100644 --- a/src/ui/io.c +++ b/src/ui/io.c @@ -1,4 +1,4 @@ -#include "io.h" +#include "app_io.h" #include "ux.h" diff --git a/src/ui/ui_common.h b/src/ui/ui_common.h index 130f35b..00ea0e2 100644 --- a/src/ui/ui_common.h +++ b/src/ui/ui_common.h @@ -2,7 +2,7 @@ #include -#include "io.h" +#include "app_io.h" #include "os.h" #include "ux.h" diff --git a/src/utils.c b/src/utils.c index e9f5997..b828cc1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,8 +1,6 @@ #include "utils.h" -#include "globals.h" - -void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static 65]) { +void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]) { if (dst == NULL || raw_pubkey == NULL) { THROW(EXCEPTION_MALFORMED_APDU); } diff --git a/src/utils.h b/src/utils.h index 1b5a969..cee2d4a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -2,11 +2,12 @@ #include #include +#include "app_globals.h" #define MEMCLEAR(element) explicit_bzero(&element, sizeof(element)) #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) -void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static 65]); +void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]); void bin2hex(uint8_t *dst, uint8_t *data, uint64_t inlen); diff --git a/tests/usage.md b/tests/usage.md index be8890f..201d146 100644 --- a/tests/usage.md +++ b/tests/usage.md @@ -20,7 +20,7 @@ You can use for this the container `ghcr.io/ledgerhq/ledger-app-builder/ledger-a docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest cd # replace with the name of your app, (eg boilerplate) docker run --user "$(id -u)":"$(id -g)" --rm -ti -v "$(realpath .):/app" --privileged -v "/dev/bus/usb:/dev/bus/usb" ledger-app-builder-lite:latest -make clean && make BOLOS_SDK=$_SDK # replace with one of [NANOS, NANOX, NANOSP, STAX] +make clean && make BOLOS_SDK=$_SDK # replace with one of [NANOS, NANOX, NANOSP, STAX, FLEX] exit ``` @@ -41,7 +41,7 @@ You can use for this the container `ghcr.io/ledgerhq/ledger-app-builder/ledger-a docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest cd app-/ # replace with the name of your app, (eg boilerplate) docker run --user "$(id -u)":"$(id -g)" --rm -ti -v "$(realpath .):/app" --privileged -v "/dev/bus/usb:/dev/bus/usb" ledger-app-builder-lite:latest -make clean && make BOLOS_SDK=$_SDK load # replace with one of [NANOS, NANOX, NANOSP, STAX] +make clean && make BOLOS_SDK=$_SDK load # replace with one of [NANOS, NANOX, NANOSP, STAX, FLEX] exit ``` @@ -65,7 +65,7 @@ Standard useful pytest options Custom pytest options ``` - --device run the test on the specified device [nanos,nanox,nanosp,stax,all]. This parameter is mandatory + --device run the test on the specified device [nanos,nanox,nanosp,stax,flex,all]. This parameter is mandatory --backend run the tests against the backend [speculos, ledgercomm, ledgerwallet]. Speculos is the default --display on Speculos, enables the display of the app screen using QT --golden_run on Speculos, screen comparison functions will save the current screen instead of comparing