From f2effa357557483fe37da54dec4d53f96313431b Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 25 Mar 2024 23:03:00 -0500 Subject: [PATCH] add most basic bip86 address derivation stub to be tested according to https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#test-vectors --- .../isar/models/blockchain_data/address.dart | 4 +++- lib/utilities/enums/derive_path_type_enum.dart | 1 + lib/wallets/crypto_currency/coins/bitcoin.dart | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/models/isar/models/blockchain_data/address.dart b/lib/models/isar/models/blockchain_data/address.dart index 8adaa4ce5..16516edf4 100644 --- a/lib/models/isar/models/blockchain_data/address.dart +++ b/lib/models/isar/models/blockchain_data/address.dart @@ -164,7 +164,7 @@ enum AddressType { stellar, tezos, frostMS, - ; + p2tr; String get readableName { switch (this) { @@ -196,6 +196,8 @@ enum AddressType { return "Tezos"; case AddressType.frostMS: return "FrostMS"; + case AddressType.p2tr: + return "Taproot"; // Why not use P2TR, P2PKH, etc.? } } } diff --git a/lib/utilities/enums/derive_path_type_enum.dart b/lib/utilities/enums/derive_path_type_enum.dart index 6d2371735..eb86aa6d5 100644 --- a/lib/utilities/enums/derive_path_type_enum.dart +++ b/lib/utilities/enums/derive_path_type_enum.dart @@ -15,6 +15,7 @@ enum DerivePathType { bch44, bip49, bip84, + bip86, eth, eCash44, } diff --git a/lib/wallets/crypto_currency/coins/bitcoin.dart b/lib/wallets/crypto_currency/coins/bitcoin.dart index 01ce800e8..7008d8b3b 100644 --- a/lib/wallets/crypto_currency/coins/bitcoin.dart +++ b/lib/wallets/crypto_currency/coins/bitcoin.dart @@ -30,6 +30,7 @@ class Bitcoin extends Bip39HDCurrency with PaynymCurrencyInterface { DerivePathType.bip44, DerivePathType.bip49, DerivePathType.bip84, + DerivePathType.bip86, // P2TR. ]; @override @@ -115,6 +116,9 @@ class Bitcoin extends Bip39HDCurrency with PaynymCurrencyInterface { case DerivePathType.bip84: purpose = 84; break; + case DerivePathType.bip86: + purpose = 86; + break; default: throw Exception("DerivePathType $derivePathType not supported"); } @@ -157,6 +161,16 @@ class Bitcoin extends Bip39HDCurrency with PaynymCurrencyInterface { return (address: addr, addressType: AddressType.p2wpkh); + case DerivePathType.bip86: + final taproot = coinlib.Taproot(internalKey: publicKey); + + final addr = coinlib.P2TRAddress.fromTaproot( + taproot, + hrp: coinlib.Network.mainnet.bech32Hrp, + ); + + return (address: addr, addressType: AddressType.p2tr); + default: throw Exception("DerivePathType $derivePathType not supported"); }