Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blindsigning page to stax #278

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
spalmer25 marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 16 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,19 @@ 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);

/// Toggles the persisted blindsign setting between "For large tx", "ON",
/// "OFF".
void toggle_blindsign_status(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
98 changes: 67 additions & 31 deletions app/src/ui_home_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,79 +28,115 @@
#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);
}
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
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.
14 changes: 10 additions & 4 deletions tests/integration/touch/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from utils import tezos_app
from utils import tezos_app, BlindsigningStatus

if __name__ == "__main__":
app = tezos_app(__file__)
Expand All @@ -22,14 +22,20 @@
app.assert_home()

app.welcome.settings()
app.assert_settings()
app.assert_expert_mode()

app.settings.toggle_expert_mode()
app.assert_settings(expert_mode=True)
app.assert_expert_mode(expert_mode=True)

app.settings.toggle_expert_mode()
app.assert_settings()
app.assert_expert_mode()

app.settings.next()
app.assert_blindsigning_status(blindsignStatus=BlindsigningStatus.Large_Tx_only)
app.settings.set_blindigning(2)
app.assert_blindsigning_status(blindsignStatus=BlindsigningStatus.ON)
app.settings.set_blindigning(3)
app.assert_blindsigning_status(blindsignStatus=BlindsigningStatus.OFF)
app.settings.next()
app.assert_info()

Expand Down
31 changes: 19 additions & 12 deletions tests/integration/touch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import os
import time
from enum import Enum

from pathlib import Path
from typing import Generator, List
Expand Down Expand Up @@ -136,15 +137,21 @@ def toggle_expert_mode(self):
"""Toggle the expert_mode switch."""
self._toggle_list.choose(1)

def toggle_blindsigning(self):
"""Toggle the blindsigning switch."""
self._toggle_list.choose(2)
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 exit(self) -> None:
"""Exits settings."""
self.multi_page_exit()


class BlindsigningStatus(Enum):
Large_Tx_only = 1
ON = 2
OFF = 3

class TezosAppScreen(metaclass=MetaScreen):
use_case_welcome = UseCaseHomeExt
use_case_settings = UseCaseSettings
Expand Down Expand Up @@ -244,16 +251,16 @@ def assert_home(self):
def assert_info(self):
self.assert_screen("info", True)

def assert_settings(self,
blindsigning = False,
expert_mode = False):
suffix=""
if blindsigning:
suffix += "_blindsigning"
def assert_expert_mode(self, expert_mode=False):
suffix = ""
if expert_mode:
suffix += "_expert"
if suffix != "":
suffix += "_on"
suffix += "_expert_on"
self.assert_screen("settings" + suffix)

def assert_blindsigning_status(
self, blindsignStatus=BlindsigningStatus.Large_Tx_only
):
suffix = "_" + str(blindsignStatus).replace(".", "-")
self.assert_screen("settings" + suffix)

def quit(self):
Expand Down
Loading