forked from pontem-network/ledger-app-aptos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbagl_display.c
423 lines (384 loc) · 13 KB
/
bagl_display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/*****************************************************************************
* Ledger App Aptos.
* (c) 2020 Ledger SAS.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifdef HAVE_BAGL
#include <stdbool.h> // bool
#include <string.h> // memset
#include "os.h"
#include "ux.h"
#include "glyphs.h"
#include "io.h"
#include "bagl_display.h"
#include "display.h"
#include "settings.h"
#include "menu.h"
#include "constants.h"
#include "../globals.h"
#include "../sw.h"
#include "action/validate.h"
#include "../common/user_format.h"
#define DOTS "[...]"
static action_validate_cb g_validate_callback;
static action_extend_ctx_t g_allow_blind_sign_ctx;
// Validate/Invalidate public key and go back to home
static void ui_action_validate_pubkey(bool choice) {
validate_pubkey(choice);
ui_menu_main();
}
// Validate/Invalidate transaction and go back to home
static void ui_action_validate_transaction(bool choice) {
validate_transaction(choice);
ui_menu_main();
}
// Action to allow blind signing in settings
static void ui_action_allow_blind_signing(const ux_flow_step_t *const *steps) {
settings_allow_blind_signing_change(1);
// Passed UX_FLOW steps are expected to contain a blind signing warning on the first step.
// Skip it for better UX here.
ux_flow_init(0, steps, steps[1]);
}
#ifdef TARGET_NANOS
UX_STEP_NOCB(ux_display_blind_sign_banner_step,
bnnn_paging,
{
.title = "Error",
.text = "Blind signing must be enabled in Settings",
});
#else
// Step with icon and text
UX_STEP_NOCB(ux_display_blind_sign_banner_step,
pnn,
{
&C_icon_warning,
"Blind signing must be",
"enabled in Settings",
});
#endif
// Step with approve button
UX_STEP_CB(ux_display_approve_step,
pb,
(*g_validate_callback)(true),
{
&C_icon_validate_14,
"Approve",
});
// Step with reject button
UX_STEP_CB(ux_display_reject_step,
pb,
(*g_validate_callback)(false),
{
&C_icon_crossmark,
"Reject",
});
// Step with the button to change settings
UX_STEP_CB(ux_display_allow_blind_sign_step,
pnn,
{ g_allow_blind_sign_ctx.call(g_allow_blind_sign_ctx.steps); },
{
&C_icon_validate_14,
"Allow",
"Blind Signing",
});
// FLOW to display blind signing banner:
// #1 screen : warning icon + "Blind signing must be enabled in Settings"
// #2 screen : reject button
UX_FLOW(ux_display_blind_sign_banner_flow,
&ux_display_blind_sign_banner_step,
&ux_display_allow_blind_sign_step,
&ux_display_reject_step);
void ui_flow_display(const ux_flow_step_t *const *steps) {
ux_flow_init(0, steps, NULL);
}
// This function should always use UX_FLOW containing the blind signing warning on the first step!
void ui_flow_verified_display(const ux_flow_step_t *const *steps) {
if (N_storage.settings.allow_blind_signing) {
ui_flow_display(steps);
} else {
g_allow_blind_sign_ctx.call = &ui_action_allow_blind_signing;
g_allow_blind_sign_ctx.steps = steps;
ui_flow_display(ux_display_blind_sign_banner_flow);
}
}
// Step with icon and text
UX_STEP_NOCB(ux_display_confirm_addr_step, pn, {&C_icon_eye, "Confirm Address"});
// Step with title/text for BIP32 path
UX_STEP_NOCB(ux_display_path_step,
bnnn_paging,
{
.title = "Path",
.text = g_bip32_path,
});
// Step with title/text for address
UX_STEP_NOCB(ux_display_address_step,
bnnn_paging,
{
.title = "Address",
.text = g_address,
});
// FLOW to display address and BIP32 path:
// #1 screen: eye icon + "Confirm Address"
// #2 screen: display BIP32 Path
// #3 screen: display address
// #4 screen: approve button
// #5 screen: reject button
UX_FLOW(ux_display_pubkey_flow,
&ux_display_confirm_addr_step,
&ux_display_path_step,
&ux_display_address_step,
&ux_display_approve_step,
&ux_display_reject_step);
int ui_display_address() {
g_validate_callback = &ui_action_validate_pubkey;
const int ret = ui_prepare_address();
if (ret == UI_PREPARED) {
ui_flow_display(ux_display_pubkey_flow);
return 0;
}
return ret;
}
// Step with icon and text
UX_STEP_NOCB(ux_display_blind_warn_step,
pnn,
{
&C_icon_warning,
"Blind",
"Signing",
});
// Step with icon and text
UX_STEP_NOCB(ux_display_review_step,
pnn,
{
&C_icon_eye,
"Review",
"Transaction",
});
// Step with icon and text
UX_STEP_NOCB(ux_display_review_msg_step,
pnn,
{
&C_icon_eye,
"Review",
"Message",
});
// Step with title/text for message
UX_STEP_NOCB(ux_display_msg_step,
bnnn_paging,
{
.title = "Message",
.text = (const char *) G_context.tx_info.raw_tx,
});
// Step with title/text for message in short form
UX_STEP_NOCB(ux_display_short_msg_step,
bnnn_paging,
{
.title = "Message",
.text = g_struct,
});
// Step with title/text for transaction type
UX_STEP_NOCB(ux_display_tx_type_step,
bnnn_paging,
{
.title = "Transaction Type",
.text = g_tx_type,
});
// Step with title/text for function
UX_STEP_NOCB(ux_display_function_step,
bnnn_paging,
{
.title = "Function",
.text = g_function,
});
// Step with title/text for coin type
UX_STEP_NOCB(ux_display_coin_type_step,
bnnn_paging,
{
.title = "Coin Type",
.text = g_struct,
});
// Step with title/text for receiver
UX_STEP_NOCB(ux_display_receiver_step,
bnnn_paging,
{
.title = "Receiver",
.text = g_address,
});
// Step with title/text for amount
UX_STEP_NOCB(ux_display_amount_step,
bnnn_paging,
{
.title = "Amount",
.text = g_amount,
});
// Step with title/text for gas fee
UX_STEP_NOCB(ux_display_gas_fee_step,
bnnn_paging,
{
.title = "Gas Fee",
.text = g_gas_fee,
});
// FLOW to display default transaction information:
// #1 screen : warning icon + "Blind Signing"
// #2 screen : eye icon + "Review Transaction"
// #3 screen : display tx type
// #4 screen : display gas fee
// #5 screen : approve button
// #6 screen : reject button
UX_FLOW(ux_display_blind_tx_default_flow,
&ux_display_blind_warn_step,
&ux_display_review_step,
&ux_display_tx_type_step,
&ux_display_gas_fee_step,
&ux_display_approve_step,
&ux_display_reject_step);
// SEQUENCE to display message information:
// #1 screen : eye icon + "Review Message"
// #2 screen : display message
// #3 screen : approve button
// #4 screen : reject button
#define SEQUENCE_MESSAGE \
&ux_display_review_msg_step, &ux_display_msg_step, &ux_display_approve_step, \
&ux_display_reject_step
UX_FLOW(ux_display_message_flow, SEQUENCE_MESSAGE);
// preceding screen : warning icon + "Blind Signing"
UX_FLOW(ux_display_blind_message_flow, &ux_display_blind_warn_step, SEQUENCE_MESSAGE);
// FLOW to display message information in short form:
// #1 screen : eye icon + "Review Message"
// #2 screen : display short message
// #3 screen : approve button
// #4 screen : reject button
#define SEQUENCE_SHORT_MESSAGE \
&ux_display_review_msg_step, &ux_display_short_msg_step, &ux_display_approve_step, \
&ux_display_reject_step
UX_FLOW(ux_display_short_message_flow, SEQUENCE_SHORT_MESSAGE);
// preceding screen : warning icon + "Blind Signing"
UX_FLOW(ux_display_blind_short_message_flow, &ux_display_blind_warn_step, SEQUENCE_SHORT_MESSAGE);
// FLOW to display entry_function transaction information:
// #1 screen : warning icon + "Blind Signing"
// #2 screen : eye icon + "Review Transaction"
// #3 screen : display tx type
// #4 screen : display function name
// #5 screen : display gas fee
// #6 screen : approve button
// #7 screen : reject button
UX_FLOW(ux_display_blind_tx_entry_function_flow,
&ux_display_blind_warn_step,
&ux_display_review_step,
&ux_display_tx_type_step,
&ux_display_function_step,
&ux_display_gas_fee_step,
&ux_display_approve_step,
&ux_display_reject_step);
// FLOW to display aptos_account_transfer transaction information:
// #1 screen : eye icon + "Review Transaction"
// #2 screen : display tx type
// #3 screen : display function name
// #4 screen : display destination address
// #5 screen : display amount
// #6 screen : display gas fee
// #7 screen : approve button
// #8 screen : reject button
UX_FLOW(ux_display_tx_aptos_account_transfer_flow,
&ux_display_review_step,
&ux_display_tx_type_step,
&ux_display_function_step,
&ux_display_receiver_step,
&ux_display_amount_step,
&ux_display_gas_fee_step,
&ux_display_approve_step,
&ux_display_reject_step);
// FLOW to display coin_transfer transaction information:
// #1 screen : eye icon + "Review Transaction"
// #2 screen : display tx type
// #3 screen : display function name
// #4 screen : display coin type
// #5 screen : display destination address
// #6 screen : display amount
// #7 screen : display gas fee
// #8 screen : approve button
// #9 screen : reject button
UX_FLOW(ux_display_tx_coin_transfer_flow,
&ux_display_review_step,
&ux_display_tx_type_step,
&ux_display_function_step,
&ux_display_coin_type_step,
&ux_display_receiver_step,
&ux_display_amount_step,
&ux_display_gas_fee_step,
&ux_display_approve_step,
&ux_display_reject_step);
int ui_display_transaction() {
g_validate_callback = &ui_action_validate_transaction;
const int ret = ui_prepare_transaction();
if (ret == UI_PREPARED) {
ui_flow_verified_display(ux_display_blind_tx_default_flow);
return 0;
}
return ret;
}
int ui_display_message() {
if (N_storage.settings.show_full_message) {
if (is_str_interrupted((const char *) G_context.tx_info.raw_tx,
G_context.tx_info.raw_tx_len)) {
ui_flow_verified_display(ux_display_blind_message_flow);
} else {
ui_flow_display(ux_display_message_flow);
}
} else {
memset(g_struct, 0, sizeof(g_struct));
bool short_enough = G_context.tx_info.raw_tx_len < sizeof(g_struct);
snprintf(g_struct,
sizeof(g_struct),
short_enough ? "%.*s" : "%.*s" DOTS,
short_enough ? G_context.tx_info.raw_tx_len : sizeof(g_struct) - sizeof(DOTS),
G_context.tx_info.raw_tx);
PRINTF("Message: %s\n", g_struct);
if (short_enough) {
if (is_str_interrupted(g_struct, sizeof(g_struct))) {
ui_flow_verified_display(ux_display_blind_short_message_flow);
} else {
ui_flow_display(ux_display_short_message_flow);
}
} else {
ui_flow_verified_display(ux_display_blind_short_message_flow);
}
}
return 0;
}
int ui_display_entry_function() {
const int ret = ui_prepare_entry_function();
if (ret == UI_PREPARED) {
ui_flow_verified_display(ux_display_blind_tx_entry_function_flow);
return 0;
}
return ret;
}
int ui_display_tx_aptos_account_transfer() {
const int ret = ui_prepare_tx_aptos_account_transfer();
if (ret == UI_PREPARED) {
ui_flow_display(ux_display_tx_aptos_account_transfer_flow);
return 0;
}
return ret;
}
int ui_display_tx_coin_transfer() {
const int ret = ui_prepare_tx_coin_transfer();
if (ret == UI_PREPARED) {
ui_flow_display(ux_display_tx_coin_transfer_flow);
return 0;
}
return ret;
}
#endif