-
Notifications
You must be signed in to change notification settings - Fork 306
fix(sdk-core): return clear 401 for wrong wallet passphrase #9365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shubham-damkondwar
wants to merge
1
commit into
master
Choose a base branch
from
COINS-1257
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * @prettier | ||
| */ | ||
| import * as assert from 'assert'; | ||
| import { retryPromise } from '../../src/retryPromise'; | ||
|
|
||
| describe('retryPromise', function () { | ||
| it('rethrows the original non-ECONNREFUSED error without wrapping', async function () { | ||
| const original = Object.assign(new Error('Internal Server Error'), { status: 500 }); | ||
| await assert.rejects( | ||
| () => | ||
| retryPromise( | ||
| async () => { | ||
| throw original; | ||
| }, | ||
| () => undefined, | ||
| { retryLimit: 1 } | ||
| ), | ||
| (err: Error) => err === original | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2562,7 +2562,7 @@ export class Wallet implements IWallet { | |
| } | ||
| userPrv = await decryptKeychainPrivateKey(this.bitgo, userKeychain, params.walletPassphrase); | ||
| if (!userPrv) { | ||
| throw new Error('failed to decrypt user keychain'); | ||
| throw new IncorrectPasswordError(); | ||
| } | ||
| } | ||
| return userPrv; | ||
|
|
@@ -4812,18 +4812,13 @@ export class Wallet implements IWallet { | |
| const reqId = params.reqId || undefined; | ||
| await this.tssUtils.deleteSignatureShares(txRequestId, reqId); | ||
|
|
||
| try { | ||
| const signedTxRequest = await this.tssUtils.signEddsaTssUsingExternalSigner( | ||
| txRequestId, | ||
| params.customCommitmentGeneratingFunction, | ||
| params.customRShareGeneratingFunction, | ||
| params.customGShareGeneratingFunction, | ||
| reqId | ||
| ); | ||
| return signedTxRequest; | ||
| } catch (e) { | ||
| throw new Error('failed to sign transaction ' + e); | ||
| } | ||
| return this.tssUtils.signEddsaTssUsingExternalSigner( | ||
| txRequestId, | ||
| params.customCommitmentGeneratingFunction, | ||
| params.customRShareGeneratingFunction, | ||
| params.customGShareGeneratingFunction, | ||
| reqId | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -4919,23 +4914,18 @@ export class Wallet implements IWallet { | |
| throw new Error('Generator function for S share required to sign transactions with External Signer.'); | ||
| } | ||
|
|
||
| try { | ||
| assert(this.tssUtils, 'tssUtils must be defined'); | ||
| const signedTxRequest = await this.tssUtils.signEcdsaTssUsingExternalSigner( | ||
| { | ||
| txRequest: txRequestId, | ||
| reqId: params.reqId || new RequestTracer(), | ||
| }, | ||
| RequestType.tx, | ||
| params.customPaillierModulusGeneratingFunction, | ||
| params.customKShareGeneratingFunction, | ||
| params.customMuDeltaShareGeneratingFunction, | ||
| params.customSShareGeneratingFunction | ||
| ); | ||
| return signedTxRequest; | ||
| } catch (e) { | ||
| throw new Error('failed to sign transaction ' + e); | ||
| } | ||
| assert(this.tssUtils, 'tssUtils must be defined'); | ||
| return this.tssUtils.signEcdsaTssUsingExternalSigner( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| { | ||
| txRequest: txRequestId, | ||
| reqId: params.reqId || new RequestTracer(), | ||
| }, | ||
| RequestType.tx, | ||
| params.customPaillierModulusGeneratingFunction, | ||
| params.customKShareGeneratingFunction, | ||
| params.customMuDeltaShareGeneratingFunction, | ||
| params.customSShareGeneratingFunction | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -4974,21 +4964,16 @@ export class Wallet implements IWallet { | |
| ); | ||
| } | ||
|
|
||
| try { | ||
| assert(this.tssUtils, 'tssUtils must be defined'); | ||
| const signedTxRequest = await this.tssUtils.signEddsaMPCv2TssUsingExternalSigner( | ||
| { | ||
| txRequest: txRequestId, | ||
| reqId: params.reqId || new RequestTracer(), | ||
| }, | ||
| params.customEddsaMPCv2SigningRound1GenerationFunction, | ||
| params.customEddsaMPCv2SigningRound2GenerationFunction, | ||
| params.customEddsaMPCv2SigningRound3GenerationFunction | ||
| ); | ||
| return signedTxRequest; | ||
| } catch (e) { | ||
| throw new Error('failed to sign transaction ' + e); | ||
| } | ||
| assert(this.tssUtils, 'tssUtils must be defined'); | ||
| return this.tssUtils.signEddsaMPCv2TssUsingExternalSigner( | ||
| { | ||
| txRequest: txRequestId, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| reqId: params.reqId || new RequestTracer(), | ||
| }, | ||
| params.customEddsaMPCv2SigningRound1GenerationFunction, | ||
| params.customEddsaMPCv2SigningRound2GenerationFunction, | ||
| params.customEddsaMPCv2SigningRound3GenerationFunction | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -5021,21 +5006,16 @@ export class Wallet implements IWallet { | |
| throw new Error('Generator function for MPCv2 Round 3 share required to sign transactions with External Signer.'); | ||
| } | ||
|
|
||
| try { | ||
| assert(this.tssUtils, 'tssUtils must be defined'); | ||
| const signedTxRequest = await this.tssUtils.signEcdsaMPCv2TssUsingExternalSigner( | ||
| { | ||
| txRequest: txRequestId, | ||
| reqId: params.reqId || new RequestTracer(), | ||
| }, | ||
| params.customMPCv2SigningRound1GenerationFunction, | ||
| params.customMPCv2SigningRound2GenerationFunction, | ||
| params.customMPCv2SigningRound3GenerationFunction | ||
| ); | ||
| return signedTxRequest; | ||
| } catch (e) { | ||
| throw new Error('failed to sign transaction ' + e); | ||
| } | ||
| assert(this.tssUtils, 'tssUtils must be defined'); | ||
| return this.tssUtils.signEcdsaMPCv2TssUsingExternalSigner( | ||
| { | ||
| txRequest: txRequestId, | ||
| reqId: params.reqId || new RequestTracer(), | ||
| }, | ||
| params.customMPCv2SigningRound1GenerationFunction, | ||
| params.customMPCv2SigningRound2GenerationFunction, | ||
| params.customMPCv2SigningRound3GenerationFunction | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -5056,33 +5036,29 @@ export class Wallet implements IWallet { | |
| throw new Error('prv required to sign transactions with TSS'); | ||
| } | ||
|
|
||
| try { | ||
| let txRequest: string | TxRequest = params.txPrebuild.txRequestId; | ||
| let txParams: TransactionParams | undefined = params.txPrebuild.buildParams; | ||
|
|
||
| // EdDSA MPCv2 re-sign path: buildParams is absent when the UI calls signAndSendTxRequest with | ||
| // only txRequestId. Derive txParams from the persisted intent so verifyTransaction receives | ||
| // the correct recipients before DSG starts. Other TSS variants are unaffected by the guard. | ||
| if (!txParams && this.multisigTypeVersion() === 'MPCv2' && this.baseCoin.getMPCAlgorithm() === 'eddsa') { | ||
| txRequest = await getTxRequest( | ||
| this.bitgo, | ||
| this.id(), | ||
| params.txPrebuild.txRequestId, | ||
| params.reqId || new RequestTracer() | ||
| ); | ||
| txParams = txParamsFromIntent(txRequest.intent, this.baseCoin.getChain()); | ||
| } | ||
| let txRequest: string | TxRequest = params.txPrebuild.txRequestId; | ||
| let txParams: TransactionParams | undefined = params.txPrebuild.buildParams; | ||
|
|
||
| return await this.tssUtils!.signTxRequest({ | ||
| txRequest, | ||
| txParams, | ||
| prv: params.prv, | ||
| reqId: params.reqId || new RequestTracer(), | ||
| apiVersion: params.apiVersion, | ||
| }); | ||
| } catch (e) { | ||
| throw new Error('failed to sign transaction ' + e); | ||
| // EdDSA MPCv2 re-sign path: buildParams is absent when the UI calls signAndSendTxRequest with | ||
| // only txRequestId. Derive txParams from the persisted intent so verifyTransaction receives | ||
| // the correct recipients before DSG starts. Other TSS variants are unaffected by the guard. | ||
| if (!txParams && this.multisigTypeVersion() === 'MPCv2' && this.baseCoin.getMPCAlgorithm() === 'eddsa') { | ||
| txRequest = await getTxRequest( | ||
| this.bitgo, | ||
| this.id(), | ||
| params.txPrebuild.txRequestId, | ||
| params.reqId || new RequestTracer() | ||
| ); | ||
| txParams = txParamsFromIntent(txRequest.intent, this.baseCoin.getChain()); | ||
| } | ||
|
|
||
| return this.tssUtils!.signTxRequest({ | ||
| txRequest, | ||
| txParams, | ||
| prv: params.prv, | ||
| reqId: params.reqId || new RequestTracer(), | ||
| apiVersion: params.apiVersion, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -5383,11 +5359,7 @@ export class Wallet implements IWallet { | |
| // which means that the user is handling the signing in external signing mode | ||
| if (!customSigningFunction && keychains?.[0]?.encryptedPrv && walletPassphrase) { | ||
| if (!(await decryptKeychainPrivateKey(this.bitgo, keychains[0], walletPassphrase))) { | ||
| const error: Error & { code?: string } = new Error( | ||
| `unable to decrypt keychain with the given wallet passphrase` | ||
| ); | ||
| error.code = 'wallet_passphrase_incorrect'; | ||
| throw error; | ||
| throw new IncorrectPasswordError(); | ||
| } | ||
| } | ||
| return keychains; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be changing the error log for other cases as well