Skip to content

Commit b17eb7d

Browse files
committed
refactor(sdk-core): simplify signature cleanup logic in ensureCleanSigSharesAndSignTransaction
- Changed isFull detection to use AND logic with explicit array length checks - Made cleanup default for all Full TxRequests by removing isPartiallySigned conditional - Updated JSDoc to clarify that cleanup always happens for Full TxRequests Ticket: COIN-5989
1 parent 71b889c commit b17eb7d

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,8 +3568,9 @@ export class Wallet implements IWallet {
35683568

35693569
/**
35703570
* Ensures signature shares are in a clean state before signing a transaction.
3571-
* Automatically detects if a TxRequest is a partially signed Full TxRequest and deletes stale signatures.
3572-
* Use this for Express API and other integrations that need automatic cleanup of partial signatures.
3571+
* Automatically deletes signature shares for Full TxRequests before signing to prevent
3572+
* issues with stale or partial signatures.
3573+
* Use this for Express API and other integrations that need automatic cleanup of signatures.
35733574
*
35743575
* @param params - signing options
35753576
* @returns signed transaction
@@ -3582,26 +3583,13 @@ export class Wallet implements IWallet {
35823583
if (txRequestId && this.tssUtils && this.multisigType() === 'tss') {
35833584
const txRequest = await this.tssUtils.getTxRequest(txRequestId);
35843585

3585-
// Check if txRequest is Full (not Lite)
3586+
// Always clean signature shares for Full TxRequests before signing
35863587
const isFull =
3587-
txRequest.apiVersion === 'full' ||
3588-
(txRequest.transactions ?? []).length > 0 ||
3589-
(txRequest.messages ?? []).length > 0;
3588+
txRequest.apiVersion === 'full' &&
3589+
((txRequest.transactions ?? []).length > 0 || (txRequest.messages ?? []).length > 0);
35903590

35913591
if (isFull) {
3592-
// Check if there are any partial signature shares present
3593-
// Signature shares array is populated during signing and cleared when complete
3594-
let isPartiallySigned = false;
3595-
3596-
if (txRequest.transactions && txRequest.transactions.length > 0) {
3597-
isPartiallySigned = txRequest.transactions.some((tx) => (tx.signatureShares ?? []).length > 0);
3598-
} else if (txRequest.messages && txRequest.messages.length > 0) {
3599-
isPartiallySigned = txRequest.messages.some((msg) => (msg.signatureShares ?? []).length > 0);
3600-
}
3601-
3602-
if (isPartiallySigned) {
3603-
await this.tssUtils.deleteSignatureShares(txRequestId);
3604-
}
3592+
await this.tssUtils.deleteSignatureShares(txRequestId);
36053593
}
36063594
}
36073595

0 commit comments

Comments
 (0)