11import * as utxolib from '@bitgo/utxo-lib' ;
22import { BIP32Interface , bip32 } from '@bitgo/secp256k1' ;
33import { Dimensions } from '@bitgo/unspents' ;
4- import { fixedScriptWallet } from '@bitgo/wasm-utxo' ;
4+ import { fixedScriptWallet , CoinName } from '@bitgo/wasm-utxo' ;
55import { BitGoBase , IWallet , Keychain , Triple , Wallet } from '@bitgo/sdk-core' ;
66import { decrypt } from '@bitgo/sdk-api' ;
77
@@ -388,14 +388,16 @@ function createSweepTransactionUtxolib<TNumber extends number | bigint = number>
388388 * @param unspents
389389 * @param targetAddress
390390 * @param feeRateSatVB
391+ * @param coinName - BitGo coin name (e.g. 'btc', 'tbtc', 'ltc')
391392 * @return unsigned PSBT
392393 */
393394function createSweepTransactionWasm < TNumber extends number | bigint = number > (
394395 network : utxolib . Network ,
395396 walletKeys : RootWalletKeys ,
396397 unspents : WalletUnspent < TNumber > [ ] ,
397398 targetAddress : string ,
398- feeRateSatVB : number
399+ feeRateSatVB : number ,
400+ coinName : CoinName
399401) : utxolib . bitgo . UtxoPsbt {
400402 const inputValue = unspentSum < bigint > (
401403 unspents . map ( ( u ) => ( { ...u , value : BigInt ( u . value ) } ) ) ,
@@ -408,9 +410,8 @@ function createSweepTransactionWasm<TNumber extends number | bigint = number>(
408410 addWalletInputsToWasmPsbt ( wasmPsbt , unspentsBigint , walletKeys ) ;
409411
410412 // Calculate dimensions using wasm-utxo Dimensions
411- const targetOutputScript = utxolib . address . toOutputScript ( targetAddress , network ) ;
412413 const vsize = fixedScriptWallet . Dimensions . fromPsbt ( wasmPsbt )
413- . plus ( fixedScriptWallet . Dimensions . fromOutput ( new Uint8Array ( targetOutputScript ) ) )
414+ . plus ( fixedScriptWallet . Dimensions . fromOutput ( targetAddress , coinName ) )
414415 . getVSize ( ) ;
415416 const fee = BigInt ( Math . round ( vsize * feeRateSatVB ) ) ;
416417
@@ -429,6 +430,7 @@ function createSweepTransactionWasm<TNumber extends number | bigint = number>(
429430 * @param targetAddress
430431 * @param feeRateSatVB
431432 * @param backend - Which backend to use for PSBT creation (default: 'wasm-utxo')
433+ * @param coinName - BitGo coin name (required for wasm-utxo backend)
432434 * @return unsigned PSBT
433435 */
434436function createSweepTransaction < TNumber extends number | bigint = number > (
@@ -437,10 +439,14 @@ function createSweepTransaction<TNumber extends number | bigint = number>(
437439 unspents : WalletUnspent < TNumber > [ ] ,
438440 targetAddress : string ,
439441 feeRateSatVB : number ,
440- backend : PsbtBackend = 'wasm-utxo'
442+ backend : PsbtBackend = 'wasm-utxo' ,
443+ coinName ?: CoinName
441444) : utxolib . bitgo . UtxoPsbt {
442445 if ( backend === 'wasm-utxo' ) {
443- return createSweepTransactionWasm ( network , walletKeys , unspents , targetAddress , feeRateSatVB ) ;
446+ if ( ! coinName ) {
447+ throw new Error ( 'coinName is required for wasm-utxo backend' ) ;
448+ }
449+ return createSweepTransactionWasm ( network , walletKeys , unspents , targetAddress , feeRateSatVB , coinName ) ;
444450 } else {
445451 return createSweepTransactionUtxolib ( network , walletKeys , unspents , targetAddress , feeRateSatVB ) ;
446452 }
@@ -502,7 +508,8 @@ export async function recoverCrossChain<TNumber extends number | bigint = number
502508 walletUnspents ,
503509 params . recoveryAddress ,
504510 feeRateSatVB ,
505- backend
511+ backend ,
512+ params . sourceCoin . getChain ( ) as CoinName
506513 ) ;
507514
508515 // For unsigned recovery, return unsigned PSBT hex
0 commit comments