Skip to content

Commit

Permalink
Merge pull request #4406 from BitGo/WP-1665-pending-approval-txreques…
Browse files Browse the repository at this point in the history
…tlite-approval-flow

fix: pending approvals for txRequestLite should not use multiSig flow
  • Loading branch information
alebusse authored Apr 11, 2024
2 parents 721ce66 + 7802998 commit 16518bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
24 changes: 24 additions & 0 deletions modules/bitgo/test/v2/unit/pendingApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@ describe('Pending Approvals:', () => {
scope.done();
});

it('should approve for transactionRequestLite if we cannot recreate transaction', async () => {
const pendingApprovalData2 = { ...pendingApprovalData, txRequestId: '1234-4567-6789' };
const pendingApproval = new PendingApproval(bitgo, basecoin, pendingApprovalData2, wallet);

const paScope = nock(bgUrl)
.put(`/api/v2/${coin}/pendingapprovals/${pendingApprovalData.id}`, {
state: 'approved',
otp: undefined,
})
.reply(200, {
...pendingApprovalData2,
state: 'approved',
});
const recreateTransactionTssStub = sandbox.stub(PendingApproval.prototype, 'recreateAndSignTSSTransaction');
const recreateTransactionStub = sandbox.stub(PendingApproval.prototype, 'recreateAndSignTransaction');

pendingApproval.type().should.equal(Type.TRANSACTION_REQUEST);
await pendingApproval.approve({});
recreateTransactionTssStub.notCalled.should.be.true();
recreateTransactionStub.notCalled.should.be.true();

paScope.isDone().should.be.true();
});

function testRecreateTransaction(coinName: string, recreateTransaction: boolean, type: Type) {
it(`[${coinName}] should ${
recreateTransaction ? 'not ' : ''
Expand Down
14 changes: 9 additions & 5 deletions modules/sdk-core/src/bitgo/pendingApproval/pendingApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,17 @@ export class PendingApproval implements IPendingApproval {
};
}

const transaction = _.get(
this.info(),
`transactionRequest.coinSpecific.${this.baseCoin.type}`
) as PreApproveResult;

// this user may not have spending privileges or a passphrase may not have been passed in
if (!this.canRecreateTransaction(params)) {
// If this is a TransactionRequest, then the txRequest already has the unsigned transaction
if (this._pendingApproval.txRequestId) {
return undefined;
}
// If this is a MultiSig, then we need to fetch the half signed tx to propagate to the approval API
const transaction = _.get(
this.info(),
`transactionRequest.coinSpecific.${this.baseCoin.type}`
) as PreApproveResult;
if (!_.isObject(transaction)) {
throw new Error('there is neither an original transaction object nor can a new one be recreated');
}
Expand Down

0 comments on commit 16518bb

Please sign in to comment.