NBGL message signing refactoring
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
static const uint8_t EIP_712_MAGIC[] = {0x19, 0x01};
|
||||
|
||||
unsigned int ui_712_approve_cb() {
|
||||
unsigned int ui_712_approve_cb(void) {
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
uint8_t signature[100];
|
||||
@@ -75,7 +75,7 @@ unsigned int ui_712_approve_cb() {
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
|
||||
unsigned int ui_712_reject_cb() {
|
||||
unsigned int ui_712_reject_cb(void) {
|
||||
reset_app_context();
|
||||
G_io_apdu_buffer[0] = 0x69;
|
||||
G_io_apdu_buffer[1] = 0x85;
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#include "ui_nbgl.h"
|
||||
#include "ui_712_common.h"
|
||||
#include "common_712.h"
|
||||
|
||||
static void (*g_resume_func)(void) = NULL;
|
||||
|
||||
void nbgl_712_review_approve(void) {
|
||||
ui_712_approve_cb(NULL);
|
||||
}
|
||||
|
||||
void nbgl_712_review_reject(void) {
|
||||
ui_712_reject_cb(NULL);
|
||||
}
|
||||
|
||||
void nbgl_712_confirm_rejection_cb(bool confirm) {
|
||||
if (confirm) {
|
||||
nbgl_useCaseStatus("Message signing\ncancelled", false, nbgl_712_review_reject);
|
||||
} else {
|
||||
(*g_resume_func)();
|
||||
}
|
||||
}
|
||||
|
||||
void nbgl_712_confirm_rejection(void) {
|
||||
nbgl_useCaseChoice(&C_warning64px,
|
||||
"Reject message?",
|
||||
NULL,
|
||||
"Yes, reject",
|
||||
"Go back to message",
|
||||
nbgl_712_confirm_rejection_cb);
|
||||
}
|
||||
|
||||
void nbgl_712_review_choice(bool confirm) {
|
||||
if (confirm) {
|
||||
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, nbgl_712_review_approve);
|
||||
} else {
|
||||
nbgl_712_confirm_rejection();
|
||||
}
|
||||
}
|
||||
|
||||
void nbgl_712_start(void (*resume_func)(void), const char *title) {
|
||||
g_resume_func = resume_func;
|
||||
nbgl_useCaseReviewStart(&C_Message_64px,
|
||||
title,
|
||||
NULL,
|
||||
"Reject",
|
||||
resume_func,
|
||||
nbgl_712_confirm_rejection);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#ifndef UI_712_COMMON_H_
|
||||
#define UI_712_COMMON_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
void nbgl_712_approve(void);
|
||||
void nbgl_712_reject(void);
|
||||
void nbgl_712_confirm_rejection_cb(bool confirm);
|
||||
void nbgl_712_confirm_rejection(void);
|
||||
void nbgl_712_review_choice(bool confirm);
|
||||
void nbgl_712_start(void (*resume_func)(void), const char *title);
|
||||
|
||||
#endif // UI_712_COMMON_H_
|
||||
57
src_nbgl/ui_message_signing.c
Normal file
57
src_nbgl/ui_message_signing.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "ui_nbgl.h"
|
||||
#include "common_712.h"
|
||||
#include "ui_message_signing.h"
|
||||
#include "glyphs.h"
|
||||
|
||||
static void (*g_resume_func)(void) = NULL;
|
||||
static void (*g_approved_func)(void) = NULL;
|
||||
static void (*g_rejected_func)(void) = NULL;
|
||||
|
||||
static void ui_message_rejection_handler(bool confirm) {
|
||||
if (confirm) {
|
||||
nbgl_useCaseStatus("Message signing\ncancelled", false, g_rejected_func);
|
||||
} else {
|
||||
(*g_resume_func)();
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_message_confirm_rejection(void) {
|
||||
nbgl_useCaseChoice(&C_warning64px,
|
||||
"Reject message?",
|
||||
NULL,
|
||||
"Yes, reject",
|
||||
"Go back to message",
|
||||
ui_message_rejection_handler);
|
||||
}
|
||||
|
||||
void ui_message_review_choice(bool confirm) {
|
||||
if (confirm) {
|
||||
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, g_approved_func);
|
||||
} else {
|
||||
ui_message_confirm_rejection();
|
||||
}
|
||||
}
|
||||
|
||||
void ui_message_start(const char *title,
|
||||
void (*start_func)(void),
|
||||
void (*resume_func)(void),
|
||||
void (*approved_func)(void),
|
||||
void (*rejected_func)(void)) {
|
||||
g_resume_func = resume_func;
|
||||
g_approved_func = approved_func;
|
||||
g_rejected_func = rejected_func;
|
||||
nbgl_useCaseReviewStart(&C_Message_64px,
|
||||
title,
|
||||
NULL,
|
||||
"Reject",
|
||||
start_func,
|
||||
ui_message_confirm_rejection);
|
||||
}
|
||||
|
||||
void ui_message_712_approved(void) {
|
||||
ui_712_approve_cb();
|
||||
}
|
||||
|
||||
void ui_message_712_rejected(void) {
|
||||
ui_712_reject_cb();
|
||||
}
|
||||
16
src_nbgl/ui_message_signing.h
Normal file
16
src_nbgl/ui_message_signing.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef UI_MESSAGE_SIGNING_H_
|
||||
#define UI_MESSAGE_SIGNING_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
void ui_message_review_choice(bool confirm);
|
||||
void ui_message_start(const char *title,
|
||||
void (*start_func)(void),
|
||||
void (*resume_func)(void),
|
||||
void (*approved_func)(void),
|
||||
void (*rejected_func)(void));
|
||||
|
||||
void ui_message_712_approved(void);
|
||||
void ui_message_712_rejected(void);
|
||||
|
||||
#endif // UI_MESSAGE_SIGNING_H_
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "common_712.h"
|
||||
#include "nbgl_use_case.h"
|
||||
#include "network.h"
|
||||
#include "ui_712_common.h"
|
||||
#include "ui_message_signing.h"
|
||||
|
||||
static nbgl_layoutTagValue_t pair;
|
||||
|
||||
@@ -62,11 +62,15 @@ static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
|
||||
}
|
||||
|
||||
static void handle_display(nbgl_navCallback_t cb) {
|
||||
nbgl_useCaseRegularReview(0, 0, "Reject", NULL, cb, nbgl_712_review_choice);
|
||||
nbgl_useCaseRegularReview(0, 0, "Reject", NULL, cb, ui_message_review_choice);
|
||||
}
|
||||
|
||||
void ui_712_start(void) {
|
||||
nbgl_712_start(&ui_712_switch_to_message, "Review typed message");
|
||||
ui_message_start("Review typed message",
|
||||
NULL,
|
||||
&ui_712_switch_to_message,
|
||||
&ui_message_712_approved,
|
||||
&ui_message_712_rejected);
|
||||
}
|
||||
|
||||
void ui_712_switch_to_message(void) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "common_712.h"
|
||||
#include "network.h"
|
||||
#include "ethUtils.h"
|
||||
#include "ui_712_common.h"
|
||||
#include "ui_message_signing.h"
|
||||
|
||||
static nbgl_layoutTagValue_t pairs[2];
|
||||
|
||||
@@ -43,9 +43,13 @@ static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
|
||||
}
|
||||
|
||||
static void start_review(void) {
|
||||
nbgl_useCaseRegularReview(0, 2, "Reject", NULL, display_review_page, nbgl_712_review_choice);
|
||||
nbgl_useCaseRegularReview(0, 2, "Reject", NULL, display_review_page, ui_message_review_choice);
|
||||
}
|
||||
|
||||
void ui_sign_712_v0(void) {
|
||||
nbgl_712_start(&start_review, "Sign typed message");
|
||||
ui_message_start("Sign typed message",
|
||||
NULL,
|
||||
&start_review,
|
||||
&ui_message_712_approved,
|
||||
&ui_message_712_rejected);
|
||||
}
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
#include "glyphs.h"
|
||||
#include "nbgl_use_case.h"
|
||||
#include "common_ui.h"
|
||||
#include "ui_message_signing.h"
|
||||
#include "ui_signing.h"
|
||||
|
||||
typedef enum {
|
||||
UI_191_NBGL_START_REVIEW_DISPLAYED = 0,
|
||||
UI_191_NBGL_GO_TO_NEXT_CONTENT,
|
||||
UI_191_NBGL_BACK_FROM_REJECT_CANCEL,
|
||||
UI_191_NBGL_GO_TO_SIGN,
|
||||
UI_191_NBGL_SIGN_DISPLAYED,
|
||||
} e_ui_nbgl_191_state;
|
||||
UI_191_ACTION_IDLE = 0,
|
||||
UI_191_ACTION_ADVANCE_IN_MESSAGE,
|
||||
UI_191_ACTION_GO_TO_SIGN
|
||||
} e_ui_191_action;
|
||||
|
||||
static e_ui_191_action g_action;
|
||||
|
||||
static e_ui_nbgl_191_state state;
|
||||
static e_ui_nbgl_191_state state_before_reject_cancel;
|
||||
static bool skip_message;
|
||||
|
||||
static nbgl_layoutTagValue_t pair;
|
||||
@@ -37,7 +37,7 @@ static bool display_message(nbgl_pageContent_t *content) {
|
||||
uint16_t len = 0;
|
||||
bool reached;
|
||||
|
||||
if (state != UI_191_NBGL_BACK_FROM_REJECT_CANCEL) {
|
||||
if (g_action == UI_191_ACTION_ADVANCE_IN_MESSAGE) {
|
||||
strncpy(staxSharedBuffer + eip191MessageIdx,
|
||||
strings.tmp.tmp + stringsTmpTmpIdx,
|
||||
SHARED_BUFFER_SIZE - eip191MessageIdx);
|
||||
@@ -55,7 +55,7 @@ static bool display_message(nbgl_pageContent_t *content) {
|
||||
stringsTmpTmpIdx = 0;
|
||||
question_switcher();
|
||||
|
||||
if (state != UI_191_NBGL_GO_TO_SIGN) {
|
||||
if (g_action != UI_191_ACTION_GO_TO_SIGN) {
|
||||
return false;
|
||||
}
|
||||
} else if (reached || eip191MessageIdx == SHARED_BUFFER_SIZE) {
|
||||
@@ -72,13 +72,7 @@ static bool display_message(nbgl_pageContent_t *content) {
|
||||
content->tagValueList.nbMaxLinesForValue = 9;
|
||||
content->tagValueList.wrapping = false;
|
||||
|
||||
if (state == UI_191_NBGL_BACK_FROM_REJECT_CANCEL) {
|
||||
// We come back from Reject screen.
|
||||
// The previously displayed content must be redisplayed.
|
||||
// Do not call question_switcher() to avoid replacing
|
||||
// string.tmp.tmp content.
|
||||
state = state_before_reject_cancel;
|
||||
} else if (stringsTmpTmpIdx >= strlen(strings.tmp.tmp)) {
|
||||
if ((g_action != UI_191_ACTION_IDLE) && (stringsTmpTmpIdx >= strlen(strings.tmp.tmp))) {
|
||||
// Fetch the next content to display into strings.tmp.tmp buffer.
|
||||
stringsTmpTmpIdx = 0;
|
||||
question_switcher();
|
||||
@@ -88,9 +82,9 @@ static bool display_message(nbgl_pageContent_t *content) {
|
||||
|
||||
static void display_sign(nbgl_pageContent_t *content) {
|
||||
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = &C_Message_64px;
|
||||
content->infoLongPress.text = "Sign Message?";
|
||||
content->infoLongPress.text = "Sign Message";
|
||||
content->infoLongPress.longPressText = "Hold to sign";
|
||||
state = UI_191_NBGL_SIGN_DISPLAYED;
|
||||
g_position = UI_SIGNING_POSITION_SIGN;
|
||||
}
|
||||
|
||||
static bool nav_callback(uint8_t page, nbgl_pageContent_t *content) {
|
||||
@@ -100,7 +94,7 @@ static bool nav_callback(uint8_t page, nbgl_pageContent_t *content) {
|
||||
skip_message = true;
|
||||
skip_rest_of_message();
|
||||
}
|
||||
if ((state != UI_191_NBGL_GO_TO_SIGN) && (state != UI_191_NBGL_SIGN_DISPLAYED)) {
|
||||
if ((g_action != UI_191_ACTION_GO_TO_SIGN) && (g_position != UI_SIGNING_POSITION_SIGN)) {
|
||||
if (skip_message) {
|
||||
// do not refresh when this callback triggers after user validation
|
||||
ret = false;
|
||||
@@ -114,68 +108,48 @@ static bool nav_callback(uint8_t page, nbgl_pageContent_t *content) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void choice_callback(bool confirm) {
|
||||
if (confirm) {
|
||||
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, sign_message);
|
||||
sign_message();
|
||||
}
|
||||
}
|
||||
|
||||
static void continue_review(void) {
|
||||
nbgl_useCaseForwardOnlyReview("Reject", NULL, nav_callback, choice_callback);
|
||||
nbgl_useCaseForwardOnlyReview("Reject", NULL, nav_callback, ui_message_review_choice);
|
||||
}
|
||||
|
||||
static void confirm_transaction_rejection_choice(bool confirm) {
|
||||
if (confirm) {
|
||||
reject_message();
|
||||
static void resume_message(void) {
|
||||
e_ui_191_action action_bak = g_action;
|
||||
|
||||
if (g_position == UI_SIGNING_POSITION_START) {
|
||||
ui_191_start();
|
||||
} else {
|
||||
// Go to previous screen accordingly
|
||||
if (state == UI_191_NBGL_START_REVIEW_DISPLAYED) {
|
||||
ui_191_start();
|
||||
} else {
|
||||
if (state != UI_191_NBGL_SIGN_DISPLAYED) {
|
||||
state_before_reject_cancel = state;
|
||||
state = UI_191_NBGL_BACK_FROM_REJECT_CANCEL;
|
||||
}
|
||||
continue_review();
|
||||
}
|
||||
g_action = UI_191_ACTION_IDLE;
|
||||
continue_review();
|
||||
g_action = action_bak;
|
||||
}
|
||||
}
|
||||
|
||||
static void confirm_transaction_rejection() {
|
||||
nbgl_useCaseChoice(&C_warning64px,
|
||||
"Reject message?",
|
||||
NULL,
|
||||
"Yes, Reject",
|
||||
"Go back to message",
|
||||
confirm_transaction_rejection_choice);
|
||||
}
|
||||
|
||||
void ui_191_start(void) {
|
||||
state = UI_191_NBGL_START_REVIEW_DISPLAYED;
|
||||
g_position = UI_SIGNING_POSITION_START;
|
||||
|
||||
skip_message = false;
|
||||
eip191MessageIdx = 0;
|
||||
stringsTmpTmpIdx = 0;
|
||||
|
||||
nbgl_useCaseReviewStart(&C_Message_64px,
|
||||
"Review message",
|
||||
NULL,
|
||||
"Reject",
|
||||
continue_review,
|
||||
confirm_transaction_rejection);
|
||||
ui_message_start("Review message",
|
||||
&ui_191_switch_to_message,
|
||||
&resume_message,
|
||||
&sign_message,
|
||||
&reject_message);
|
||||
}
|
||||
|
||||
void ui_191_switch_to_message(void) {
|
||||
g_position = UI_SIGNING_POSITION_REVIEW;
|
||||
g_action = UI_191_ACTION_ADVANCE_IN_MESSAGE;
|
||||
// No question mechanism on Stax:
|
||||
// Message is already displayed
|
||||
state = UI_191_NBGL_GO_TO_NEXT_CONTENT;
|
||||
continue_review();
|
||||
}
|
||||
|
||||
void ui_191_switch_to_sign(void) {
|
||||
g_action = UI_191_ACTION_GO_TO_SIGN;
|
||||
// Next nav_callback callback must display
|
||||
// the hold to approve screen
|
||||
state = UI_191_NBGL_GO_TO_SIGN;
|
||||
if (skip_message) {
|
||||
continue_review(); // to force screen refresh
|
||||
}
|
||||
|
||||
3
src_nbgl/ui_signing.c
Normal file
3
src_nbgl/ui_signing.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "ui_signing.h"
|
||||
|
||||
e_ui_signing_position g_position;
|
||||
12
src_nbgl/ui_signing.h
Normal file
12
src_nbgl/ui_signing.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef UI_SIGNING_H_
|
||||
#define UI_SIGNING_H_
|
||||
|
||||
typedef enum {
|
||||
UI_SIGNING_POSITION_START = 0,
|
||||
UI_SIGNING_POSITION_REVIEW,
|
||||
UI_SIGNING_POSITION_SIGN
|
||||
} e_ui_signing_position;
|
||||
|
||||
extern e_ui_signing_position g_position;
|
||||
|
||||
#endif // UI_SIGNING_H_
|
||||
Reference in New Issue
Block a user