From 78a9ab8123122314042f65d86928442fa8a74761 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Fri, 15 Oct 2021 16:43:44 +0200 Subject: [PATCH] feat(legacy): Add BIP86 paths to coin_path_check(). --- legacy/firmware/crypto.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/legacy/firmware/crypto.c b/legacy/firmware/crypto.c index 139975a157..e1ffc439fd 100644 --- a/legacy/firmware/crypto.c +++ b/legacy/firmware/crypto.c @@ -655,6 +655,7 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type, valid = valid && check_cointype(coin, address_n[1], check_known); if (check_script_type) { valid = valid && has_multisig; + // we do not support Multisig with Taproot yet valid = valid && (script_type == InputScriptType_SPENDMULTISIG || script_type == InputScriptType_SPENDP2SHWITNESS || script_type == InputScriptType_SPENDWITNESS); @@ -722,6 +723,31 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type, return valid; } + // m/86' : BIP86 Taproot + // m / purpose' / coin_type' / account' / change / address_index + if (address_n_count > 0 && address_n[0] == (0x80000000 + 86)) { + valid = valid && coin->has_taproot; + valid = valid && (coin->bech32_prefix != NULL); + if (check_known) { + valid = valid && (address_n_count == 5); + } else { + valid = valid && (address_n_count >= 2); + } + valid = valid && check_cointype(coin, address_n[1], check_known); + if (check_script_type) { + // we do not support Multisig with Taproot yet + valid = valid && !has_multisig; + valid = valid && (script_type == InputScriptType_SPENDTAPROOT); + } + if (check_known) { + valid = valid && ((address_n[2] & 0x80000000) == 0x80000000); + valid = valid && ((address_n[2] & 0x7fffffff) <= PATH_MAX_ACCOUNT); + valid = valid && (address_n[3] <= PATH_MAX_CHANGE); + valid = valid && (address_n[4] <= PATH_MAX_ADDRESS_INDEX); + } + return valid; + } + // Green Address compatibility pattern. Will be removed in the future. // m / [1,4] / address_index if (address_n_count > 0 && (address_n[0] == 1 || address_n[0] == 4)) {