eth: split ux from rest of source
This commit is contained in:
1
Makefile
1
Makefile
@@ -194,6 +194,7 @@ SDK_SOURCE_PATH += lib_ux
|
||||
ifeq ($(TARGET_NAME),TARGET_NANOX)
|
||||
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
|
||||
endif
|
||||
APP_SOURCE_PATH += src_bagl
|
||||
|
||||
### initialize plugin SDK submodule if needed, rebuild it, and warn if a difference is noticed
|
||||
ifeq ($(CHAIN),ethereum)
|
||||
|
||||
24
src/common_ui.h
Normal file
24
src/common_ui.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef _COMMON_UI_H_
|
||||
#define _COMMON_UI_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
void ui_idle(void);
|
||||
void ui_warning_contract_data(void);
|
||||
void ui_display_public_eth2(void);
|
||||
void ui_display_privacy_public_key(void);
|
||||
void ui_display_privacy_shared_secret(void);
|
||||
void ui_display_public_key(void);
|
||||
void ui_display_sign(void);
|
||||
void ui_sign_712_v0(void);
|
||||
void ui_display_stark_public(void);
|
||||
void ui_confirm_selector(void);
|
||||
void ui_confirm_parameter(void);
|
||||
void ui_stark_limit_order(void);
|
||||
void ui_stark_unsafe_sign(void);
|
||||
void ui_stark_transfer(bool selfTransfer, bool conditional);
|
||||
|
||||
#include "ui_callbacks.h"
|
||||
#include <string.h>
|
||||
|
||||
#endif // _COMMON_UI_H_
|
||||
@@ -1,8 +1,4 @@
|
||||
#include "shared_context.h"
|
||||
#ifdef HAVE_UX_FLOW
|
||||
#include "ui_flow.h"
|
||||
#endif
|
||||
#include "ui_callbacks.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "ux.h"
|
||||
#include "feature_signTx.h"
|
||||
|
||||
21
src/main.c
21
src/main.c
@@ -17,8 +17,7 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "ui_flow.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
@@ -84,24 +83,6 @@ void reset_app_context() {
|
||||
memset((uint8_t *) &tmpContent, 0, sizeof(tmpContent));
|
||||
}
|
||||
|
||||
void ui_idle(void) {
|
||||
// reserve a display stack slot if none yet
|
||||
if (G_ux.stack_count == 0) {
|
||||
ux_stack_push();
|
||||
}
|
||||
ux_flow_init(0, ux_idle_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_warning_contract_data(void) {
|
||||
ux_flow_init(0, ux_warning_contract_data_flow, NULL);
|
||||
}
|
||||
|
||||
unsigned int io_seproxyhal_touch_exit(__attribute__((unused)) const bagl_element_t *e) {
|
||||
// Go back to the dashboard
|
||||
os_sched_exit(0);
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
|
||||
void io_seproxyhal_send_status(uint32_t sw) {
|
||||
G_io_apdu_buffer[0] = ((sw >> 8) & 0xff);
|
||||
G_io_apdu_buffer[1] = (sw & 0xff);
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "stark_utils.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "utils.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
extraInfo_t *getKnownToken(uint8_t *contractAddress);
|
||||
|
||||
static unsigned char const C_cx_Stark256_n[] = {
|
||||
// n: 0x0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
|
||||
@@ -19,6 +19,9 @@ unsigned int io_seproxyhal_touch_signMessage712_v0_cancel(const bagl_element_t *
|
||||
unsigned int io_seproxyhal_touch_eth2_address_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_privacy_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_privacy_cancel(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_stark_pubkey_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_stark_ok(const bagl_element_t *e);
|
||||
|
||||
void ui_idle(void);
|
||||
void ui_warning_contract_data(void);
|
||||
|
||||
77
src_bagl/common_ui.c
Normal file
77
src_bagl/common_ui.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifdef HAVE_BAGL
|
||||
|
||||
#include "common_ui.h"
|
||||
#include "ux.h"
|
||||
#include "ui_flow.h"
|
||||
|
||||
void ui_idle(void) {
|
||||
// reserve a display stack slot if none yet
|
||||
if (G_ux.stack_count == 0) {
|
||||
ux_stack_push();
|
||||
}
|
||||
ux_flow_init(0, ux_idle_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_warning_contract_data(void) {
|
||||
ux_flow_init(0, ux_warning_contract_data_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_display_public_eth2(void) {
|
||||
ux_flow_init(0, ux_display_public_eth2_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_display_privacy_public_key(void) {
|
||||
ux_flow_init(0, ux_display_privacy_public_key_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_display_privacy_shared_secret(void) {
|
||||
ux_flow_init(0, ux_display_privacy_shared_secret_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_display_public_key(void) {
|
||||
ux_flow_init(0, ux_display_public_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_display_sign(void) {
|
||||
ux_flow_init(0, ux_sign_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_sign_712_v0(void) {
|
||||
ux_flow_init(0, ux_sign_712_v0_flow, NULL);
|
||||
}
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
void ui_display_stark_public(void) {
|
||||
ux_flow_init(0, ux_display_stark_public_flow, NULL);
|
||||
}
|
||||
void ui_stark_limit_order(void) {
|
||||
ux_flow_init(0, ux_stark_limit_order_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_stark_unsafe_sign(void) {
|
||||
ux_flow_init(0, ux_stark_unsafe_sign_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_stark_transfer(bool selfTransfer, bool conditional) {
|
||||
if (selfTransfer) {
|
||||
ux_flow_init(
|
||||
0,
|
||||
(conditional ? ux_stark_self_transfer_conditional_flow : ux_stark_self_transfer_flow),
|
||||
NULL);
|
||||
} else {
|
||||
ux_flow_init(0,
|
||||
(conditional ? ux_stark_transfer_conditional_flow : ux_stark_transfer_flow),
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
#endif // HAVE_STARKWARE
|
||||
|
||||
void ui_confirm_selector(void) {
|
||||
ux_flow_init(0, ux_confirm_selector_flow, NULL);
|
||||
}
|
||||
|
||||
void ui_confirm_parameter(void) {
|
||||
ux_flow_init(0, ux_confirm_parameter_flow, NULL);
|
||||
}
|
||||
|
||||
#endif // HAVE_BAGL
|
||||
@@ -30,6 +30,8 @@ extern const ux_flow_step_t* const ux_display_privacy_public_key_flow[];
|
||||
|
||||
extern const ux_flow_step_t* const ux_display_privacy_shared_secret_flow[];
|
||||
|
||||
extern const ux_flow_step_t* ux_approval_tx_flow[15];
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
extern const ux_flow_step_t* const ux_display_stark_public_flow[];
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "network.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "ui_plugin.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
@@ -3,8 +3,6 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_stark_pubkey_ok(const bagl_element_t *e);
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
ux_display_stark_public_flow_1_step,
|
||||
@@ -4,8 +4,6 @@
|
||||
#include "ui_callbacks.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_stark_ok(const bagl_element_t *e);
|
||||
|
||||
void stark_sign_display_master_account() {
|
||||
snprintf(strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
#include "ui_flow.h"
|
||||
|
||||
void handleGetAppConfiguration(uint8_t p1,
|
||||
uint8_t p2,
|
||||
const uint8_t *workBuffer,
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
#include "ui_flow.h"
|
||||
#include "feature_getEth2PublicKey.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
static const uint8_t BLS12_381_FIELD_MODULUS[] = {
|
||||
0x1a, 0x01, 0x11, 0xea, 0x39, 0x7f, 0xe6, 0x9a, 0x4b, 0x1b, 0xa7, 0xb6, 0x43, 0x4b, 0xac, 0xd7,
|
||||
@@ -75,7 +76,7 @@ void handleGetEth2PublicKey(uint8_t p1,
|
||||
}
|
||||
#ifndef NO_CONSENT
|
||||
else {
|
||||
ux_flow_init(0, ux_display_public_eth2_flow, NULL);
|
||||
ui_display_public_eth2();
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
#include "ui_flow.h"
|
||||
#include "feature_getPublicKey.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
void handleGetPublicKey(uint8_t p1,
|
||||
uint8_t p2,
|
||||
@@ -64,7 +65,7 @@ void handleGetPublicKey(uint8_t p1,
|
||||
"0x%.*s",
|
||||
40,
|
||||
tmpCtx.publicKeyContext.address);
|
||||
ux_flow_init(0, ux_display_public_flow, NULL);
|
||||
ui_display_public_key();
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "apdu_constants.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
#include "ui_flow.h"
|
||||
#include "feature_performPrivacyOperation.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
#define P2_PUBLIC_ENCRYPTION_KEY 0x00
|
||||
#define P2_SHARED_SECRET 0x01
|
||||
@@ -108,9 +108,9 @@ void handlePerformPrivacyOperation(uint8_t p1,
|
||||
32,
|
||||
privateKeyData);
|
||||
if (p2 == P2_PUBLIC_ENCRYPTION_KEY) {
|
||||
ux_flow_init(0, ux_display_privacy_public_key_flow, NULL);
|
||||
ui_display_privacy_public_key();
|
||||
} else {
|
||||
ux_flow_init(0, ux_display_privacy_shared_secret_flow, NULL);
|
||||
ui_display_privacy_shared_secret();
|
||||
}
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ui_flow.h"
|
||||
#include "tokens.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
#ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ui_flow.h"
|
||||
#include "tokens.h"
|
||||
#include "utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
#define TYPE_SIZE 1
|
||||
#define VERSION_SIZE 1
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ui_flow.h"
|
||||
#include "tokens.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
void handleSetExternalPlugin(uint8_t p1,
|
||||
uint8_t p2,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ui_flow.h"
|
||||
#include "tokens.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
// Supported internal plugins
|
||||
#define ERC721_STR "ERC721"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "utils.h"
|
||||
#include "ui_flow.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
static const char SIGN_MAGIC[] =
|
||||
"\x19"
|
||||
@@ -188,7 +188,7 @@ void handleSignPersonalMessage(uint8_t p1,
|
||||
#ifdef NO_CONSENT
|
||||
io_seproxyhal_touch_signMessage_ok(NULL);
|
||||
#else // NO_CONSENT
|
||||
ux_flow_init(0, ux_sign_flow, NULL);
|
||||
ui_display_sign();
|
||||
#endif // NO_CONSENT
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "utils.h"
|
||||
#include "ui_flow.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
void handleSignEIP712Message(uint8_t p1,
|
||||
uint8_t p2,
|
||||
@@ -29,7 +29,7 @@ void handleSignEIP712Message(uint8_t p1,
|
||||
#ifdef NO_CONSENT
|
||||
io_seproxyhal_touch_signMessage_ok(NULL);
|
||||
#else // NO_CONSENT
|
||||
ux_flow_init(0, ux_sign_712_v0_flow, NULL);
|
||||
ui_sign_712_v0();
|
||||
#endif // NO_CONSENT
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ui_flow.h"
|
||||
#include "feature_signTx.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "shared_context.h"
|
||||
#include "utils.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "ui_flow.h"
|
||||
#include "feature_signTx.h"
|
||||
#ifdef HAVE_STARKWARE
|
||||
#include "stark_utils.h"
|
||||
@@ -9,6 +7,8 @@
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "network.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
#include "ui_callbacks.h"
|
||||
|
||||
#define ERR_SILENT_MODE_CHECK_FAILED 0x6001
|
||||
|
||||
@@ -144,7 +144,7 @@ customStatus_e customProcessor(txContext_t *context) {
|
||||
dataContext.tokenContext.fieldOffset = 0;
|
||||
if (fieldPos == 0) {
|
||||
array_hexstr(strings.tmp.tmp, dataContext.tokenContext.data, 4);
|
||||
ux_flow_init(0, ux_confirm_selector_flow, NULL);
|
||||
ui_confirm_selector();
|
||||
} else {
|
||||
uint32_t offset = 0;
|
||||
uint32_t i;
|
||||
@@ -159,7 +159,7 @@ customStatus_e customProcessor(txContext_t *context) {
|
||||
strings.tmp.tmp[offset++] = ':';
|
||||
}
|
||||
}
|
||||
ux_flow_init(0, ux_confirm_parameter_flow, NULL);
|
||||
ui_confirm_parameter();
|
||||
}
|
||||
} else {
|
||||
return CUSTOM_HANDLED;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include "apdu_constants.h"
|
||||
#include "stark_utils.h"
|
||||
#include "feature_stark_getPublicKey.h"
|
||||
#include "ui_flow.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
void handleStarkwareGetPublicKey(uint8_t p1,
|
||||
uint8_t p2,
|
||||
@@ -55,7 +56,7 @@ void handleStarkwareGetPublicKey(uint8_t p1,
|
||||
"0x%.*H",
|
||||
32,
|
||||
tmpCtx.publicKeyContext.publicKey.W + 1);
|
||||
ux_flow_init(0, ux_display_stark_public_flow, NULL);
|
||||
ui_display_stark_public();
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ui_flow.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
void handleStarkwareProvideQuantum(uint8_t p1,
|
||||
__attribute__((unused)) uint8_t p2,
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "stark_utils.h"
|
||||
#include "ui_flow.h"
|
||||
#include "poorstream.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
#define U8BE(buf, off) \
|
||||
(uint64_t)((((uint64_t) U4BE(buf, off)) << 32) | (((uint64_t) U4BE(buf, off + 4)) & 0xFFFFFFFF))
|
||||
@@ -249,20 +249,9 @@ void handleStarkwareSignMessage(uint8_t p1,
|
||||
}
|
||||
}
|
||||
if (order) {
|
||||
ux_flow_init(0, ux_stark_limit_order_flow, NULL);
|
||||
ui_stark_limit_order();
|
||||
} else {
|
||||
if (selfTransfer) {
|
||||
ux_flow_init(
|
||||
0,
|
||||
(dataContext.starkContext.conditional ? ux_stark_self_transfer_conditional_flow
|
||||
: ux_stark_self_transfer_flow),
|
||||
NULL);
|
||||
} else {
|
||||
ux_flow_init(0,
|
||||
(dataContext.starkContext.conditional ? ux_stark_transfer_conditional_flow
|
||||
: ux_stark_transfer_flow),
|
||||
NULL);
|
||||
}
|
||||
ui_stark_transfer(selfTransfer, dataContext.starkContext.conditional);
|
||||
}
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "stark_utils.h"
|
||||
#include "ui_flow.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
void handleStarkwareUnsafeSign(uint8_t p1,
|
||||
uint8_t p2,
|
||||
@@ -47,7 +47,7 @@ void handleStarkwareUnsafeSign(uint8_t p1,
|
||||
explicit_bzero(privateKeyData, sizeof(privateKeyData));
|
||||
io_seproxyhal_io_heartbeat();
|
||||
memmove(dataContext.starkContext.w1, publicKey.W + 1, 32);
|
||||
ux_flow_init(0, ux_stark_unsafe_sign_flow, NULL);
|
||||
ui_stark_unsafe_sign();
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user