Skip to content

Commit 01be344

Browse files
committed
fix(sdk-core): vss
Ticket: BG-61217
1 parent 41bec54 commit 01be344

7 files changed

Lines changed: 29 additions & 44 deletions

File tree

modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ describe('TSS Ecdsa Utils:', async function () {
199199
should.equal(backupToBitgoEncryptedNShare.publicShare, encryptedNShare.publicShare);
200200
});
201201

202-
// TODO BG-61214 renable VSS
203-
xit('should generate TSS key chains', async function () {
202+
it('should generate TSS key chains', async function () {
204203
const backupShareHolder: BackupKeyShare = {
205204
userHeldKeyShare: backupKeyShare,
206205
};
@@ -265,8 +264,7 @@ describe('TSS Ecdsa Utils:', async function () {
265264
backupKeychain.provider?.should.equal(backupProvider);
266265
});
267266

268-
// TODO BG-61214 renable VSS
269-
xit('should generate TSS key chains with optional params', async function () {
267+
it('should generate TSS key chains with optional params', async function () {
270268
const enterprise = 'enterprise';
271269
const backupShareHolder: BackupKeyShare = {
272270
userHeldKeyShare: backupKeyShare,
@@ -718,13 +716,15 @@ describe('TSS Ecdsa Utils:', async function () {
718716
publicShare: userToBitgoShare.publicShare,
719717
privateShare: userToBitgoShare.encryptedPrivateShare,
720718
n: userToBitgoShare.n,
719+
v: userToBitgoShare.v,
721720
},
722721
{
723722
from: 'bitgo',
724723
to: 'backup',
725724
publicShare: backupToBitgoShare.publicShare,
726725
privateShare: backupToBitgoShare.encryptedPrivateShare,
727726
n: backupToBitgoShare.n,
727+
v: backupToBitgoShare.v,
728728
},
729729
],
730730
};

modules/bitgo/test/v2/unit/tss/ecdsa.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@ describe('Ecdsa tss helper functions tests', function () {
8484
nock.cleanAll();
8585
});
8686

87-
// TODO BG-61214 renable VSS
88-
xit('should encrypt n shares foreach user', async function () {
89-
87+
it('should encrypt n shares foreach user', async function () {
9088
for (let i = 2; i <= 3; i++) {
9189
const encryptedNShare = await ECDSAMethods.encryptNShare(userKeyShare, i, bitgoGpgKeypair.publicKey);
9290
const decryptedNShare = await ECDSAMethods.decryptNShare({ nShare: encryptedNShare, senderPublicArmor: userGpgKeypair.publicKey, recipientPrivateArmor: bitgoGpgKeypair.privateKey });
9391
decryptedNShare.u.should.equal(userKeyShare.nShares[i].u);
94-
const publicKey = userKeyShare.pShare.y + userKeyShare.nShares[3].v + userKeyShare.pShare.chaincode;
92+
const publicKey = userKeyShare.pShare.y + userKeyShare.pShare.chaincode;
9593
encryptedNShare.i.should.equal(i);
94+
encryptedNShare.v!.should.equal(userKeyShare.nShares[3].v!);
9695
encryptedNShare.j.should.equal(1);
9796
encryptedNShare.publicShare.should.equal(publicKey);
9897
}
@@ -120,8 +119,7 @@ describe('Ecdsa tss helper functions tests', function () {
120119
nock.cleanAll();
121120
});
122121

123-
// TODO BG-58151 re-enable test
124-
xit('should create combined user key', async function () {
122+
it('should create combined user key', async function () {
125123
const bitgoToUserShare = await ECDSAMethods.encryptNShare(bitgoKeyShare, 1, userGpgKeypair.publicKey, false);
126124
const backupToUserShare = await ECDSAMethods.encryptNShare(backupKeyShare, 1, userGpgKeypair.publicKey, false);
127125
const combinedUserKey = await createCombinedKey(
@@ -148,8 +146,7 @@ describe('Ecdsa tss helper functions tests', function () {
148146
should.not.exist(combinedUserKey.signingMaterial.userNShare);
149147
});
150148

151-
// TODO BG-61214 renable VSS
152-
xit('should create combined backup key', async function () {
149+
it('should create combined backup key', async function () {
153150
const bitgoToBackupShare = await encryptNShare(
154151
bitgoKeyShare,
155152
2,
@@ -184,8 +181,7 @@ describe('Ecdsa tss helper functions tests', function () {
184181
should.not.exist(combinedBackupKey.signingMaterial.backupNShare);
185182
});
186183

187-
// TODO BG-58151 re-enable test
188-
xit('should fail if common keychains do not match', async function () {
184+
it('should fail if common keychains do not match', async function () {
189185
const bitgoToUserShare = await encryptNShare(
190186
bitgoKeyShare,
191187
1,
@@ -213,8 +209,7 @@ describe('Ecdsa tss helper functions tests', function () {
213209
).should.be.rejectedWith('Common keychains do not match');
214210
});
215211

216-
// TODO BG-58151 re-enable test
217-
xit('should fail if gpg keys are mismatched', async function () {
212+
it('should fail if gpg keys are mismatched', async function () {
218213
const bitgoToUserShare = await encryptNShare(
219214
bitgoKeyShare,
220215
1,

modules/sdk-core/src/account-lib/mpc/tss/ecdsa/ecdsa.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,16 @@ export default class Ecdsa {
108108
// Add secret shares
109109
const x = allShares.map((participant) => hexToBigInt(participant['u'])).reduce(Ecdsa.curve.scalarAdd);
110110

111-
// TODO BG-61214 renable VSS
112-
// // Verify shares.
113-
// for (const share of nShares) {
114-
// if ('v' in share) {
115-
// try {
116-
// Ecdsa.shamir.verify(hexToBigInt(share.u), [hexToBigInt(share.y), hexToBigInt(share.v!)], pShare.i);
117-
// } catch (err) {
118-
// throw new Error(`Could not verify share from participant ${share.j}. Verification error: ${err}`);
119-
// }
120-
// }
121-
// }
111+
// Verify shares.
112+
for (const share of nShares) {
113+
if (share.v) {
114+
try {
115+
Ecdsa.shamir.verify(hexToBigInt(share.u), [hexToBigInt(share.y), hexToBigInt(share.v!)], pShare.i);
116+
} catch (err) {
117+
throw new Error(`Could not verify share from participant ${share.j}. Verification error: ${err}`);
118+
}
119+
}
120+
}
122121

123122
// Chaincode will be used in future when we add support for key derivation for ecdsa
124123
const chaincodes = [pShare, ...nShares].map(({ chaincode }) => bigIntFromBufferBE(Buffer.from(chaincode, 'hex')));

modules/sdk-core/src/bitgo/keychain/iKeychains.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface ApiKeyShare {
7676
privateShare: string;
7777
privateShareProof?: string;
7878
n?: string;
79+
v?: string;
7980
}
8081

8182
export interface CreateBackupOptions {

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ export async function encryptNShare(
297297

298298
const publicShare = Buffer.concat([
299299
Buffer.from(keyShare.pShare.y, 'hex'),
300-
// TODO: BG-61214
301-
// Buffer.from(nShare.v!, 'hex'),
302300
Buffer.from(keyShare.pShare.chaincode, 'hex'),
303301
]).toString('hex');
302+
304303
let privateShare;
305304
if (isbs58Encoded) {
306305
privateShare = bip32.fromPrivateKey(Buffer.from(nShare.u, 'hex'), Buffer.from(nShare.chaincode, 'hex')).toBase58();
@@ -322,6 +321,7 @@ export async function encryptNShare(
322321
publicShare,
323322
encryptedPrivateShare,
324323
n: nShare.n,
324+
v: nShare.v,
325325
};
326326
}
327327

@@ -364,30 +364,16 @@ export async function decryptNShare(encryptedNShare: DecryptableNShare, isbs58En
364364
u = priv.slice(0, 64);
365365
}
366366

367-
// TODO BG-61214
368-
// let v, chaincode: string;
369-
// if (encryptedNShare.nShare.publicShare.length > 132) {
370-
// v = encryptedNShare.nShare.publicShare.slice(66, 132);
371-
// chaincode = encryptedNShare.nShare.publicShare.slice(132, 196);
372-
// } else {
373-
// chaincode = encryptedNShare.nShare.publicShare.slice(66, 132);
374-
// }
375-
376367
const nShare: NShare = {
377368
i: encryptedNShare.nShare.i,
378369
j: encryptedNShare.nShare.j,
379370
n: encryptedNShare.nShare.n,
380371
y: encryptedNShare.nShare.publicShare.slice(0, 66),
381372
u: u,
382-
// TODO BG-61214
383373
chaincode: encryptedNShare.nShare.publicShare.slice(66, 130),
374+
v: encryptedNShare.nShare.v,
384375
};
385376

386-
// TODO BG-61214
387-
// if (v) {
388-
// nShare.v = v;
389-
// }
390-
391377
return nShare;
392378
}
393379

modules/sdk-core/src/bitgo/tss/ecdsa/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type EncryptedNShare = {
3939
// signed and encrypted gpg armor
4040
encryptedPrivateShare: string;
4141
n: string;
42+
v?: string;
4243
};
4344

4445
// NShare with information needed to decrypt and verify a GPG mesasge

modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,15 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
281281
publicShare: userToBitgoShare.publicShare,
282282
privateShare: userToBitgoShare.encryptedPrivateShare,
283283
n: userToBitgoShare.n,
284+
v: userToBitgoShare.v,
284285
},
285286
{
286287
from: 'backup',
287288
to: 'bitgo',
288289
publicShare: backupToBitgoShare.publicShare,
289290
privateShare: backupToBitgoShare.encryptedPrivateShare,
290291
n: backupToBitgoShare.n,
292+
v: backupToBitgoShare.v,
291293
},
292294
],
293295
userGPGPublicKey: userGpgKey.publicKey,
@@ -465,6 +467,7 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
465467
publicShare: bitGoToRecipientShare.publicShare,
466468
encryptedPrivateShare: bitGoToRecipientShare.privateShare,
467469
n: bitGoToRecipientShare.n!,
470+
v: bitGoToRecipientShare.v,
468471
},
469472
recipientPrivateArmor: userGpgKey.privateKey,
470473
senderPublicArmor: bitgoPublicGpgKey.armor(),

0 commit comments

Comments
 (0)