@@ -2176,7 +2176,7 @@ export class Wallet implements IWallet {
2176
2176
}
2177
2177
2178
2178
// 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 ( {
2180
2180
reqId : params . reqId ,
2181
2181
walletPassphrase : params . walletPassphrase ,
2182
2182
customSigningFunction : params . customSigningFunction ,
@@ -2192,10 +2192,24 @@ export class Wallet implements IWallet {
2192
2192
} else {
2193
2193
txPrebuildQuery = params . prebuildTx ? Promise . resolve ( params . prebuildTx ) : this . prebuildTransaction ( params ) ;
2194
2194
}
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 !== null || ( 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
+ }
2199
2213
try {
2200
2214
await this . baseCoin . verifyTransaction ( {
2201
2215
txParams : { ...txPrebuild . buildParams , ...params } ,
0 commit comments