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 10, 2024
1 parent 6d5c041 commit c69f3a5
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 49 deletions.
11 changes: 9 additions & 2 deletions app/src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ toggle_expert_mode(void)
}

void
toggle_blindsign_status(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);
2 changes: 1 addition & 1 deletion app/src/ui_home.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void
ui_home_init(void)
{
FUNC_ENTER(("void"));
tz_ui_home_redisplay();
tz_ui_home_redisplay(INIT_HOME_PAGE);
FUNC_LEAVE();
}
#endif // HAVE_NBGL
99 changes: 68 additions & 31 deletions app/src/ui_home_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,79 +28,116 @@
#include "globals.h"
#include "nbgl_use_case.h"

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

// -----------------------------------------------------------
// --------------------- SETTINGS MENU -----------------------
// -----------------------------------------------------------
#define SETTING_INFO_NB 2
#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
};
enum {
EXPERT_MODE_PAGE = 0,
BLINDSIGN_PAGE = 1
};

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
= (nbgl_state_t)(switch_value);
expert_mode_switch.initState = (nbgl_state_t)(switch_value);
tz_ui_home_redisplay(EXPERT_MODE_PAGE);
}
if (token == BLINDSIGN_MODE_TOKEN) {
blindsign_state_t blindsign_status = (blindsign_state_t)(index % 3);
set_blindsign_status(blindsign_status);
tz_ui_home_redisplay(BLINDSIGN_PAGE);
}
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}
};

static const nbgl_genericContents_t tezos_settingContents
= {.callbackCallNeeded = false,
.contentsList = contentsList,
.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
= (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.initState = (nbgl_state_t)(N_settings.expert_mode);
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
tz_ui_home_redisplay(void)
tz_ui_home_redisplay(uint8_t page)
{
FUNC_ENTER(("void"));

initSettings();
static nbgl_genericContents_t tezos_settingContents = {0};
tezos_settingContents.callbackCallNeeded = false;
tezos_settingContents.nbContents = SETTINGS_CONTENTS_NB;

static nbgl_content_t contents[SETTINGS_CONTENTS_NB] = {0};
get_contents(EXPERT_MODE_TOKEN_ID, &contents[EXPERT_MODE_TOKEN_ID]);
get_contents(BLINDSIGN_MODE_TOKEN_ID, &contents[BLINDSIGN_MODE_TOKEN_ID]);

tezos_settingContents.contentsList = contents;

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

nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT,
INIT_HOME_PAGE, &tezos_settingContents,
&infoList, NULL, app_exit);
nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT, page,
&tezos_settingContents, &infoList, NULL,
app_exit);

FUNC_LEAVE();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/ui_home_nbgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@

#ifdef HAVE_NBGL

void tz_ui_home_redisplay(void);
void tz_ui_home_redisplay(uint8_t page);

#endif
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions tests/integration/touch/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
app.settings.toggle_expert_mode()
app.assert_settings()

app.settings.next()
app.assert_settings(blindsigning=True, blindsigning_status=0)
app.settings.set_blindigning(2)
app.assert_settings(blindsigning=True, blindsigning_status=1)
app.settings.set_blindigning(3)
app.assert_settings(blindsigning=True, blindsigning_status=2)
app.settings.next()
app.assert_info()

Expand Down
9 changes: 7 additions & 2 deletions tests/integration/touch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def toggle_expert_mode(self):
"""Toggle the expert_mode switch."""
self._toggle_list.choose(1)

def set_blindigning(self, value: int):
if value not in [1, 2, 3]:
raise ValueError("Value must be 1, 2 or 3")
self._toggle_list.choose(value)

def toggle_blindsigning(self):
"""Toggle the blindsigning switch."""
self._toggle_list.choose(2)
Expand Down Expand Up @@ -246,10 +251,10 @@ def assert_info(self):

def assert_settings(self,
blindsigning = False,
expert_mode = False):
expert_mode = False, blindsigning_status = 0):
suffix=""
if blindsigning:
suffix += "_blindsigning"
suffix += "_blindsigning_" + str(blindsigning_status)
if expert_mode:
suffix += "_expert"
if suffix != "":
Expand Down

0 comments on commit c69f3a5

Please sign in to comment.