Skip to content

Commit 6d014c2

Browse files
committed
fix(sdk-core): pass round to getBitgoSignatureShare helper
Ticket: WCI-626 EdDSA MPCv2 signing can receive multiple BitGo-to-signer shares in a txRequest. Selecting only by sender/recipient can pick a stale round-1 output during round 2. - Add shareType param to getBitgoSignatureShare to filter by round output type. - Update EdDSA MPCv2 callers to request round-1 or round-2 output explicitly. - Remove inline reverse().find() in offline round-3 path in favour of the helper. - Update tests to expect round-specific missing share error messages.
1 parent bbe7ebb commit 6d014c2

3 files changed

Lines changed: 14 additions & 20 deletions

File tree

modules/sdk-core/src/bitgo/tss/common.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from 'assert';
22
import openpgp from 'openpgp';
33

4+
import { MPCv2SigningState } from '@bitgo/public-types';
45
import { BitGoBase } from '../bitgoBase';
56
import { TxRequestChallengeResponse } from './types';
67
import {
@@ -20,12 +21,16 @@ const debug = require('debug')('bitgo:tss:common');
2021

2122
export function getBitgoSignatureShare(
2223
signatureShares: SignatureShareRecord[],
23-
signerShareType: SignatureShareType
24+
signerShareType: SignatureShareType,
25+
shareType: MPCv2SigningState
2426
): SignatureShareRecord {
2527
const bitgoShare = signatureShares.find(
26-
(share) => share.from === SignatureShareType.BITGO && share.to === signerShareType
28+
(share) =>
29+
share.from === SignatureShareType.BITGO &&
30+
share.to === signerShareType &&
31+
JSON.parse(share.share).type === shareType
2732
);
28-
assert(bitgoShare, 'Missing BitGo signature share');
33+
assert(bitgoShare, `Missing BitGo ${shareType} signature share`);
2934
return bitgoShare;
3035
}
3136

modules/sdk-core/src/bitgo/utils/tss/eddsa/eddsaMPCv2.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
469469
? latestTxRequest.transactions![0].signatureShares
470470
: latestTxRequest.messages![0].signatureShares;
471471

472-
const bitgoShareRoundOne = getBitgoSignatureShare(signatureShares1, signerShareType);
472+
const bitgoShareRoundOne = getBitgoSignatureShare(signatureShares1, signerShareType, 'round1Output');
473473
const parsedBitGoToUserSigShareRoundOne = decodeWithCodec(
474474
EddsaMPCv2SignatureShareRound1Output,
475475
JSON.parse(bitgoShareRoundOne.share),
@@ -508,7 +508,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
508508
? latestTxRequest.transactions![0].signatureShares
509509
: latestTxRequest.messages![0].signatureShares;
510510

511-
const bitgoShareRoundTwo = getBitgoSignatureShare(txRequestSignatureShares, signerShareType);
511+
const bitgoShareRoundTwo = getBitgoSignatureShare(txRequestSignatureShares, signerShareType, 'round2Output');
512512
const parsedBitGoToUserSigShareRoundTwo = decodeWithCodec(
513513
EddsaMPCv2SignatureShareRound2Output,
514514
JSON.parse(bitgoShareRoundTwo.share),
@@ -649,7 +649,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
649649
const signatureShares = transactions[0].signatureShares;
650650
assert(signatureShares, 'Missing signature shares in round 1 txRequest');
651651

652-
const bitgoShareRoundOne = getBitgoSignatureShare(signatureShares, SignatureShareType.USER);
652+
const bitgoShareRoundOne = getBitgoSignatureShare(signatureShares, SignatureShareType.USER, 'round1Output');
653653
const parsedBitGoToUserSigShareRoundOne = decodeWithCodec(
654654
EddsaMPCv2SignatureShareRound1Output,
655655
JSON.parse(bitgoShareRoundOne.share),
@@ -754,18 +754,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
754754
const signatureShares = transactions[0].signatureShares;
755755
assert(signatureShares, 'Missing signature shares in round 2 txRequest');
756756

757-
const bitgoShareRoundTwo = [...signatureShares].reverse().find((share) => {
758-
if (share.from !== SignatureShareType.BITGO || share.to !== SignatureShareType.USER) {
759-
return false;
760-
}
761-
762-
try {
763-
return JSON.parse(share.share).type === 'round2Output';
764-
} catch {
765-
return false;
766-
}
767-
});
768-
assert(bitgoShareRoundTwo, 'Missing BitGo round 2 signature share');
757+
const bitgoShareRoundTwo = getBitgoSignatureShare(signatureShares, SignatureShareType.USER, 'round2Output');
769758

770759
const parsedBitGoToUserSigShareRoundTwo = decodeWithCodec(
771760
EddsaMPCv2SignatureShareRound2Output,

modules/sdk-core/test/unit/bitgo/utils/tss/eddsa/eddsaMPCv2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ describe('EddsaMPCv2Utils.createOfflineRound2Share', () => {
799799
encryptedUserGpgPrvKey: round1.encryptedUserGpgPrvKey,
800800
encryptedRound1Session: round1.encryptedRound1Session,
801801
}),
802-
/Missing BitGo signature share/
802+
/Missing BitGo round1Output signature share/
803803
);
804804
});
805805

@@ -1114,7 +1114,7 @@ describe('EddsaMPCv2Utils.createOfflineRound3Share', () => {
11141114
encryptedUserGpgPrvKey: round1.encryptedUserGpgPrvKey,
11151115
encryptedRound2Session: round2.encryptedRound2Session,
11161116
}),
1117-
/Missing BitGo round 2 signature share/
1117+
/Missing BitGo round2Output signature share/
11181118
);
11191119
});
11201120

0 commit comments

Comments
 (0)