1- import * as utxolib from '@bitgo/utxo-lib' ;
21import { BIP32Interface , bip32 } from '@bitgo/secp256k1' ;
3- import { CoinName , fixedScriptWallet } from '@bitgo/wasm-utxo' ;
2+ import { CoinName , fixedScriptWallet , address as wasmAddress } from '@bitgo/wasm-utxo' ;
43import { BitGoBase , IWallet , Keychain , Triple , Wallet } from '@bitgo/sdk-core' ;
54import { decrypt } from '@bitgo/sdk-api' ;
65
76import { AbstractUtxoCoin , TransactionInfo } from '../abstractUtxoCoin' ;
87import { signAndVerifyPsbt } from '../transaction/fixedScript/signTransaction' ;
9- import { getNetworkFromCoinName , UtxoCoinName } from '../names' ;
8+ import { UtxoCoinName } from '../names' ;
109import { encodeTransaction } from '../transaction/decode' ;
1110import { getReplayProtectionPubkeys } from '../transaction/fixedScript/replayProtection' ;
1211import { toTNumber } from '../tnumber' ;
13- import type { Unspent , WalletUnspent } from '../unspent' ;
12+ import { unspentSum , type Unspent , type WalletUnspent } from '../unspent' ;
1413
1514import { createEmptyWasmPsbt , addWalletInputsToWasmPsbt , addOutputToWasmPsbt , getRecoveryAmount } from './psbt' ;
1615
17- const { unspentSum } = utxolib . bitgo ;
18- type RootWalletKeys = utxolib . bitgo . RootWalletKeys ;
19-
2016export interface BuildRecoveryTransactionOptions {
2117 wallet : string ;
2218 faultyTxId : string ;
@@ -86,7 +82,7 @@ export async function getWallet(
8682export async function getWalletKeys (
8783 recoveryCoin : AbstractUtxoCoin ,
8884 wallet : IWallet | WalletV1
89- ) : Promise < RootWalletKeys > {
85+ ) : Promise < fixedScriptWallet . RootWalletKeys > {
9086 let xpubs : Triple < string > ;
9187
9288 if ( wallet instanceof Wallet ) {
@@ -99,7 +95,7 @@ export async function getWalletKeys(
9995 xpubs = ( wallet as WalletV1 ) . keychains . map ( ( k ) => k . xpub ) as Triple < string > ;
10096 }
10197
102- return new utxolib . bitgo . RootWalletKeys ( xpubs . map ( ( k ) => bip32 . fromBase58 ( k ) ) as Triple < BIP32Interface > ) ;
98+ return fixedScriptWallet . RootWalletKeys . from ( xpubs ) ;
10399}
104100
105101export async function isWalletAddress ( wallet : IWallet | WalletV1 , address : string ) : Promise < boolean > {
@@ -203,7 +199,7 @@ async function getAllRecoveryOutputs<TNumber extends number | bigint = number>(
203199 return {
204200 ...recoveryOutput ,
205201 address : coin . canonicalAddress ( recoveryOutput . address ) ,
206- value : utxolib . bitgo . toTNumber < TNumber > ( BigInt ( recoveryOutput . value ) , amountType ) ,
202+ value : toTNumber ( BigInt ( recoveryOutput . value ) , amountType ) as TNumber ,
207203 } ;
208204 } ) ;
209205}
@@ -216,8 +212,8 @@ type ScriptId = {
216212 index : number ;
217213} ;
218214
219- async function getScriptId ( coin : AbstractUtxoCoin , wallet : IWallet | WalletV1 , script : Buffer ) : Promise < ScriptId > {
220- const address = utxolib . address . fromOutputScript ( script , coin . network ) ;
215+ async function getScriptId ( coin : AbstractUtxoCoin , wallet : IWallet | WalletV1 , script : Uint8Array ) : Promise < ScriptId > {
216+ const address = wasmAddress . fromOutputScriptWithCoin ( script , coin . name ) ;
221217 let addressData : { chain : number ; index : number } ;
222218 if ( wallet instanceof Wallet ) {
223219 addressData = await wallet . getAddress ( { address } ) ;
@@ -253,7 +249,7 @@ async function toWalletUnspents<TNumber extends number | bigint = number>(
253249 for ( const address of addresses ) {
254250 let scriptId ;
255251 try {
256- scriptId = await getScriptId ( recoveryCoin , wallet , utxolib . address . toOutputScript ( address , sourceCoin . network ) ) ;
252+ scriptId = await getScriptId ( recoveryCoin , wallet , wasmAddress . toOutputScriptWithCoin ( address , sourceCoin . name ) ) ;
257253 } catch ( e ) {
258254 console . error ( `error getting scriptId for ${ address } :` , e ) ;
259255 continue ;
@@ -346,10 +342,7 @@ function createSweepTransaction<TNumber extends number | bigint = number>(
346342 targetAddress : string ,
347343 feeRateSatVB : number
348344) : fixedScriptWallet . BitGoPsbt {
349- const inputValue = unspentSum < bigint > (
350- unspents . map ( ( u ) => ( { ...u , value : BigInt ( u . value ) } ) ) ,
351- 'bigint'
352- ) ;
345+ const inputValue = unspentSum ( unspents ) ;
353346
354347 // Create PSBT with wasm-utxo and add wallet inputs using shared utilities
355348 const unspentsBigint = unspents . map ( ( u ) => ( { ...u , value : BigInt ( u . value ) } ) ) ;
0 commit comments