Skip to content

Commit edaf926

Browse files
pranavjain97claude
andcommitted
test(bitgo): add e2e tests for v2 encryption in DKLS and EdDSA keygen
WCN-32: Verify that createKeychains with encryptionVersion: 2 produces v2 envelopes for encryptedPrv/reducedEncryptedPrv and that they are decryptable via decryptAsync. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 887f22d commit edaf926

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

modules/bitgo/test/v2/unit/internal/tssUtils/ecdsaMPCv2/createKeychains.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,55 @@ describe('TSS Ecdsa MPCv2 Utils:', async function () {
176176
assert.equal(bitgoKeychain.source, 'bitgo');
177177
});
178178

179+
it('should generate TSS MPCv2 keys with v2 encryption envelopes', async function () {
180+
const bitgoSession = new DklsDkg.Dkg(3, 2, 2);
181+
182+
const round1Nock = await nockKeyGenRound1(bitgoSession, 1);
183+
const round2Nock = await nockKeyGenRound2(bitgoSession, 1);
184+
const round3Nock = await nockKeyGenRound3(bitgoSession, 1);
185+
const addKeyNock = await nockAddKeyChain(coinName, 3);
186+
const params = {
187+
passphrase: 'test',
188+
enterprise: enterpriseId,
189+
originalPasscodeEncryptionCode: '123456',
190+
encryptionVersion: 2 as const,
191+
};
192+
const { userKeychain, backupKeychain, bitgoKeychain } = await tssUtils.createKeychains(params);
193+
assert.ok(round1Nock.isDone());
194+
assert.ok(round2Nock.isDone());
195+
assert.ok(round3Nock.isDone());
196+
assert.ok(addKeyNock.isDone());
197+
198+
assert.ok(userKeychain);
199+
assert.equal(userKeychain.source, 'user');
200+
assert.ok(userKeychain.commonKeychain);
201+
assert.ok(ECDSAUtils.EcdsaMPCv2Utils.validateCommonKeychainPublicKey(userKeychain.commonKeychain));
202+
203+
// Verify v2 envelopes for encryptedPrv
204+
assert.ok(userKeychain.encryptedPrv);
205+
const encryptedPrvParsed: { v: number } = JSON.parse(userKeychain.encryptedPrv);
206+
assert.equal(encryptedPrvParsed.v, 2, 'encryptedPrv should be a v2 envelope');
207+
208+
// Verify v2 envelopes for reducedEncryptedPrv
209+
assert.ok(userKeychain.reducedEncryptedPrv);
210+
const reducedEncryptedPrvParsed: { v: number } = JSON.parse(userKeychain.reducedEncryptedPrv);
211+
assert.equal(reducedEncryptedPrvParsed.v, 2, 'reducedEncryptedPrv should be a v2 envelope');
212+
213+
// Verify v2 envelope is decryptable via decryptAsync
214+
const decrypted = await bitgo.decryptAsync({ input: userKeychain.encryptedPrv, password: params.passphrase });
215+
assert.ok(decrypted, 'decryptAsync should successfully decrypt v2 envelope');
216+
217+
// Verify backup keychain also uses v2 envelopes
218+
assert.ok(backupKeychain);
219+
assert.equal(backupKeychain.source, 'backup');
220+
assert.ok(backupKeychain.encryptedPrv);
221+
const backupEncryptedPrvParsed: { v: number } = JSON.parse(backupKeychain.encryptedPrv);
222+
assert.equal(backupEncryptedPrvParsed.v, 2, 'backup encryptedPrv should be a v2 envelope');
223+
224+
assert.ok(bitgoKeychain);
225+
assert.equal(bitgoKeychain.source, 'bitgo');
226+
});
227+
179228
it('should generate TSS MPCv2 keys for retrofit', async function () {
180229
const xiList = [
181230
Array.from(bigIntToBufferBE(BigInt(1), 32)),

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,49 @@ describe('TSS Utils:', async function () {
546546
})
547547
.should.be.rejectedWith('Failed to create backup keychain - commonKeychains do not match.');
548548
});
549+
550+
it('should generate TSS key chains with v2 encryption envelopes', async function () {
551+
const passphrase = 'passphrase';
552+
const userKeyShare = MPC.keyShare(1, 2, 3);
553+
const backupKeyShare = MPC.keyShare(2, 2, 3);
554+
555+
await nockBitgoKeychain({
556+
coin: coinName,
557+
userKeyShare,
558+
backupKeyShare,
559+
bitgoKeyShare,
560+
userGpgKey,
561+
backupGpgKey,
562+
bitgoGpgKey,
563+
});
564+
await nockUserKeychain({ coin: coinName });
565+
await nockBackupKeychain({ coin: coinName });
566+
567+
const bitgoKeychain = await tssUtils.createBitgoKeychain({
568+
userGpgKey,
569+
backupGpgKey,
570+
userKeyShare,
571+
backupKeyShare,
572+
});
573+
const userKeychain = await tssUtils.createUserKeychain({
574+
userGpgKey,
575+
backupGpgKey,
576+
userKeyShare,
577+
backupKeyShare,
578+
bitgoKeychain,
579+
passphrase,
580+
encryptionVersion: 2,
581+
});
582+
583+
should.exist(userKeychain.encryptedPrv);
584+
const envelope = JSON.parse(userKeychain.encryptedPrv!);
585+
envelope.v.should.equal(2);
586+
587+
const decrypted = await bitgo.decryptAsync({ input: userKeychain.encryptedPrv!, password: passphrase });
588+
should.exist(decrypted);
589+
const parsed: Record<string, unknown> = JSON.parse(decrypted);
590+
should.exist(parsed.uShare);
591+
});
549592
});
550593

551594
describe('signTxRequest:', function () {

0 commit comments

Comments
 (0)