From 059555039cf5d0960047c7b0e57b4a28b0f44be2 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Wed, 7 Feb 2018 19:56:50 +0100 Subject: [PATCH] cashaddr: Don't show coin prefix on the display. While technically part of the address, the coin prefix, e.g., bitcoincash: is implicit and doesn't need to be checked by the user. We still include it in the QR-code though. Also set case-insensitive flag for QR-code. --- firmware/fsm.c | 16 +++++++++++----- firmware/layout2.c | 10 ++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/firmware/fsm.c b/firmware/fsm.c index cacf44d1a8..d6e653efec 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -217,11 +217,15 @@ static HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n, return &node; } -static bool fsm_layoutAddress(const char *address, const char *desc, bool ignorecase, const uint32_t *address_n, size_t address_n_count) +static bool fsm_layoutAddress(const char *address, const char *desc, bool ignorecase, size_t prefixlen, const uint32_t *address_n, size_t address_n_count) { bool qrcode = false; for (;;) { - layoutAddress(address, desc, qrcode, ignorecase, address_n, address_n_count); + const char* display_addr = address; + if (prefixlen && !qrcode) { + display_addr += prefixlen; + } + layoutAddress(display_addr, desc, qrcode, ignorecase, address_n, address_n_count); if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) { return true; } @@ -835,7 +839,9 @@ void fsm_msgGetAddress(GetAddress *msg) } } - if (!fsm_layoutAddress(address, desc, msg->script_type == InputScriptType_SPENDWITNESS, msg->address_n, msg->address_n_count)) { + bool is_cashaddr = coin->cashaddr_prefix != NULL; + bool is_bech32 = msg->script_type == InputScriptType_SPENDWITNESS; + if (!fsm_layoutAddress(address, desc, is_cashaddr || is_bech32, is_cashaddr ? strlen(coin->cashaddr_prefix) + 1 : 0, msg->address_n, msg->address_n_count)) { return; } } @@ -868,7 +874,7 @@ void fsm_msgEthereumGetAddress(EthereumGetAddress *msg) char address[43] = { '0', 'x' }; ethereum_address_checksum(resp->address.bytes, address + 2); - if (!fsm_layoutAddress(address, desc, false, msg->address_n, msg->address_n_count)) { + if (!fsm_layoutAddress(address, desc, false, 0, msg->address_n, msg->address_n_count)) { return; } } @@ -1293,7 +1299,7 @@ void fsm_msgNEMGetAddress(NEMGetAddress *msg) strlcpy(desc, network, sizeof(desc)); strlcat(desc, ":", sizeof(desc)); - if (!fsm_layoutAddress(resp->address, desc, true, msg->address_n, msg->address_n_count)) { + if (!fsm_layoutAddress(resp->address, desc, true, 0, msg->address_n, msg->address_n_count)) { return; } } diff --git a/firmware/layout2.c b/firmware/layout2.c index 3c17174d43..9dd53368d4 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -250,6 +250,16 @@ void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out) bn_format_uint64(out->amount, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out) - 3); strlcat(str_out, " to", sizeof(str_out)); const char *addr = out->address; + if (coin->cashaddr_prefix) { + /* If this is a cashaddr address, remove the prefix from the + * string presented to the user + */ + int prefix_len = strlen(coin->cashaddr_prefix); + if (strncmp(addr, coin->cashaddr_prefix, prefix_len) == 0 + && addr[prefix_len] == ':') { + addr += prefix_len + 1; + } + } int addrlen = strlen(addr); int numlines = addrlen <= 42 ? 2 : 3; int linelen = (addrlen - 1) / numlines + 1;