mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 22:40:59 +00:00
add bip84 (native segwit)
This commit is contained in:
parent
6a2b92c49e
commit
94fcc8c9a4
@ -686,7 +686,7 @@ static bool path_mismatched(const CoinInfo *coin, const GetAddress *msg)
|
||||
// m / purpose' / coin_type' / account' / change / address_index
|
||||
if (msg->address_n[0] == (0x80000000 + 44)) {
|
||||
mismatch |= (msg->script_type != InputScriptType_SPENDADDRESS);
|
||||
mismatch |= (msg->address_n_count == 5);
|
||||
mismatch |= (msg->address_n_count != 5);
|
||||
mismatch |= (msg->address_n[1] != coin->coin_type);
|
||||
mismatch |= (msg->address_n[2] & 0x80000000) == 0;
|
||||
mismatch |= (msg->address_n[3] & 0x80000000) == 0x80000000;
|
||||
@ -698,18 +698,18 @@ static bool path_mismatched(const CoinInfo *coin, const GetAddress *msg)
|
||||
// m / purpose' / cosigner_index / change / address_index
|
||||
if (msg->address_n[0] == (0x80000000 + 45)) {
|
||||
mismatch |= (msg->script_type != InputScriptType_SPENDMULTISIG);
|
||||
mismatch |= (msg->address_n_count == 4);
|
||||
mismatch |= (msg->address_n_count != 4);
|
||||
mismatch |= (msg->address_n[1] & 0x80000000) == 0x80000000;
|
||||
mismatch |= (msg->address_n[2] & 0x80000000) == 0x80000000;
|
||||
mismatch |= (msg->address_n[3] & 0x80000000) == 0x80000000;
|
||||
return mismatch;
|
||||
}
|
||||
|
||||
// m/45' - BIP48 Copay Multisig P2SH
|
||||
// m/48' - BIP48 Copay Multisig P2SH
|
||||
// m / purpose' / coin_type' / account' / change / address_index
|
||||
if (msg->address_n[0] == (0x80000000 + 48)) {
|
||||
mismatch |= (msg->script_type != InputScriptType_SPENDMULTISIG);
|
||||
mismatch |= (msg->address_n_count == 5);
|
||||
mismatch |= (msg->address_n_count != 5);
|
||||
mismatch |= (msg->address_n[1] != coin->coin_type);
|
||||
mismatch |= (msg->address_n[2] & 0x80000000) == 0;
|
||||
mismatch |= (msg->address_n[3] & 0x80000000) == 0x80000000;
|
||||
@ -723,7 +723,21 @@ static bool path_mismatched(const CoinInfo *coin, const GetAddress *msg)
|
||||
mismatch |= (msg->script_type != InputScriptType_SPENDP2SHWITNESS);
|
||||
mismatch |= !coin->has_segwit;
|
||||
mismatch |= !coin->has_address_type_p2sh;
|
||||
mismatch |= (msg->address_n_count == 5);
|
||||
mismatch |= (msg->address_n_count != 5);
|
||||
mismatch |= (msg->address_n[1] != coin->coin_type);
|
||||
mismatch |= (msg->address_n[2] & 0x80000000) == 0;
|
||||
mismatch |= (msg->address_n[3] & 0x80000000) == 0x80000000;
|
||||
mismatch |= (msg->address_n[4] & 0x80000000) == 0x80000000;
|
||||
return mismatch;
|
||||
}
|
||||
|
||||
// m/84' : BIP84 Native SegWit
|
||||
// m / purpose' / coin_type' / account' / change / address_index
|
||||
if (msg->address_n[0] == (0x80000000 + 84)) {
|
||||
mismatch |= (msg->script_type != InputScriptType_SPENDWITNESS);
|
||||
mismatch |= !coin->has_segwit;
|
||||
mismatch |= !coin->bech32_prefix;
|
||||
mismatch |= (msg->address_n_count != 5);
|
||||
mismatch |= (msg->address_n[1] != coin->coin_type);
|
||||
mismatch |= (msg->address_n[2] & 0x80000000) == 0;
|
||||
mismatch |= (msg->address_n[3] & 0x80000000) == 0x80000000;
|
||||
|
@ -356,16 +356,22 @@ static const char *address_n_str(const uint32_t *address_n, size_t address_n_cou
|
||||
// known BIP44/49 path
|
||||
static char path[100];
|
||||
if (address_n_count == 5 &&
|
||||
(address_n[0] == (0x80000000 + 44) || address_n[0] == (0x80000000 + 49)) &&
|
||||
(address_n[0] == (0x80000000 + 44) || address_n[0] == (0x80000000 + 49) || address_n[0] == (0x80000000 + 84)) &&
|
||||
(address_n[1] & 0x80000000) &&
|
||||
(address_n[2] & 0x80000000) &&
|
||||
(address_n[3] <= 1) &&
|
||||
(address_n[4] <= BIP32_MAX_LAST_ELEMENT)) {
|
||||
bool segwit = (address_n[0] == (0x80000000 + 49));
|
||||
bool native_segwit = (address_n[0] == (0x80000000 + 84));
|
||||
bool p2sh_segwit = (address_n[0] == (0x80000000 + 49));
|
||||
bool legacy = false;
|
||||
const CoinInfo *coin = coinByCoinType(address_n[1]);
|
||||
const char *abbr = 0;
|
||||
if (segwit) {
|
||||
if (native_segwit) {
|
||||
if (coin && coin->has_segwit && coin->bech32_prefix) {
|
||||
abbr = coin->coin_shortcut + 1;
|
||||
}
|
||||
} else
|
||||
if (p2sh_segwit) {
|
||||
if (coin && coin->has_segwit && coin->has_address_type_p2sh) {
|
||||
abbr = coin->coin_shortcut + 1;
|
||||
}
|
||||
@ -383,9 +389,15 @@ static const char *address_n_str(const uint32_t *address_n, size_t address_n_cou
|
||||
if (abbr && accnum < 100) {
|
||||
memset(path, 0, sizeof(path));
|
||||
strlcpy(path, abbr, sizeof(path));
|
||||
// TODO: how to name accounts?
|
||||
// currently we have "legacy account", "account" and "segwit account"
|
||||
// for BIP44/P2PKH, BIP49/P2SH-P2WPKH and BIP84/P2WPKH respectivelly
|
||||
if (legacy) {
|
||||
strlcat(path, " legacy", sizeof(path));
|
||||
}
|
||||
if (native_segwit) {
|
||||
strlcat(path, " segwit", sizeof(path));
|
||||
}
|
||||
strlcat(path, " account #", sizeof(path));
|
||||
char acc[3];
|
||||
memset(acc, 0, sizeof(acc));
|
||||
|
Loading…
Reference in New Issue
Block a user