Improve error-handling of chain ID when parsing APDUs

This commit is contained in:
Alexandre Paillier
2024-02-05 10:21:54 +01:00
parent 0f9bec8ec7
commit 91352af57c
5 changed files with 28 additions and 8 deletions

View File

@@ -144,3 +144,15 @@ const char *get_displayable_ticker(const uint64_t *chain_id) {
}
return ticker;
}
/**
* Checks wether the app can support the given chain ID
*
* - If the given chain ID is the same as the app's one
* - If both chain IDs are present in the array of Ethereum-compatible networks
*/
bool app_compatible_with_chain_id(const uint64_t *chain_id) {
return ((chainConfig->chainId == *chain_id) ||
(chain_is_ethereum_compatible(&chainConfig->chainId) &&
chain_is_ethereum_compatible(chain_id)));
}

View File

@@ -3,10 +3,16 @@
#include <stdint.h>
#include <stdbool.h>
#define UNSUPPORTED_CHAIN_ID_MSG(id) \
do { \
PRINTF("Unsupported chain ID: %u (app: %u)\n", id, chainConfig->chainId); \
} while (0)
const char *get_network_name_from_chain_id(const uint64_t *chain_id);
const char *get_network_ticker_from_chain_id(const uint64_t *chain_id);
bool chain_is_ethereum_compatible(const uint64_t *chain_id);
bool app_compatible_with_chain_id(const uint64_t *chain_id);
uint64_t get_tx_chain_id(void);