diff --git a/src_features/signMessageEIP712/eip712.h b/src_features/signMessageEIP712/eip712.h index 41c54f9..26ed8d1 100644 --- a/src_features/signMessageEIP712/eip712.h +++ b/src_features/signMessageEIP712/eip712.h @@ -57,6 +57,13 @@ typedef enum #define TYPESIZE_MASK (1 << 6) #define TYPENAME_ENUM (0xF) +typedef enum +{ + EIP712_TYPE_HASH, + EIP712_FIELD_HASH, + EIP712_STRUCT_HASH +} e_eip712_hash_type; + #define KECCAK256_HASH_BYTESIZE 32 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) diff --git a/src_features/signMessageEIP712/type_hash.c b/src_features/signMessageEIP712/type_hash.c index bd5680e..3ccad3c 100644 --- a/src_features/signMessageEIP712/type_hash.c +++ b/src_features/signMessageEIP712/type_hash.c @@ -37,23 +37,27 @@ const uint8_t *type_hash(const void *const structs_array, // restore the memory location mem_dealloc(mem_alloc(0) - mem_loc_bak); - // copy hash into memory - if ((hash_ptr = mem_alloc(KECCAK256_HASH_BYTESIZE)) == NULL) + if ((hash_ptr = mem_alloc(KECCAK256_HASH_BYTESIZE + 1)) == NULL) { return NULL; } + + // set TypeHash marker + *hash_ptr = EIP712_TYPE_HASH; + + // copy hash into memory cx_hash((cx_hash_t*)&global_sha3, CX_LAST, NULL, 0, - hash_ptr, + hash_ptr + 1, KECCAK256_HASH_BYTESIZE); #ifdef DEBUG // print computed hash printf("-> 0x"); for (int idx = 0; idx < KECCAK256_HASH_BYTESIZE; ++idx) { - printf("%.02x", hash_ptr[idx]); + printf("%.02x", (hash_ptr + 1)[idx]); } printf("\n"); #endif