@@ -57,7 +57,7 @@ import {
5757 v1Sweep ,
5858 V1SweepParams ,
5959} from './recovery' ;
60- import { isReplayProtectionUnspent } from './transaction/fixedScript/replayProtection' ;
60+ import { getReplayProtectionPubkeys , isReplayProtectionUnspent } from './transaction/fixedScript/replayProtection' ;
6161import { supportedCrossChainRecoveries } from './config' ;
6262import {
6363 assertValidTransactionRecipient ,
@@ -81,6 +81,7 @@ import {
8181 getMainnetCoinName ,
8282 getNetworkFromCoinName ,
8383 isTestnetCoin ,
84+ isUtxoCoinNameMainnet ,
8485 UtxoCoinName ,
8586 UtxoCoinNameMainnet ,
8687} from './names' ;
@@ -143,6 +144,28 @@ type UtxoCustomSigningFunction<TNumber extends number | bigint> = {
143144
144145const { isChainCode, scriptTypeForChain, outputScripts } = bitgo ;
145146
147+ /**
148+ * Check if a decoded transaction has at least one taproot key path spend (MuSig2) input.
149+ * Works for both utxolib UtxoPsbt and wasm-utxo BitGoPsbt.
150+ */
151+ function hasKeyPathSpendInput < TNumber extends number | bigint > (
152+ tx : DecodedTransaction < TNumber > ,
153+ pubs : string [ ] | undefined ,
154+ coinName : UtxoCoinName
155+ ) : boolean {
156+ if ( tx instanceof bitgo . UtxoPsbt ) {
157+ return bitgo . isTransactionWithKeyPathSpendInput ( tx ) ;
158+ }
159+ if ( tx instanceof fixedScriptWallet . BitGoPsbt ) {
160+ assert ( pubs && isTriple ( pubs ) , 'pub triple is required to check for key path spend inputs in wasm-utxo PSBT' ) ;
161+ const rootWalletKeys = fixedScriptWallet . RootWalletKeys . fromXpubs ( pubs ) ;
162+ const replayProtection = { publicKeys : getReplayProtectionPubkeys ( coinName ) } ;
163+ const parsed = tx . parseTransactionWithWalletKeys ( rootWalletKeys , replayProtection ) ;
164+ return parsed . inputs . some ( ( input ) => input . scriptType === 'p2trMusig2KeyPath' ) ;
165+ }
166+ return false ;
167+ }
168+
146169/**
147170 * Convert ValidationError to TxIntentMismatchRecipientError with structured data
148171 *
@@ -379,14 +402,17 @@ export abstract class AbstractUtxoCoin
379402
380403 public altScriptHash ?: number ;
381404 public supportAltScriptDestination ?: boolean ;
382- public defaultSdkBackend : SdkBackend = 'utxolib' ;
383405 public readonly amountType : 'number' | 'bigint' ;
384406
385407 protected constructor ( bitgo : BitGoBase , amountType : 'number' | 'bigint' = 'number' ) {
386408 super ( bitgo ) ;
387409 this . amountType = amountType ;
388410 }
389411
412+ get defaultSdkBackend ( ) : SdkBackend {
413+ return isUtxoCoinNameMainnet ( this . name ) ? 'utxolib' : 'wasm-utxo' ;
414+ }
415+
390416 /**
391417 * @deprecated - will be removed when we drop support for utxolib
392418 * Use `name` property instead.
@@ -814,7 +840,7 @@ export abstract class AbstractUtxoCoin
814840
815841 const tx = this . decodeTransaction ( txHex ) ;
816842
817- const isTxWithKeyPathSpendInput = tx instanceof bitgo . UtxoPsbt && bitgo . isTransactionWithKeyPathSpendInput ( tx ) ;
843+ const isTxWithKeyPathSpendInput = hasKeyPathSpendInput ( tx , signTransactionParams . pubs , this . name ) ;
818844
819845 if ( ! isTxWithKeyPathSpendInput ) {
820846 return await customSigningFunction ( { ...signTransactionParams , coin : this } ) ;
0 commit comments