Skip to content

Commit

Permalink
Remove chain configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Z4karia authored Apr 12, 2024
1 parent 8fcb2e5 commit 105dc21
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
5 changes: 2 additions & 3 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ static void extractHDPath_HRP(uint32_t rx, uint32_t offset) {

// Check if HRP was sent
if ((rx - offset) > sizeof(uint32_t) * HDPATH_LEN_DEFAULT) {
uint8_t hrp_bech32_len = extractHRP(rx, offset + sizeof(uint32_t) * HDPATH_LEN_DEFAULT);
encoding = checkChainConfig(hdPath[1], bech32_hrp, hrp_bech32_len);
encoding = checkChainConfig(hdPath[1]);
if (encoding == UNSUPPORTED) {
ZEMU_LOGF(50, "Chain config not supported for: %s\n", bech32_hrp)
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
Expand Down Expand Up @@ -160,7 +159,7 @@ __Z_INLINE void handleGetAddrSecp256K1(volatile uint32_t *flags, volatile uint32
extractHDPath(rx, OFFSET_DATA + 1 + len);

// Verify encoding
encoding = checkChainConfig(hdPath[1], bech32_hrp, bech32_hrp_len);
encoding = checkChainConfig(hdPath[1]);
if (encoding == UNSUPPORTED) {
ZEMU_LOGF(50, "Chain config not supported for: %s\n", bech32_hrp)
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
Expand Down
29 changes: 1 addition & 28 deletions app/src/chain_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,10 @@
#include "chain_config.h"
#include <zxmacros.h>

typedef struct {
const uint32_t path;
const char *hrp;
const address_encoding_e encoding;
} chain_config_t;

// To enable custom config for a new chain, just add a new entry in this array with path, hrp and encoding
static const chain_config_t chainConfig[] = {
// {118, cosmos, BECH32_COSMOS},
{60, "inj", BECH32_ETH},
{60, "evmos", BECH32_ETH}
};

static const uint32_t chainConfigLen = sizeof(chainConfig) / sizeof(chainConfig[0]);

address_encoding_e checkChainConfig(uint32_t path, const char* hrp, uint8_t hrpLen) {
address_encoding_e checkChainConfig(uint32_t path) {
// Always allowed for 118 (default Cosmos)
if (path == HDPATH_1_DEFAULT) {
return BECH32_COSMOS;
}

// Check special cases
for (uint32_t i = 0; i < chainConfigLen; i++) {
if (path == (0x80000000u | chainConfig[i].path)) {
const char* hrpPtr = (const char *) PIC(chainConfig[i].hrp);
const uint16_t hrpPtrLen = strlen(hrpPtr);
if (hrpPtrLen == hrpLen && memcmp(hrpPtr, hrp, hrpLen) == 0) {
return chainConfig[i].encoding;
}
}
}

return UNSUPPORTED;
}
2 changes: 1 addition & 1 deletion app/src/chain_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {
#include <stdbool.h>
#include "coin.h"

address_encoding_e checkChainConfig(uint32_t path, const char* hrp, uint8_t hrpLen);
address_encoding_e checkChainConfig(uint32_t path);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 105dc21

Please sign in to comment.