Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ describe('TSS Ecdsa Utils:', async function () {
backupNShare: backupKeyShare.nShares[1],
}),
reqId,
txParams: { recipients: [{ address: '0xrecipient', amount: '1000' }] },
});
signedTxRequest.unsignedTxs.should.deepEqual(txRequest.unsignedTxs);
const userGpgActual = sendShareSpy.getCalls()[0].args[10] as string;
Expand All @@ -764,12 +765,46 @@ describe('TSS Ecdsa Utils:', async function () {
backupNShare: backupKeyShare.nShares[1],
}),
reqId,
txParams: { recipients: [{ address: '0xrecipient', amount: '1000' }] },
});
signedTxRequest.unsignedTxs.should.deepEqual(txRequest.unsignedTxs);
const userGpgActual = sendShareSpy.getCalls()[0].args[10] as string;
userGpgActual.should.startWith('-----BEGIN PGP PUBLIC KEY BLOCK-----');
});

it('signTxRequest should fail when txParams is missing', async function () {
await tssUtils
.signTxRequest({
txRequest,
prv: JSON.stringify({
pShare: userKeyShare.pShare,
bitgoNShare: bitgoKeyShare.nShares[1],
backupNShare: backupKeyShare.nShares[1],
}),
reqId,
})
.should.be.rejectedWith(
'Recipient details are required to verify this transaction before signing. Pass txParams with at least one recipient.'
);
});

it('signTxRequest should fail when txParams has empty recipients', async function () {
await tssUtils
.signTxRequest({
txRequest,
prv: JSON.stringify({
pShare: userKeyShare.pShare,
bitgoNShare: bitgoKeyShare.nShares[1],
backupNShare: backupKeyShare.nShares[1],
}),
reqId,
txParams: { recipients: [] },
})
.should.be.rejectedWith(
'Recipient details are required to verify this transaction before signing. Pass txParams with at least one recipient.'
);
});

it('signTxRequest should fail with wrong recipient', async function () {
// To generate these Hex values, we used the bitgo-ui to create a transaction and then
// used the `signableHex` and `serializedTxHex` values from the prebuild.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ describe('signTxRequest:', function () {
txRequest,
prv: userPrvBase64,
reqId,
txParams: { recipients: [{ address: '0xrecipient', amount: '1000' }] },
});
nockPromises[0].isDone().should.be.true();
nockPromises[1].isDone().should.be.true();
Expand All @@ -215,6 +216,7 @@ describe('signTxRequest:', function () {
prv: backupPrvBase64,
mpcv2PartyId: 1,
reqId,
txParams: { recipients: [{ address: '0xrecipient', amount: '1000' }] },
});
nockPromises[0].isDone().should.be.true();
nockPromises[1].isDone().should.be.true();
Expand All @@ -236,6 +238,7 @@ describe('signTxRequest:', function () {
txRequest,
prv: userPrvBase64,
reqId,
txParams: { recipients: [{ address: '0xrecipient', amount: '1000' }] },
});
nockPromises[0].isDone().should.be.true();
nockPromises[1].isDone().should.be.true();
Expand All @@ -257,6 +260,7 @@ describe('signTxRequest:', function () {
txRequest,
prv: userPrvBase64,
reqId,
txParams: { recipients: [{ address: '0xrecipient', amount: '1000' }] },
});
nockPromises[0].isDone().should.be.true();
nockPromises[1].isDone().should.be.true();
Expand All @@ -277,11 +281,41 @@ describe('signTxRequest:', function () {
txRequest,
prv: userPrvBase64,
reqId,
txParams: { recipients: [{ address: '0xrecipient', amount: '1000' }] },
})
.should.be.rejectedWith('Too many requests, slow down!');
nockPromises[0].isDone().should.be.true();
nockPromises[1].isDone().should.be.false();
});

it('rejects signTxRequest when txParams is missing', async function () {
const userShare = fs.readFileSync(shareFiles[vector.party1]);
const userPrvBase64 = Buffer.from(userShare).toString('base64');
await tssUtils
.signTxRequest({
txRequest,
prv: userPrvBase64,
reqId,
})
.should.be.rejectedWith(
'Recipient details are required to verify this transaction before signing. Pass txParams with at least one recipient.'
);
});

it('rejects signTxRequest when txParams has empty recipients', async function () {
const userShare = fs.readFileSync(shareFiles[vector.party1]);
const userPrvBase64 = Buffer.from(userShare).toString('base64');
await tssUtils
.signTxRequest({
txRequest,
prv: userPrvBase64,
reqId,
txParams: { recipients: [] },
})
.should.be.rejectedWith(
'Recipient details are required to verify this transaction before signing. Pass txParams with at least one recipient.'
);
});
});

export function getBitGoPartyGpgKeyPrv(key: openpgp.SerializedKeyPair<string>): DklsTypes.PartyGpgKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ export class PendingApproval implements IPendingApproval {
}

const decryptedPrv = await this.wallet.getPrv({ walletPassphrase });
const txRequest = await this.tssUtils!.recreateTxRequest(txRequestId, decryptedPrv, reqId);
const pendingApprovalRecipients = this._pendingApproval.info?.transactionRequest?.recipients;
const txParams = pendingApprovalRecipients?.length ? { recipients: pendingApprovalRecipients } : undefined;
const txRequest = await this.tssUtils!.recreateTxRequest(txRequestId, decryptedPrv, reqId, txParams);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the behavior here if txParams is undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If txParams is undefined, recreateTxRequest still calls signTxRequest with txParams omitted. For ECDSA transaction signing, the SDK then throws error because recipients are required for verification—same guard as when callers omit txParams elsewhere. It’s only “optional” at the recreateTxRequest call site when the pending approval has no transactionRequest.recipients; downstream ECDSA tx signing rejects that instead of defaulting to empty recipients.

if (txRequest.apiVersion === 'lite') {
if (!txRequest.unsignedTxs || txRequest.unsignedTxs.length === 0) {
throw new Error('Unexpected error, no transactions found in txRequest.');
Expand Down
10 changes: 8 additions & 2 deletions modules/sdk-core/src/bitgo/utils/tss/baseTSSUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
TxRequest,
TxRequestVersion,
} from './baseTypes';
import { TransactionParams } from '../../baseCoin/iBaseCoin';
import { GShare, SignShare } from '../../../account-lib/mpc/tss';
import { RequestTracer } from '../util';
import { envRequiresBitgoPubGpgKeyConfig, getBitgoMpcGpgPubKey } from '../../tss/bitgoPubKeys';
Expand Down Expand Up @@ -533,11 +534,16 @@ export default class BaseTssUtils<KeyShare> extends MpcUtils implements ITssUtil
* @param {RequestTracer} reqId id tracer.
* @returns {Promise<any>}
*/
async recreateTxRequest(txRequestId: string, decryptedPrv: string, reqId: IRequestTracer): Promise<TxRequest> {
async recreateTxRequest(
txRequestId: string,
decryptedPrv: string,
reqId: IRequestTracer,
txParams?: TransactionParams
): Promise<TxRequest> {
await this.deleteSignatureShares(txRequestId, reqId);
// after delete signatures shares get the tx without them
const txRequest = await getTxRequest(this.bitgo, this.wallet.id(), txRequestId, reqId);
return await this.signTxRequest({ txRequest, prv: decryptedPrv, reqId });
return await this.signTxRequest({ txRequest, prv: decryptedPrv, reqId, txParams });
}

/**
Expand Down
7 changes: 6 additions & 1 deletion modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,12 @@ export interface ITssUtils<KeyShare = EDDSA.KeyShare> {
deleteSignatureShares(txRequestId: string): Promise<SignatureShareRecord[]>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sendTxRequest(txRequestId: string): Promise<any>;
recreateTxRequest(txRequestId: string, decryptedPrv: string, reqId: IRequestTracer): Promise<TxRequest>;
recreateTxRequest(
txRequestId: string,
decryptedPrv: string,
reqId: IRequestTracer,
txParams?: TransactionParams
): Promise<TxRequest>;
getTxRequest(txRequestId: string): Promise<TxRequest>;
supportedTxRequestVersions(): TxRequestVersion[];
}
11 changes: 9 additions & 2 deletions modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
} from '../../../tss/types';
import { BaseEcdsaUtils } from './base';
import { IRequestTracer } from '../../../../api';
import { InvalidTransactionError } from '../../../errors';

const encryptNShare = ECDSAMethods.encryptNShare;

Expand Down Expand Up @@ -745,21 +746,27 @@ export class EcdsaUtils extends BaseEcdsaUtils {
const unsignedTx =
txRequest.apiVersion === 'full' ? txRequest.transactions![0].unsignedTx : txRequest.unsignedTxs[0];

if (!params.txParams?.recipients?.length) {
throw new InvalidTransactionError(
'Recipient details are required to verify this transaction before signing. Pass txParams with at least one recipient.'
);
}

// For ICP transactions, the HSM signs the serializedTxHex, while the user signs the signableHex separately.
// Verification cannot be performed directly on the signableHex alone. However, we can parse the serializedTxHex
// to regenerate the signableHex and compare it against the provided value for verification.
// In contrast, for other coin families, verification is typically done using just the signableHex.
if (this.baseCoin.getConfig().family === 'icp') {
await this.baseCoin.verifyTransaction({
txPrebuild: { txHex: unsignedTx.serializedTxHex, txInfo: unsignedTx.signableHex },
txParams: params.txParams || { recipients: [] },
txParams: params.txParams,
wallet: this.wallet,
walletType: this.wallet.multisigType(),
});
} else {
await this.baseCoin.verifyTransaction({
txPrebuild: { txHex: unsignedTx.signableHex },
txParams: params.txParams || { recipients: [] },
txParams: params.txParams,
wallet: this.wallet,
walletType: this.wallet.multisigType(),
});
Expand Down
11 changes: 9 additions & 2 deletions modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsaMPCv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
verifyBitGoMessagesAndSignaturesRoundOne,
verifyBitGoMessagesAndSignaturesRoundTwo,
} from '../../../tss/ecdsa/ecdsaMPCv2';
import { InvalidTransactionError } from '../../../errors';
import { KeyCombined } from '../../../tss/ecdsa/types';
import { generateGPGKeyPair } from '../../opengpgUtils';
import {
Expand Down Expand Up @@ -736,21 +737,27 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils {
const unsignedTx =
txRequest.apiVersion === 'full' ? txRequest.transactions![0].unsignedTx : txRequest.unsignedTxs[0];

if (!params.txParams?.recipients?.length) {
throw new InvalidTransactionError(
'Recipient details are required to verify this transaction before signing. Pass txParams with at least one recipient.'
);
}
Comment on lines +740 to +744
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


// For ICP transactions, the HSM signs the serializedTxHex, while the user signs the signableHex separately.
// Verification cannot be performed directly on the signableHex alone. However, we can parse the serializedTxHex
// to regenerate the signableHex and compare it against the provided value for verification.
// In contrast, for other coin families, verification is typically done using just the signableHex.
if (this.baseCoin.getConfig().family === 'icp') {
await this.baseCoin.verifyTransaction({
txPrebuild: { txHex: unsignedTx.serializedTxHex, txInfo: unsignedTx.signableHex },
txParams: params.txParams || { recipients: [] },
txParams: params.txParams,
wallet: this.wallet,
walletType: this.wallet.multisigType(),
});
} else {
await this.baseCoin.verifyTransaction({
txPrebuild: { txHex: unsignedTx.signableHex },
txParams: params.txParams || { recipients: [] },
txParams: params.txParams,
wallet: this.wallet,
walletType: this.wallet.multisigType(),
});
Expand Down
Loading