From 29a4375dfbd8297ac9450a661f88475136847150 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 5 May 2023 11:54:39 +0200 Subject: [PATCH] Stax ENS support --- src_nbgl/ui_approve_tx.c | 65 +++++++++++++++++++++++++++------------- src_nbgl/ui_settings.c | 42 +++++++++++++++++++++----- 2 files changed, 79 insertions(+), 28 deletions(-) diff --git a/src_nbgl/ui_approve_tx.c b/src_nbgl/ui_approve_tx.c index 78c9d81..b3aec12 100644 --- a/src_nbgl/ui_approve_tx.c +++ b/src_nbgl/ui_approve_tx.c @@ -5,6 +5,7 @@ #include "ui_nbgl.h" #include "network.h" #include "plugins.h" +#include "domain_name.h" // 1 more than actually displayed on screen, because of calculations in StaticReview #define MAX_PLUGIN_ITEMS_PER_SCREEN 4 @@ -27,6 +28,9 @@ struct tx_approval_context_t { bool fromPlugin; bool blindSigning; bool displayNetwork; +#ifdef HAVE_DOMAIN_NAME + bool domain_name_match; +#endif }; static struct tx_approval_context_t tx_approval_context; @@ -35,10 +39,12 @@ static void reviewContinueCommon(void); static void reviewReject(void) { io_seproxyhal_touch_tx_cancel(NULL); + memset(&tx_approval_context, 0, sizeof(tx_approval_context)); } static void confirmTransation(void) { io_seproxyhal_touch_tx_ok(NULL); + memset(&tx_approval_context, 0, sizeof(tx_approval_context)); } static void onConfirmAbandon(void) { @@ -88,32 +94,41 @@ static nbgl_layoutTagValue_t *getTagValuePair(uint8_t pairIndex) { } } } else { - // if displayNonce is false, we skip index 2 - if ((pairIndex > 1) && (!N_storage.displayNonce)) { - pairIndex++; - } + uint8_t target_index = 0; - switch (pairIndex) { - case 0: - pair.item = "Amount"; - pair.value = strings.common.fullAmount; - break; - case 1: + if (pairIndex == target_index++) { + pair.item = "Amount"; + pair.value = strings.common.fullAmount; + } +#ifdef HAVE_DOMAIN_NAME + if (tx_approval_context.domain_name_match) { + if (pairIndex == target_index++) { + pair.item = "Domain"; + pair.value = g_domain_name; + } + } + if (!tx_approval_context.domain_name_match || N_storage.verbose_domain_name) { +#endif // HAVE_DOMAIN_NAME + if (pairIndex == target_index++) { pair.item = "Address"; pair.value = strings.common.fullAddress; - break; - case 2: + } +#ifdef HAVE_DOMAIN_NAME + } +#endif // HAVE_DOMAIN_NAME + if (N_storage.displayNonce) { + if (pairIndex == target_index++) { pair.item = "Nonce"; pair.value = strings.common.nonce; - break; - case 3: - pair.item = "Max fees"; - pair.value = strings.common.maxFee; - break; - case 4: - pair.item = "Network"; - pair.value = strings.common.network_name; - break; + } + } + if (pairIndex == target_index++) { + pair.item = "Max fees"; + pair.value = strings.common.maxFee; + } + if (pairIndex == target_index++) { + pair.item = "Network"; + pair.value = strings.common.network_name; } } // counter is used as index to circular buffer @@ -177,6 +192,14 @@ static void reviewContinueCommon(void) { if (N_storage.displayNonce) { nbPairs++; } +#ifdef HAVE_DOMAIN_NAME + uint64_t chain_id = get_tx_chain_id(); + tx_approval_context.domain_name_match = + has_domain_name(&chain_id, tmpContent.txContent.destination); + if (tx_approval_context.domain_name_match && N_storage.verbose_domain_name) { + nbPairs += 1; + } +#endif // HAVE_DOMAIN_NAME if (tx_approval_context.displayNetwork) { nbPairs++; } diff --git a/src_nbgl/ui_settings.c b/src_nbgl/ui_settings.c index b55d323..c952140 100644 --- a/src_nbgl/ui_settings.c +++ b/src_nbgl/ui_settings.c @@ -5,26 +5,38 @@ static const char* const infoTypes[] = {"Version", APPNAME " App"}; static const char* const infoContents[] = {APPVERSION, "(c) 2022 Ledger"}; -enum { BLIND_SIGNING_TOKEN = FIRST_USER_TOKEN, DEBUG_TOKEN, NONCE_TOKEN, EIP712_VERBOSE_TOKEN }; +enum { + BLIND_SIGNING_TOKEN = FIRST_USER_TOKEN, + DEBUG_TOKEN, + NONCE_TOKEN, +#ifdef HAVE_EIP712_FULL_SUPPORT + EIP712_VERBOSE_TOKEN, +#endif // HAVE_EIP712_FULL_SUPPORT +#ifdef HAVE_DOMAIN_NAME + DOMAIN_NAME_VERBOSE_TOKEN +#endif // HAVE_DOMAIN_NAME +}; static nbgl_layoutSwitch_t switches[3]; static bool navCallback(uint8_t page, nbgl_pageContent_t* content) { + uint8_t index = 0; + switch (page) { case 0: - switches[0] = + switches[index++] = (nbgl_layoutSwitch_t){.initState = N_storage.dataAllowed ? ON_STATE : OFF_STATE, .text = "Blind signing", .subText = "Enable transaction blind\nsigning", .token = BLIND_SIGNING_TOKEN, .tuneId = TUNE_TAP_CASUAL}; - switches[1] = + switches[index++] = (nbgl_layoutSwitch_t){.initState = N_storage.contractDetails ? ON_STATE : OFF_STATE, .text = "Debug", .subText = "Display contract data\ndetails", .token = DEBUG_TOKEN, .tuneId = TUNE_TAP_CASUAL}; - switches[2] = + switches[index++] = (nbgl_layoutSwitch_t){.initState = N_storage.displayNonce ? ON_STATE : OFF_STATE, .text = "Nonce", .subText = "Display account nonce\nin transaction", @@ -32,20 +44,28 @@ static bool navCallback(uint8_t page, nbgl_pageContent_t* content) { .tuneId = TUNE_TAP_CASUAL}; content->type = SWITCHES_LIST; - content->switchesList.nbSwitches = 3; + content->switchesList.nbSwitches = index; content->switchesList.switches = (nbgl_layoutSwitch_t*) switches; break; case 1: - switches[0] = + switches[index++] = (nbgl_layoutSwitch_t){.initState = N_storage.verbose_eip712 ? ON_STATE : OFF_STATE, .text = "Verbose EIP712", .subText = "Ignore filtering and\ndisplay raw content", .token = EIP712_VERBOSE_TOKEN, .tuneId = TUNE_TAP_CASUAL}; +#ifdef HAVE_DOMAIN_NAME + switches[index++] = (nbgl_layoutSwitch_t){ + .initState = N_storage.verbose_domain_name ? ON_STATE : OFF_STATE, + .text = "Verbose domains", + .subText = "Show resolved address", + .token = DOMAIN_NAME_VERBOSE_TOKEN, + .tuneId = TUNE_TAP_CASUAL}; +#endif // HAVE_DOMAIN_NAME content->type = SWITCHES_LIST; - content->switchesList.nbSwitches = 1; + content->switchesList.nbSwitches = index; content->switchesList.switches = (nbgl_layoutSwitch_t*) switches; break; @@ -80,10 +100,18 @@ static void controlsCallback(int token, uint8_t index) { value = (N_storage.displayNonce ? 0 : 1); nvm_write((void*) &N_storage.displayNonce, (void*) &value, sizeof(uint8_t)); break; +#ifdef HAVE_EIP712_FULL_SUPPORT case EIP712_VERBOSE_TOKEN: value = (N_storage.verbose_eip712 ? 0 : 1); nvm_write((void*) &N_storage.verbose_eip712, (void*) &value, sizeof(uint8_t)); break; +#endif // HAVE_EIP712_FULL_SUPPORT +#ifdef HAVE_DOMAIN_NAME + case DOMAIN_NAME_VERBOSE_TOKEN: + value = (N_storage.verbose_domain_name ? 0 : 1); + nvm_write((void*) &N_storage.verbose_domain_name, (void*) &value, sizeof(uint8_t)); + break; +#endif // HAVE_DOMAIN_NAME } }