Skip to content

Commit 5d178fc

Browse files
committed
feat(sdk-core): integrate DKLS VRF DKG into createKeychains for safe roots
Ticket: WCN-2447
1 parent 95d9a1f commit 5d178fc

8 files changed

Lines changed: 1111 additions & 6 deletions

File tree

modules/bitgo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"@bitgo/utxo-lib": "^11.24.4",
138138
"@types/superagent": "^4.1.3",
139139
"bignumber.js": "^9.1.1",
140+
"cbor-x": "1.5.9",
140141
"lodash": "^4.18.0",
141142
"openpgp": "5.11.3",
142143
"stellar-sdk": "^10.0.1",

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

Lines changed: 528 additions & 0 deletions
Large diffs are not rendered by default.

modules/sdk-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@bitgo/sdk-lib-mpc": "^10.18.0",
4545
"@bitgo/secp256k1": "^1.11.1",
4646
"@bitgo/sjcl": "^1.1.0",
47+
"cbor-x": "1.5.9",
4748
"@bitgo/statics": "^59.12.0",
4849
"@bitgo/utxo-lib": "^11.24.4",
4950
"@noble/curves": "1.8.1",

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,14 @@ export class Keychains implements IKeychains {
414414
if (this.baseCoin.getMPCAlgorithm() === 'eddsa') {
415415
MpcUtils = isMPCv2 ? EDDSAUtils.EddsaMPCv2Utils : EDDSAUtils.default;
416416
} else {
417-
MpcUtils = isMPCv2 ? ECDSAUtils.EcdsaMPCv2Utils : ECDSAUtils.EcdsaUtils;
417+
// A safeId on a keygen ceremony selects the VRF variant, which additionally runs the
418+
// VRF DKG alongside the signing DKG. Ordinary TSS wallet creation never sets safeId
419+
// and keeps the plain MPCv2 flow.
420+
MpcUtils = isMPCv2
421+
? params.safeId
422+
? ECDSAUtils.EcdsaVrfMPCv2Utils
423+
: ECDSAUtils.EcdsaMPCv2Utils
424+
: ECDSAUtils.EcdsaUtils;
418425
}
419426

420427
const mpcUtils = new MpcUtils(this.bitgo, this.baseCoin);

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

Lines changed: 549 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './ecdsa';
22
export * from './ecdsaMPCv2';
3+
export * from './ecdsaVrfMPCv2';
34
export * from './types';
45
export * from './typesMPCv2';
56
export * from './SMC/utils';

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,30 @@ export const generateMPCv2KeyRequestBody = t.union([
2020
MPCv2KeyGenRound3Request,
2121
]);
2222

23-
export type GenerateMPCv2KeyRequestBody = t.TypeOf<typeof generateMPCv2KeyRequestBody>;
24-
2523
export const generateMPCv2KeyRequestResponse = t.union([
2624
MPCv2KeyGenRound1Response,
2725
MPCv2KeyGenRound2Response,
2826
MPCv2KeyGenRound3Response,
2927
]);
3028

31-
export type GenerateMPCv2KeyRequestResponse = t.TypeOf<typeof generateMPCv2KeyRequestResponse>;
29+
/**
30+
* Optional VRF DKG message fields carried on the MPCv2-R1/R2 keygen round payloads as
31+
* opaque base64 blobs. Only set when the ceremony runs the VRF DKG alongside the
32+
* signing DKG (safe root keys); ordinary TSS wallet creation payloads are unchanged.
33+
*/
34+
export type MpcV2VrfKeyGenRequestFields = {
35+
userVrfMsg1?: string;
36+
backupVrfMsg1?: string;
37+
userVrfMsg2?: string;
38+
backupVrfMsg2?: string;
39+
};
40+
41+
export type MpcV2VrfKeyGenResponseFields = {
42+
bitgoVrfMsg1?: string;
43+
bitgoVrfMsg2?: string;
44+
};
45+
46+
export type GenerateMPCv2KeyRequestBody = t.TypeOf<typeof generateMPCv2KeyRequestBody> & MpcV2VrfKeyGenRequestFields;
47+
48+
export type GenerateMPCv2KeyRequestResponse = t.TypeOf<typeof generateMPCv2KeyRequestResponse> &
49+
MpcV2VrfKeyGenResponseFields;

modules/sdk-lib-mpc/src/tss/dkls-vrf/dkg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ export class VrfDkg {
194194
.filter((m) => m.to_id === undefined)
195195
.map((m) => ({ payload: new Uint8Array(m.payload), from: m.from_id }));
196196
nextRoundDeserializedMessages.p2pMessages = nextRoundMessages
197-
.filter((m) => m.to_id !== undefined)
198-
.map((m) => ({ payload: new Uint8Array(m.payload), from: m.from_id, to: m.to_id! }));
197+
.filter((m): m is VrfWasmMessage & { to_id: number } => m.to_id !== undefined)
198+
.map((m) => ({ payload: new Uint8Array(m.payload), from: m.from_id, to: m.to_id }));
199199
return nextRoundDeserializedMessages;
200200
} catch (e) {
201201
throw Error(`Error while creating VRF messages from party ${this.partyIdx}, state ${this.vrfState}: ${e}`);

0 commit comments

Comments
 (0)