Skip to content

Commit

Permalink
Port transaction review steps to 'nbgl_useCaseReview' in ui_sign712.c…
Browse files Browse the repository at this point in the history
… and ui_message_signing.c
  • Loading branch information
cedelavergne-ledger committed Apr 15, 2024
1 parent c85656e commit 325e5d7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 126 deletions.
28 changes: 8 additions & 20 deletions src_nbgl/ui_message_signing.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,11 @@
static void (*g_approved_func)(void) = NULL;
static void (*g_rejected_func)(void) = NULL;

static void ui_message_rejection_handler() {
nbgl_useCaseStatus("Message signing\ncancelled", false, g_rejected_func);
}

static void ui_message_confirm_rejection(void) {
nbgl_useCaseConfirm(REJECT_QUESTION(TEXT_MESSAGE),
NULL,
REJECT_CONFIRM_BUTTON,
RESUME(TEXT_MESSAGE),
ui_message_rejection_handler);
}

void ui_message_review_choice(bool confirm) {
if (confirm) {
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, g_approved_func);
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, g_approved_func);
} else {
ui_message_confirm_rejection();
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, g_rejected_func);
}
}

Expand All @@ -33,12 +21,12 @@ void ui_message_start(const char *title,
void (*rejected_func)(void)) {
g_approved_func = approved_func;
g_rejected_func = rejected_func;
nbgl_useCaseReviewStart(&C_Review_64px,
title,
NULL,
REJECT_BUTTON,
start_func,
ui_message_confirm_rejection);
// nbgl_useCaseReviewStart(&C_Review_64px,
// title,
// NULL,
// REJECT_BUTTON,
// start_func,
// ui_message_confirm_rejection);
}

void ui_message_712_approved(void) {
Expand Down
81 changes: 31 additions & 50 deletions src_nbgl/ui_sign_712.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,56 @@
#include "ui_signing.h"

static nbgl_layoutTagValue_t pair;
static nbgl_layoutTagValueList_t pairsList;

static bool display_sign_page(uint8_t page, nbgl_pageContent_t *content) {
(void) page;
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = TEXT_SIGN_EIP712;
content->infoLongPress.longPressText = SIGN_BUTTON;
return true;
static void reviewChoice(bool confirm) {
if (confirm) {
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, ui_message_712_approved);
} else {
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, ui_message_712_rejected);
}
}

static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
bool ret;
void ui_712_start(void) {
uint16_t len;
g_position = UI_SIGNING_POSITION_START;

switch (page) {
case 0:
// limit the value to one page
nbgl_getTextMaxLenInNbLines(BAGL_FONT_INTER_MEDIUM_32px,
strings.tmp.tmp,
SCREEN_WIDTH - (2 * BORDER_MARGIN),
NB_MAX_LINES_IN_REVIEW,
// limit the value to one page
nbgl_getTextMaxLenInNbLines(BAGL_FONT_INTER_MEDIUM_32px,
strings.tmp.tmp,
SCREEN_WIDTH - (2 * BORDER_MARGIN),
NB_MAX_LINES_IN_REVIEW,
#if (API_LEVEL == 0 || API_LEVEL >= 14)
&len,
false);
&len,
false);
#else
&len);
&len);
#endif
strings.tmp.tmp[len] = '\0';
strings.tmp.tmp[len] = '\0';

pair.item = strings.tmp.tmp2;
pair.value = strings.tmp.tmp;
content->type = TAG_VALUE_LIST;
content->tagValueList.nbPairs = 1;
content->tagValueList.pairs = &pair;
content->tagValueList.wrapping = false;
ret = true;
break;
pair.item = strings.tmp.tmp2;
pair.value = strings.tmp.tmp;

case 1:
if (ui_712_next_field() == EIP712_NO_MORE_FIELD) {
ui_712_switch_to_sign();
}
__attribute__((fallthrough));
default:
ret = false;
break;
}
return ret;
}
pairsList.nbPairs = 1;
pairsList.pairs = &pair;

static void handle_display(nbgl_navCallback_t cb) {
nbgl_useCaseRegularReview(0, 0, REJECT_BUTTON, NULL, cb, ui_message_review_choice);
}

void ui_712_start(void) {
g_position = UI_SIGNING_POSITION_START;
ui_message_start(TEXT_REVIEW_EIP712,
&ui_712_switch_to_message,
&ui_message_712_approved,
&ui_message_712_rejected);
nbgl_useCaseReview(TYPE_MESSAGE,
&pairsList,
&C_Review_64px,
TEXT_REVIEW_EIP712,
NULL,
TEXT_SIGN_EIP712,
reviewChoice);
}

void ui_712_switch_to_message(void) {
g_position = UI_SIGNING_POSITION_REVIEW;
handle_display(display_review_page);
ui_712_start();
}

void ui_712_switch_to_sign(void) {
g_position = UI_SIGNING_POSITION_SIGN;
handle_display(display_sign_page);
ui_712_start();
}

#endif // HAVE_EIP712_FULL_SUPPORT
85 changes: 29 additions & 56 deletions src_nbgl/ui_sign_712_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,45 @@
#include "ui_signing.h"

static nbgl_layoutTagValue_t pairs[2];

static void start_review(void); // forward declaration
static nbgl_layoutTagValueList_t pairsList;

static char *format_hash(const uint8_t *hash, char *buffer, size_t buffer_size, size_t offset) {
snprintf(buffer + offset, buffer_size - offset, "0x%.*H", KECCAK256_HASH_BYTESIZE, hash);
return buffer + offset;
}

static bool display_review_page(uint8_t page, nbgl_pageContent_t *content) {
if (page == 0) {
pairs[0].item = "Domain hash";
pairs[0].value = format_hash(tmpCtx.messageSigningContext712.domainHash,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
0);
pairs[1].item = "Message hash";
pairs[1].value = format_hash(tmpCtx.messageSigningContext712.messageHash,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
70);

content->type = TAG_VALUE_LIST;
content->tagValueList.nbPairs = 2;
content->tagValueList.pairs = (nbgl_layoutTagValue_t *) pairs;
} else if (page == 1) {
g_position = UI_SIGNING_POSITION_SIGN;
content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(true);
content->infoLongPress.text = TEXT_SIGN_EIP712;
content->infoLongPress.longPressText = SIGN_BUTTON;
static void reviewChoice(bool confirm) {
if (confirm) {
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, ui_message_712_approved);
} else {
return false;
}
// valid page so return true
return true;
}

static void display_review(void) {
uint8_t page;

switch (g_position) {
case UI_SIGNING_POSITION_REVIEW:
page = 0;
break;
case UI_SIGNING_POSITION_SIGN:
page = 1;
break;
default:
return; // should not happen
nbgl_useCaseReviewStatus(STATUS_TYPE_MESSAGE_SIGNED, ui_message_712_rejected);
}
nbgl_useCaseRegularReview(page,
2,
REJECT_BUTTON,
NULL,
display_review_page,
ui_message_review_choice);
}

static void start_review(void) {
g_position = UI_SIGNING_POSITION_REVIEW;
display_review();
}

void ui_sign_712_v0(void) {
g_position = UI_SIGNING_POSITION_START;
ui_message_start(TEXT_REVIEW_EIP712,
&start_review,
&ui_message_712_approved,
&ui_message_712_rejected);
explicit_bzero(pairs, sizeof(pairs));
explicit_bzero(&pairsList, sizeof(pairsList));

pairs[0].item = "Domain hash";
pairs[0].value = format_hash(tmpCtx.messageSigningContext712.domainHash,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
0);
pairs[1].item = "Message hash";
pairs[1].value = format_hash(tmpCtx.messageSigningContext712.messageHash,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
70);

pairsList.nbPairs = 2;
pairsList.pairs = pairs;

nbgl_useCaseReview(TYPE_MESSAGE,
&pairsList,
&C_Review_64px,
TEXT_REVIEW_EIP712,
NULL,
"Sign transaction\nto send BOL",
reviewChoice);
}
1 change: 1 addition & 0 deletions src_nbgl/ui_sign_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static e_ui_191_action g_action;
static bool skip_message;

static nbgl_layoutTagValue_t pair;
static nbgl_layoutTagValueList_t pairsList;

Check notice

Code scanning / CodeQL

Unused static variable Note

Static variable pairsList is never read.

static uint32_t eip191MessageIdx = 0;
static uint32_t stringsTmpTmpIdx = 0;
Expand Down

0 comments on commit 325e5d7

Please sign in to comment.