@@ -13,11 +13,12 @@ import {
1313 Triple ,
1414} from '@bitgo/sdk-core' ;
1515import { bitgo } from '@bitgo/utxo-lib' ;
16- import * as wasmUtxo from '@bitgo/wasm-utxo' ;
16+ import { fixedScriptWallet } from '@bitgo/wasm-utxo' ;
1717
1818import { getNetworkFromCoinName , UtxoCoinName } from '../names' ;
1919
20- type ScriptType2Of3 = bitgo . outputScripts . ScriptType2Of3 ;
20+ type ScriptType2Of3 = fixedScriptWallet . OutputScriptType ;
21+ type ChainCode = fixedScriptWallet . ChainCode ;
2122
2223export interface FixedScriptAddressCoinSpecific {
2324 outputScript ?: string ;
@@ -39,22 +40,21 @@ interface GenerateFixedScriptAddressOptions extends GenerateAddressOptions {
3940}
4041
4142function supportsAddressType ( coinName : UtxoCoinName , addressType : ScriptType2Of3 ) : boolean {
42- const network = getNetworkFromCoinName ( coinName ) ;
43- return bitgo . outputScripts . isSupportedScriptType ( network , addressType ) ;
43+ return fixedScriptWallet . supportsScriptType ( coinName , addressType ) ;
4444}
4545
4646export function generateAddressWithChainAndIndex (
4747 coinName : UtxoCoinName ,
48- keychains : bitgo . RootWalletKeys | Triple < string > ,
49- chain : bitgo . ChainCode ,
48+ keychains : fixedScriptWallet . RootWalletKeys | bitgo . RootWalletKeys | Triple < string > ,
49+ chain : ChainCode ,
5050 index : number ,
5151 format : CreateAddressFormat | undefined
5252) : string {
5353 // Convert CreateAddressFormat to AddressFormat for wasm-utxo
5454 // 'base58' -> 'default', 'cashaddr' -> 'cashaddr'
5555 const wasmFormat = format === 'base58' ? 'default' : format ;
5656 const network = getNetworkFromCoinName ( coinName ) ;
57- return wasmUtxo . fixedScriptWallet . address ( keychains , chain , index , network , wasmFormat ) ;
57+ return fixedScriptWallet . address ( keychains , chain , index , network , wasmFormat ) ;
5858}
5959
6060/**
@@ -77,14 +77,14 @@ export function generateAddress(coinName: UtxoCoinName, params: GenerateFixedScr
7777
7878 const { keychains, chain, segwit = false , bech32 = false } = params as GenerateFixedScriptAddressOptions ;
7979
80- let derivationChain = bitgo . getExternalChainCode ( 'p2sh' ) ;
81- if ( _ . isNumber ( chain ) && _ . isInteger ( chain ) && bitgo . isChainCode ( chain ) ) {
80+ let derivationChain : ChainCode = fixedScriptWallet . ChainCode . value ( 'p2sh' , 'external ') ;
81+ if ( _ . isNumber ( chain ) && _ . isInteger ( chain ) && fixedScriptWallet . ChainCode . is ( chain ) ) {
8282 derivationChain = chain ;
8383 }
8484
8585 function convertFlagsToAddressType ( ) : ScriptType2Of3 {
86- if ( bitgo . isChainCode ( chain ) ) {
87- return bitgo . scriptTypeForChain ( chain ) ;
86+ if ( fixedScriptWallet . ChainCode . is ( chain ) ) {
87+ return fixedScriptWallet . ChainCode . scriptType ( chain ) ;
8888 }
8989 if ( _ . isBoolean ( segwit ) && segwit ) {
9090 return 'p2shP2wsh' ;
@@ -97,7 +97,7 @@ export function generateAddress(coinName: UtxoCoinName, params: GenerateFixedScr
9797
9898 const addressType = params . addressType || convertFlagsToAddressType ( ) ;
9999
100- if ( addressType !== bitgo . scriptTypeForChain ( derivationChain ) ) {
100+ if ( addressType !== fixedScriptWallet . ChainCode . scriptType ( derivationChain ) ) {
101101 throw new AddressTypeChainMismatchError ( addressType , derivationChain ) ;
102102 }
103103
0 commit comments