Merge remote-tracking branch 'origin/develop' into HEAD

This commit is contained in:
Alexandre Paillier
2022-09-14 17:27:25 +02:00
61 changed files with 505 additions and 72 deletions

77
src_bagl/common_ui.c Normal file
View 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

226
src_bagl/ui_flow.c Normal file
View File

@@ -0,0 +1,226 @@
#include "shared_context.h"
#include "ui_callbacks.h"
void display_settings(const ux_flow_step_t* const start_step);
void switch_settings_blind_signing(void);
void switch_settings_display_data(void);
void switch_settings_display_nonce(void);
#ifdef HAVE_EIP712_FULL_SUPPORT
void switch_settings_verbose_eip712(void);
#endif // HAVE_EIP712_FULL_SUPPORT
//////////////////////////////////////////////////////////////////////
// clang-format off
UX_STEP_NOCB(
ux_idle_flow_1_step,
nn, //pnn,
{
//"", //&C_icon_dashboard,
"Application",
"is ready",
});
UX_STEP_NOCB(
ux_idle_flow_2_step,
bn,
{
"Version",
APPVERSION,
});
UX_STEP_CB(
ux_idle_flow_3_step,
pb,
display_settings(NULL),
{
&C_icon_eye,
"Settings",
});
UX_STEP_CB(
ux_idle_flow_4_step,
pb,
os_sched_exit(-1),
{
&C_icon_dashboard_x,
"Quit",
});
// clang-format on
UX_FLOW(ux_idle_flow,
&ux_idle_flow_1_step,
&ux_idle_flow_2_step,
&ux_idle_flow_3_step,
&ux_idle_flow_4_step,
FLOW_LOOP);
#if defined(TARGET_NANOS)
// clang-format off
UX_STEP_CB(
ux_settings_flow_blind_signing_step,
bnnn_paging,
switch_settings_blind_signing(),
{
.title = "Blind signing",
.text = strings.common.fullAddress,
});
UX_STEP_CB(
ux_settings_flow_display_data_step,
bnnn_paging,
switch_settings_display_data(),
{
.title = "Debug data",
.text = strings.common.fullAddress + 9
});
UX_STEP_CB(
ux_settings_flow_display_nonce_step,
bnnn_paging,
switch_settings_display_nonce(),
{
.title = "Account nonce",
.text = strings.common.fullAddress + 18
});
#else
UX_STEP_CB(
ux_settings_flow_blind_signing_step,
bnnn,
switch_settings_blind_signing(),
{
"Blind signing",
"Transaction",
"blind signing",
strings.common.fullAddress,
});
UX_STEP_CB(
ux_settings_flow_display_data_step,
bnnn,
switch_settings_display_data(),
{
"Debug data",
"Show contract data",
"details",
strings.common.fullAddress + 9
});
UX_STEP_CB(
ux_settings_flow_display_nonce_step,
bnnn,
switch_settings_display_nonce(),
{
"Nonce",
"Show account nonce",
"in transactions",
strings.common.fullAddress + 18
});
#endif
#ifdef HAVE_EIP712_FULL_SUPPORT
UX_STEP_CB(
ux_settings_flow_verbose_eip712_step,
bnnn,
switch_settings_verbose_eip712(),
{
"Verbose EIP-712",
"Ignore filtering &",
"display raw content",
strings.common.fullAddress + 27
});
#endif // HAVE_EIP712_FULL_SUPPORT
UX_STEP_CB(
ux_settings_flow_back_step,
pb,
ui_idle(),
{
&C_icon_back_x,
"Back",
});
// clang-format on
UX_FLOW(ux_settings_flow,
&ux_settings_flow_blind_signing_step,
&ux_settings_flow_display_data_step,
&ux_settings_flow_display_nonce_step,
#ifdef HAVE_EIP712_FULL_SUPPORT
&ux_settings_flow_verbose_eip712_step,
#endif // HAVE_EIP712_FULL_SUPPORT
&ux_settings_flow_back_step);
void display_settings(const ux_flow_step_t* const start_step) {
const char* const values[] = {"Enabled", "Disabled"};
bool settings[] = {N_storage.dataAllowed,
N_storage.contractDetails,
N_storage.displayNonce,
#ifdef HAVE_EIP712_FULL_SUPPORT
N_storage.verbose_eip712
#endif // HAVE_EIP712_FULL_SUPPORT
};
uint8_t offset = 0;
uint8_t increment = MAX(strlen(values[0]), strlen(values[1])) + 1;
for (unsigned int i = 0; i < (sizeof(settings) / sizeof(settings[0])); ++i) {
strlcpy(strings.common.fullAddress + offset,
(settings[i] ? values[0] : values[1]),
sizeof(strings.common.fullAddress) - offset);
offset += increment;
}
ux_flow_init(0, ux_settings_flow, start_step);
}
void switch_settings_blind_signing(void) {
uint8_t value = (N_storage.dataAllowed ? 0 : 1);
nvm_write((void*) &N_storage.dataAllowed, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_blind_signing_step);
}
void switch_settings_display_data(void) {
uint8_t value = (N_storage.contractDetails ? 0 : 1);
nvm_write((void*) &N_storage.contractDetails, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_display_data_step);
}
void switch_settings_display_nonce(void) {
uint8_t value = (N_storage.displayNonce ? 0 : 1);
nvm_write((void*) &N_storage.displayNonce, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_display_nonce_step);
}
#ifdef HAVE_EIP712_FULL_SUPPORT
void switch_settings_verbose_eip712(void) {
bool value = !N_storage.verbose_eip712;
nvm_write((void*) &N_storage.verbose_eip712, (void*) &value, sizeof(value));
display_settings(&ux_settings_flow_verbose_eip712_step);
}
#endif // HAVE_EIP712_FULL_SUPPORT
//////////////////////////////////////////////////////////////////////
// clang-format off
#if defined(TARGET_NANOS)
UX_STEP_CB(
ux_warning_contract_data_step,
bnnn_paging,
ui_idle(),
{
"Error",
"Blind signing must be enabled in Settings",
});
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2)
UX_STEP_CB(
ux_warning_contract_data_step,
pnn,
ui_idle(),
{
&C_icon_crossmark,
"Blind signing must be",
"enabled in Settings",
});
#endif
// clang-format on
UX_FLOW(ux_warning_contract_data_flow, &ux_warning_contract_data_step);

65
src_bagl/ui_flow.h Normal file
View File

@@ -0,0 +1,65 @@
#ifndef _UI_FLOW_H_
#define _UI_FLOW_H_
#include "shared_context.h"
#include "os_io_seproxyhal.h"
#include "ux.h"
extern const ux_flow_step_t* const ux_idle_flow[];
extern const ux_flow_step_t* const ux_warning_contract_data_flow[];
extern const ux_flow_step_t* const ux_settings_flow[];
extern const ux_flow_step_t* const ux_display_public_flow[];
extern const ux_flow_step_t* const ux_confirm_selector_flow[];
extern const ux_flow_step_t* const ux_confirm_parameter_flow[];
extern const ux_flow_step_t* const ux_approval_allowance_flow[];
extern const ux_flow_step_t* const ux_sign_flow[];
extern const ux_flow_step_t* const ux_sign_712_v0_flow[];
extern const ux_flow_step_t* const ux_display_public_eth2_flow[];
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[];
extern const ux_flow_step_t* const ux_stark_limit_order_flow[];
extern const ux_flow_step_t* const ux_stark_transfer_flow[];
extern const ux_flow_step_t* const ux_stark_self_transfer_flow[];
extern const ux_flow_step_t* const ux_stark_transfer_conditional_flow[];
extern const ux_flow_step_t* const ux_stark_self_transfer_conditional_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_register_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_deposit_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_withdraw_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_verify_vault_id_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_escape_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_verify_escape_flow[];
extern const ux_flow_step_t* const ux_stark_unsafe_sign_flow[];
#endif
#endif // _UI_FLOW_H_

View File

@@ -0,0 +1,72 @@
#include "shared_context.h"
#include "ui_callbacks.h"
// clang-format off
UX_STEP_NOCB(ux_approval_allowance_1_step,
pnn,
{
&C_icon_eye,
"Review",
"transaction",
});
UX_STEP_NOCB(
ux_approval_allowance_2_step,
bnnn_paging,
{
.title = "Allowance",
.text = " "
});
UX_STEP_NOCB(
ux_approval_allowance_3_step,
bnnn_paging,
{
.title = "Contract Name",
.text = strings.common.fullAddress,
});
UX_STEP_NOCB(
ux_approval_allowance_4_step,
bnnn_paging,
{
.title = "Amount",
.text = strings.common.fullAmount
});
UX_STEP_NOCB(
ux_approval_allowance_5_step,
bnnn_paging,
{
.title = "Max Fees",
.text = strings.common.maxFee,
});
UX_STEP_CB(
ux_approval_allowance_6_step,
pbb,
io_seproxyhal_touch_tx_ok(NULL),
{
&C_icon_validate_14,
"Accept",
"and send",
});
UX_STEP_CB(
ux_approval_allowance_7_step,
pb,
io_seproxyhal_touch_tx_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_approval_allowance_flow,
&ux_approval_allowance_1_step,
&ux_approval_allowance_2_step,
&ux_approval_allowance_3_step,
&ux_approval_allowance_4_step,
&ux_approval_allowance_5_step,
&ux_approval_allowance_6_step,
&ux_approval_allowance_7_step);

View File

@@ -0,0 +1,51 @@
#ifdef HAVE_ETH2
#include "shared_context.h"
#include "ui_callbacks.h"
void prepare_eth2_public_key() {
snprintf(strings.tmp.tmp, 100, "0x%.*H", 48, tmpCtx.publicKeyContext.publicKey.W);
}
// clang-format off
UX_STEP_NOCB(
ux_display_public_eth2_flow_1_step,
pnn,
{
&C_icon_eye,
"Verify ETH2",
"public key",
});
UX_STEP_NOCB_INIT(
ux_display_public_eth2_flow_2_step,
bnnn_paging,
prepare_eth2_public_key(),
{
.title = "Public Key",
.text = strings.tmp.tmp,
});
UX_STEP_CB(
ux_display_public_eth2_flow_3_step,
pb,
io_seproxyhal_touch_eth2_address_ok(NULL),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_display_public_eth2_flow_4_step,
pb,
io_seproxyhal_touch_address_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_display_public_eth2_flow,
&ux_display_public_eth2_flow_1_step,
&ux_display_public_eth2_flow_2_step,
&ux_display_public_eth2_flow_3_step,
&ux_display_public_eth2_flow_4_step);
#endif

View File

@@ -0,0 +1,42 @@
#include "shared_context.h"
#include "ui_callbacks.h"
// clang-format off
UX_STEP_NOCB(
ux_display_public_flow_1_step,
pnn,
{
&C_icon_eye,
"Verify",
"address",
});
UX_STEP_NOCB(
ux_display_public_flow_2_step,
bnnn_paging,
{
.title = "Address",
.text = strings.common.fullAddress,
});
UX_STEP_CB(
ux_display_public_flow_3_step,
pb,
io_seproxyhal_touch_address_ok(NULL),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_display_public_flow_4_step,
pb,
io_seproxyhal_touch_address_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_display_public_flow,
&ux_display_public_flow_1_step,
&ux_display_public_flow_2_step,
&ux_display_public_flow_3_step,
&ux_display_public_flow_4_step);

View File

@@ -0,0 +1,67 @@
#include "shared_context.h"
#include "ui_callbacks.h"
// clang-format off
UX_STEP_NOCB(
ux_display_privacy_public_key_flow_1_step,
pnn,
{
&C_icon_eye,
"Provide public",
"privacy key",
});
UX_STEP_NOCB(
ux_display_privacy_public_key_flow_2_step,
bnnn_paging,
{
.title = "Address",
.text = strings.common.fullAddress,
});
UX_STEP_NOCB(
ux_display_privacy_public_key_flow_3_step,
bnnn_paging,
{
.title = "Key",
.text = strings.common.fullAmount,
});
UX_STEP_CB(
ux_display_privacy_public_key_flow_4_step,
pb,
io_seproxyhal_touch_privacy_ok(NULL),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_display_privacy_public_key_flow_5_step,
pb,
io_seproxyhal_touch_privacy_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
UX_STEP_NOCB(
ux_display_privacy_shared_secret_flow_1_step,
pnn,
{
&C_icon_eye,
"Provide privacy",
"secret key",
});
// clang-format on
UX_FLOW(ux_display_privacy_public_key_flow,
&ux_display_privacy_public_key_flow_1_step,
&ux_display_privacy_public_key_flow_2_step,
&ux_display_privacy_public_key_flow_3_step,
&ux_display_privacy_public_key_flow_4_step,
&ux_display_privacy_public_key_flow_5_step);
UX_FLOW(ux_display_privacy_shared_secret_flow,
&ux_display_privacy_shared_secret_flow_1_step,
&ux_display_privacy_public_key_flow_2_step,
&ux_display_privacy_public_key_flow_3_step,
&ux_display_privacy_public_key_flow_4_step,
&ux_display_privacy_public_key_flow_5_step);

View File

@@ -0,0 +1,44 @@
#include "shared_context.h"
#include "ui_callbacks.h"
// clang-format off
UX_STEP_NOCB(
ux_sign_flow_1_step,
pnn,
{
&C_icon_certificate,
"Sign",
"message",
});
UX_STEP_NOCB(
ux_sign_flow_2_step,
bnnn_paging,
{
.title = "Message",
.text = strings.tmp.tmp,
});
UX_STEP_CB(
ux_sign_flow_3_step,
pbb,
io_seproxyhal_touch_signMessage_ok(NULL),
{
&C_icon_validate_14,
"Sign",
"message",
});
UX_STEP_CB(
ux_sign_flow_4_step,
pbb,
io_seproxyhal_touch_signMessage_cancel(NULL),
{
&C_icon_crossmark,
"Cancel",
"signature",
});
// clang-format on
UX_FLOW(ux_sign_flow,
&ux_sign_flow_1_step,
&ux_sign_flow_2_step,
&ux_sign_flow_3_step,
&ux_sign_flow_4_step);

View File

@@ -0,0 +1,72 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "common_712.h"
#include "ethUtils.h"
void prepare_domain_hash_v0() {
snprintf(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
"0x%.*H",
KECCAK256_HASH_BYTESIZE,
tmpCtx.messageSigningContext712.domainHash);
}
void prepare_message_hash_v0() {
snprintf(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
"0x%.*H",
KECCAK256_HASH_BYTESIZE,
tmpCtx.messageSigningContext712.messageHash);
}
// clang-format off
UX_STEP_NOCB(
ux_sign_712_v0_flow_1_step,
pnn,
{
&C_icon_certificate,
"Sign",
"typed message",
});
UX_STEP_NOCB_INIT(
ux_sign_712_v0_flow_2_step,
bnnn_paging,
prepare_domain_hash_v0(),
{
.title = "Domain hash",
.text = strings.tmp.tmp,
});
UX_STEP_NOCB_INIT(
ux_sign_712_v0_flow_3_step,
bnnn_paging,
prepare_message_hash_v0(),
{
.title = "Message hash",
.text = strings.tmp.tmp,
});
UX_STEP_CB(
ux_sign_712_v0_flow_4_step,
pbb,
ui_712_approve_cb(NULL),
{
&C_icon_validate_14,
"Sign",
"message",
});
UX_STEP_CB(
ux_sign_712_v0_flow_5_step,
pbb,
ui_712_reject_cb(NULL),
{
&C_icon_crossmark,
"Cancel",
"signature",
});
// clang-format on
UX_FLOW(ux_sign_712_v0_flow,
&ux_sign_712_v0_flow_1_step,
&ux_sign_712_v0_flow_2_step,
&ux_sign_712_v0_flow_3_step,
&ux_sign_712_v0_flow_4_step,
&ux_sign_712_v0_flow_5_step);

237
src_bagl/ui_flow_signTx.c Normal file
View File

@@ -0,0 +1,237 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "chainConfig.h"
#include "utils.h"
#include "feature_signTx.h"
#include "network.h"
#include "eth_plugin_handler.h"
#include "ui_plugin.h"
#include "common_ui.h"
// clang-format off
UX_STEP_NOCB(
ux_confirm_selector_flow_1_step,
pnn,
{
&C_icon_eye,
"Verify",
"selector",
});
UX_STEP_NOCB(
ux_confirm_selector_flow_2_step,
bn,
{
"Selector",
strings.tmp.tmp
});
UX_STEP_CB(
ux_confirm_selector_flow_3_step,
pb,
io_seproxyhal_touch_data_ok(NULL),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_confirm_selector_flow_4_step,
pb,
io_seproxyhal_touch_data_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_confirm_selector_flow,
&ux_confirm_selector_flow_1_step,
&ux_confirm_selector_flow_2_step,
&ux_confirm_selector_flow_3_step,
&ux_confirm_selector_flow_4_step);
//////////////////////////////////////////////////////////////////////
// clang-format off
UX_STEP_NOCB(
ux_confirm_parameter_flow_1_step,
pnn,
{
&C_icon_eye,
"Verify",
strings.tmp.tmp2
});
UX_STEP_NOCB(
ux_confirm_parameter_flow_2_step,
bnnn_paging,
{
.title = "Parameter",
.text = strings.tmp.tmp,
});
UX_STEP_CB(
ux_confirm_parameter_flow_3_step,
pb,
io_seproxyhal_touch_data_ok(NULL),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_confirm_parameter_flow_4_step,
pb,
io_seproxyhal_touch_data_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_confirm_parameter_flow,
&ux_confirm_parameter_flow_1_step,
&ux_confirm_parameter_flow_2_step,
&ux_confirm_parameter_flow_3_step,
&ux_confirm_parameter_flow_4_step);
//////////////////////////////////////////////////////////////////////
// clang-format off
UX_STEP_NOCB(ux_approval_review_step,
pnn,
{
&C_icon_eye,
"Review",
"transaction",
});
UX_STEP_NOCB(
ux_approval_amount_step,
bnnn_paging,
{
.title = "Amount",
.text = strings.common.fullAmount
});
UX_STEP_NOCB(
ux_approval_address_step,
bnnn_paging,
{
.title = "Address",
.text = strings.common.fullAddress,
});
UX_STEP_NOCB_INIT(
ux_plugin_approval_id_step,
bnnn_paging,
plugin_ui_get_id(),
{
.title = strings.common.fullAddress,
.text = strings.common.fullAmount
});
UX_STEP_INIT(
ux_plugin_approval_before_step,
NULL,
NULL,
{
display_next_plugin_item(true);
});
UX_FLOW_DEF_NOCB(
ux_plugin_approval_display_step,
bnnn_paging,
{
.title = strings.common.fullAddress,
.text = strings.common.fullAmount
});
UX_STEP_INIT(
ux_plugin_approval_after_step,
NULL,
NULL,
{
display_next_plugin_item(false);
});
UX_STEP_NOCB(
ux_approval_fees_step,
bnnn_paging,
{
.title = "Max Fees",
.text = strings.common.maxFee,
});
UX_STEP_NOCB(
ux_approval_network_step,
bnnn_paging,
{
.title = "Network",
.text = strings.common.network_name,
});
UX_STEP_CB(
ux_approval_accept_step,
pbb,
io_seproxyhal_touch_tx_ok(NULL),
{
&C_icon_validate_14,
"Accept",
"and send",
});
UX_STEP_CB(
ux_approval_reject_step,
pb,
io_seproxyhal_touch_tx_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
UX_STEP_NOCB(
ux_approval_nonce_step,
bnnn_paging,
{
.title = "Nonce",
.text = strings.common.nonce,
});
UX_STEP_NOCB(ux_approval_blind_signing_warning_step,
pbb,
{
&C_icon_warning,
"Blind",
"Signing",
});
// clang-format on
const ux_flow_step_t *ux_approval_tx_flow[15];
void ux_approve_tx(bool fromPlugin) {
int step = 0;
ux_approval_tx_flow[step++] = &ux_approval_review_step;
if (!fromPlugin && tmpContent.txContent.dataPresent && !N_storage.contractDetails) {
ux_approval_tx_flow[step++] = &ux_approval_blind_signing_warning_step;
}
if (fromPlugin) {
// Add the special dynamic display logic
ux_approval_tx_flow[step++] = &ux_plugin_approval_id_step;
ux_approval_tx_flow[step++] = &ux_plugin_approval_before_step;
ux_approval_tx_flow[step++] = &ux_plugin_approval_display_step;
ux_approval_tx_flow[step++] = &ux_plugin_approval_after_step;
} else {
// We're in a regular transaction, just show the amount and the address
ux_approval_tx_flow[step++] = &ux_approval_amount_step;
ux_approval_tx_flow[step++] = &ux_approval_address_step;
}
if (N_storage.displayNonce) {
ux_approval_tx_flow[step++] = &ux_approval_nonce_step;
}
uint64_t chain_id = get_chain_id();
if (chainConfig->chainId == ETHEREUM_MAINNET_CHAINID && chain_id != chainConfig->chainId) {
ux_approval_tx_flow[step++] = &ux_approval_network_step;
}
ux_approval_tx_flow[step++] = &ux_approval_fees_step;
ux_approval_tx_flow[step++] = &ux_approval_accept_step;
ux_approval_tx_flow[step++] = &ux_approval_reject_step;
ux_approval_tx_flow[step++] = FLOW_END_STEP;
ux_flow_init(0, ux_approval_tx_flow, NULL);
}

View File

@@ -0,0 +1,46 @@
#ifdef HAVE_STARKWARE
#include "shared_context.h"
#include "ui_callbacks.h"
// clang-format off
UX_STEP_NOCB(
ux_display_stark_public_flow_1_step,
pnn,
{
&C_icon_eye,
"Verify",
"Stark key",
});
UX_STEP_NOCB(
ux_display_stark_public_flow_2_step,
bnnn_paging,
{
.title = "Stark Key",
.text = strings.tmp.tmp,
});
UX_STEP_CB(
ux_display_stark_public_flow_3_step,
pb,
io_seproxyhal_touch_stark_pubkey_ok(NULL),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(
ux_display_stark_public_flow_4_step,
pb,
io_seproxyhal_touch_address_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_display_stark_public_flow,
&ux_display_stark_public_flow_1_step,
&ux_display_stark_public_flow_2_step,
&ux_display_stark_public_flow_3_step,
&ux_display_stark_public_flow_4_step);
#endif

View File

@@ -0,0 +1,239 @@
#ifdef HAVE_STARKWARE
#include "shared_context.h"
#include "ui_callbacks.h"
#include "ethUtils.h"
void stark_sign_display_master_account() {
snprintf(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
"0x%.*H",
32,
dataContext.starkContext.transferDestination);
}
void stark_sign_display_condition_fact() {
snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "0x%.*H", 32, dataContext.starkContext.fact);
}
// clang-format off
UX_STEP_NOCB(ux_stark_limit_order_1_step,
pnn,
{
&C_icon_eye,
"Review",
"transaction",
});
UX_STEP_NOCB(ux_stark_limit_order_2_step,
bnnn_paging,
{
.title = "Limit",
.text = "Order"
});
UX_STEP_NOCB(ux_stark_limit_order_3_step,
bnnn_paging,
{
.title = "Trading",
.text = "Pair"
});
UX_STEP_NOCB(ux_stark_limit_order_4_step,
bnnn_paging,
{
.title = "Sell",
.text = strings.common.fullAmount
});
UX_STEP_NOCB(ux_stark_limit_order_5_step,
bnnn_paging,
{
.title = "Buy",
.text = strings.common.maxFee
});
UX_STEP_NOCB(ux_stark_limit_order_6_step,
bnnn_paging,
{
.title = "Token Account",
.text = strings.common.fullAddress
});
UX_STEP_CB(
ux_stark_limit_order_7_step,
pbb,
io_seproxyhal_touch_stark_ok(NULL),
{
&C_icon_validate_14,
"Accept",
"and send",
});
UX_STEP_CB(
ux_stark_limit_order_8_step,
pb,
io_seproxyhal_touch_tx_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_stark_limit_order_flow,
&ux_stark_limit_order_1_step,
&ux_stark_limit_order_2_step,
&ux_stark_limit_order_3_step,
&ux_stark_limit_order_4_step,
&ux_stark_limit_order_5_step,
&ux_stark_limit_order_6_step,
&ux_stark_limit_order_7_step,
&ux_stark_limit_order_8_step);
//////////////////////////////////////////////////////////////////////
// clang-format off
UX_STEP_NOCB(ux_stark_transfer_1_step,
pnn,
{
&C_icon_eye,
"Review",
"transaction",
});
UX_STEP_NOCB(ux_stark_transfer_2_step,
bnnn_paging,
{
.title = "Transfer",
.text = " "
});
UX_STEP_NOCB(ux_stark_self_transfer_2_step,
bnnn_paging,
{
.title = "Self",
.text = "Transfer"
});
UX_STEP_NOCB(ux_stark_conditional_transfer_2_step,
bnnn_paging,
{
.title = "Conditional",
.text = "Transfer"
});
UX_STEP_NOCB(ux_stark_self_conditional_transfer_2_step,
bnnn_paging,
{
.title = "Conditional",
.text = "Self Transfer"
});
UX_STEP_NOCB(ux_stark_transfer_3_step,
bnnn_paging,
{
.title = "Amount",
.text = tmpContent.tmp
});
UX_STEP_NOCB(ux_stark_transfer_4_step,
bnnn_paging,
{
.title = "Master Account",
.text = strings.tmp.tmp
});
UX_STEP_NOCB(ux_stark_transfer_5_step,
bnnn_paging,
{
.title = "Token Account",
.text = strings.tmp.tmp2
});
UX_STEP_CB(
ux_stark_transfer_6_step,
pbb,
io_seproxyhal_touch_stark_ok(NULL),
{
&C_icon_validate_14,
"Accept",
"and send",
});
UX_STEP_CB(
ux_stark_transfer_7_step,
pb,
io_seproxyhal_touch_tx_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
UX_STEP_NOCB_INIT(
ux_stark_conditional_transfer_4_step,
bnnn_paging,
stark_sign_display_master_account(),
{
.title = "Master Account",
.text = strings.tmp.tmp
});
UX_STEP_NOCB_INIT(
ux_stark_conditional_transfer_8_step,
bnnn_paging,
getEthDisplayableAddress(dataContext.starkContext.conditionAddress,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
&global_sha3,
chainConfig->chainId),
{
.title = "Cond. Address",
.text = strings.tmp.tmp
});
UX_STEP_NOCB_INIT(
ux_stark_conditional_transfer_9_step,
bnnn_paging,
stark_sign_display_condition_fact(),
{
.title = "Cond. Fact",
.text = strings.tmp.tmp
});
// clang-format on
UX_FLOW(ux_stark_transfer_flow,
&ux_stark_transfer_1_step,
&ux_stark_transfer_2_step,
&ux_stark_transfer_3_step,
&ux_stark_transfer_4_step,
&ux_stark_transfer_5_step,
&ux_stark_transfer_6_step,
&ux_stark_transfer_7_step);
UX_FLOW(ux_stark_self_transfer_flow,
&ux_stark_transfer_1_step,
&ux_stark_self_transfer_2_step,
&ux_stark_transfer_3_step,
&ux_stark_transfer_5_step,
&ux_stark_transfer_6_step,
&ux_stark_transfer_7_step);
UX_FLOW(ux_stark_transfer_conditional_flow,
&ux_stark_transfer_1_step,
&ux_stark_conditional_transfer_2_step,
&ux_stark_transfer_3_step,
&ux_stark_conditional_transfer_4_step,
&ux_stark_transfer_5_step,
&ux_stark_conditional_transfer_8_step,
&ux_stark_conditional_transfer_9_step,
&ux_stark_transfer_6_step,
&ux_stark_transfer_7_step);
UX_FLOW(ux_stark_self_transfer_conditional_flow,
&ux_stark_transfer_1_step,
&ux_stark_self_conditional_transfer_2_step,
&ux_stark_transfer_3_step,
&ux_stark_transfer_5_step,
&ux_stark_conditional_transfer_8_step,
&ux_stark_conditional_transfer_9_step,
&ux_stark_transfer_6_step,
&ux_stark_transfer_7_step);
#endif

View File

@@ -0,0 +1,70 @@
#ifdef HAVE_STARKWARE
#include "shared_context.h"
#include "ui_callbacks.h"
unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(const bagl_element_t *e);
void stark_unsafe_sign_display_account() {
snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "0x%.*H", 32, dataContext.starkContext.w1);
}
void stark_unsafe_sign_display_hash() {
snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "0x%.*H", 32, dataContext.starkContext.w2);
}
// clang-format off
UX_STEP_NOCB(ux_stark_unsafe_sign_1_step,
pnn,
{
&C_icon_warning,
"Unsafe",
"Stark Sign",
});
UX_STEP_NOCB_INIT(
ux_stark_unsafe_sign_2_step,
bnnn_paging,
stark_unsafe_sign_display_account(),
{
.title = "From Account",
.text = strings.tmp.tmp
});
UX_STEP_NOCB_INIT(
ux_stark_unsafe_sign_3_step,
bnnn_paging,
stark_unsafe_sign_display_hash(),
{
.title = "Hash",
.text = strings.tmp.tmp
});
UX_STEP_CB(
ux_stark_unsafe_sign_4_step,
pbb,
io_seproxyhal_touch_stark_unsafe_sign_ok(NULL),
{
&C_icon_validate_14,
"Accept",
"and send",
});
UX_STEP_CB(
ux_stark_unsafe_sign_5_step,
pb,
io_seproxyhal_touch_tx_cancel(NULL),
{
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(ux_stark_unsafe_sign_flow,
&ux_stark_unsafe_sign_1_step,
&ux_stark_unsafe_sign_2_step,
&ux_stark_unsafe_sign_3_step,
&ux_stark_unsafe_sign_4_step,
&ux_stark_unsafe_sign_5_step);
#endif

76
src_bagl/ui_plugin.c Normal file
View File

@@ -0,0 +1,76 @@
#include "feature_signTx.h"
#include "ux.h"
#include "eth_plugin_handler.h"
#include "ui_callbacks.h"
#include "ui_plugin.h"
// This function is not exported by the SDK
void ux_layout_paging_redisplay_by_addr(unsigned int stack_slot);
void plugin_ui_get_id() {
ethQueryContractID_t pluginQueryContractID;
eth_plugin_prepare_query_contract_ID(&pluginQueryContractID,
strings.common.fullAddress,
sizeof(strings.common.fullAddress),
strings.common.fullAmount,
sizeof(strings.common.fullAmount));
// Query the original contract for ID if it's not an internal alias
if (!eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_ID, (void *) &pluginQueryContractID)) {
PRINTF("Plugin query contract ID call failed\n");
io_seproxyhal_touch_tx_cancel(NULL);
}
}
void plugin_ui_get_item() {
ethQueryContractUI_t pluginQueryContractUI;
eth_plugin_prepare_query_contract_UI(&pluginQueryContractUI,
dataContext.tokenContext.pluginUiCurrentItem,
strings.common.fullAddress,
sizeof(strings.common.fullAddress),
strings.common.fullAmount,
sizeof(strings.common.fullAmount));
if (!eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_UI, (void *) &pluginQueryContractUI)) {
PRINTF("Plugin query contract UI call failed\n");
io_seproxyhal_touch_tx_cancel(NULL);
}
}
void display_next_plugin_item(bool entering) {
if (entering) {
if (dataContext.tokenContext.pluginUiState == PLUGIN_UI_OUTSIDE) {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_INSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
plugin_ui_get_item();
ux_flow_next();
} else {
if (dataContext.tokenContext.pluginUiCurrentItem > 0) {
dataContext.tokenContext.pluginUiCurrentItem--;
plugin_ui_get_item();
ux_flow_next();
} else {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
ux_flow_prev();
}
}
} else {
if (dataContext.tokenContext.pluginUiState == PLUGIN_UI_OUTSIDE) {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_INSIDE;
plugin_ui_get_item();
ux_flow_prev();
} else {
if (dataContext.tokenContext.pluginUiCurrentItem <
dataContext.tokenContext.pluginUiMaxItems - 1) {
dataContext.tokenContext.pluginUiCurrentItem++;
plugin_ui_get_item();
ux_flow_prev();
// Reset multi page layout to the first page
G_ux.layout_paging.current = 0;
ux_layout_paging_redisplay_by_addr(G_ux.stack_count - 1);
} else {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
ux_flow_next();
}
}
}
}

8
src_bagl/ui_plugin.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _UI_PLUGIN_H_
#define _UI_PLUGIN_H_
void plugin_ui_get_id();
void plugin_ui_get_item();
void display_next_plugin_item(bool entering);
#endif // _UI_PLUGIN_H_