Skip to content

Commit

Permalink
Add support for Blindsign ui (#146)
Browse files Browse the repository at this point in the history
* add blindsign ui and warning screens

* bump version
  • Loading branch information
chcmedeiros authored Oct 10, 2024
1 parent 8a087f3 commit c4c3548
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/ui/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ void view_error_show();

void view_custom_error_show(const char *upper, const char *lower);

void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
void view_blindsign_error_show();

void view_review_init(viewfunc_getItem_t viewfuncGetItem,
viewfunc_getNumItems_t viewfuncGetNumItems,
viewfunc_accept_t viewfuncAccept);

void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem, viewfunc_getNumItems_t view_funcGetInnerNumItems,
Expand Down
2 changes: 2 additions & 0 deletions app/ui/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ void view_error_show_impl();

void view_custom_error_show_impl();

void view_blindsign_error_show_impl();

void h_paging_init();

void h_inspect_init();
Expand Down
4 changes: 4 additions & 0 deletions app/ui/view_nano.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ void view_custom_error_show(const char *upper, const char *lower) {
view_custom_error_show_impl();
}

void view_blindsign_error_show() {
view_blindsign_error_show_impl();
}

///////////////////////////////////
// Paging related
bool h_paging_can_increase() {
Expand Down
39 changes: 37 additions & 2 deletions app/ui/view_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ typedef enum {
#ifdef APP_SECRET_MODE_ENABLED
SECRET_MODE,
#endif
#ifdef APP_BLINDSIGN_MODE_ENABLED
BLINDSIGN_MODE,
#endif
} settings_list_e;

typedef enum {
EXPERT_MODE_TOKEN = FIRST_USER_TOKEN,
ACCOUNT_MODE_TOKEN,
SECRET_MODE_TOKEN,
BLINDSIGN_MODE_TOKEN,
} config_token_e;

void app_quit(void) {
Expand All @@ -96,6 +100,10 @@ static const char *const INFO_VALUES_PAGE[] = {APPVERSION, "Zondax AG", "https:/

static void h_expert_toggle() { app_mode_set_expert(!app_mode_expert()); }

#ifdef APP_BLINDSIGN_MODE_ENABLED
static void h_blindsign_toggle() { app_mode_set_blindsign(!app_mode_blindsign()); }
#endif

static void confirm_error(__Z_UNUSED bool confirm) { h_error_accept(0); }

static void reviewAddressChoice(bool confirm) {
Expand Down Expand Up @@ -157,6 +165,13 @@ void view_custom_error_show(const char *upper, const char *lower) {
nbgl_useCaseChoice(&C_Important_Circle_64px, viewdata.key, viewdata.value, "Ok", "", confirm_error);
}

void view_blindsign_error_show() {
nbgl_useCaseChoice(&C_Warning_64px,
"This message cannot\nbe clear-signed",
"Enable blind-signing in\nthe settings to sign\nthis transaction.",
"Exit", "", confirm_error);
}

void view_error_show_impl() {
nbgl_useCaseChoice(&C_Important_Circle_64px, viewdata.key, viewdata.value, "Ok", NULL, confirm_setting);
}
Expand Down Expand Up @@ -247,6 +262,15 @@ static bool settings_screen_callback(uint8_t page, nbgl_pageContent_t *content)
settings[0].tuneId = TUNE_TAP_CASUAL;
settings[0].token = EXPERT_MODE_TOKEN;

#ifdef APP_BLINDSIGN_MODE_ENABLED
settings[BLINDSIGN_MODE].initState = app_mode_blindsign();
settings[BLINDSIGN_MODE].text = "Blind sign";
settings[BLINDSIGN_MODE].tuneId = TUNE_TAP_CASUAL;
settings[BLINDSIGN_MODE].token = BLINDSIGN_MODE_TOKEN;
content->switchesList.nbSwitches++;

#endif

#ifdef APP_ACCOUNT_MODE_ENABLED
if (app_mode_expert() || app_mode_account()) {
settings[ACCOUNT_MODE].initState = app_mode_account();
Expand Down Expand Up @@ -313,6 +337,12 @@ static void settings_toggle_callback(int token, __Z_UNUSED uint8_t index) {
break;
#endif

#ifdef APP_BLINDSIGN_MODE_ENABLED
case BLINDSIGN_MODE_TOKEN:
h_blindsign_toggle();
break;
#endif

default:
ZEMU_LOGF(50, "Toggling setting not found\n")
break;
Expand Down Expand Up @@ -436,9 +466,14 @@ static void config_useCaseReview(nbgl_operationType_t type) {
pairList.pairs = NULL; // to indicate that callback should be used
pairList.callback = update_item_callback;
pairList.startIndex = 0;

nbgl_useCaseReview(type, &pairList, &C_icon_stax_64, (intro_message == NULL ? "Review transaction" : intro_message),
if (app_mode_blindsign()) {
nbgl_useCaseReviewBlindSigning(type, &pairList, &C_icon_stax_64, (intro_message == NULL ? "Review transaction" : intro_message), NULL,
"Accept risk and sign transaction ?", NULL, reviewTransactionChoice);
} else {
nbgl_useCaseReview(type, &pairList, &C_icon_stax_64, (intro_message == NULL ? "Review transaction" : intro_message),
NULL, APPROVE_LABEL_NBGL, reviewTransactionChoice);
}

}

static void config_useCaseReviewLight(const char *title, const char *validate) {
Expand Down
41 changes: 41 additions & 0 deletions app/ui/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ static void h_shortcut_toggle();
static void h_shortcut_update();
#endif

#ifdef APP_BLINDSIGN_MODE_ENABLED
static void h_blindsign_toggle();
static void h_blindsign_update();
#endif

enum MAINMENU_SCREENS {
SCREEN_HOME = 0,
SCREEN_EXPERT,
Expand All @@ -72,6 +77,9 @@ enum MAINMENU_SCREENS {
#ifdef SHORTCUT_MODE_ENABLED
SCREEN_SHORTCUT,
#endif
#ifdef APP_BLINDSIGN_MODE_ENABLED
SCREEN_BLINDSIGN,
#endif
};

ux_state_t ux;
Expand All @@ -87,6 +95,10 @@ const ux_menu_entry_t menu_main[] = {
{NULL, NULL, 0, &C_icon_app, MENU_MAIN_APP_LINE1, viewdata.key, 33, 12},
{NULL, h_expert_toggle, 0, &C_icon_app, "Expert mode:", viewdata.value, 33, 12},

#ifdef APP_BLINDSIGN_MODE_ENABLED
{NULL, h_blindsign_toggle, 0, &C_icon_app, "Blind sign:", viewdata.value, 33, 12},
#endif

#ifdef APP_ACCOUNT_MODE_ENABLED
{NULL, h_account_toggle, 0, &C_icon_app, "Account:", viewdata.value, 33, 12},
#endif
Expand Down Expand Up @@ -126,6 +138,12 @@ const ux_menu_entry_t menu_custom_error[] = {
UX_MENU_END
};

const ux_menu_entry_t blindsign_error[] = {
{NULL, NULL, 0, &C_icon_warning, "Blindsing Mode", " Required", 33, 12},
{NULL, h_error_accept, 0, &C_icon_validate_14, "Exit", NULL, 50, 29},
UX_MENU_END
};

static const bagl_element_t view_message[] = {
UI_BACKGROUND,
UI_LabelLine(UIID_LABEL + 0, 0, 8, UI_SCREEN_WIDTH, UI_11PX, UI_WHITE, UI_BLACK, viewdata.key),
Expand Down Expand Up @@ -194,6 +212,11 @@ const bagl_element_t* idle_preprocessor(__Z_UNUSED const ux_menu_entry_t* entry,
case SCREEN_EXPERT:
h_expert_update();
break;
#ifdef APP_BLINDSIGN_MODE_ENABLED
case SCREEN_BLINDSIGN:
h_blindsign_update();
break;
#endif
#ifdef APP_ACCOUNT_MODE_ENABLED
case SCREEN_ACCOUNT:
h_account_update();
Expand Down Expand Up @@ -344,6 +367,10 @@ void view_custom_error_show_impl() {
UX_MENU_DISPLAY(0, menu_custom_error, NULL);
}

void view_blindsign_error_show_impl() {
UX_MENU_DISPLAY(0, blindsign_error, NULL);
}

void h_expert_toggle() {
app_mode_set_expert(!app_mode_expert());
view_idle_show(1, NULL);
Expand All @@ -356,6 +383,20 @@ void h_expert_update() {
}
}

#ifdef APP_BLINDSIGN_MODE_ENABLED
void h_blindsign_toggle() {
app_mode_set_blindsign(!app_mode_blindsign());
view_idle_show(SCREEN_BLINDSIGN, NULL);
}

void h_blindsign_update() {
snprintf(viewdata.value, MAX_CHARS_PER_VALUE_LINE, "disabled");
if (app_mode_blindsign()) {
snprintf(viewdata.value, MAX_CHARS_PER_VALUE_LINE, "enabled");
}
}
#endif

#ifdef APP_ACCOUNT_MODE_ENABLED
void h_account_toggle() {
if(app_mode_expert()) {
Expand Down
63 changes: 63 additions & 0 deletions app/ui/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ static void h_shortcut_toggle();
static void h_shortcut_update();
#endif

#ifdef APP_BLINDSIGN_MODE_ENABLED
static void h_blindsign_toggle();
static void h_blindsign_update();
#endif

static void ui_idle();
static void h_shortcut(unsigned int);
static void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t* const start_step);
const ux_flow_step_t *ux_review_flow[MAX_REVIEW_UX_SCREENS];
Expand Down Expand Up @@ -95,9 +101,16 @@ UX_STEP_CB_INIT(ux_idle_flow_7_step, bn, h_account_update(), h_account_toggle()
UX_STEP_CB_INIT(ux_idle_flow_8_step, bn, h_shortcut_update(), h_shortcut_toggle(), { "Shortcut mode:", viewdata.value, });
#endif

#ifdef APP_BLINDSIGN_MODE_ENABLED
UX_STEP_CB_INIT(ux_idle_flow_9_step, bn, h_blindsign_update(), h_blindsign_toggle(), { "Blind sign:", viewdata.value, });
#endif

const ux_flow_step_t *const ux_idle_flow [] = {
&ux_idle_flow_1_step,
&ux_idle_flow_2_step,
#ifdef APP_BLINDSIGN_MODE_ENABLED
&ux_idle_flow_9_step,
#endif
#ifdef APP_ACCOUNT_MODE_ENABLED
&ux_idle_flow_7_step,
#endif
Expand Down Expand Up @@ -158,6 +171,25 @@ UX_FLOW(
);

///////////
UX_STEP_CB(
ux_warning_blind_sign_step,
pnn,
ui_idle(),
{
&C_icon_crossmark,
"Blind signing must be",
"enabled in Settings",
});
UX_FLOW(ux_warning_blind_sign_flow, &ux_warning_blind_sign_step);

UX_STEP_NOCB(ux_approval_blind_signing_warning_step,
pbb,
{
&C_icon_warning,
"Blind",
"Signing",
});
///////////

UX_FLOW_DEF_NOCB(ux_review_flow_1_review_title, pbb, { &C_icon_app, REVIEW_SCREEN_TITLE, REVIEW_SCREEN_TXN_VALUE,});
UX_FLOW_DEF_NOCB(ux_review_flow_2_review_title, pbb, { &C_icon_app, REVIEW_SCREEN_TITLE, REVIEW_SCREEN_ADDR_VALUE,});
Expand All @@ -183,6 +215,14 @@ UX_STEP_CB_INIT(ux_review_flow_5_step, pb, NULL, h_shortcut(0), { &C_icon_eye,
//////////////////////////
//////////////////////////

void ui_idle(void) {
// reserve a display stack slot if none yet
if (G_ux.stack_count == 0) {
ux_stack_push();
}
ux_flow_init(0, ux_idle_flow, NULL);
}

void h_review_update() {
zxerr_t err = h_review_update_data();
switch(err) {
Expand Down Expand Up @@ -279,6 +319,20 @@ void h_expert_update() {
}
}

#ifdef APP_BLINDSIGN_MODE_ENABLED
void h_blindsign_toggle() {
app_mode_set_blindsign(!app_mode_blindsign());
ux_flow_init(0, ux_idle_flow, &ux_idle_flow_9_step);
}

void h_blindsign_update() {
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "disabled");
if (app_mode_blindsign()) {
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "enabled");
}
}
#endif

#ifdef APP_ACCOUNT_MODE_ENABLED
void h_account_toggle() {
if(app_mode_expert()) {
Expand Down Expand Up @@ -417,6 +471,11 @@ void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t* const st
case REVIEW_GENERIC:
case REVIEW_TXN:
default:
#ifdef APP_BLINDSIGN_MODE_ENABLED
if(app_mode_blindsign()) {
ux_review_flow[index++] = &ux_approval_blind_signing_warning_step;
}
#endif
ux_review_flow[index++] = &ux_review_flow_1_review_title;
if(app_mode_shortcut()) {
ux_review_flow[index++] = &ux_review_flow_5_step;
Expand Down Expand Up @@ -463,4 +522,8 @@ void view_custom_error_show_impl() {
}
ux_flow_init(0, ux_custom_error_flow, NULL);
}

void view_blindsign_error_show_impl() {
ux_flow_init(0, ux_warning_blind_sign_flow, NULL);
}
#endif
4 changes: 4 additions & 0 deletions include/app_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ bool app_mode_shortcut();

void app_mode_set_shortcut(uint8_t val);

bool app_mode_blindsign();

void app_mode_set_blindsign(uint8_t val);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion include/zxversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
#pragma once

#define ZXLIB_MAJOR 29
#define ZXLIB_MINOR 0
#define ZXLIB_MINOR 1
#define ZXLIB_PATCH 0
15 changes: 15 additions & 0 deletions src/app_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
typedef struct {
uint8_t expert;
uint8_t account;
uint8_t blindsign;
} app_mode_persistent_t;

typedef struct {
Expand Down Expand Up @@ -60,6 +61,16 @@ void app_mode_set_account(uint8_t val) {
MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t));
}

bool app_mode_blindsign() { return N_appmode.blindsign; }

void app_mode_set_blindsign(uint8_t val) {
app_mode_persistent_t mode;
mode.expert = N_appmode.expert;
mode.account = N_appmode.account;
mode.blindsign = val;
MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t));
}

#else
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
Expand All @@ -83,6 +94,10 @@ void app_mode_set_expert(uint8_t val) { app_mode.expert = val; }

void app_mode_set_account(uint8_t val) { app_mode.account = val; }

bool app_mode_blindsign() { return app_mode.blindsign; }

void app_mode_set_blindsign(uint8_t val) { app_mode.blindsign = val; }

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
Expand Down

0 comments on commit c4c3548

Please sign in to comment.