Renamed Item to Asset & changed the set marker type to boolean
Also renamed the reset assets function
This commit is contained in:
@@ -80,6 +80,7 @@ void reset_app_context() {
|
|||||||
eth2WithdrawalIndex = 0;
|
eth2WithdrawalIndex = 0;
|
||||||
#endif
|
#endif
|
||||||
memset((uint8_t *) &tmpCtx, 0, sizeof(tmpCtx));
|
memset((uint8_t *) &tmpCtx, 0, sizeof(tmpCtx));
|
||||||
|
forget_known_assets();
|
||||||
memset((uint8_t *) &txContext, 0, sizeof(txContext));
|
memset((uint8_t *) &txContext, 0, sizeof(txContext));
|
||||||
memset((uint8_t *) &tmpContent, 0, sizeof(tmpContent));
|
memset((uint8_t *) &tmpContent, 0, sizeof(tmpContent));
|
||||||
}
|
}
|
||||||
@@ -156,7 +157,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
|
|||||||
|
|
||||||
switch (G_io_apdu_buffer[OFFSET_INS]) {
|
switch (G_io_apdu_buffer[OFFSET_INS]) {
|
||||||
case INS_GET_PUBLIC_KEY:
|
case INS_GET_PUBLIC_KEY:
|
||||||
reset_known_tokens();
|
forget_known_assets();
|
||||||
handleGetPublicKey(G_io_apdu_buffer[OFFSET_P1],
|
handleGetPublicKey(G_io_apdu_buffer[OFFSET_P1],
|
||||||
G_io_apdu_buffer[OFFSET_P2],
|
G_io_apdu_buffer[OFFSET_P2],
|
||||||
G_io_apdu_buffer + OFFSET_CDATA,
|
G_io_apdu_buffer + OFFSET_CDATA,
|
||||||
@@ -231,7 +232,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case INS_SIGN_PERSONAL_MESSAGE:
|
case INS_SIGN_PERSONAL_MESSAGE:
|
||||||
reset_known_tokens();
|
forget_known_assets();
|
||||||
*flags |= IO_ASYNCH_REPLY;
|
*flags |= IO_ASYNCH_REPLY;
|
||||||
if (!handleSignPersonalMessage(G_io_apdu_buffer[OFFSET_P1],
|
if (!handleSignPersonalMessage(G_io_apdu_buffer[OFFSET_P1],
|
||||||
G_io_apdu_buffer[OFFSET_P2],
|
G_io_apdu_buffer[OFFSET_P2],
|
||||||
@@ -244,7 +245,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
|
|||||||
case INS_SIGN_EIP_712_MESSAGE:
|
case INS_SIGN_EIP_712_MESSAGE:
|
||||||
switch (G_io_apdu_buffer[OFFSET_P2]) {
|
switch (G_io_apdu_buffer[OFFSET_P2]) {
|
||||||
case P2_EIP712_LEGACY_IMPLEM:
|
case P2_EIP712_LEGACY_IMPLEM:
|
||||||
reset_known_tokens();
|
forget_known_assets();
|
||||||
handleSignEIP712Message_v0(G_io_apdu_buffer[OFFSET_P1],
|
handleSignEIP712Message_v0(G_io_apdu_buffer[OFFSET_P1],
|
||||||
G_io_apdu_buffer[OFFSET_P2],
|
G_io_apdu_buffer[OFFSET_P2],
|
||||||
G_io_apdu_buffer + OFFSET_CDATA,
|
G_io_apdu_buffer + OFFSET_CDATA,
|
||||||
@@ -266,7 +267,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
|
|||||||
#ifdef HAVE_ETH2
|
#ifdef HAVE_ETH2
|
||||||
|
|
||||||
case INS_GET_ETH2_PUBLIC_KEY:
|
case INS_GET_ETH2_PUBLIC_KEY:
|
||||||
reset_known_tokens();
|
forget_known_assets();
|
||||||
handleGetEth2PublicKey(G_io_apdu_buffer[OFFSET_P1],
|
handleGetEth2PublicKey(G_io_apdu_buffer[OFFSET_P1],
|
||||||
G_io_apdu_buffer[OFFSET_P2],
|
G_io_apdu_buffer[OFFSET_P2],
|
||||||
G_io_apdu_buffer + OFFSET_CDATA,
|
G_io_apdu_buffer + OFFSET_CDATA,
|
||||||
|
|||||||
@@ -1,29 +1,30 @@
|
|||||||
#include "manage_asset_info.h"
|
#include "manage_asset_info.h"
|
||||||
|
#include "shared_context.h"
|
||||||
|
|
||||||
void reset_known_tokens(void) {
|
void forget_known_assets(void) {
|
||||||
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS);
|
memset(tmpCtx.transactionContext.assetSet, false, MAX_ASSETS);
|
||||||
tmpCtx.transactionContext.currentItemIndex = 0;
|
tmpCtx.transactionContext.currentAssetIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static extraInfo_t *get_asset_info(uint8_t index) {
|
static extraInfo_t *get_asset_info(uint8_t index) {
|
||||||
if (index >= MAX_ITEMS) {
|
if (index >= MAX_ASSETS) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return &tmpCtx.transactionContext.extraInfo[index];
|
return &tmpCtx.transactionContext.extraInfo[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool asset_info_is_set(uint8_t index) {
|
static bool asset_info_is_set(uint8_t index) {
|
||||||
if (index >= MAX_ITEMS) {
|
if (index >= MAX_ASSETS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return tmpCtx.transactionContext.tokenSet[index] != 0;
|
return tmpCtx.transactionContext.assetSet[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
extraInfo_t *get_asset_info_by_addr(const uint8_t *contractAddress) {
|
extraInfo_t *get_asset_info_by_addr(const uint8_t *contractAddress) {
|
||||||
// Works for ERC-20 & NFT tokens since both structs in the union have the
|
// Works for ERC-20 & NFT tokens since both structs in the union have the
|
||||||
// contract address aligned
|
// contract address aligned
|
||||||
for (uint8_t i = 0; i < MAX_ITEMS; i++) {
|
for (uint8_t i = 0; i < MAX_ASSETS; i++) {
|
||||||
extraInfo_t *currentItem = &tmpCtx.transactionContext.extraInfo[i];
|
extraInfo_t *currentItem = get_asset_info(i);
|
||||||
if (asset_info_is_set(i) &&
|
if (asset_info_is_set(i) &&
|
||||||
(memcmp(currentItem->token.address, contractAddress, ADDRESS_LENGTH) == 0)) {
|
(memcmp(currentItem->token.address, contractAddress, ADDRESS_LENGTH) == 0)) {
|
||||||
PRINTF("Token found at index %d\n", i);
|
PRINTF("Token found at index %d\n", i);
|
||||||
@@ -35,12 +36,13 @@ extraInfo_t *get_asset_info_by_addr(const uint8_t *contractAddress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extraInfo_t *get_current_asset_info(void) {
|
extraInfo_t *get_current_asset_info(void) {
|
||||||
return get_asset_info(tmpCtx.transactionContext.currentItemIndex);
|
return get_asset_info(tmpCtx.transactionContext.currentAssetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void validate_current_asset_info(void) {
|
void validate_current_asset_info(void) {
|
||||||
// mark it as set
|
// mark it as set
|
||||||
tmpCtx.transactionContext.tokenSet[tmpCtx.transactionContext.currentItemIndex] = 1;
|
tmpCtx.transactionContext.assetSet[tmpCtx.transactionContext.currentAssetIndex] = true;
|
||||||
// increment index
|
// increment index
|
||||||
tmpCtx.transactionContext.currentItemIndex = (tmpCtx.transactionContext.currentItemIndex + 1) % MAX_ITEMS;
|
tmpCtx.transactionContext.currentAssetIndex =
|
||||||
|
(tmpCtx.transactionContext.currentAssetIndex + 1) % MAX_ASSETS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "common_utils.h"
|
#include "common_utils.h"
|
||||||
#include "asset_info.h"
|
#include "asset_info.h"
|
||||||
|
|
||||||
void reset_known_tokens(void);
|
void forget_known_assets(void);
|
||||||
extraInfo_t *get_asset_info_by_addr(const uint8_t *contractAddress);
|
extraInfo_t *get_asset_info_by_addr(const uint8_t *contractAddress);
|
||||||
extraInfo_t *get_current_asset_info(void);
|
extraInfo_t *get_current_asset_info(void);
|
||||||
void validate_current_asset_info(void);
|
void validate_current_asset_info(void);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#define N_storage (*(volatile internalStorage_t *) PIC(&N_storage_real))
|
#define N_storage (*(volatile internalStorage_t *) PIC(&N_storage_real))
|
||||||
|
|
||||||
|
#define MAX_ASSETS MAX_ITEMS // TODO: Temporary, remove once plugin SDK is updated
|
||||||
|
|
||||||
typedef struct bip32_path_t {
|
typedef struct bip32_path_t {
|
||||||
uint8_t length;
|
uint8_t length;
|
||||||
uint32_t path[MAX_BIP32_PATH];
|
uint32_t path[MAX_BIP32_PATH];
|
||||||
@@ -77,9 +79,9 @@ typedef struct publicKeyContext_t {
|
|||||||
typedef struct transactionContext_t {
|
typedef struct transactionContext_t {
|
||||||
bip32_path_t bip32;
|
bip32_path_t bip32;
|
||||||
uint8_t hash[INT256_LENGTH];
|
uint8_t hash[INT256_LENGTH];
|
||||||
union extraInfo_t extraInfo[MAX_ITEMS];
|
union extraInfo_t extraInfo[MAX_ASSETS];
|
||||||
uint8_t tokenSet[MAX_ITEMS];
|
bool assetSet[MAX_ASSETS];
|
||||||
uint8_t currentItemIndex;
|
uint8_t currentAssetIndex;
|
||||||
} transactionContext_t;
|
} transactionContext_t;
|
||||||
|
|
||||||
typedef struct messageSigningContext_t {
|
typedef struct messageSigningContext_t {
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ void handleProvideErc20TokenInformation(uint8_t p1,
|
|||||||
|
|
||||||
tokenDefinition_t *token = &get_current_asset_info()->token;
|
tokenDefinition_t *token = &get_current_asset_info()->token;
|
||||||
|
|
||||||
PRINTF("Provisioning currentItemIndex %d\n", tmpCtx.transactionContext.currentItemIndex);
|
PRINTF("Provisioning currentAssetIndex %d\n", tmpCtx.transactionContext.currentAssetIndex);
|
||||||
|
|
||||||
if (dataLength < 1) {
|
if (dataLength < 1) {
|
||||||
THROW(0x6A80);
|
THROW(0x6A80);
|
||||||
@@ -138,10 +138,11 @@ void handleProvideErc20TokenInformation(uint8_t p1,
|
|||||||
memmove(token->address, workBuffer + offset, 20);
|
memmove(token->address, workBuffer + offset, 20);
|
||||||
offset += 20;
|
offset += 20;
|
||||||
dataLength -= 20;
|
dataLength -= 20;
|
||||||
// TODO: Handle 64-bit long chain IDs
|
// TODO: 4 bytes for this is overkill
|
||||||
token->decimals = U4BE(workBuffer, offset);
|
token->decimals = U4BE(workBuffer, offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
dataLength -= 4;
|
dataLength -= 4;
|
||||||
|
// TODO: Handle 64-bit long chain IDs
|
||||||
chain_id = U4BE(workBuffer, offset);
|
chain_id = U4BE(workBuffer, offset);
|
||||||
if (!app_compatible_with_chain_id(&chain_id)) {
|
if (!app_compatible_with_chain_id(&chain_id)) {
|
||||||
UNSUPPORTED_CHAIN_ID_MSG(chain_id);
|
UNSUPPORTED_CHAIN_ID_MSG(chain_id);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void handleProvideNFTInformation(uint8_t p1,
|
|||||||
}
|
}
|
||||||
nftInfo_t *nft = &get_current_asset_info()->nft;
|
nftInfo_t *nft = &get_current_asset_info()->nft;
|
||||||
|
|
||||||
PRINTF("Provisioning currentItemIndex %d\n", tmpCtx.transactionContext.currentItemIndex);
|
PRINTF("Provisioning currentAssetIndex %d\n", tmpCtx.transactionContext.currentAssetIndex);
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user