Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ int wallet_generate_key(HDNode *node, const char *keypath, const uint8_t *privke
idx != (BIP44_PURPOSE_P2WPKH_P2SH + (BIP44_PURPOSE_HARDENED ? BIP44_PRIME : 0))) {
return DBB_WARN_KEYPATH;
}

// get coin type and do not enforce value checking, coin type is application specific and business logic oriented.
// it could be another coin or could be a self-sovereign digital identity relying on DPKI for example
idx = keypath_array[BIP44_LEVEL_COIN_TYPE];
if (idx != (BIP44_COIN_TYPE_BTC + (BIP44_COIN_TYPE_HARDENED ? BIP44_PRIME : 0)) &&
idx != (BIP44_COIN_TYPE_LTC + (BIP44_COIN_TYPE_HARDENED ? BIP44_PRIME : 0)) &&
idx != (BIP44_COIN_TYPE_TESTNET + (BIP44_COIN_TYPE_HARDENED ? BIP44_PRIME : 0))) {
// if hardening is assumed on cointype check to ensure prime bit is set.
if(BIP44_COIN_TYPE_HARDENED && (idx & BIP44_PRIME) == 0){
return DBB_WARN_KEYPATH;
}

}
idx = keypath_array[BIP44_LEVEL_ACCOUNT];
if (idx > (BIP44_ACCOUNT_MAX + (BIP44_ACCOUNT_HARDENED ? BIP44_PRIME : 0)) ||
idx < (BIP44_ACCOUNT_HARDENED ? BIP44_PRIME : 0)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/tests_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ static void tests_seed_xpub_backup(void)
ASSERT_REPORT_HAS_NOT(flag_msg(DBB_WARN_KEYPATH));
ASSERT_REPORT_HAS(cmd_str(CMD_echo));

// AUX coin type just use random number for coin type, should be accepted
snprintf(kp, sizeof(kp), "m/%i%s/%i%s/%i%s/%i%s/%i%s",
BIP44_PURPOSE_P2WPKH, BIP44_PURPOSE_HARDENED ? "p" : "",
BIP44_COIN_TYPE_BTC+123, BIP44_COIN_TYPE_HARDENED ? "p" : "",
BIP44_ACCOUNT_MAX, BIP44_ACCOUNT_HARDENED ? "p" : "",
BIP44_CHANGE_MAX, BIP44_CHANGE_HARDENED ? "p" : "",
BIP44_ADDRESS_MAX, BIP44_ADDRESS_HARDENED ? "p" : "");
api_format_send_cmd(cmd_str(CMD_xpub), kp, KEY_STANDARD);
ASSERT_REPORT_HAS("\"xpub\":");
ASSERT_REPORT_HAS_NOT(flag_msg(DBB_WARN_KEYPATH));
ASSERT_REPORT_HAS(cmd_str(CMD_echo));

// TESTNET
snprintf(kp, sizeof(kp), "m/%i%s/%i%s/%i%s/%i%s/%i%s",
BIP44_PURPOSE_P2PKH, BIP44_PURPOSE_HARDENED ? "p" : "",
Expand Down