add most basic bip86 address derivation stub

to be tested according to https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#test-vectors
This commit is contained in:
sneurlax 2024-03-25 23:03:00 -05:00 committed by julian
parent 6fdfa166f2
commit f2effa3575
3 changed files with 18 additions and 1 deletions

View file

@ -164,7 +164,7 @@ enum AddressType {
stellar, stellar,
tezos, tezos,
frostMS, frostMS,
; p2tr;
String get readableName { String get readableName {
switch (this) { switch (this) {
@ -196,6 +196,8 @@ enum AddressType {
return "Tezos"; return "Tezos";
case AddressType.frostMS: case AddressType.frostMS:
return "FrostMS"; return "FrostMS";
case AddressType.p2tr:
return "Taproot"; // Why not use P2TR, P2PKH, etc.?
} }
} }
} }

View file

@ -15,6 +15,7 @@ enum DerivePathType {
bch44, bch44,
bip49, bip49,
bip84, bip84,
bip86,
eth, eth,
eCash44, eCash44,
} }

View file

@ -30,6 +30,7 @@ class Bitcoin extends Bip39HDCurrency with PaynymCurrencyInterface {
DerivePathType.bip44, DerivePathType.bip44,
DerivePathType.bip49, DerivePathType.bip49,
DerivePathType.bip84, DerivePathType.bip84,
DerivePathType.bip86, // P2TR.
]; ];
@override @override
@ -115,6 +116,9 @@ class Bitcoin extends Bip39HDCurrency with PaynymCurrencyInterface {
case DerivePathType.bip84: case DerivePathType.bip84:
purpose = 84; purpose = 84;
break; break;
case DerivePathType.bip86:
purpose = 86;
break;
default: default:
throw Exception("DerivePathType $derivePathType not supported"); throw Exception("DerivePathType $derivePathType not supported");
} }
@ -157,6 +161,16 @@ class Bitcoin extends Bip39HDCurrency with PaynymCurrencyInterface {
return (address: addr, addressType: AddressType.p2wpkh); 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: default:
throw Exception("DerivePathType $derivePathType not supported"); throw Exception("DerivePathType $derivePathType not supported");
} }