@@ -26,6 +26,7 @@ const supportedCoins = [
2626] ;
2727
2828const segwitCoins = [ "Bitcoin" , "Testnet" , "BitcoinGold" , "Litecoin" ] ;
29+ const taprootCoins = [ "Bitcoin" , "Testnet" ] ;
2930
3031function legacyAccount ( coin : core . Coin , slip44 : number , accountIdx : number ) : core . BTCAccountPath {
3132 return {
@@ -51,6 +52,14 @@ function segwitNativeAccount(coin: core.Coin, slip44: number, accountIdx: number
5152 } ;
5253}
5354
55+ function taprootAccount ( coin : core . Coin , slip44 : number , accountIdx : number ) : core . BTCAccountPath {
56+ return {
57+ coin,
58+ scriptType : core . BTCInputScriptType . SpendTaproot ,
59+ addressNList : [ 0x80000000 + 86 , 0x80000000 + slip44 , 0x80000000 + accountIdx ] ,
60+ } ;
61+ }
62+
5463function packVarint ( n : number ) : string {
5564 if ( n < 253 ) return n . toString ( 16 ) . padStart ( 2 , "0" ) ;
5665 else if ( n < 0xffff ) return "FD" + n . toString ( 16 ) . padStart ( 4 , "0" ) ;
@@ -120,6 +129,7 @@ function prepareSignTx(
120129 if (
121130 inputTx . scriptType === core . BTCInputScriptType . SpendP2SHWitness ||
122131 inputTx . scriptType === core . BTCInputScriptType . SpendWitness ||
132+ inputTx . scriptType === core . BTCInputScriptType . SpendTaproot ||
123133 inputTx . scriptType === core . BTCInputScriptType . External
124134 )
125135 return ;
@@ -248,6 +258,7 @@ export async function btcSupportsScriptType(coin: core.Coin, scriptType?: core.B
248258 if ( ! supportedCoins . includes ( coin ) ) return false ;
249259 if ( ! segwitCoins . includes ( coin ) && scriptType === core . BTCInputScriptType . SpendP2SHWitness ) return false ;
250260 if ( ! segwitCoins . includes ( coin ) && scriptType === core . BTCInputScriptType . SpendWitness ) return false ;
261+ if ( ! taprootCoins . includes ( coin ) && scriptType === core . BTCInputScriptType . SpendTaproot ) return false ;
251262 return true ;
252263}
253264
@@ -546,6 +557,7 @@ export function btcGetAccountPaths(msg: core.BTCGetAccountPaths): Array<core.BTC
546557 const bip44 = legacyAccount ( msg . coin , slip44 , msg . accountIdx ) ;
547558 const bip49 = segwitAccount ( msg . coin , slip44 , msg . accountIdx ) ;
548559 const bip84 = segwitNativeAccount ( msg . coin , slip44 , msg . accountIdx ) ;
560+ const bip86 = taprootAccount ( msg . coin , slip44 , msg . accountIdx ) ;
549561
550562 // For BTC Forks
551563 const btcLegacy = legacyAccount ( msg . coin , core . slip44ByCoin ( "Bitcoin" ) , msg . accountIdx ) ;
@@ -558,12 +570,12 @@ export function btcGetAccountPaths(msg: core.BTCGetAccountPaths): Array<core.BTC
558570 let paths : Array < core . BTCAccountPath > =
559571 (
560572 {
561- Bitcoin : [ bip44 , bip49 , bip84 ] ,
573+ Bitcoin : [ bip44 , bip49 , bip84 , bip86 ] ,
562574 Litecoin : [ bip44 , bip49 , bip84 ] ,
563575 Dash : [ bip44 ] ,
564576 DigiByte : [ bip44 , bip49 , bip84 ] ,
565577 Dogecoin : [ bip44 ] ,
566- Testnet : [ bip44 , bip49 , bip84 ] ,
578+ Testnet : [ bip44 , bip49 , bip84 , bip86 ] ,
567579 BitcoinCash : [ bip44 , btcLegacy ] ,
568580 BitcoinSV : [ bip44 , bchLegacy , btcLegacy ] ,
569581 BitcoinGold : [ bip44 , bip49 , bip84 , btcLegacy , btcSegwit , btcSegwitNative ] ,
@@ -581,7 +593,7 @@ export function btcGetAccountPaths(msg: core.BTCGetAccountPaths): Array<core.BTC
581593export function btcIsSameAccount ( msg : Array < core . BTCAccountPath > ) : boolean {
582594 if ( msg . length < 1 ) return false ;
583595
584- if ( msg . length > 3 ) return false ;
596+ if ( msg . length > 4 ) return false ;
585597
586598 const account0 = msg [ 0 ] ;
587599 if ( account0 . addressNList . length != 3 ) return false ;
@@ -592,6 +604,7 @@ export function btcIsSameAccount(msg: Array<core.BTCAccountPath>): boolean {
592604 [ core . BTCInputScriptType . SpendAddress ] : 0x80000000 + 44 ,
593605 [ core . BTCInputScriptType . SpendP2SHWitness ] : 0x80000000 + 49 ,
594606 [ core . BTCInputScriptType . SpendWitness ] : 0x80000000 + 84 ,
607+ [ core . BTCInputScriptType . SpendTaproot ] : 0x80000000 + 86 ,
595608 } as Partial < Record < core . BTCInputScriptType , number > > ;
596609 if ( purposeForScriptType [ account0 . scriptType ] !== purpose ) return false ;
597610
@@ -604,12 +617,13 @@ export function btcIsSameAccount(msg: Array<core.BTCAccountPath>): boolean {
604617 if ( idx < 0x80000000 ) return false ;
605618
606619 // Accounts must have the same SLIP44 and Account Idx, but may have differing
607- // purpose fields (so long as they're BIP44/BIP49/BIP84)
620+ // purpose fields (so long as they're BIP44/BIP49/BIP84/BIP86 )
608621 if (
609622 msg . find ( ( path ) => {
610623 if ( path . addressNList . length != 3 ) return true ;
611624
612- if ( ! [ 0x80000000 + 44 , 0x80000000 + 49 , 0x80000000 + 84 ] . includes ( path . addressNList [ 0 ] ) ) return true ;
625+ if ( ! [ 0x80000000 + 44 , 0x80000000 + 49 , 0x80000000 + 84 , 0x80000000 + 86 ] . includes ( path . addressNList [ 0 ] ) )
626+ return true ;
613627
614628 if ( purposeForScriptType [ path . scriptType ] !== path . addressNList [ 0 ] ) return true ;
615629
0 commit comments