Skip to content

Commit 32a103f

Browse files
Merge pull request #584 from LedgerHQ/cev/B2CA-1558_eip191-streaming
NBGL porting: improve EIP191
2 parents aa300c9 + 43adc49 commit 32a103f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+228
-360
lines changed

client/src/ledger_app_clients/ethereum/eip712/InputData.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from client import keychain
1111
from client.client import EthAppClient, EIP712FieldType
1212

13+
from ragger.firmware import Firmware
1314

1415
# global variables
1516
app_client: EthAppClient = None
@@ -391,7 +392,7 @@ def next_timeout(_signum: int, _frame):
391392

392393

393394
def enable_autonext():
394-
if app_client._client.firmware.device in ("stax", "flex"):
395+
if app_client._client.firmware in (Firmware.STAX, Firmware.FLEX):
395396
delay = 1/3
396397
else:
397398
delay = 1/4

client/src/ledger_app_clients/ethereum/settings.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,29 @@ class SettingID(Enum):
1111
DEBUG_DATA = auto()
1212

1313

14-
def get_device_settings(device: str) -> list[SettingID]:
15-
if device == "nanos":
14+
def get_device_settings(firmware: Firmware) -> list[SettingID]:
15+
if firmware == Firmware.NANOS:
1616
return [
1717
SettingID.NONCE,
1818
SettingID.DEBUG_DATA,
1919
]
20-
if device in ("nanox", "nanosp", "stax", "flex"):
21-
return [
22-
SettingID.VERBOSE_ENS,
23-
SettingID.VERBOSE_EIP712,
24-
SettingID.NONCE,
25-
SettingID.DEBUG_DATA,
26-
]
27-
return []
20+
return [
21+
SettingID.VERBOSE_ENS,
22+
SettingID.VERBOSE_EIP712,
23+
SettingID.NONCE,
24+
SettingID.DEBUG_DATA,
25+
]
2826

2927

30-
def get_setting_per_page(device: str) -> int:
31-
if device == "stax":
28+
def get_setting_per_page(firmware: Firmware) -> int:
29+
if firmware == Firmware.STAX:
3230
return 3
3331
return 2
3432

3533

36-
def get_setting_position(device: str, setting: Union[NavInsID, SettingID]) -> tuple[int, int]:
37-
settings_per_page = get_setting_per_page(device)
38-
if device == "stax":
34+
def get_setting_position(firmware: Firmware, setting: Union[NavInsID, SettingID]) -> tuple[int, int]:
35+
settings_per_page = get_setting_per_page(firmware)
36+
if firmware == Firmware.STAX:
3937
screen_height = 672 # px
4038
header_height = 88 # px
4139
footer_height = 92 # px
@@ -47,15 +45,15 @@ def get_setting_position(device: str, setting: Union[NavInsID, SettingID]) -> tu
4745
option_offset = 420 # px
4846
usable_height = screen_height - (header_height + footer_height)
4947
setting_height = usable_height // settings_per_page
50-
index_in_page = get_device_settings(device).index(SettingID(setting)) % settings_per_page
48+
index_in_page = get_device_settings(firmware).index(SettingID(setting)) % settings_per_page
5149
return option_offset, header_height + (setting_height * index_in_page) + (setting_height // 2)
5250

5351

54-
def settings_toggle(fw: Firmware, nav: Navigator, to_toggle: list[SettingID]):
52+
def settings_toggle(firmware: Firmware, nav: Navigator, to_toggle: list[SettingID]):
5553
moves: list[Union[NavIns, NavInsID]] = list()
56-
settings = get_device_settings(fw.device)
54+
settings = get_device_settings(firmware)
5755
# Assume the app is on the home page
58-
if fw.device.startswith("nano"):
56+
if firmware.is_nano:
5957
moves += [NavInsID.RIGHT_CLICK] * 2
6058
moves += [NavInsID.BOTH_CLICK]
6159
for setting in settings:
@@ -65,12 +63,12 @@ def settings_toggle(fw: Firmware, nav: Navigator, to_toggle: list[SettingID]):
6563
moves += [NavInsID.BOTH_CLICK] # Back
6664
else:
6765
moves += [NavInsID.USE_CASE_HOME_SETTINGS]
68-
settings_per_page = get_setting_per_page(fw.device)
66+
settings_per_page = get_setting_per_page(firmware)
6967
for setting in settings:
7068
setting_idx = settings.index(setting)
7169
if (setting_idx > 0) and (setting_idx % settings_per_page) == 0:
7270
moves += [NavInsID.USE_CASE_SETTINGS_NEXT]
7371
if setting in to_toggle:
74-
moves += [NavIns(NavInsID.TOUCH, get_setting_position(fw.device, setting))]
72+
moves += [NavIns(NavInsID.TOUCH, get_setting_position(firmware, setting))]
7573
moves += [NavInsID.USE_CASE_SETTINGS_MULTI_PAGE_EXIT]
7674
nav.navigate(moves, screen_change_before_first_instruction=False)

ledger_app.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ sdk = "C"
44
devices = ["nanos", "nanox", "nanos+", "stax", "flex"]
55

66
[use_cases] # Coherent build options that make sense for your application
7-
debug = "DEBUG=1"
8-
use_test_keys = "DEBUG=1 CAL_TEST_KEY=1 DOMAIN_NAME_TEST_KEY=1 SET_PLUGIN_TEST_KEY=1 NFT_TEST_KEY=1"
9-
cal_bypass = "DEBUG=1 BYPASS_SIGNATURES=1"
7+
test_keys = "CAL_TEST_KEY=1 DOMAIN_NAME_TEST_KEY=1 SET_PLUGIN_TEST_KEY=1 NFT_TEST_KEY=1"
8+
dbg_test_keys = "DEBUG=1 CAL_TEST_KEY=1 DOMAIN_NAME_TEST_KEY=1 SET_PLUGIN_TEST_KEY=1 NFT_TEST_KEY=1"
9+
cal_bypass = "BYPASS_SIGNATURES=1"
10+
dbg_cal_bypass = "DEBUG=1 BYPASS_SIGNATURES=1"
1011

1112
[tests]
1213
unit_directory = "./tests/unit"

src_nbgl/ui_approve_tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void reviewChoice(bool confirm) {
5151
}
5252
}
5353

54-
static const nbgl_icon_details_t *get_tx_icon(void) {
54+
const nbgl_icon_details_t *get_tx_icon(void) {
5555
const nbgl_icon_details_t *icon = NULL;
5656

5757
if (tx_approval_context.fromPlugin && (pluginType == EXTERNAL)) {

src_nbgl/ui_confirm_parameter_selector.c

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,25 @@
44
#include "network.h"
55

66
typedef enum { PARAMETER_CONFIRMATION, SELECTOR_CONFIRMATION } e_confirmation_type;
7+
static nbgl_contentTagValue_t pair;
8+
static nbgl_contentTagValueList_t pairsList;
79

8-
enum {
9-
TOKEN_APPROVE = FIRST_USER_TOKEN,
10-
};
11-
12-
static void reviewReject(void) {
13-
io_seproxyhal_touch_data_cancel(NULL);
14-
}
15-
16-
static void long_press_cb(int token, uint8_t index, int page) {
17-
UNUSED(index);
18-
UNUSED(page);
19-
if (token == TOKEN_APPROVE) {
10+
static void reviewChoice(bool confirm) {
11+
if (confirm) {
2012
io_seproxyhal_touch_data_ok(NULL);
13+
} else {
14+
io_seproxyhal_touch_data_cancel(NULL);
2115
}
2216
}
2317

2418
static void buildScreen(e_confirmation_type confirm_type) {
25-
static nbgl_genericContents_t contents = {0};
26-
static nbgl_content_t contentsList[3] = {0};
27-
static nbgl_contentTagValue_t pair = {0};
28-
uint8_t nbContents = 0;
2919
uint32_t buf_size = SHARED_BUFFER_SIZE / 2;
20+
nbgl_operationType_t op = TYPE_TRANSACTION;
3021

22+
pair.item = (confirm_type == PARAMETER_CONFIRMATION) ? "Parameter" : "Selector";
23+
pair.value = strings.tmp.tmp;
24+
pairsList.nbPairs = 1;
25+
pairsList.pairs = &pair;
3126
snprintf(g_stax_shared_buffer,
3227
buf_size,
3328
"Verify %s",
@@ -38,37 +33,16 @@ static void buildScreen(e_confirmation_type confirm_type) {
3833
"Confirm %s",
3934
(confirm_type == PARAMETER_CONFIRMATION) ? "parameter" : "selector");
4035

41-
pair.item = (confirm_type == PARAMETER_CONFIRMATION) ? "Parameter" : "Selector";
42-
pair.value = strings.tmp.tmp;
43-
44-
// Title page
45-
contentsList[nbContents].type = CENTERED_INFO;
46-
contentsList[nbContents].content.centeredInfo.text1 = g_stax_shared_buffer;
47-
contentsList[nbContents].content.centeredInfo.icon = get_app_icon(true);
48-
contentsList[nbContents].content.centeredInfo.style = LARGE_CASE_INFO;
49-
nbContents++;
50-
51-
// Values to be reviewed
52-
contentsList[nbContents].type = TAG_VALUE_LIST;
53-
contentsList[nbContents].content.tagValueList.pairs = &pair;
54-
contentsList[nbContents].content.tagValueList.nbPairs = 1;
55-
nbContents++;
56-
57-
// Approval screen
58-
contentsList[nbContents].type = INFO_LONG_PRESS;
59-
contentsList[nbContents].content.infoLongPress.text = g_stax_shared_buffer + buf_size;
60-
contentsList[nbContents].content.infoLongPress.icon = get_app_icon(true);
61-
contentsList[nbContents].content.infoLongPress.longPressText = "Hold to confirm";
62-
contentsList[nbContents].content.infoLongPress.longPressToken = TOKEN_APPROVE;
63-
contentsList[nbContents].content.infoLongPress.tuneId = NB_TUNES;
64-
contentsList[nbContents].contentActionCallback = long_press_cb;
65-
nbContents++;
66-
67-
contents.callbackCallNeeded = false;
68-
contents.contentsList = contentsList;
69-
contents.nbContents = nbContents;
70-
71-
nbgl_useCaseGenericReview(&contents, REJECT_BUTTON, reviewReject);
36+
if (tmpContent.txContent.dataPresent) {
37+
op |= BLIND_OPERATION;
38+
}
39+
nbgl_useCaseReview(op,
40+
&pairsList,
41+
get_tx_icon(),
42+
g_stax_shared_buffer,
43+
NULL,
44+
g_stax_shared_buffer + buf_size,
45+
reviewChoice);
7246
}
7347

7448
void ui_confirm_parameter(void) {

src_nbgl/ui_display_privacy.c

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,32 @@
44
#include "nbgl_use_case.h"
55
#include "nbgl_content.h"
66

7-
enum {
8-
TOKEN_APPROVE = FIRST_USER_TOKEN,
9-
};
10-
11-
static void reviewReject(void) {
12-
io_seproxyhal_touch_privacy_cancel(NULL);
13-
}
14-
15-
static void long_press_cb(int token, uint8_t index, int page) {
16-
UNUSED(index);
17-
UNUSED(page);
18-
if (token == TOKEN_APPROVE) {
7+
static void reviewChoice(bool confirm) {
8+
if (confirm) {
199
io_seproxyhal_touch_privacy_ok(NULL);
10+
} else {
11+
io_seproxyhal_touch_privacy_cancel(NULL);
2012
}
2113
}
2214

2315
static void buildFirstPage(const char *review_string) {
24-
static nbgl_genericContents_t contents = {0};
25-
static nbgl_content_t contentsList[3] = {0};
2616
static nbgl_contentTagValue_t pairs[2] = {0};
27-
uint8_t nbContents = 0;
28-
uint8_t nbPairs = 0;
29-
30-
pairs[nbPairs].item = "Address";
31-
pairs[nbPairs].value = strings.common.toAddress;
32-
nbPairs++;
33-
pairs[nbPairs].item = "Key";
34-
pairs[nbPairs].value = strings.common.fullAmount;
35-
nbPairs++;
36-
37-
// Title page
38-
contentsList[nbContents].type = CENTERED_INFO;
39-
contentsList[nbContents].content.centeredInfo.text1 = review_string;
40-
contentsList[nbContents].content.centeredInfo.icon = get_app_icon(true);
41-
contentsList[nbContents].content.centeredInfo.style = LARGE_CASE_INFO;
42-
nbContents++;
43-
44-
// Values to be reviewed
45-
contentsList[nbContents].type = TAG_VALUE_LIST;
46-
contentsList[nbContents].content.tagValueList.pairs = pairs;
47-
contentsList[nbContents].content.tagValueList.nbPairs = nbPairs;
48-
nbContents++;
49-
50-
// Approval screen
51-
contentsList[nbContents].type = INFO_LONG_PRESS;
52-
contentsList[nbContents].content.infoLongPress.text = review_string;
53-
contentsList[nbContents].content.infoLongPress.icon = get_app_icon(true);
54-
contentsList[nbContents].content.infoLongPress.longPressText = "Hold to approve";
55-
contentsList[nbContents].content.infoLongPress.longPressToken = TOKEN_APPROVE;
56-
contentsList[nbContents].content.infoLongPress.tuneId = NB_TUNES;
57-
contentsList[nbContents].contentActionCallback = long_press_cb;
58-
nbContents++;
59-
60-
contents.callbackCallNeeded = false;
61-
contents.contentsList = contentsList;
62-
contents.nbContents = nbContents;
63-
64-
nbgl_useCaseGenericReview(&contents, REJECT_BUTTON, reviewReject);
17+
static nbgl_contentTagValueList_t pairsList = {0};
18+
19+
pairs[0].item = "Address";
20+
pairs[0].value = strings.common.toAddress;
21+
pairs[1].item = "Key";
22+
pairs[1].value = strings.common.fullAmount;
23+
pairsList.nbPairs = 2;
24+
pairsList.pairs = pairs;
25+
26+
nbgl_useCaseReview(TYPE_OPERATION,
27+
&pairsList,
28+
get_tx_icon(),
29+
review_string,
30+
NULL,
31+
review_string,
32+
reviewChoice);
6533
}
6634

6735
void ui_display_privacy_public_key(void) {

src_nbgl/ui_message_signing.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
11
#include "ui_nbgl.h"
2-
#include "ui_signing.h"
32
#include "ui_logic.h"
4-
#include "ui_message_signing.h"
5-
#include "glyphs.h"
6-
7-
static void (*g_approved_func)(void) = NULL;
8-
static void (*g_rejected_func)(void) = NULL;
9-
10-
static void ui_message_rejection_handler() {
11-
nbgl_useCaseStatus("Message signing\ncancelled", false, g_rejected_func);
12-
}
13-
14-
static void ui_message_confirm_rejection(void) {
15-
nbgl_useCaseConfirm(REJECT_QUESTION(TEXT_MESSAGE),
16-
NULL,
17-
REJECT_CONFIRM_BUTTON,
18-
RESUME(TEXT_MESSAGE),
19-
ui_message_rejection_handler);
20-
}
21-
22-
void ui_message_review_choice(bool confirm) {
23-
if (confirm) {
24-
nbgl_useCaseStatus("MESSAGE\nSIGNED", true, g_approved_func);
25-
} else {
26-
ui_message_confirm_rejection();
27-
}
28-
}
29-
30-
void ui_message_start(const char *title,
31-
void (*start_func)(void),
32-
void (*approved_func)(void),
33-
void (*rejected_func)(void)) {
34-
g_approved_func = approved_func;
35-
g_rejected_func = rejected_func;
36-
nbgl_useCaseReviewStart(&C_Review_64px,
37-
title,
38-
NULL,
39-
REJECT_BUTTON,
40-
start_func,
41-
ui_message_confirm_rejection);
42-
}
433

444
static void ui_message_712_approved(void) {
455
ui_712_approve();

src_nbgl/ui_message_signing.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#define TEXT_REVIEW_EIP712 REVIEW(TEXT_TYPED_MESSAGE)
1010
#define TEXT_SIGN_EIP712 SIGN(TEXT_TYPED_MESSAGE)
1111

12-
void ui_message_review_choice(bool confirm);
13-
void ui_message_start(const char *title,
14-
void (*start_func)(void),
15-
void (*approved_func)(void),
16-
void (*rejected_func)(void));
1712
void ui_typed_message_review_choice(bool confirm);
1813

1914
#endif // UI_MESSAGE_SIGNING_H_

src_nbgl/ui_nbgl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern char g_stax_shared_buffer[SHARED_BUFFER_SIZE];
1111
extern nbgl_page_t* pageContext;
1212

1313
const nbgl_icon_details_t* get_app_icon(bool caller_icon);
14+
const nbgl_icon_details_t* get_tx_icon(void);
1415

1516
void ui_idle(void);
1617

0 commit comments

Comments
 (0)