diff --git a/src_features/signMessageEIP712/eip712.h b/src_features/signMessageEIP712/eip712.h index 7846841..75f63f9 100644 --- a/src_features/signMessageEIP712/eip712.h +++ b/src_features/signMessageEIP712/eip712.h @@ -64,6 +64,9 @@ typedef enum #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#define DOMAIN_STRUCT_NAME "EIP712Domain" +#define DOMAIN_STRUCT_NAME_LENGTH 12 + // TODO: Move these into a new file const char *get_struct_name(const uint8_t *ptr, uint8_t *const length); const uint8_t *get_struct_fields_array(const uint8_t *ptr, diff --git a/src_features/signMessageEIP712/path.c b/src_features/signMessageEIP712/path.c index 29cc696..59a8223 100644 --- a/src_features/signMessageEIP712/path.c +++ b/src_features/signMessageEIP712/path.c @@ -135,18 +135,21 @@ static bool path_depth_list_pop(void) } else { - if (allzeroes(tmpCtx.messageSigningContext712.domainHash, KECCAK256_HASH_BYTESIZE)) + switch (path_struct->root_type) { - memcpy(tmpCtx.messageSigningContext712.domainHash, - shash, - KECCAK256_HASH_BYTESIZE); - } - else - { - memcpy(tmpCtx.messageSigningContext712.messageHash, - shash, - KECCAK256_HASH_BYTESIZE); - mem_reset(); + case ROOT_DOMAIN: + memcpy(tmpCtx.messageSigningContext712.domainHash, + shash, + KECCAK256_HASH_BYTESIZE); + break; + case ROOT_MESSAGE: + memcpy(tmpCtx.messageSigningContext712.messageHash, + shash, + KECCAK256_HASH_BYTESIZE); + mem_reset(); + break; + default: + break; } #ifdef DEBUG PRINTF("Hash = 0x"); @@ -332,6 +335,16 @@ bool path_set_root(const char *const struct_name, uint8_t name_length) // init array levels at 0 path_struct->array_depth_count = 0; + if ((name_length == DOMAIN_STRUCT_NAME_LENGTH) && + (strncmp(struct_name, DOMAIN_STRUCT_NAME, DOMAIN_STRUCT_NAME_LENGTH) == 0)) + { + path_struct->root_type = ROOT_DOMAIN; + } + else + { + path_struct->root_type = ROOT_MESSAGE; + } + // because the first field could be a struct type path_update(); return true; diff --git a/src_features/signMessageEIP712/path.h b/src_features/signMessageEIP712/path.h index f9e1885..ffec68f 100644 --- a/src_features/signMessageEIP712/path.h +++ b/src_features/signMessageEIP712/path.h @@ -13,6 +13,12 @@ typedef struct uint8_t size; } s_array_depth; +typedef enum +{ + ROOT_DOMAIN, + ROOT_MESSAGE +} e_root_type; + typedef struct { uint8_t depth_count; @@ -20,6 +26,7 @@ typedef struct uint8_t array_depth_count; s_array_depth array_depths[MAX_ARRAY_DEPTH]; const void *root_struct; + e_root_type root_type; } s_path; bool path_set_root(const char *const struct_name, uint8_t length);