Skip to content

Commit d39bfc6

Browse files
Merge pull request #944 from LedgerHQ/feat/apa/eip712_show_network
EIP-712 filtered flow - show network
2 parents d4fb82c + 3faf79b commit d39bfc6

42 files changed

Lines changed: 42 additions & 6 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/features/signMessageEIP712/commands_712.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ uint16_t handle_eip712_struct_impl(uint8_t p1,
147147
reply_apdu = false;
148148
}
149149
}
150+
if ((path_get_root_type() == ROOT_MESSAGE) &&
151+
(ui_712_get_filtering_mode() == EIP712_FILTERING_FULL)) {
152+
ret = ui_712_review_network(&eip712_context->chain_id);
153+
}
150154
ui_712_field_flags_reset();
151155
}
152156
break;

src/features/signMessageEIP712/path.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,19 +411,25 @@ static bool path_update(bool skip_if_array, bool stop_at_array, bool do_typehash
411411
* @return boolean indicating if it was successful or not
412412
*/
413413
bool path_set_root(const char *struct_name, uint8_t name_length) {
414+
const s_struct_712 *new_root;
414415
uint8_t hash[KECCAK256_HASH_BYTESIZE];
415416

416417
if (path_struct == NULL) {
417418
apdu_response_code = SWO_INCORRECT_DATA;
418419
return false;
419420
}
420421

421-
if ((path_struct->root_struct = get_structn(struct_name, name_length)) == NULL) {
422+
if ((new_root = get_structn(struct_name, name_length)) == NULL) {
422423
return false;
423424
}
425+
if (new_root == path_struct->root_struct) {
426+
PRINTF("Error: already at that root struct!\n");
427+
return false;
428+
}
429+
path_struct->root_struct = new_root;
424430

425431
if (path_struct->root_struct == NULL) {
426-
PRINTF("Struct name not found (");
432+
PRINTF("Error: struct name not found (");
427433
for (int i = 0; i < name_length; ++i) {
428434
PRINTF("%c", struct_name[i]);
429435
}
@@ -451,8 +457,14 @@ bool path_set_root(const char *struct_name, uint8_t name_length) {
451457

452458
if ((name_length == strlen(DOMAIN_STRUCT_NAME)) &&
453459
(strncmp(struct_name, DOMAIN_STRUCT_NAME, name_length) == 0)) {
460+
if (path_struct->root_type != ROOT_NONE) {
461+
return false;
462+
}
454463
path_struct->root_type = ROOT_DOMAIN;
455464
} else {
465+
if (path_struct->root_type != ROOT_DOMAIN) {
466+
return false;
467+
}
456468
path_struct->root_type = ROOT_MESSAGE;
457469
}
458470

@@ -701,7 +713,7 @@ e_root_type path_get_root_type(void) {
701713
*
702714
* @return pointer to the root structure definition
703715
*/
704-
const void *path_get_root(void) {
716+
const s_struct_712 *path_get_root(void) {
705717
if (path_struct == NULL) {
706718
return NULL;
707719
}

src/features/signMessageEIP712/path.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <stdint.h>
44
#include <stdbool.h>
5+
#include "typed_data.h"
56
#include "list.h"
67
#include "cx.h"
78

@@ -14,14 +15,14 @@ typedef struct {
1415
uint8_t index;
1516
} s_array_depth;
1617

17-
typedef enum { ROOT_DOMAIN, ROOT_MESSAGE } e_root_type;
18+
typedef enum { ROOT_NONE = 0, ROOT_DOMAIN, ROOT_MESSAGE } e_root_type;
1819

1920
typedef struct {
2021
uint8_t depth_count;
2122
uint8_t depths[MAX_PATH_DEPTH];
2223
uint8_t array_depth_count;
2324
s_array_depth array_depths[MAX_ARRAY_DEPTH];
24-
const void *root_struct;
25+
const s_struct_712 *root_struct;
2526
e_root_type root_type;
2627
} s_path;
2728

@@ -37,7 +38,7 @@ bool path_init(void);
3738
void path_deinit(void);
3839
bool path_new_array_depth(const uint8_t *data, uint8_t length);
3940
e_root_type path_get_root_type(void);
40-
const void *path_get_root(void);
41+
const s_struct_712 *path_get_root(void);
4142
const void *path_get_nth_field(uint8_t n);
4243
const void *path_backup_get_nth_field(uint8_t n);
4344
bool path_exists_in_backup(const char *path, size_t length);

src/features/signMessageEIP712/ui_logic.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,24 @@ bool ui_712_review_struct(const s_struct_712 *struct_ptr) {
298298
return ui_712_redraw_generic_step();
299299
}
300300

301+
bool ui_712_review_network(const uint64_t *chain_id) {
302+
const char *title = "Network";
303+
const char *buf;
304+
305+
if (*chain_id == chainConfig->chainId) {
306+
return true;
307+
}
308+
ui_712_set_title(title, strlen(title));
309+
if ((buf = get_network_name_from_chain_id(chain_id)) == NULL) {
310+
if (!u64_to_string(*chain_id, strings.tmp.tmp, NETWORK_STRING_MAX_SIZE)) {
311+
return false;
312+
}
313+
buf = strings.tmp.tmp;
314+
}
315+
ui_712_set_value(buf, strlen(buf));
316+
return ui_712_redraw_generic_step();
317+
}
318+
301319
/**
302320
* Show the hash of the message on the generic UI step
303321
*/

src/features/signMessageEIP712/ui_logic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef struct {
6565
bool ui_712_init(void);
6666
void ui_712_deinit(void);
6767
bool ui_712_review_struct(const s_struct_712 *struct_ptr);
68+
bool ui_712_review_network(const uint64_t *chain_id);
6869
bool ui_712_feed_to_display(const s_struct_712_field *field_ptr,
6970
const uint8_t *data,
7071
uint8_t length,
482 Bytes
2.42 KB
-123 Bytes
90 Bytes
7 Bytes

0 commit comments

Comments
 (0)