Skip to content

Commit 77f5c93

Browse files
EIP-712 addresses can now be displayed as a token ticker or a trusted domain name
1 parent adbe34c commit 77f5c93

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

src_features/signMessageEIP712/ui_logic.c

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "typed_data.h"
1717
#include "commands_712.h"
1818
#include "common_ui.h"
19+
#include "domain_name.h"
1920

2021
static t_ui_context *ui_ctx = NULL;
2122

@@ -184,6 +185,46 @@ static void ui_712_format_str(const uint8_t *const data, uint8_t length) {
184185
}
185186
}
186187

188+
/**
189+
* Find a substitute token ticker for a given address
190+
*
191+
* @param[in] addr the given address
192+
* @return the ticker name if found, \ref NULL otherwise
193+
*/
194+
static const char *get_address_token_ticker(const uint8_t *addr) {
195+
tokenDefinition_t *token;
196+
197+
// Loop over the received token informations
198+
for (uint8_t token_idx = 0; token_idx < MAX_ITEMS; ++token_idx) {
199+
if (tmpCtx.transactionContext.tokenSet[token_idx] == 1) {
200+
token = &tmpCtx.transactionContext.extraInfo[token_idx].token;
201+
if (memcmp(token->address, addr, ADDRESS_LENGTH) == 0) {
202+
return token->ticker;
203+
}
204+
}
205+
}
206+
return NULL;
207+
}
208+
209+
/**
210+
* Find a substitute (token ticker or domain name) for a given address
211+
*
212+
* @param[in] addr the given address
213+
* @return the substitute if found, \ref NULL otherwise
214+
*/
215+
static const char *get_address_substitute(const uint8_t *addr) {
216+
const char *str = NULL;
217+
218+
str = get_address_token_ticker(addr);
219+
if (str == NULL) {
220+
if (has_domain_name(&eip712_context->chain_id, addr)) {
221+
// No handling of the verbose domains setting
222+
str = g_domain_name;
223+
}
224+
}
225+
return str;
226+
}
227+
187228
/**
188229
* Format a given data as a string representation of an address
189230
*
@@ -196,13 +237,20 @@ static bool ui_712_format_addr(const uint8_t *const data, uint8_t length) {
196237
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
197238
return false;
198239
}
240+
199241
if (ui_712_field_shown()) {
200-
if (!getEthDisplayableAddress((uint8_t *) data,
201-
strings.tmp.tmp,
202-
sizeof(strings.tmp.tmp),
203-
&global_sha3,
204-
chainConfig->chainId)) {
205-
THROW(APDU_RESPONSE_ERROR_NO_INFO);
242+
const char *sub;
243+
244+
if (!N_storage.verbose_eip712 && ((sub = get_address_substitute(data)) != NULL)) {
245+
ui_712_set_value(sub, strlen(sub));
246+
} else {
247+
if (!getEthDisplayableAddress((uint8_t *) data,
248+
strings.tmp.tmp,
249+
sizeof(strings.tmp.tmp),
250+
&global_sha3,
251+
chainConfig->chainId)) {
252+
THROW(APDU_RESPONSE_ERROR_NO_INFO);
253+
}
206254
}
207255
}
208256
return true;

0 commit comments

Comments
 (0)