Skip to content

Commit 045559a

Browse files
BitGo Agentbitgobot
authored andcommitted
feat(sdk-lib-mpc): EddsaRetrofitData type + DKG retrofit constructor + getFirstMessage routing
Add optional `retrofitData` parameter to the `DKG` constructor so parties can seed a retrofit DKG ceremony from their existing MPCv1 scalar instead of generating fresh key material. - Import and store `EddsaRetrofitData` on the `DKG` class instance. - Constructor gains a 4th optional param: `retrofitData?: EddsaRetrofitData`. - `getFirstMessage` branches on `this.retrofitData`: when set it calls `wasm.ed25519_dkg_round0_import` (ships in WCI-1217) passing the party's clamped scalar, aggregate public key, and chain code; otherwise it falls through to the existing `ed25519_dkg_round0_process` path. - Export `EddsaRetrofitData` as a named type from `eddsa-mps/index.ts` so callers can import it directly without going through `MPSTypes`. The `as any` cast on the wasm call-site is intentional and temporary: `ed25519_dkg_round0_import` will be typed once WCI-1217 lands. Ticket: WCI-1261 Session-Id: ac4bfdd3-68f2-464c-bb89-a871628f8093 Task-Id: bf6d94d3-a6fd-40c3-9c4a-efc7ffd08fdf
1 parent 9957029 commit 045559a

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

modules/sdk-lib-mpc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
]
3737
},
3838
"dependencies": {
39-
"@bitgo/wasm-mps": "1.10.0",
39+
"@bitgo/wasm-mps": "1.12.0",
4040
"@noble/curves": "1.8.1",
4141
"@silencelaboratories/dkls-wasm-ll-node": "1.2.0-pre.4",
4242
"@silencelaboratories/dkls-wasm-ll-web": "1.2.0-pre.4",

modules/sdk-lib-mpc/src/tss/eddsa-mps/dkg.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { MsgState, Share } from '@bitgo/wasm-mps';
22
import { encode } from 'cbor-x';
33
import crypto from 'crypto';
4-
import { DeserializedMessage, DeserializedMessages, DkgState, EddsaReducedKeyShare } from './types';
4+
import { DeserializedMessage, DeserializedMessages, DkgState, EddsaReducedKeyShare, EddsaRetrofitData } from './types';
55

66
type NodeWasmer = typeof import('@bitgo/wasm-mps');
77
type WebWasmer = typeof import('@bitgo/wasm-mps/web');
@@ -44,13 +44,16 @@ export class DKG {
4444
private shareChaincode: Buffer | null = null;
4545
/** Lazily loaded WASM module */
4646
private wasmMps: WasmMps | null = null;
47+
/** Optional MPCv1 retrofit data; when set, round0 uses ed25519_dkg_round0_import */
48+
private retrofitData: EddsaRetrofitData | undefined;
4749

4850
protected dkgState: DkgState = DkgState.Uninitialized;
4951

50-
constructor(n: number, t: number, partyIdx: number) {
52+
constructor(n: number, t: number, partyIdx: number, retrofitData?: EddsaRetrofitData) {
5153
this.n = n;
5254
this.t = t;
5355
this.partyIdx = partyIdx;
56+
this.retrofitData = retrofitData;
5457
}
5558

5659
private async loadWasmMps(): Promise<void> {
@@ -124,7 +127,18 @@ export class DKG {
124127
const wasm = this.getWasmMps();
125128
let result: MsgState;
126129
try {
127-
result = wasm.ed25519_dkg_round0_process(this.partyIdx, this.decryptionKey!, this.otherPubKeys!, seed);
130+
if (this.retrofitData) {
131+
result = wasm.ed25519_dkg_round0_import(
132+
this.partyIdx,
133+
this.decryptionKey!,
134+
this.otherPubKeys!,
135+
Buffer.from(this.retrofitData.s_i_0, 'hex'),
136+
Buffer.from(this.retrofitData.expectedPk, 'hex'),
137+
Buffer.from(this.retrofitData.chainCode, 'hex'),
138+
);
139+
} else {
140+
result = wasm.ed25519_dkg_round0_process(this.partyIdx, this.decryptionKey!, this.otherPubKeys!, seed);
141+
}
128142
} catch (err) {
129143
throw new Error(`Error while creating the first message from party ${this.partyIdx}: ${err}`);
130144
}

modules/sdk-lib-mpc/src/tss/eddsa-mps/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * as EddsaMPSDsg from './dsg';
33
export * as MPSUtil from './util';
44
export * as MPSTypes from './types';
55
export * as MPSComms from './commsLayer';
6+
export type { EddsaRetrofitData } from './types';

0 commit comments

Comments
 (0)