Skip to content

Commit

Permalink
Cleanup top level functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Apr 30, 2024
1 parent a609ea2 commit 733064d
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 515 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ APP_SOURCE_FILES += $(filter-out ./ethereum-plugin-sdk/src/main.c, $(wildcard ./
INCLUDES_PATH += ./ethereum-plugin-sdk/src
APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/crypto_helpers.c
APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/format.c
APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/io.c
INCLUDES_PATH += ${BOLOS_SDK}/lib_standard_app

ifeq ($(TARGET_NAME),TARGET_STAX)
Expand Down
136 changes: 59 additions & 77 deletions src/apdu_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,100 +35,82 @@

#define COMMON_CLA 0xB0

#define APDU_RESPONSE_TX_TYPE_NOT_SUPPORTED 0x6501
#define APDU_RESPONSE_CHAINID_OUT_BUF_SMALL 0x6502
#define APDU_RESPONSE_PLUGIN_ERROR 0x6503 // Unused?
#define APDU_RESPONSE_UINT256_ERROR 0x6504 // Unused?
#define APDU_RESPONSE_INCORRECT_LENGTH 0x6700
#define APDU_RESPONSE_SECURITY_NOT_SATISFIED 0x6982
#define APDU_RESPONSE_INVALID_CLA 0x6e00


#define APDU_RESPONSE_OK 0x9000
#define APDU_RESPONSE_ERROR_NO_INFO 0x6a00
#define APDU_RESPONSE_ERROR_NO_INFO 0x6a00 // Undefined in doc
#define APDU_RESPONSE_INVALID_DATA 0x6a80
#define APDU_RESPONSE_INSUFFICIENT_MEMORY 0x6a84
#define APDU_RESPONSE_INVALID_INS 0x6d00
#define APDU_RESPONSE_INSUFFICIENT_MEMORY 0x6a84 // Undefined in doc
#define APDU_RESPONSE_INVALID_INS 0x6d00 // Unused, and undefined in doc
#define APDU_RESPONSE_INVALID_P1_P2 0x6b00
#define APDU_RESPONSE_CONDITION_NOT_SATISFIED 0x6985
#define APDU_RESPONSE_REF_DATA_NOT_FOUND 0x6a88
#define APDU_RESPONSE_PLUGIN_NOT_INSTALLED 0x6984 // Undefined in doc
#define APDU_RESPONSE_CONDITION_NOT_SATISFIED 0x6985 // Undefined in doc
#define APDU_RESPONSE_REF_DATA_NOT_FOUND 0x6a88 // Undefined in doc
#define APDU_RESPONSE_UNKNOWN 0x6f00

enum { OFFSET_CLA = 0, OFFSET_INS, OFFSET_P1, OFFSET_P2, OFFSET_LC, OFFSET_CDATA };

#define ERR_APDU_EMPTY 0x6982
#define ERR_APDU_SIZE_MISMATCH 0x6983

void handleGetPublicKey(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleProvideErc20TokenInformation(uint8_t p1,
uint8_t p2,
const uint8_t *workBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleProvideNFTInformation(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleSign(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleGetAppConfiguration(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);
bool handleSignPersonalMessage(uint8_t p1,
uint8_t p2,
const uint8_t *const payload,
uint8_t length);
void handleSignEIP712Message_v0(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);

void handleSetExternalPlugin(uint8_t p1,
uint8_t p2,
const uint8_t *workBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);

void handleSetPlugin(uint8_t p1,
uint8_t p2,
const uint8_t *workBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);

void handlePerformPrivacyOperation(uint8_t p1,
uint8_t p2,
const uint8_t *workBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);
#define ERR_APDU_EMPTY 0x6981 // Undefined in doc
#define ERR_APDU_SIZE_MISMATCH 0x6983 // Unused, and undefined in doc

uint32_t handleGetPublicKey(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);

uint32_t handleProvideErc20TokenInformation(const uint8_t *workBuffer,
uint8_t dataLength,
unsigned int *tx);

uint32_t handleProvideNFTInformation(const uint8_t *dataBuffer, uint8_t dataLength);

uint32_t handleSign(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags);

uint32_t handleGetAppConfiguration(unsigned int *tx);

uint32_t handleSignPersonalMessage(uint8_t p1,
const uint8_t *const payload,
uint8_t length);

uint32_t handleSignEIP712Message_v0(uint8_t p1,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags);

uint32_t handleSetExternalPlugin(const uint8_t *workBuffer, uint8_t dataLength);

uint32_t handleSetPlugin(const uint8_t *workBuffer, uint8_t dataLength);

uint32_t handlePerformPrivacyOperation(uint8_t p1,
uint8_t p2,
const uint8_t *workBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);

#ifdef HAVE_ETH2

void handleGetEth2PublicKey(uint8_t p1,
uint32_t handleGetEth2PublicKey(uint8_t p1,
uint8_t p2,
const uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleSetEth2WinthdrawalIndex(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx);

#endif

extern uint16_t apdu_response_code;

#endif // _APDU_CONSTANTS_H_
2 changes: 2 additions & 0 deletions src/common_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <stdbool.h>
#include <stdint.h>

void app_global_init(void);

void ui_idle(void);
void ui_warning_contract_data(void);
void ui_display_public_eth2(void);
Expand Down
31 changes: 6 additions & 25 deletions src/handle_swap_sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "handle_swap_sign_transaction.h"
#include "shared_context.h"
#include "common_utils.h"
#include "common_ui.h"
#include "network.h"
#ifdef HAVE_NBGL
#include "nbgl_use_case.h"
Expand Down Expand Up @@ -81,38 +82,18 @@ void __attribute__((noreturn)) finalize_exchange_sign_transaction(bool is_succes
}

void __attribute__((noreturn)) handle_swap_sign_transaction(const chain_config_t* config) {
#ifdef HAVE_NBGL
// On Stax, display a spinner at startup
UX_INIT();
nbgl_useCaseSpinner("Signing");
#endif // HAVE_NBGL

app_global_init();
chainConfig = config;
reset_app_context();
G_called_from_swap = true;
G_swap_response_ready = false;
io_seproxyhal_init();

if (N_storage.initialized != 0x01) {
internalStorage_t storage;
storage.dataAllowed = 0x00;
storage.contractDetails = 0x00;
storage.initialized = 0x01;
storage.displayNonce = 0x00;
storage.contractDetails = 0x00;
nvm_write((void*) &N_storage, (void*) &storage, sizeof(internalStorage_t));
}
#ifdef HAVE_NBGL
nbgl_useCaseSpinner("Signing");
#endif // HAVE_NBGL

PRINTF("USB power ON/OFF\n");
USB_power(0);
USB_power(1);
#ifdef HAVE_BLE
// grab the current plane mode setting
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
BLE_power(0, NULL);
BLE_power(1, NULL);
#endif // HAVE_BLE
app_main();

// Failsafe
os_sched_exit(-1);
}

0 comments on commit 733064d

Please sign in to comment.