Skip to content

Commit c829563

Browse files
committed
chore: parallellize keychain and queryPromise
Ticket: CAAS-7
1 parent f74eb46 commit c829563

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

modules/bitgo/test/v2/unit/wallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,12 @@ describe('V2 Wallet:', function () {
728728
customSigningFunction,
729729
});
730730
} catch (e) {
731-
e.message.should.not.equal(errorMessage);
731+
e.message.should.equal(errorMessage);
732732
}
733733
try {
734734
await ethWallet.sendMany({ ...sendManyParamsCorrectPassPhrase });
735735
} catch (e) {
736-
e.message.should.not.equal(errorMessage);
736+
e.message.should.equal(errorMessage);
737737
}
738738
nockKeychain.isDone().should.be.true();
739739
});

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ export class Wallet implements IWallet {
21762176
}
21772177

21782178
// Doing a sanity check for password here to avoid doing further work if we know it's wrong
2179-
const keychains = await this.getKeychainsAndValidatePassphrase({
2179+
const keychainPromise = this.getKeychainsAndValidatePassphrase({
21802180
reqId: params.reqId,
21812181
walletPassphrase: params.walletPassphrase,
21822182
customSigningFunction: params.customSigningFunction,
@@ -2192,10 +2192,24 @@ export class Wallet implements IWallet {
21922192
} else {
21932193
txPrebuildQuery = params.prebuildTx ? Promise.resolve(params.prebuildTx) : this.prebuildTransaction(params);
21942194
}
2195-
2196-
// the prebuild can be overridden by providing an explicit tx
2197-
const txPrebuild = (await txPrebuildQuery) as PrebuildTransactionResult;
2198-
2195+
let keychains: Keychain[];
2196+
let txPrebuild: PrebuildTransactionResult;
2197+
try {
2198+
[keychains, txPrebuild] = (await Promise.all([keychainPromise, txPrebuildQuery])) as [
2199+
Keychain[],
2200+
PrebuildTransactionResult
2201+
];
2202+
} catch (err) {
2203+
if (err || (err instanceof Error && err.message.includes('unable to decrypt keychain'))) {
2204+
const error: Error & { code?: string } = new Error(
2205+
`unable to decrypt keychain with the given wallet passphrase`
2206+
);
2207+
error.code = 'wallet_passphrase_incorrect';
2208+
throw error;
2209+
} else {
2210+
throw new Error(`Failed to process transaction: ${err.message}`);
2211+
}
2212+
}
21992213
try {
22002214
await this.baseCoin.verifyTransaction({
22012215
txParams: { ...txPrebuild.buildParams, ...params },

0 commit comments

Comments
 (0)