diff --git a/src/wallet.c b/src/wallet.c index d890ffe9..b95152e6 100644 --- a/src/wallet.c +++ b/src/wallet.c @@ -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)) { diff --git a/tests/tests_api.c b/tests/tests_api.c index 147a9e51..55ff00f5 100644 --- a/tests/tests_api.c +++ b/tests/tests_api.c @@ -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" : "",