Better split between business logic & UI code for EIP-712
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
#ifdef HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
#include "ui_flow_712.h"
|
||||
#include "ui_logic.h"
|
||||
#include "shared_context.h" // strings
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
ux_712_step_review,
|
||||
pnn,
|
||||
{
|
||||
&C_icon_eye,
|
||||
"Review",
|
||||
"typed message",
|
||||
});
|
||||
UX_STEP_NOCB(
|
||||
ux_712_step_dynamic,
|
||||
bnnn_paging,
|
||||
{
|
||||
.title = strings.tmp.tmp2,
|
||||
.text = strings.tmp.tmp,
|
||||
}
|
||||
);
|
||||
UX_STEP_INIT(
|
||||
ux_712_step_dummy,
|
||||
NULL,
|
||||
NULL,
|
||||
{
|
||||
ui_712_next_field();
|
||||
}
|
||||
);
|
||||
UX_STEP_CB(
|
||||
ux_712_step_approve,
|
||||
pb,
|
||||
ui_712_approve(NULL),
|
||||
{
|
||||
&C_icon_validate_14,
|
||||
"Approve",
|
||||
});
|
||||
UX_STEP_CB(
|
||||
ux_712_step_reject,
|
||||
pb,
|
||||
ui_712_reject(NULL),
|
||||
{
|
||||
&C_icon_crossmark,
|
||||
"Reject",
|
||||
});
|
||||
// clang-format on
|
||||
|
||||
UX_FLOW(ux_712_flow,
|
||||
&ux_712_step_review,
|
||||
&ux_712_step_dynamic,
|
||||
&ux_712_step_dummy,
|
||||
&ux_712_step_approve,
|
||||
&ux_712_step_reject);
|
||||
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef UI_FLOW_712_H_
|
||||
#define UI_FLOW_712_H_
|
||||
|
||||
#ifdef HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
#include "ux_flow_engine.h"
|
||||
|
||||
extern const ux_flow_step_t* const ux_712_flow[];
|
||||
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
#endif // UI_FLOW_712_H_
|
||||
@@ -1,72 +1,87 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "common_712.h"
|
||||
#include "ethUtils.h"
|
||||
#ifdef HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
void prepare_domain_hash_v0() {
|
||||
snprintf(strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
"0x%.*H",
|
||||
KECCAK256_HASH_BYTESIZE,
|
||||
tmpCtx.messageSigningContext712.domainHash);
|
||||
}
|
||||
#include "ui_logic.h"
|
||||
#include "shared_context.h" // strings
|
||||
|
||||
void prepare_message_hash_v0() {
|
||||
snprintf(strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
"0x%.*H",
|
||||
KECCAK256_HASH_BYTESIZE,
|
||||
tmpCtx.messageSigningContext712.messageHash);
|
||||
enum { UI_712_POS_REVIEW, UI_712_POS_END };
|
||||
static uint8_t ui_pos;
|
||||
|
||||
static void dummy_cb(void) {
|
||||
if (!ui_712_next_field()) {
|
||||
if (ui_pos == UI_712_POS_REVIEW) {
|
||||
ux_flow_next();
|
||||
ui_pos = UI_712_POS_END;
|
||||
} else // UI_712_POS_END
|
||||
{
|
||||
ux_flow_prev();
|
||||
ui_pos = UI_712_POS_REVIEW;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
ux_sign_712_v0_flow_1_step,
|
||||
ux_712_step_review,
|
||||
pnn,
|
||||
{
|
||||
&C_icon_certificate,
|
||||
"Sign",
|
||||
&C_icon_eye,
|
||||
"Review",
|
||||
"typed message",
|
||||
});
|
||||
UX_STEP_NOCB_INIT(
|
||||
ux_sign_712_v0_flow_2_step,
|
||||
bnnn_paging,
|
||||
prepare_domain_hash_v0(),
|
||||
{
|
||||
.title = "Domain hash",
|
||||
UX_STEP_NOCB(
|
||||
ux_712_step_dynamic,
|
||||
bnnn_paging,
|
||||
{
|
||||
.title = strings.tmp.tmp2,
|
||||
.text = strings.tmp.tmp,
|
||||
});
|
||||
UX_STEP_NOCB_INIT(
|
||||
ux_sign_712_v0_flow_3_step,
|
||||
bnnn_paging,
|
||||
prepare_message_hash_v0(),
|
||||
{
|
||||
.title = "Message hash",
|
||||
.text = strings.tmp.tmp,
|
||||
});
|
||||
}
|
||||
);
|
||||
UX_STEP_INIT(
|
||||
ux_712_step_dummy,
|
||||
NULL,
|
||||
NULL,
|
||||
{
|
||||
dummy_cb();
|
||||
}
|
||||
);
|
||||
UX_STEP_CB(
|
||||
ux_sign_712_v0_flow_4_step,
|
||||
pbb,
|
||||
ui_712_approve_cb(NULL),
|
||||
ux_712_step_approve,
|
||||
pb,
|
||||
ui_712_approve(NULL),
|
||||
{
|
||||
&C_icon_validate_14,
|
||||
"Sign",
|
||||
"message",
|
||||
"Approve",
|
||||
});
|
||||
UX_STEP_CB(
|
||||
ux_sign_712_v0_flow_5_step,
|
||||
pbb,
|
||||
ui_712_reject_cb(NULL),
|
||||
ux_712_step_reject,
|
||||
pb,
|
||||
ui_712_reject(NULL),
|
||||
{
|
||||
&C_icon_crossmark,
|
||||
"Cancel",
|
||||
"signature",
|
||||
"Reject",
|
||||
});
|
||||
// clang-format on
|
||||
|
||||
UX_FLOW(ux_sign_712_v0_flow,
|
||||
&ux_sign_712_v0_flow_1_step,
|
||||
&ux_sign_712_v0_flow_2_step,
|
||||
&ux_sign_712_v0_flow_3_step,
|
||||
&ux_sign_712_v0_flow_4_step,
|
||||
&ux_sign_712_v0_flow_5_step);
|
||||
UX_FLOW(ux_712_flow,
|
||||
&ux_712_step_review,
|
||||
&ux_712_step_dynamic,
|
||||
&ux_712_step_dummy,
|
||||
&ux_712_step_approve,
|
||||
&ux_712_step_reject);
|
||||
|
||||
void ui_712_start(void) {
|
||||
ux_flow_init(0, ux_712_flow, NULL);
|
||||
ui_pos = UI_712_POS_REVIEW;
|
||||
}
|
||||
|
||||
void ui_712_switch_to_message(void) {
|
||||
ux_flow_init(0, ux_712_flow, &ux_712_step_dynamic);
|
||||
ui_pos = UI_712_POS_REVIEW;
|
||||
}
|
||||
|
||||
void ui_712_switch_to_sign(void) {
|
||||
ux_flow_init(0, ux_712_flow, &ux_712_step_approve);
|
||||
ui_pos = UI_712_POS_END;
|
||||
}
|
||||
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
72
src_bagl/ui_flow_signMessage712_v0.c
Normal file
72
src_bagl/ui_flow_signMessage712_v0.c
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "common_712.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
void prepare_domain_hash_v0() {
|
||||
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,
|
||||
sizeof(strings.tmp.tmp),
|
||||
"0x%.*H",
|
||||
KECCAK256_HASH_BYTESIZE,
|
||||
tmpCtx.messageSigningContext712.messageHash);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
ux_sign_712_v0_flow_1_step,
|
||||
pnn,
|
||||
{
|
||||
&C_icon_certificate,
|
||||
"Sign",
|
||||
"typed message",
|
||||
});
|
||||
UX_STEP_NOCB_INIT(
|
||||
ux_sign_712_v0_flow_2_step,
|
||||
bnnn_paging,
|
||||
prepare_domain_hash_v0(),
|
||||
{
|
||||
.title = "Domain hash",
|
||||
.text = strings.tmp.tmp,
|
||||
});
|
||||
UX_STEP_NOCB_INIT(
|
||||
ux_sign_712_v0_flow_3_step,
|
||||
bnnn_paging,
|
||||
prepare_message_hash_v0(),
|
||||
{
|
||||
.title = "Message hash",
|
||||
.text = strings.tmp.tmp,
|
||||
});
|
||||
UX_STEP_CB(
|
||||
ux_sign_712_v0_flow_4_step,
|
||||
pbb,
|
||||
ui_712_approve_cb(NULL),
|
||||
{
|
||||
&C_icon_validate_14,
|
||||
"Sign",
|
||||
"message",
|
||||
});
|
||||
UX_STEP_CB(
|
||||
ux_sign_712_v0_flow_5_step,
|
||||
pbb,
|
||||
ui_712_reject_cb(NULL),
|
||||
{
|
||||
&C_icon_crossmark,
|
||||
"Cancel",
|
||||
"signature",
|
||||
});
|
||||
// clang-format on
|
||||
|
||||
UX_FLOW(ux_sign_712_v0_flow,
|
||||
&ux_sign_712_v0_flow_1_step,
|
||||
&ux_sign_712_v0_flow_2_step,
|
||||
&ux_sign_712_v0_flow_3_step,
|
||||
&ux_sign_712_v0_flow_4_step,
|
||||
&ux_sign_712_v0_flow_5_step);
|
||||
Reference in New Issue
Block a user