Skip to content

Commit

Permalink
Add blindsigning settings ux in touch (stax/flex)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkyaraj-23 committed Sep 9, 2024
1 parent 6361949 commit e0780da
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 36 deletions.
14 changes: 10 additions & 4 deletions app/src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ init_globals(void)
memset(&G_ux, 0, sizeof(G_ux));
memset(&G_ux_params, 0, sizeof(G_ux_params));
}

void
toggle_expert_mode(void)
{
Expand All @@ -46,11 +46,17 @@ toggle_expert_mode(void)
nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings));
}

void
toggle_blindsign_status(void)
void set_blindsign_status(blindsign_state_t status)
{
settings_t tmp;
memcpy(&tmp, (void *)&N_settings, sizeof(tmp));
tmp.blindsign_status = (tmp.blindsign_status + 1) % 3;
tmp.blindsign_status = status;
nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings));
}

void
toggle_blindsign_status(void)
{
blindsign_state_t status = (N_settings.blindsign_status + 1) % 3;
set_blindsign_status(status);
}
23 changes: 12 additions & 11 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@
#include "utils.h"

#include "parser/parser_state.h"
/**
* @brief Zeros out all application-specific globals and SDK-specific
* UI/exchange buffers.
*/
void init_globals(void);

/// Toggles the persisted expert_mode setting
void toggle_expert_mode(void);

/// toggles the blindsign setting between "For large tx", "ON", "OFF".
void toggle_blindsign_status(void);

#define MAX_APDU_SIZE 235
#define MAX_SIGNATURE_SIZE 100
Expand Down Expand Up @@ -149,3 +138,15 @@ extern unsigned int app_stack_canary; // From SDK
*
*/
extern unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];

/**
* @brief Zeros out all application-specific globals and SDK-specific
* UI/exchange buffers.
*/
void init_globals(void);

/// Toggles the persisted expert_mode setting
void toggle_expert_mode(void);

/// set the blindsign setting between "For large tx", "ON", "OFF".
void set_blindsign_status(blindsign_state_t status);
71 changes: 51 additions & 20 deletions app/src/ui_home_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,97 @@
#include "globals.h"
#include "nbgl_use_case.h"

static void
controls_callback(int token, __attribute__((unused)) uint8_t index,
__attribute__((unused)) int page);
void tz_ui_home_redisplay(void);

// -----------------------------------------------------------
// --------------------- SETTINGS MENU -----------------------
// -----------------------------------------------------------
#define SETTING_INFO_NB 2
#define SETTINGS_SWITCHES_NB 1
#define SETTINGS_RADIO_NB 3
static const char *const infoTypes[] = {"Version", "Developer"};
static const char *const infoContents[]
= {APPVERSION, "Trilitech Kanvas Limited et al."};

enum {
EXPERT_MODE_TOKEN = FIRST_USER_TOKEN,
BLINDSIGN_MODE_TOKEN
};
enum {
EXPERT_MODE_TOKEN_ID = 0,
SETTINGS_SWITCHES_NB
BLINDSIGN_MODE_TOKEN_ID,
SETTINGS_CONTENTS_NB
};

static nbgl_layoutSwitch_t switches[SETTINGS_SWITCHES_NB] = {0};

static nbgl_contentSwitch_t expert_mode_switch = {0};
static const nbgl_contentInfoList_t infoList = {.nbInfos = SETTING_INFO_NB,
.infoTypes = infoTypes,
.infoContents = infoContents};

static const char *const blindsign_choices_text[] = {
"Blindsign For Large Tx", "Blindsigning ON", "Blindsigning OFF"};

static void
get_contents(uint8_t index, nbgl_content_t *content)
{
FUNC_ENTER(("Index: %d", index));
if(index == EXPERT_MODE_TOKEN_ID) {
content->content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB;
content->content.switchesList.switches = &expert_mode_switch;
content->type = SWITCHES_LIST;
content->contentActionCallback = controls_callback;
}
else{
content->content.choicesList.nbChoices = SETTINGS_RADIO_NB;
content->content.choicesList.names = blindsign_choices_text;
content->content.choicesList.token = BLINDSIGN_MODE_TOKEN;
content->content.choicesList.initChoice = N_settings.blindsign_status;
content->type = CHOICES_LIST;
content->contentActionCallback = controls_callback;
}
FUNC_LEAVE();
}

static void
controls_callback(int token, __attribute__((unused)) uint8_t index,
__attribute__((unused)) int page)
{
FUNC_ENTER(("Token : %d, Index: %d, Page: %d", token, index, page));
uint8_t switch_value;
if (token == EXPERT_MODE_TOKEN) {
switch_value = !N_settings.expert_mode;
toggle_expert_mode();
switches[EXPERT_MODE_TOKEN_ID].initState
expert_mode_switch.initState
= (nbgl_state_t)(switch_value);
}
if(token == BLINDSIGN_MODE_TOKEN) {
blindsign_state_t blindsign_status = (blindsign_state_t)(index % 3);
set_blindsign_status(blindsign_status);
}
FUNC_LEAVE();
}

#define SETTINGS_CONTENTS_NB 1
static const nbgl_content_t contentsList[SETTINGS_CONTENTS_NB] = {
{.content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB,
.content.switchesList.switches = switches,
.type = SWITCHES_LIST,
.contentActionCallback = controls_callback}
};

#define HOME_TEXT "This app enables signing transactions on the Tezos Network"

static const nbgl_genericContents_t tezos_settingContents
= {.callbackCallNeeded = false,
.contentsList = contentsList,
= {.callbackCallNeeded = true,
.contentGetterCallback = get_contents,
.nbContents = SETTINGS_CONTENTS_NB};
;

#define HOME_TEXT "This app enables signing transactions on the Tezos Network"
void
initSettings(void)
{
switches[EXPERT_MODE_TOKEN_ID].initState
expert_mode_switch.initState
= (nbgl_state_t)(N_settings.expert_mode);
switches[EXPERT_MODE_TOKEN_ID].text = "Expert mode";
switches[EXPERT_MODE_TOKEN_ID].subText = "Enable expert mode signing";
switches[EXPERT_MODE_TOKEN_ID].token = EXPERT_MODE_TOKEN;
switches[EXPERT_MODE_TOKEN_ID].tuneId = TUNE_TAP_CASUAL;
expert_mode_switch.text = "Expert mode";
expert_mode_switch.subText = "Enable expert mode signing";
expert_mode_switch.token = EXPERT_MODE_TOKEN;
expert_mode_switch.tuneId = TUNE_TAP_CASUAL;

}

void
Expand All @@ -97,6 +127,7 @@ tz_ui_home_redisplay(void)
FUNC_ENTER(("void"));

initSettings();
PRINTF("Entered settings and initialized\n");

nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT,
INIT_HOME_PAGE, &tezos_settingContents,
Expand Down
2 changes: 1 addition & 1 deletion app/src/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void
blindsign_toggle()
{
FUNC_ENTER();
toggle_blindsign_status();
set_blindsign_status((N_settings.blindsign_status + 1) % 3);
ui_settings_init(SETTINGS_BLINDSIGN_PAGE);
FUNC_LEAVE();
}
Expand Down

0 comments on commit e0780da

Please sign in to comment.