@@ -5,10 +5,10 @@ import { btcBackupKey } from './fixtures';
55import { type TestBitGoAPI , TestBitGo } from '@bitgo/sdk-test' ;
66
77import { Tbtc } from '../../src' ;
8- import { BitGoAPI } from '@bitgo/sdk-api' ;
8+ import { BitGoAPI , encrypt } from '@bitgo/sdk-api' ;
99import * as utxolib from '@bitgo/utxo-lib' ;
1010
11- const { getDefaultWalletKeys , toKeychainObjects } = require ( '../../../ bitgo/test/v2/unit/coins/utxo/util/keychains' ) ;
11+ import { Wallet } from '@ bitgo/sdk-core' ;
1212
1313describe ( 'BTC:' , ( ) => {
1414 let bitgo : TestBitGoAPI ;
@@ -120,14 +120,14 @@ describe('BTC:', () => {
120120 } ) ;
121121
122122 it ( 'should detect hex spoofing in BUILD_SIGN_SEND' , async ( ) : Promise < void > => {
123- const rootWalletKey = getDefaultWalletKeys ( ) ;
124- const keysObj = toKeychainObjects ( rootWalletKey , 'pass' ) ;
123+ const keyTriple = utxolib . testutil . getKeyTriple ( 'default' ) ;
124+ const rootWalletKey = new utxolib . bitgo . RootWalletKeys ( keyTriple ) ;
125+ const [ user ] = keyTriple ;
125126
126- const { Wallet } = await import ( '@bitgo/sdk-core' ) ;
127127 const wallet = new Wallet ( bitgoTest , coin , {
128128 id : '5b34252f1bf349930e34020a' ,
129129 coin : 'tbtc' ,
130- keys : keysObj . map ( ( k ) => k . id ) ,
130+ keys : [ 'user' , 'backup' , 'bitgo' ] ,
131131 } ) ;
132132
133133 const originalPsbt = utxolib . testutil . constructPsbt (
@@ -138,7 +138,6 @@ describe('BTC:', () => {
138138 'unsigned' as const
139139 ) ;
140140 utxolib . bitgo . addXpubsToPsbt ( originalPsbt , rootWalletKey ) ;
141-
142141 const spoofedPsbt = utxolib . testutil . constructPsbt (
143142 [ { scriptType : 'p2wsh' as const , value : BigInt ( 10000 ) } ] ,
144143 [ { address : 'tb1pjgg9ty3s2ztp60v6lhgrw76f7hxydzuk9t9mjsndh3p2gf2ah7gs4850kn' , value : BigInt ( 9000 ) } ] ,
@@ -165,7 +164,15 @@ describe('BTC:', () => {
165164 return [ 200 , { txid : 'test-txid-123' , status : 'signed' } ] ;
166165 } ) ;
167166
168- keysObj . forEach ( ( k , i ) => nock ( bgUrl ) . get ( `/api/v2/${ wallet . coin ( ) } /key/${ wallet . keyIds ( ) [ i ] } ` ) . reply ( 200 , k ) ) ;
167+ const pubs = keyTriple . map ( ( k ) => k . neutered ( ) . toBase58 ( ) ) ;
168+ const responses = [
169+ { pub : pubs [ 0 ] , encryptedPrv : encrypt ( 'pass' , user . toBase58 ( ) ) } ,
170+ { pub : pubs [ 1 ] } ,
171+ { pub : pubs [ 2 ] } ,
172+ ] ;
173+ wallet
174+ . keyIds ( )
175+ . forEach ( ( id , i ) => nock ( bgUrl ) . get ( `/api/v2/${ wallet . coin ( ) } /key/${ id } ` ) . reply ( 200 , responses [ i ] ) ) ;
169176
170177 await assert . rejects (
171178 wallet . consolidateUnspents ( { walletPassphrase : 'pass' } ) ,
@@ -187,14 +194,14 @@ describe('BTC:', () => {
187194 } ) ;
188195
189196 it ( 'should detect hex spoofing in fanout BUILD_SIGN_SEND' , async ( ) : Promise < void > => {
190- const rootWalletKey = getDefaultWalletKeys ( ) ;
191- const keysObj = toKeychainObjects ( rootWalletKey , 'pass' ) ;
197+ const keyTriple = utxolib . testutil . getKeyTriple ( 'default' ) ;
198+ const rootWalletKey = new utxolib . bitgo . RootWalletKeys ( keyTriple ) ;
199+ const [ user ] = keyTriple ;
192200
193- const { Wallet } = await import ( '@bitgo/sdk-core' ) ;
194201 const wallet = new Wallet ( bitgoTest , coin , {
195202 id : '5b34252f1bf349930e34020a' ,
196203 coin : 'tbtc' ,
197- keys : keysObj . map ( ( k ) => k . id ) ,
204+ keys : [ 'user' , 'backup' , 'bitgo' ] ,
198205 } ) ;
199206
200207 const originalPsbt = utxolib . testutil . constructPsbt (
@@ -232,7 +239,15 @@ describe('BTC:', () => {
232239 return [ 200 , { txid : 'test-txid-123' , status : 'signed' } ] ;
233240 } ) ;
234241
235- keysObj . forEach ( ( k , i ) => nock ( bgUrl ) . get ( `/api/v2/${ wallet . coin ( ) } /key/${ wallet . keyIds ( ) [ i ] } ` ) . reply ( 200 , k ) ) ;
242+ const pubs = keyTriple . map ( ( k ) => k . neutered ( ) . toBase58 ( ) ) ;
243+ const responses = [
244+ { pub : pubs [ 0 ] , encryptedPrv : encrypt ( 'pass' , user . toBase58 ( ) ) } ,
245+ { pub : pubs [ 1 ] } ,
246+ { pub : pubs [ 2 ] } ,
247+ ] ;
248+ wallet
249+ . keyIds ( )
250+ . forEach ( ( id , i ) => nock ( bgUrl ) . get ( `/api/v2/${ wallet . coin ( ) } /key/${ id } ` ) . reply ( 200 , responses [ i ] ) ) ;
236251
237252 await assert . rejects (
238253 wallet . fanoutUnspents ( { walletPassphrase : 'pass' } ) ,
0 commit comments