@@ -142,12 +142,11 @@ describe('Sign an arbitrary payload with trading account key', function () {
142142describe ( 'With the handler to sign an arbitrary payload in external signing mode' , ( ) => {
143143 let bitgo : BitGo ;
144144
145- const walletId = '61f039aad587c2000745c687373e0fa9 ' ;
146- const walletPassword = 'wDX058%c4plL1@pP ' ;
145+ const walletId = 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6 ' ;
146+ const walletPassword = 'test-wallet-passphrase ' ;
147147 const secret =
148148 'xprv9s21ZrQH143K3EuPWCBuqnWxydaQV6et9htQige4EswvcHKEzNmkVmwTwKoadyHzJYppuADB7Us7AbaNLToNvoFoSxuWqndQRYtnNy5DUY2' ;
149- const validPrv =
150- '{"61f039aad587c2000745c687373e0fa9":"{\\"iv\\":\\"+1u1Y9cvsYuRMeyH2slnXQ==\\",\\"v\\":1,\\"iter\\":10000,\\"ks\\":256,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"54kOXTqJ9mc=\\",\\"ct\\":\\"JF5wQ82wa1dYyFxFlbHCvK4a+A6MTHdhOqc5uXsz2icWhkY2Lin/3Ab8ZwvwDaR1JYKmC/g1gXIGwVZEOl1M/bRHY420h7sDtmTS6Ebse5NWbF0ItfUJlk6HVATGa+C6mkbaVxJ4kQW/ehnT3riqzU069ATPz8E=\\"}"}' ;
149+ let validPrv : string ;
151150
152151 const payload = {
153152 this : {
@@ -157,16 +156,20 @@ describe('With the handler to sign an arbitrary payload in external signing mode
157156 } ,
158157 } ;
159158
160- before ( ( ) => {
159+ before ( async ( ) => {
161160 bitgo = new BitGo ( { env : 'test' } ) ;
161+ const encryptedPrv = await bitgo . encrypt ( {
162+ password : walletPassword ,
163+ input : secret ,
164+ encryptionVersion : 1 ,
165+ } ) ;
166+ validPrv = JSON . stringify ( { [ walletId ] : encryptedPrv } ) ;
162167 } ) ;
163168
164169 it ( 'should return a payload signed with trading account key read from the local file system' , async ( ) => {
165170 const stubbedSignature = Buffer . from ( 'mysign' ) ;
166171 const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( validPrv ) ;
167- const envStub = sinon
168- . stub ( process , 'env' )
169- . value ( { WALLET_61f039aad587c2000745c687373e0fa9_PASSPHRASE : walletPassword } ) ;
172+ const envStub = sinon . stub ( process , 'env' ) . value ( { [ `WALLET_${ walletId } _PASSPHRASE` ] : walletPassword } ) ;
170173
171174 const signMessageStub = sinon . stub ( Coin . Ofc . prototype , 'signMessage' ) . resolves ( stubbedSignature ) ;
172175
@@ -248,9 +251,7 @@ describe('With the handler to sign an arbitrary payload in external signing mode
248251 it ( 'should prioritize request body passphrase over environment variable' , async ( ) => {
249252 const stubbedSignature = Buffer . from ( 'mysign' ) ;
250253 const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( validPrv ) ;
251- const envStub = sinon
252- . stub ( process , 'env' )
253- . value ( { WALLET_61f039aad587c2000745c687373e0fa9_PASSPHRASE : walletPassword } ) ;
254+ const envStub = sinon . stub ( process , 'env' ) . value ( { [ `WALLET_${ walletId } _PASSPHRASE` ] : walletPassword } ) ;
254255
255256 const signMessageStub = sinon . stub ( Coin . Ofc . prototype , 'signMessage' ) . resolves ( stubbedSignature ) ;
256257
@@ -290,7 +291,7 @@ describe('With the handler to sign an arbitrary payload in external signing mode
290291 } ) ;
291292
292293 describe ( 'With invalid setup' , ( ) => {
293- const invalidPrv = '{"61f039aad587c2000745c687373e0fa9":" invalid"}' ;
294+ const invalidPrv = JSON . stringify ( { [ walletId ] : ' invalid' } ) ;
294295
295296 it ( 'should throw an error with missing wallet passphrase in env' , async ( ) => {
296297 const req = {
@@ -306,14 +307,12 @@ describe('With the handler to sign an arbitrary payload in external signing mode
306307 } as unknown as ExpressApiRouteRequest < 'express.v2.ofc.extSignPayload' , 'post' > ;
307308
308309 await handleV2OFCSignPayloadInExtSigningMode ( req ) . should . be . rejectedWith (
309- ' Could not find wallet passphrase WALLET_61f039aad587c2000745c687373e0fa9_PASSPHRASE in environment'
310+ ` Could not find wallet passphrase WALLET_ ${ walletId } _PASSPHRASE in environment`
310311 ) ;
311312 } ) ;
312313
313314 it ( 'should throw an error with undefined signerFileSystemPath in env' , async ( ) => {
314- const envStub = sinon
315- . stub ( process , 'env' )
316- . value ( { WALLET_61f039aad587c2000745c687373e0fa9_PASSPHRASE : walletPassword } ) ;
315+ const envStub = sinon . stub ( process , 'env' ) . value ( { [ `WALLET_${ walletId } _PASSPHRASE` ] : walletPassword } ) ;
317316
318317 const req = {
319318 bitgo,
@@ -338,9 +337,7 @@ describe('With the handler to sign an arbitrary payload in external signing mode
338337
339338 it ( 'should throw error when trying to decrypt with invalid private key' , async ( ) => {
340339 const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( invalidPrv ) ;
341- const envStub = sinon
342- . stub ( process , 'env' )
343- . value ( { WALLET_61f039aad587c2000745c687373e0fa9_PASSPHRASE : walletPassword } ) ;
340+ const envStub = sinon . stub ( process , 'env' ) . value ( { [ `WALLET_${ walletId } _PASSPHRASE` ] : walletPassword } ) ;
344341
345342 const req = {
346343 bitgo,
@@ -367,9 +364,7 @@ describe('With the handler to sign an arbitrary payload in external signing mode
367364
368365 it ( 'should throw error when trying to decrypt with invalid wallet passphrase key' , async ( ) => {
369366 const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( validPrv ) ;
370- const envStub = sinon
371- . stub ( process , 'env' )
372- . value ( { WALLET_61f039aad587c2000745c687373e0fa9_PASSPHRASE : 'invalidPassphrase' } ) ;
367+ const envStub = sinon . stub ( process , 'env' ) . value ( { [ `WALLET_${ walletId } _PASSPHRASE` ] : 'invalidPassphrase' } ) ;
373368
374369 const req = {
375370 bitgo,
0 commit comments