diff --git a/Makefile b/Makefile index 872bc15..d2c0b32 100644 --- a/Makefile +++ b/Makefile @@ -140,6 +140,7 @@ endif # EIP-712 ifneq ($(TARGET_NAME),TARGET_NANOS) DEFINES += HAVE_EIP712_FULL_SUPPORT +#DEFINES += HAVE_EIP712_HALF_BLIND # temporary endif # Enabling debug PRINTF diff --git a/src_features/signMessageEIP712/entrypoint.c b/src_features/signMessageEIP712/entrypoint.c index e744ff1..cb4eb34 100644 --- a/src_features/signMessageEIP712/entrypoint.c +++ b/src_features/signMessageEIP712/entrypoint.c @@ -448,6 +448,9 @@ bool handle_eip712_sign(const uint8_t *const apdu_buf) { return false; } +#ifdef HAVE_EIP712_HALF_BLIND + ui_712_message_hash(); +#endif // HAVE_EIP712_HALF_BLIND ui_712_end_sign(); return true; } diff --git a/src_features/signMessageEIP712/field_hash.c b/src_features/signMessageEIP712/field_hash.c index ef019ac..6dde239 100644 --- a/src_features/signMessageEIP712/field_hash.c +++ b/src_features/signMessageEIP712/field_hash.c @@ -66,7 +66,14 @@ bool field_hash(const uint8_t *data, if (IS_DYN(field_type)) { cx_keccak_init(&global_sha3, 256); // init hash +#ifdef HAVE_EIP712_HALF_BLIND + if (path_get_root_type() == ROOT_DOMAIN) + { +#endif // HAVE_EIP712_HALF_BLIND ui_712_new_field(field_ptr, data, data_length); +#ifdef HAVE_EIP712_HALF_BLIND + } +#endif // HAVE_EIP712_HALF_BLIND } } fh->remaining_size -= data_length; @@ -123,7 +130,14 @@ bool field_hash(const uint8_t *data, { return false; } +#ifdef HAVE_EIP712_HALF_BLIND + if (path_get_root_type() == ROOT_DOMAIN) + { +#endif // HAVE_EIP712_HALF_BLIND ui_712_new_field(field_ptr, data, data_length); +#ifdef HAVE_EIP712_HALF_BLIND + } +#endif // HAVE_EIP712_HALF_BLIND } else { @@ -159,6 +173,15 @@ bool field_hash(const uint8_t *data, path_advance(); fh->state = FHS_IDLE; +#ifdef HAVE_EIP712_HALF_BLIND + if (path_get_root_type() == ROOT_MESSAGE) + { + G_io_apdu_buffer[0] = 0x90; + G_io_apdu_buffer[1] = 0x00; + io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); + } +#endif // HAVE_EIP712_HALF_BLIND + } else { diff --git a/src_features/signMessageEIP712/path.c b/src_features/signMessageEIP712/path.c index 1b199a2..7638d31 100644 --- a/src_features/signMessageEIP712/path.c +++ b/src_features/signMessageEIP712/path.c @@ -382,7 +382,21 @@ bool path_set_root(const char *const struct_name, uint8_t name_length) // because the first field could be a struct type path_update(); +#ifdef HAVE_EIP712_HALF_BLIND + // Only show field for the domain + if (path_get_root_type() == ROOT_MESSAGE) + { + G_io_apdu_buffer[0] = 0x90; + G_io_apdu_buffer[1] = 0x00; + io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); + } + else + { +#endif // HAVE_EIP712_HALF_BLIND ui_712_new_root_struct(path_struct->root_struct); +#ifdef HAVE_EIP712_HALF_BLIND + } +#endif // HAVE_EIP712_HALF_BLIND return true; } diff --git a/src_features/signMessageEIP712/ui_logic.c b/src_features/signMessageEIP712/ui_logic.c index e6048ce..67869bc 100644 --- a/src_features/signMessageEIP712/ui_logic.c +++ b/src_features/signMessageEIP712/ui_logic.c @@ -63,6 +63,7 @@ void ui_712_new_root_struct(const void *const struct_ptr) { return; } + strcpy(strings.tmp.tmp2, "Review struct"); const char *struct_name; uint8_t struct_name_length; @@ -82,6 +83,20 @@ void ui_712_new_root_struct(const void *const struct_ptr) } } +#ifdef HAVE_EIP712_HALF_BLIND +void ui_712_message_hash(void) +{ + strcpy(strings.tmp.tmp2, "Message hash"); + snprintf(strings.tmp.tmp, + sizeof(strings.tmp.tmp), + "0x%.*H", + KECCAK256_HASH_BYTESIZE, + tmpCtx.messageSigningContext712.messageHash); + G_ux.flow_stack[G_ux.stack_count - 1].index = 0; + ux_flow_next(); +} +#endif // HAVE_EIP712_HALF_BLIND + /** * Used to notify of a new field to review in the current struct (key + value) * @@ -98,6 +113,7 @@ void ui_712_new_field(const void *const field_ptr, const uint8_t *const data, { return; } + // Key if ((key = get_struct_field_keyname(field_ptr, &key_len)) != NULL) { @@ -174,7 +190,10 @@ void ui_712_end_sign(void) return; } ui_ctx->end_reached = true; + +#ifndef HAVE_EIP712_HALF_BLIND ui_712_next_field(); +#endif // HAVE_EIP712_HALF_BLIND } /** diff --git a/src_features/signMessageEIP712/ui_logic.h b/src_features/signMessageEIP712/ui_logic.h index acfb52c..0458256 100644 --- a/src_features/signMessageEIP712/ui_logic.h +++ b/src_features/signMessageEIP712/ui_logic.h @@ -27,6 +27,9 @@ void ui_712_new_field(const void *const field_ptr, const uint8_t *const data, ui void ui_712_end_sign(void); unsigned int ui_712_approve(const bagl_element_t *e); unsigned int ui_712_reject(const bagl_element_t *e); +#ifdef HAVE_EIP712_HALF_BLIND +void ui_712_message_hash(void); +#endif // HAVE_EIP712_HALF_BLIND #endif // HAVE_EIP712_FULL_SUPPORT diff --git a/src_features/signMessageEIP712_v0/ui_flow_signMessage712.c b/src_features/signMessageEIP712_v0/ui_flow_signMessage712.c index 02e9e14..230852e 100644 --- a/src_features/signMessageEIP712_v0/ui_flow_signMessage712.c +++ b/src_features/signMessageEIP712_v0/ui_flow_signMessage712.c @@ -1,13 +1,22 @@ #include "shared_context.h" #include "ui_callbacks.h" #include "common_712.h" +#include "ethUtils.h" void prepare_domain_hash_v0() { - snprintf(strings.tmp.tmp, 70, "0x%.*H", 32, tmpCtx.messageSigningContext712.domainHash); + snprintf(strings.tmp.tmp, + sizeof(strings.tmp.tmp), + "0x%.*H", + KECCAK256_HASH_BYTESIZE, + tmpCtx.messageSigningContext712.domainHash); } void prepare_message_hash_v0() { - snprintf(strings.tmp.tmp, 70, "0x%.*H", 32, tmpCtx.messageSigningContext712.messageHash); + snprintf(strings.tmp.tmp, + sizeof(strings.tmp.tmp), + "0x%.*H", + KECCAK256_HASH_BYTESIZE, + tmpCtx.messageSigningContext712.messageHash); } // clang-format off