@bcts/frost-hubert 1.0.0-alpha.22 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/frost.cjs +347 -75
- package/dist/bin/frost.cjs.map +1 -1
- package/dist/bin/frost.mjs +347 -75
- package/dist/bin/frost.mjs.map +1 -1
- package/dist/busy-DkM2jAIZ.mjs +27 -0
- package/dist/busy-DkM2jAIZ.mjs.map +1 -0
- package/dist/busy-EZU7EKr6.cjs +38 -0
- package/dist/busy-EZU7EKr6.cjs.map +1 -0
- package/dist/{chunk-uaV2rQ02.cjs → chunk-CZWwpsFl.cjs} +22 -32
- package/dist/{chunk-ClPoSABd.mjs → chunk-CjcI7cDX.mjs} +6 -12
- package/dist/cmd/index.cjs +46 -43
- package/dist/cmd/index.d.cts +2 -4
- package/dist/cmd/index.d.mts +2 -4
- package/dist/cmd/index.mjs +7 -6
- package/dist/cmd-Bw9_i2_f.cjs +130 -0
- package/dist/cmd-Bw9_i2_f.cjs.map +1 -0
- package/dist/cmd-CS1uJtuD.mjs +113 -0
- package/dist/cmd-CS1uJtuD.mjs.map +1 -0
- package/dist/common-CvH6dFvQ.mjs +282 -0
- package/dist/common-CvH6dFvQ.mjs.map +1 -0
- package/dist/common-DUWvtc08.mjs +96 -0
- package/dist/common-DUWvtc08.mjs.map +1 -0
- package/dist/common-lKP5EzHy.cjs +372 -0
- package/dist/common-lKP5EzHy.cjs.map +1 -0
- package/dist/common-lThIvJmZ.cjs +114 -0
- package/dist/common-lThIvJmZ.cjs.map +1 -0
- package/dist/dkg/index.cjs +245 -7
- package/dist/dkg/index.cjs.map +1 -0
- package/dist/dkg/index.d.cts +2 -2
- package/dist/dkg/index.d.mts +2 -2
- package/dist/dkg/index.mjs +238 -2
- package/dist/dkg/index.mjs.map +1 -0
- package/dist/finalize-BRgJK-Xv.cjs +402 -0
- package/dist/finalize-BRgJK-Xv.cjs.map +1 -0
- package/dist/finalize-BfLgzn8f.cjs +303 -0
- package/dist/finalize-BfLgzn8f.cjs.map +1 -0
- package/dist/finalize-CNTDj6aS.mjs +389 -0
- package/dist/finalize-CNTDj6aS.mjs.map +1 -0
- package/dist/finalize-EC3ikHQq.mjs +252 -0
- package/dist/finalize-EC3ikHQq.mjs.map +1 -0
- package/dist/finalize-IA01t_Qq.mjs +290 -0
- package/dist/finalize-IA01t_Qq.mjs.map +1 -0
- package/dist/finalize-UPyI1yb1.cjs +265 -0
- package/dist/finalize-UPyI1yb1.cjs.map +1 -0
- package/dist/frost/index.cjs +8 -9
- package/dist/frost/index.cjs.map +1 -1
- package/dist/frost/index.mjs +2 -3
- package/dist/frost/index.mjs.map +1 -1
- package/dist/{group-invite-Dz1Jmiky.d.cts → index-B3c-80VS.d.cts} +25 -2
- package/dist/index-B3c-80VS.d.cts.map +1 -0
- package/dist/{index-CcvTi5EA.d.cts → index-BgbSGpxn.d.mts} +102 -80
- package/dist/index-BgbSGpxn.d.mts.map +1 -0
- package/dist/{registry-impl-CE76sTXQ.d.cts → index-C8QeHNwa.d.cts} +46 -2
- package/dist/index-C8QeHNwa.d.cts.map +1 -0
- package/dist/{group-invite-Wk9CIbHL.d.mts → index-D3QTWkEm.d.mts} +25 -2
- package/dist/index-D3QTWkEm.d.mts.map +1 -0
- package/dist/{registry-impl-BETn_lEO.d.mts → index-DVbWyOs7.d.mts} +46 -2
- package/dist/index-DVbWyOs7.d.mts.map +1 -0
- package/dist/{index-DNCPeLNM.d.mts → index-F1iNEAJR.d.cts} +102 -80
- package/dist/index-F1iNEAJR.d.cts.map +1 -0
- package/dist/index.cjs +72 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +11 -10
- package/dist/index.mjs.map +1 -1
- package/dist/invite-5277FQVT.cjs +274 -0
- package/dist/invite-5277FQVT.cjs.map +1 -0
- package/dist/invite-DUTcfTgX.cjs +109 -0
- package/dist/invite-DUTcfTgX.cjs.map +1 -0
- package/dist/invite-IU4n0dq2.mjs +96 -0
- package/dist/invite-IU4n0dq2.mjs.map +1 -0
- package/dist/invite-RU-OXTNS.mjs +219 -0
- package/dist/invite-RU-OXTNS.mjs.map +1 -0
- package/dist/parallel-D1R6ZGlY.cjs +318 -0
- package/dist/parallel-D1R6ZGlY.cjs.map +1 -0
- package/dist/parallel-D6zc6VW4.mjs +235 -0
- package/dist/parallel-D6zc6VW4.mjs.map +1 -0
- package/dist/proposed-participant-Dm1Eq6mX.cjs +141 -0
- package/dist/proposed-participant-Dm1Eq6mX.cjs.map +1 -0
- package/dist/proposed-participant-cWM7iUrO.mjs +129 -0
- package/dist/proposed-participant-cWM7iUrO.mjs.map +1 -0
- package/dist/receive-CAI-x4II.cjs +213 -0
- package/dist/receive-CAI-x4II.cjs.map +1 -0
- package/dist/receive-D2Nn68L7.mjs +188 -0
- package/dist/receive-D2Nn68L7.mjs.map +1 -0
- package/dist/receive-DA_KQEgk.mjs +177 -0
- package/dist/receive-DA_KQEgk.mjs.map +1 -0
- package/dist/receive-kZMsXhbK.cjs +190 -0
- package/dist/receive-kZMsXhbK.cjs.map +1 -0
- package/dist/registry/index.cjs +881 -13
- package/dist/registry/index.cjs.map +1 -0
- package/dist/registry/index.d.cts +1 -1
- package/dist/registry/index.d.mts +1 -1
- package/dist/registry/index.mjs +867 -2
- package/dist/registry/index.mjs.map +1 -0
- package/dist/{registry-FMU-ec5K.cjs → registry-9puTaRrD.cjs} +28 -31
- package/dist/registry-9puTaRrD.cjs.map +1 -0
- package/dist/{registry-BDnNV1Rk.mjs → registry-BpCwtrRt.mjs} +7 -10
- package/dist/{registry-BDnNV1Rk.mjs.map → registry-BpCwtrRt.mjs.map} +1 -1
- package/dist/round1-4Hyx8w0x.cjs +422 -0
- package/dist/round1-4Hyx8w0x.cjs.map +1 -0
- package/dist/round1-7v9LlE11.mjs +373 -0
- package/dist/round1-7v9LlE11.mjs.map +1 -0
- package/dist/round1-BHBjru1m.cjs +465 -0
- package/dist/round1-BHBjru1m.cjs.map +1 -0
- package/dist/round1-CMLKN2RR.mjs +195 -0
- package/dist/round1-CMLKN2RR.mjs.map +1 -0
- package/dist/round1-CWSXZx5R.cjs +208 -0
- package/dist/round1-CWSXZx5R.cjs.map +1 -0
- package/dist/round1-CcQCGlIT.mjs +208 -0
- package/dist/round1-CcQCGlIT.mjs.map +1 -0
- package/dist/round1-Cgm7j1kI.mjs +452 -0
- package/dist/round1-Cgm7j1kI.mjs.map +1 -0
- package/dist/round1-DQ0fnc1H.cjs +221 -0
- package/dist/round1-DQ0fnc1H.cjs.map +1 -0
- package/dist/round2-BWz9SQIi.cjs +305 -0
- package/dist/round2-BWz9SQIi.cjs.map +1 -0
- package/dist/round2-BkNRCXgS.mjs +292 -0
- package/dist/round2-BkNRCXgS.mjs.map +1 -0
- package/dist/round2-Bl2uK93U.mjs +450 -0
- package/dist/round2-Bl2uK93U.mjs.map +1 -0
- package/dist/round2-CdUT-AhH.cjs +499 -0
- package/dist/round2-CdUT-AhH.cjs.map +1 -0
- package/dist/round2-DOA3rnV-.mjs +280 -0
- package/dist/round2-DOA3rnV-.mjs.map +1 -0
- package/dist/round2-Dg24w-TU.mjs +397 -0
- package/dist/round2-Dg24w-TU.mjs.map +1 -0
- package/dist/round2-LylCa84n.cjs +293 -0
- package/dist/round2-LylCa84n.cjs.map +1 -0
- package/dist/round2-o2Q-GMbX.cjs +410 -0
- package/dist/round2-o2Q-GMbX.cjs.map +1 -0
- package/dist/storage-B-Gu68-O.cjs +79 -0
- package/dist/storage-B-Gu68-O.cjs.map +1 -0
- package/dist/storage-Bkkliz0K.mjs +74 -0
- package/dist/storage-Bkkliz0K.mjs.map +1 -0
- package/package.json +17 -17
- package/src/bin/frost.ts +849 -128
- package/src/cmd/common.ts +19 -1
- package/src/cmd/dkg/common.ts +97 -10
- package/src/cmd/dkg/coordinator/invite.ts +5 -2
- package/src/cmd/dkg/participant/finalize.ts +52 -18
- package/src/cmd/dkg/participant/round1.ts +39 -38
- package/src/cmd/dkg/participant/round2.ts +60 -26
- package/src/cmd/sign/coordinator/round2.ts +5 -1
- package/src/cmd/sign/participant/finalize.ts +6 -2
- package/src/cmd/sign/participant/receive.ts +5 -2
- package/src/dkg/group-invite.ts +12 -2
- package/src/dkg/proposed-participant.ts +33 -5
- package/src/frost/index.ts +1 -1
- package/src/registry/owner-record.ts +13 -2
- package/src/registry/participant-record.ts +36 -4
- package/src/registry/registry-impl.ts +74 -18
- package/dist/group-invite-CrbOabFL.cjs +0 -368
- package/dist/group-invite-CrbOabFL.cjs.map +0 -1
- package/dist/group-invite-Dz1Jmiky.d.cts.map +0 -1
- package/dist/group-invite-RPElq-fm.mjs +0 -338
- package/dist/group-invite-RPElq-fm.mjs.map +0 -1
- package/dist/group-invite-Wk9CIbHL.d.mts.map +0 -1
- package/dist/index-CcvTi5EA.d.cts.map +0 -1
- package/dist/index-DNCPeLNM.d.mts.map +0 -1
- package/dist/registry-FMU-ec5K.cjs.map +0 -1
- package/dist/registry-impl-BETn_lEO.d.mts.map +0 -1
- package/dist/registry-impl-C7w4awTv.cjs +0 -865
- package/dist/registry-impl-C7w4awTv.cjs.map +0 -1
- package/dist/registry-impl-CE76sTXQ.d.cts.map +0 -1
- package/dist/registry-impl-eYXVSPwM.mjs +0 -797
- package/dist/registry-impl-eYXVSPwM.mjs.map +0 -1
- package/dist/sign-2bOp18Fs.cjs +0 -4875
- package/dist/sign-2bOp18Fs.cjs.map +0 -1
- package/dist/sign-D8C3HJ4B.mjs +0 -4736
- package/dist/sign-D8C3HJ4B.mjs.map +0 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-CjcI7cDX.mjs";
|
|
2
|
+
import { n as compareXidBytes } from "./proposed-participant-cWM7iUrO.mjs";
|
|
3
|
+
import { Registry, resolveRegistryPath } from "./registry/index.mjs";
|
|
4
|
+
import { c as parseAridUr, n as isVerbose, t as groupStateDir } from "./common-CvH6dFvQ.mjs";
|
|
5
|
+
import { n as putWithIndicator, t as getWithIndicator } from "./busy-DkM2jAIZ.mjs";
|
|
6
|
+
import { t as createStorageClient } from "./storage-Bkkliz0K.mjs";
|
|
7
|
+
import { bytesToHex, dkgPart2, hexToBytes, identifierFromU16, identifierToHex, serializeDkgRound2Package } from "./frost/index.mjs";
|
|
8
|
+
import { ARID, JSON as JSON$1, XID } from "@bcts/components";
|
|
9
|
+
import { CborDate } from "@bcts/dcbor";
|
|
10
|
+
import { Envelope, Function } from "@bcts/envelope";
|
|
11
|
+
import { SealedRequest, SealedResponse } from "@bcts/gstp";
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import { Ed25519Sha512, serde } from "@frosts/ed25519";
|
|
15
|
+
import { CoefficientCommitment, VerifiableSecretSharingCommitment, round1 } from "@frosts/core";
|
|
16
|
+
//#region src/cmd/dkg/participant/round2.ts
|
|
17
|
+
/**
|
|
18
|
+
* Copyright © 2023-2026 Blockchain Commons, LLC
|
|
19
|
+
* Copyright © 2025-2026 Parity Technologies
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* DKG participant round 2 command.
|
|
23
|
+
*
|
|
24
|
+
* Port of cmd/dkg/participant/round2.rs from frost-hubert-rust.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
var round2_exports = /* @__PURE__ */ __exportAll({ round2: () => round2$1 });
|
|
29
|
+
/**
|
|
30
|
+
* Load persisted round 1 state from disk.
|
|
31
|
+
*
|
|
32
|
+
* Port of round1_secret loading from cmd/dkg/participant/round2.rs lines 86-97.
|
|
33
|
+
*/
|
|
34
|
+
function loadRound1State(registryPath, groupId) {
|
|
35
|
+
const packagesDir = groupStateDir(registryPath, groupId.hex());
|
|
36
|
+
const round1SecretPath = path.join(packagesDir, "round1_secret.json");
|
|
37
|
+
if (!fs.existsSync(round1SecretPath)) throw new Error(`Round 1 secret not found at ${round1SecretPath}. Did you respond to the invite?`);
|
|
38
|
+
const secretJson = JSON.parse(fs.readFileSync(round1SecretPath, "utf-8"));
|
|
39
|
+
const coefficients = secretJson.coefficients.map((hex) => Ed25519Sha512.deserializeScalar(hexToBytes(hex)));
|
|
40
|
+
const commitment = new VerifiableSecretSharingCommitment(Ed25519Sha512, secretJson.commitment.map((hex) => CoefficientCommitment.deserialize(Ed25519Sha512, hexToBytes(hex))));
|
|
41
|
+
const idBytes = hexToBytes(secretJson.identifier);
|
|
42
|
+
let identifierU16 = 1;
|
|
43
|
+
if (idBytes.length >= 2) identifierU16 = idBytes[0] | idBytes[1] << 8;
|
|
44
|
+
if (identifierU16 === 0) identifierU16 = 1;
|
|
45
|
+
const parsedIdentifier = identifierFromU16(identifierU16);
|
|
46
|
+
const secretPackage = new round1.SecretPackage(Ed25519Sha512, parsedIdentifier, coefficients, commitment, secretJson.min_signers, secretJson.max_signers);
|
|
47
|
+
const round1PackagePath = path.join(packagesDir, "round1_package.json");
|
|
48
|
+
const packageJson = JSON.parse(fs.readFileSync(round1PackagePath, "utf-8"));
|
|
49
|
+
return {
|
|
50
|
+
secretPackage,
|
|
51
|
+
ourRound1Package: serde.round1PackageFromJson(packageJson)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validate the round 2 request from the coordinator.
|
|
56
|
+
*
|
|
57
|
+
* Port of request validation from cmd/dkg/participant/round2.rs lines 118-158.
|
|
58
|
+
*/
|
|
59
|
+
function validateRound2Request(sealedRequest, groupId, expectedCoordinator) {
|
|
60
|
+
if (!sealedRequest.function().equals(Function.fromString("dkgRound2"))) throw new Error(`Unexpected request function: ${sealedRequest.function().toString()}`);
|
|
61
|
+
if (sealedRequest.sender().xid().urString() !== expectedCoordinator.urString()) throw new Error(`Unexpected request sender: ${sealedRequest.sender().xid().urString()} (expected coordinator ${expectedCoordinator.urString()})`);
|
|
62
|
+
const requestGroupIdEnvelope = sealedRequest.objectForParameter("group");
|
|
63
|
+
if (requestGroupIdEnvelope === void 0) throw new Error("Request missing group parameter");
|
|
64
|
+
const requestGroupId = requestGroupIdEnvelope.extractSubject((cbor) => ARID.fromTaggedCbor(cbor));
|
|
65
|
+
if (requestGroupId.urString() !== groupId.urString()) throw new Error(`Request group ID ${requestGroupId.urString()} does not match expected ${groupId.urString()}`);
|
|
66
|
+
const responseAridEnvelope = sealedRequest.objectForParameter("responseArid");
|
|
67
|
+
if (responseAridEnvelope === void 0) throw new Error("Request missing responseArid parameter");
|
|
68
|
+
return responseAridEnvelope.extractSubject((cbor) => ARID.fromTaggedCbor(cbor));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Extract round 1 packages from the request and convert to Map<Identifier, Package>.
|
|
72
|
+
*
|
|
73
|
+
* Port of `extract_round1_packages()` from cmd/dkg/participant/round2.rs lines 291-366.
|
|
74
|
+
*/
|
|
75
|
+
function extractRound1Packages(request, groupRecord, ownerXid) {
|
|
76
|
+
const sortedXids = groupRecord.participants().map((p) => p.xid());
|
|
77
|
+
const ownerUrString = ownerXid.urString();
|
|
78
|
+
if (!sortedXids.some((xid) => xid.urString() === ownerUrString)) sortedXids.push(ownerXid);
|
|
79
|
+
sortedXids.sort((a, b) => compareXidBytes(a.toData(), b.toData()));
|
|
80
|
+
const deduped = [];
|
|
81
|
+
for (const xid of sortedXids) if (deduped.length === 0 || deduped[deduped.length - 1].urString() !== xid.urString()) deduped.push(xid);
|
|
82
|
+
const xidToIdentifier = /* @__PURE__ */ new Map();
|
|
83
|
+
for (let i = 0; i < deduped.length; i++) {
|
|
84
|
+
const identifier = identifierFromU16(i + 1);
|
|
85
|
+
xidToIdentifier.set(deduped[i].urString(), identifier);
|
|
86
|
+
}
|
|
87
|
+
const myXidStr = ownerXid.urString();
|
|
88
|
+
const packages = /* @__PURE__ */ new Map();
|
|
89
|
+
const packagesByXid = [];
|
|
90
|
+
const packageEnvelopes = request.objectsForParameter("round1Package");
|
|
91
|
+
for (const packageEnvelope of packageEnvelopes) {
|
|
92
|
+
const participantEnvelope = packageEnvelope.objectForPredicate("participant");
|
|
93
|
+
if (participantEnvelope === void 0) throw new Error("round1Package missing participant predicate");
|
|
94
|
+
const participantXid = participantEnvelope.extractSubject((cbor) => XID.fromTaggedCbor(cbor));
|
|
95
|
+
if (participantXid.urString() === myXidStr) continue;
|
|
96
|
+
const packageJson = packageEnvelope.extractSubject((cbor) => JSON$1.fromTaggedCbor(cbor));
|
|
97
|
+
const packageData = JSON.parse(new TextDecoder().decode(packageJson.toData()));
|
|
98
|
+
const pkg = serde.round1PackageFromJson(packageData);
|
|
99
|
+
const identifier = xidToIdentifier.get(participantXid.urString());
|
|
100
|
+
if (identifier === void 0) throw new Error(`Unknown participant XID in round1Package: ${participantXid.urString()}`);
|
|
101
|
+
packages.set(identifier, pkg);
|
|
102
|
+
packagesByXid.push([participantXid, pkg]);
|
|
103
|
+
}
|
|
104
|
+
const expectedPackages = xidToIdentifier.size - 1;
|
|
105
|
+
if (packages.size !== expectedPackages) throw new Error(`Expected ${expectedPackages} Round 1 packages, found ${packages.size}`);
|
|
106
|
+
return [packages, packagesByXid];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Build the response body containing Round 2 packages.
|
|
110
|
+
*
|
|
111
|
+
* Port of `build_response_body()` from cmd/dkg/participant/round2.rs lines 373-425.
|
|
112
|
+
*/
|
|
113
|
+
function buildResponseBody(groupId, participantXid, responseArid, round2Packages, groupRecord) {
|
|
114
|
+
const sortedXids = groupRecord.participants().map((p) => p.xid());
|
|
115
|
+
const participantUrString = participantXid.urString();
|
|
116
|
+
if (!sortedXids.some((xid) => xid.urString() === participantUrString)) sortedXids.push(participantXid);
|
|
117
|
+
sortedXids.sort((a, b) => compareXidBytes(a.toData(), b.toData()));
|
|
118
|
+
const deduped = [];
|
|
119
|
+
for (const xid of sortedXids) if (deduped.length === 0 || deduped[deduped.length - 1].urString() !== xid.urString()) deduped.push(xid);
|
|
120
|
+
const identifierToXid = /* @__PURE__ */ new Map();
|
|
121
|
+
for (let i = 0; i < deduped.length; i++) {
|
|
122
|
+
const identifier = identifierFromU16(i + 1);
|
|
123
|
+
identifierToXid.set(identifierToHex(identifier), deduped[i]);
|
|
124
|
+
}
|
|
125
|
+
let envelope = Envelope.unit().addType("dkgRound2Response").addAssertion("group", groupId).addAssertion("participant", participantXid).addAssertion("response_arid", responseArid);
|
|
126
|
+
for (const [identifier, pkg] of round2Packages) {
|
|
127
|
+
const idHex = identifierToHex(identifier);
|
|
128
|
+
const recipientXid = identifierToXid.get(idHex);
|
|
129
|
+
if (recipientXid === void 0) throw new Error("Unknown identifier in round2_packages");
|
|
130
|
+
const serialized = serializeDkgRound2Package(pkg);
|
|
131
|
+
const jsonStr = JSON.stringify(serialized);
|
|
132
|
+
const jsonBytes = new TextEncoder().encode(jsonStr);
|
|
133
|
+
const jsonWrapper = JSON$1.fromData(jsonBytes);
|
|
134
|
+
const packageEnvelope = Envelope.new(jsonWrapper).addAssertion("recipient", recipientXid);
|
|
135
|
+
envelope = envelope.addAssertion("round2Package", packageEnvelope);
|
|
136
|
+
}
|
|
137
|
+
return envelope;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Serialize round 2 secret package to JSON format for persistence.
|
|
141
|
+
*
|
|
142
|
+
* Mirrors the on-disk shape produced by Rust
|
|
143
|
+
* `serde_json::to_vec_pretty(&frost::keys::dkg::round2::SecretPackage)`
|
|
144
|
+
* (see `frost-rust/frost-core/src/keys/dkg.rs:269-287`):
|
|
145
|
+
*
|
|
146
|
+
* ```json
|
|
147
|
+
* {
|
|
148
|
+
* "identifier": "<lowercase hex scalar>",
|
|
149
|
+
* "commitment": ["<hex>", "<hex>", ...],
|
|
150
|
+
* "secret_share": "<hex>",
|
|
151
|
+
* "min_signers": <u16>,
|
|
152
|
+
* "max_signers": <u16>
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* `frost::keys::dkg::round2::SecretPackage` is
|
|
157
|
+
* `#[serde(deny_unknown_fields)]`. The earlier port emitted
|
|
158
|
+
* camelCase keys (`secretShare`, `minSigners`, `maxSigners`), a
|
|
159
|
+
* nested `commitment.coefficients` shape, and a numeric
|
|
160
|
+
* `identifier` — all of which Rust's standard derive would
|
|
161
|
+
* reject and which had no chance of round-tripping with Rust.
|
|
162
|
+
*
|
|
163
|
+
* `participantIndex` is unused now that the identifier comes
|
|
164
|
+
* directly from `secret.identifier.serialize()`; we keep it in the
|
|
165
|
+
* signature for source-level parity with the call sites.
|
|
166
|
+
*/
|
|
167
|
+
function serializeRound2SecretPackage(secret, _participantIndex) {
|
|
168
|
+
const commitmentCoefficients = secret.commitment.serialize().map((c) => bytesToHex(c));
|
|
169
|
+
const secretShare = bytesToHex(Ed25519Sha512.serializeScalar(secret.secretShare()));
|
|
170
|
+
return {
|
|
171
|
+
identifier: bytesToHex(secret.identifier.serialize()),
|
|
172
|
+
commitment: commitmentCoefficients,
|
|
173
|
+
secret_share: secretShare,
|
|
174
|
+
min_signers: secret.minSigners,
|
|
175
|
+
max_signers: secret.maxSigners
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Persist round 2 state to disk.
|
|
180
|
+
*
|
|
181
|
+
* Port of round 2 secret persistence from cmd/dkg/participant/round2.rs lines 229-251.
|
|
182
|
+
*/
|
|
183
|
+
function persistRound2State(registryPath, groupId, round2Secret, round1PackagesByXid, participantIndex) {
|
|
184
|
+
const packagesDir = groupStateDir(registryPath, groupId.hex());
|
|
185
|
+
fs.mkdirSync(packagesDir, { recursive: true });
|
|
186
|
+
const round2SecretPath = path.join(packagesDir, "round2_secret.json");
|
|
187
|
+
const round2SecretJson = serializeRound2SecretPackage(round2Secret, participantIndex);
|
|
188
|
+
fs.writeFileSync(round2SecretPath, JSON.stringify(round2SecretJson, null, 2));
|
|
189
|
+
const round1PackagesPath = path.join(packagesDir, "collected_round1.json");
|
|
190
|
+
const round1Json = {};
|
|
191
|
+
for (const [xid, pkg] of round1PackagesByXid) {
|
|
192
|
+
const packageJson = serde.round1PackageToJson(pkg);
|
|
193
|
+
round1Json[xid.urString()] = packageJson;
|
|
194
|
+
}
|
|
195
|
+
fs.writeFileSync(round1PackagesPath, JSON.stringify(round1Json, null, 2));
|
|
196
|
+
return round2SecretPath;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Execute the DKG participant round 2 command.
|
|
200
|
+
*
|
|
201
|
+
* Responds to the Round 2 request from the coordinator, runs FROST DKG part2
|
|
202
|
+
* to generate Round 2 packages, and posts the response back.
|
|
203
|
+
*
|
|
204
|
+
* Port of `CommandArgs::exec()` from cmd/dkg/participant/round2.rs lines 55-288.
|
|
205
|
+
*/
|
|
206
|
+
async function round2$1(_client, options, cwd) {
|
|
207
|
+
if (options.storageSelection === void 0) throw new Error("Hubert storage is required for round2");
|
|
208
|
+
const registryPath = resolveRegistryPath(options.registryPath, cwd);
|
|
209
|
+
const registry = Registry.load(registryPath);
|
|
210
|
+
const owner = registry.owner();
|
|
211
|
+
if (owner === void 0) throw new Error("Registry owner is required");
|
|
212
|
+
const groupId = parseAridUr(options.groupId);
|
|
213
|
+
const groupRecord = registry.group(groupId);
|
|
214
|
+
if (groupRecord === void 0) throw new Error("Group not found in registry");
|
|
215
|
+
const listeningAtArid = groupRecord.listeningAtArid();
|
|
216
|
+
if (listeningAtArid === void 0) throw new Error("No listening ARID for this group. Did you respond to the invite?");
|
|
217
|
+
const round1State = loadRound1State(registryPath, groupId);
|
|
218
|
+
if (isVerbose() || options.verbose === true) console.error("Fetching Round 2 request from Hubert...");
|
|
219
|
+
const client = await createStorageClient(options.storageSelection);
|
|
220
|
+
const requestEnvelope = await getWithIndicator(client, listeningAtArid, "Round 2 request", options.timeoutSeconds, options.verbose ?? false);
|
|
221
|
+
if (requestEnvelope === null || requestEnvelope === void 0) throw new Error("Round 2 request not found in Hubert storage");
|
|
222
|
+
const ownerPrivateKeys = owner.xidDocument().inceptionPrivateKeys();
|
|
223
|
+
if (ownerPrivateKeys === void 0) throw new Error("Owner XID document has no private keys");
|
|
224
|
+
const now = CborDate.now().datetime();
|
|
225
|
+
const sealedRequest = SealedRequest.tryFromEnvelope(requestEnvelope, void 0, now, ownerPrivateKeys);
|
|
226
|
+
const responseArid = validateRound2Request(sealedRequest, groupId, groupRecord.coordinator().xid());
|
|
227
|
+
const [round1Packages, round1PackagesByXid] = extractRound1Packages(sealedRequest, groupRecord, owner.xid());
|
|
228
|
+
if (isVerbose() || options.verbose === true) console.error(`Received ${round1Packages.size} Round 1 packages. Running DKG part2...`);
|
|
229
|
+
const nextResponseArid = ARID.new();
|
|
230
|
+
const round1PackagesHex = /* @__PURE__ */ new Map();
|
|
231
|
+
for (const [id, pkg] of round1Packages) round1PackagesHex.set(identifierToHex(id), pkg);
|
|
232
|
+
const [round2Secret, round2Packages] = dkgPart2(round1State.secretPackage, round1PackagesHex);
|
|
233
|
+
if (isVerbose() || options.verbose === true) console.error(`Generated ${round2Packages.size} Round 2 packages.`);
|
|
234
|
+
const round2PackagesById = /* @__PURE__ */ new Map();
|
|
235
|
+
for (const [idHex, pkg] of round2Packages) for (const [id] of round1Packages) if (identifierToHex(id) === idHex) {
|
|
236
|
+
round2PackagesById.set(id, pkg);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
const responseBody = buildResponseBody(groupId, owner.xid(), nextResponseArid, round2PackagesById, groupRecord);
|
|
240
|
+
const signerPrivateKeys = owner.xidDocument().inceptionPrivateKeys();
|
|
241
|
+
if (signerPrivateKeys === void 0) throw new Error("Owner XID document has no signing keys");
|
|
242
|
+
const coordinatorXid = groupRecord.coordinator().xid();
|
|
243
|
+
const coordinatorRecord = registry.participant(coordinatorXid);
|
|
244
|
+
let coordinatorDoc;
|
|
245
|
+
if (coordinatorRecord !== void 0) coordinatorDoc = coordinatorRecord.xidDocument();
|
|
246
|
+
else if (owner.xid().urString() === coordinatorXid.urString()) coordinatorDoc = owner.xidDocument();
|
|
247
|
+
else throw new Error(`Coordinator ${coordinatorXid.urString()} not found in registry`);
|
|
248
|
+
const peerContinuation = sealedRequest.peerContinuation();
|
|
249
|
+
let sealed = SealedResponse.newSuccess(sealedRequest.id(), owner.xidDocument()).withResult(responseBody);
|
|
250
|
+
if (peerContinuation !== void 0) sealed = sealed.withPeerContinuation(peerContinuation);
|
|
251
|
+
if (options.preview === true) {
|
|
252
|
+
const envelopeUr = sealed.toEnvelope(void 0, signerPrivateKeys, void 0).urString();
|
|
253
|
+
console.log(envelopeUr);
|
|
254
|
+
return {
|
|
255
|
+
listeningArid: nextResponseArid.urString(),
|
|
256
|
+
envelopeUr
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const sortedParticipantXids = groupRecord.participants().map((p) => p.xid());
|
|
260
|
+
const ownerXid = owner.xid();
|
|
261
|
+
const ownerXidStr = ownerXid.urString();
|
|
262
|
+
if (!sortedParticipantXids.some((x) => x.urString() === ownerXidStr)) sortedParticipantXids.push(ownerXid);
|
|
263
|
+
sortedParticipantXids.sort((a, b) => compareXidBytes(a.toData(), b.toData()));
|
|
264
|
+
const round2SecretPath = persistRound2State(registryPath, groupId, round2Secret, round1PackagesByXid, sortedParticipantXids.findIndex((x) => x.urString() === ownerXidStr) + 1);
|
|
265
|
+
await putWithIndicator(client, responseArid, sealed.toEnvelope(void 0, signerPrivateKeys, coordinatorDoc), "Round 2 Response", options.verbose ?? false);
|
|
266
|
+
const updatedGroupRecord = registry.group(groupId);
|
|
267
|
+
if (updatedGroupRecord !== void 0) {
|
|
268
|
+
const contributions = updatedGroupRecord.contributions();
|
|
269
|
+
contributions.round2Secret = round2SecretPath;
|
|
270
|
+
updatedGroupRecord.setContributions(contributions);
|
|
271
|
+
updatedGroupRecord.setListeningAtArid(nextResponseArid);
|
|
272
|
+
registry.save(registryPath);
|
|
273
|
+
}
|
|
274
|
+
if (isVerbose() || options.verbose === true) console.error(`Posted Round 2 response to ${responseArid.urString()}`);
|
|
275
|
+
return { listeningArid: nextResponseArid.urString() };
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
export { round2_exports as n, round2$1 as t };
|
|
279
|
+
|
|
280
|
+
//# sourceMappingURL=round2-DOA3rnV-.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round2-DOA3rnV-.mjs","names":["EnvelopeFunction","JSONWrapper","round2"],"sources":["../src/cmd/dkg/participant/round2.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * DKG participant round 2 command.\n *\n * Port of cmd/dkg/participant/round2.rs from frost-hubert-rust.\n *\n * @module\n */\n\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\n\nimport { ARID, JSON as JSONWrapper, XID } from \"@bcts/components\";\nimport { compareXidBytes } from \"../../../dkg/proposed-participant.js\";\nimport { CborDate } from \"@bcts/dcbor\";\nimport { Envelope, Function as EnvelopeFunction } from \"@bcts/envelope\";\nimport { SealedRequest, SealedResponse } from \"@bcts/gstp\";\nimport type { XIDDocument } from \"@bcts/xid\";\n\nimport { type GroupRecord, Registry, resolveRegistryPath } from \"../../../registry/index.js\";\nimport { getWithIndicator, putWithIndicator } from \"../../busy.js\";\nimport { groupStateDir, isVerbose } from \"../../common.js\";\nimport { createStorageClient, type StorageClient, type StorageSelection } from \"../../storage.js\";\nimport { parseAridUr } from \"../common.js\";\nimport {\n dkgPart2,\n serializeDkgRound2Package,\n identifierFromU16,\n identifierToHex,\n hexToBytes,\n bytesToHex,\n type DkgRound1Package,\n type DkgRound1SecretPackage,\n type DkgRound2SecretPackage,\n type FrostIdentifier,\n} from \"../../../frost/index.js\";\nimport { Ed25519Sha512, serde } from \"@frosts/ed25519\";\nimport { round1, CoefficientCommitment, VerifiableSecretSharingCommitment } from \"@frosts/core\";\n\n/**\n * Options for the DKG round2 command.\n */\nexport interface DkgRound2Options {\n registryPath?: string;\n groupId: string;\n timeoutSeconds?: number;\n preview?: boolean;\n storageSelection?: StorageSelection;\n verbose?: boolean;\n}\n\n/**\n * Result of the DKG round2 command.\n */\nexport interface DkgRound2Result {\n listeningArid: string;\n envelopeUr?: string;\n}\n\n/**\n * Persisted round 1 state loaded from disk.\n */\ninterface Round1State {\n secretPackage: DkgRound1SecretPackage;\n ourRound1Package: DkgRound1Package;\n}\n\n/**\n * Extracted round 1 packages from coordinator request.\n */\ntype Round1Packages = [Map<FrostIdentifier, DkgRound1Package>, [XID, DkgRound1Package][]];\n\n/**\n * Load persisted round 1 state from disk.\n *\n * Port of round1_secret loading from cmd/dkg/participant/round2.rs lines 86-97.\n */\nfunction loadRound1State(registryPath: string, groupId: ARID): Round1State {\n const packagesDir = groupStateDir(registryPath, groupId.hex());\n const round1SecretPath = path.join(packagesDir, \"round1_secret.json\");\n\n if (!fs.existsSync(round1SecretPath)) {\n throw new Error(\n `Round 1 secret not found at ${round1SecretPath}. Did you respond to the invite?`,\n );\n }\n\n // Mirrors Rust `frost::keys::dkg::round1::SecretPackage` JSON\n // (`frost-rust/frost-core/src/keys/dkg.rs:120-139`): no `header`,\n // snake_case `min_signers` / `max_signers`, identifier and\n // coefficients as lowercase hex strings, commitment as a flat array\n // of hex strings.\n const secretJson = JSON.parse(fs.readFileSync(round1SecretPath, \"utf-8\")) as {\n identifier: string;\n coefficients: string[];\n commitment: string[];\n min_signers: number;\n max_signers: number;\n };\n\n // Deserialize coefficients (scalars)\n const coefficients = secretJson.coefficients.map((hex) =>\n Ed25519Sha512.deserializeScalar(hexToBytes(hex)),\n );\n\n // Deserialize commitment (coefficient commitments)\n const coefficientCommitments = secretJson.commitment.map((hex) =>\n CoefficientCommitment.deserialize(Ed25519Sha512, hexToBytes(hex)),\n );\n\n const commitment = new VerifiableSecretSharingCommitment(Ed25519Sha512, coefficientCommitments);\n\n // Create the secret package\n // Need to find the actual identifier u16 value from the coefficients array length or saved state\n // The identifier is typically serialized as a scalar, but we need the u16 value\n // Parse it from the hex string - first 2 bytes as little-endian u16\n const idBytes = hexToBytes(secretJson.identifier);\n let identifierU16 = 1;\n if (idBytes.length >= 2) {\n identifierU16 = idBytes[0] | (idBytes[1] << 8);\n }\n if (identifierU16 === 0) {\n identifierU16 = 1; // Default to 1 if parsing failed\n }\n\n const parsedIdentifier = identifierFromU16(identifierU16);\n\n const secretPackage: DkgRound1SecretPackage = new round1.SecretPackage(\n Ed25519Sha512,\n parsedIdentifier,\n coefficients,\n commitment,\n secretJson.min_signers,\n secretJson.max_signers,\n );\n\n // Load the round 1 package as well\n const round1PackagePath = path.join(packagesDir, \"round1_package.json\");\n const packageJson = JSON.parse(fs.readFileSync(round1PackagePath, \"utf-8\")) as {\n header: { version: number; ciphersuite: string };\n commitment: string[];\n proof_of_knowledge: string;\n };\n\n const ourRound1Package = serde.round1PackageFromJson(packageJson);\n\n return { secretPackage, ourRound1Package };\n}\n\n/**\n * Validate the round 2 request from the coordinator.\n *\n * Port of request validation from cmd/dkg/participant/round2.rs lines 118-158.\n */\nfunction validateRound2Request(\n sealedRequest: SealedRequest,\n groupId: ARID,\n expectedCoordinator: XID,\n): ARID {\n // Validate the request function\n if (!sealedRequest.function().equals(EnvelopeFunction.fromString(\"dkgRound2\"))) {\n throw new Error(`Unexpected request function: ${sealedRequest.function().toString()}`);\n }\n\n // Validate the sender is the expected coordinator\n if (sealedRequest.sender().xid().urString() !== expectedCoordinator.urString()) {\n throw new Error(\n `Unexpected request sender: ${sealedRequest.sender().xid().urString()} ` +\n `(expected coordinator ${expectedCoordinator.urString()})`,\n );\n }\n\n // Validate the group ID matches\n const requestGroupIdEnvelope = sealedRequest.objectForParameter(\"group\");\n if (requestGroupIdEnvelope === undefined) {\n throw new Error(\"Request missing group parameter\");\n }\n const requestGroupId = requestGroupIdEnvelope.extractSubject((cbor) => ARID.fromTaggedCbor(cbor));\n if (requestGroupId.urString() !== groupId.urString()) {\n throw new Error(\n `Request group ID ${requestGroupId.urString()} does not match expected ${groupId.urString()}`,\n );\n }\n\n // Extract where we should post our response\n const responseAridEnvelope = sealedRequest.objectForParameter(\"responseArid\");\n if (responseAridEnvelope === undefined) {\n throw new Error(\"Request missing responseArid parameter\");\n }\n const responseArid = responseAridEnvelope.extractSubject((cbor) => ARID.fromTaggedCbor(cbor));\n\n return responseArid;\n}\n\n/**\n * Extract round 1 packages from the request and convert to Map<Identifier, Package>.\n *\n * Port of `extract_round1_packages()` from cmd/dkg/participant/round2.rs lines 291-366.\n */\nfunction extractRound1Packages(\n request: SealedRequest,\n groupRecord: GroupRecord,\n ownerXid: XID,\n): Round1Packages {\n // Build XID -> Identifier mapping based on sorted participant order\n const sortedXids: XID[] = groupRecord.participants().map((p) => p.xid());\n\n // Add owner if not already in list\n const ownerUrString = ownerXid.urString();\n if (!sortedXids.some((xid) => xid.urString() === ownerUrString)) {\n sortedXids.push(ownerXid);\n }\n\n // Sort by XID byte order — mirrors Rust `XID::cmp` (raw 32-byte\n // lex compare). The earlier port used `urString().localeCompare(...)`,\n // which differs from byte order for any byte ≥ 0x80 and is locale-\n // aware, producing different FROST identifier assignments than Rust.\n sortedXids.sort((a, b) => compareXidBytes(a.toData(), b.toData()));\n\n // Deduplicate\n const deduped: XID[] = [];\n for (const xid of sortedXids) {\n if (deduped.length === 0 || deduped[deduped.length - 1].urString() !== xid.urString()) {\n deduped.push(xid);\n }\n }\n\n // Build XID -> Identifier mapping (1-indexed)\n const xidToIdentifier = new Map<string, FrostIdentifier>();\n for (let i = 0; i < deduped.length; i++) {\n const identifier = identifierFromU16(i + 1);\n xidToIdentifier.set(deduped[i].urString(), identifier);\n }\n\n const myXidStr = ownerXid.urString();\n\n // Extract all round1Package parameters\n const packages = new Map<FrostIdentifier, DkgRound1Package>();\n const packagesByXid: [XID, DkgRound1Package][] = [];\n\n const packageEnvelopes = request.objectsForParameter(\"round1Package\");\n for (const packageEnvelope of packageEnvelopes) {\n // Extract participant XID from the envelope\n const participantEnvelope = packageEnvelope.objectForPredicate(\"participant\");\n if (participantEnvelope === undefined) {\n throw new Error(\"round1Package missing participant predicate\");\n }\n const participantXid = participantEnvelope.extractSubject((cbor) => XID.fromTaggedCbor(cbor));\n\n // Skip our own package\n if (participantXid.urString() === myXidStr) {\n continue;\n }\n\n // Extract the package bytes (stored as JSON tag)\n const packageJson = packageEnvelope.extractSubject((cbor) => JSONWrapper.fromTaggedCbor(cbor));\n const packageData = JSON.parse(new TextDecoder().decode(packageJson.toData())) as {\n header: { version: number; ciphersuite: string };\n commitment: string[];\n proof_of_knowledge: string;\n };\n\n const pkg = serde.round1PackageFromJson(packageData);\n\n // Get the identifier for this participant\n const identifier = xidToIdentifier.get(participantXid.urString());\n if (identifier === undefined) {\n throw new Error(`Unknown participant XID in round1Package: ${participantXid.urString()}`);\n }\n\n packages.set(identifier, pkg);\n packagesByXid.push([participantXid, pkg]);\n }\n\n // Validate we have the expected number of packages\n const expectedPackages = xidToIdentifier.size - 1; // Exclude ourselves\n if (packages.size !== expectedPackages) {\n throw new Error(`Expected ${expectedPackages} Round 1 packages, found ${packages.size}`);\n }\n\n return [packages, packagesByXid];\n}\n\n/**\n * Build the response body containing Round 2 packages.\n *\n * Port of `build_response_body()` from cmd/dkg/participant/round2.rs lines 373-425.\n */\nfunction buildResponseBody(\n groupId: ARID,\n participantXid: XID,\n responseArid: ARID,\n round2Packages: Map<FrostIdentifier, unknown>,\n groupRecord: GroupRecord,\n): Envelope {\n // Build Identifier -> XID mapping\n const sortedXids: XID[] = groupRecord.participants().map((p) => p.xid());\n\n // Add participant if not already in list\n const participantUrString = participantXid.urString();\n if (!sortedXids.some((xid) => xid.urString() === participantUrString)) {\n sortedXids.push(participantXid);\n }\n\n // Sort by XID byte order — mirrors Rust `XID::cmp` (raw 32-byte\n // lex compare). The earlier port used `urString().localeCompare(...)`,\n // which differs from byte order for any byte ≥ 0x80 and is locale-\n // aware, producing different FROST identifier assignments than Rust.\n sortedXids.sort((a, b) => compareXidBytes(a.toData(), b.toData()));\n\n // Deduplicate\n const deduped: XID[] = [];\n for (const xid of sortedXids) {\n if (deduped.length === 0 || deduped[deduped.length - 1].urString() !== xid.urString()) {\n deduped.push(xid);\n }\n }\n\n // Build Identifier -> XID mapping (1-indexed)\n const identifierToXid = new Map<string, XID>();\n for (let i = 0; i < deduped.length; i++) {\n const identifier = identifierFromU16(i + 1);\n identifierToXid.set(identifierToHex(identifier), deduped[i]);\n }\n\n let envelope = Envelope.unit()\n .addType(\"dkgRound2Response\")\n .addAssertion(\"group\", groupId)\n .addAssertion(\"participant\", participantXid)\n .addAssertion(\"response_arid\", responseArid);\n\n // Add each Round 2 package with the recipient's XID\n for (const [identifier, pkg] of round2Packages) {\n const idHex = identifierToHex(identifier);\n const recipientXid = identifierToXid.get(idHex);\n if (recipientXid === undefined) {\n throw new Error(\"Unknown identifier in round2_packages\");\n }\n\n // Serialize package to JSON and wrap in CBOR JSON tag\n const serialized = serializeDkgRound2Package(\n pkg as Parameters<typeof serializeDkgRound2Package>[0],\n );\n const jsonStr = JSON.stringify(serialized);\n const jsonBytes = new TextEncoder().encode(jsonStr);\n const jsonWrapper = JSONWrapper.fromData(jsonBytes);\n\n const packageEnvelope = Envelope.new(jsonWrapper).addAssertion(\"recipient\", recipientXid);\n\n envelope = envelope.addAssertion(\"round2Package\", packageEnvelope);\n }\n\n return envelope;\n}\n\n/**\n * Serialize round 2 secret package to JSON format for persistence.\n *\n * Mirrors the on-disk shape produced by Rust\n * `serde_json::to_vec_pretty(&frost::keys::dkg::round2::SecretPackage)`\n * (see `frost-rust/frost-core/src/keys/dkg.rs:269-287`):\n *\n * ```json\n * {\n * \"identifier\": \"<lowercase hex scalar>\",\n * \"commitment\": [\"<hex>\", \"<hex>\", ...],\n * \"secret_share\": \"<hex>\",\n * \"min_signers\": <u16>,\n * \"max_signers\": <u16>\n * }\n * ```\n *\n * `frost::keys::dkg::round2::SecretPackage` is\n * `#[serde(deny_unknown_fields)]`. The earlier port emitted\n * camelCase keys (`secretShare`, `minSigners`, `maxSigners`), a\n * nested `commitment.coefficients` shape, and a numeric\n * `identifier` — all of which Rust's standard derive would\n * reject and which had no chance of round-tripping with Rust.\n *\n * `participantIndex` is unused now that the identifier comes\n * directly from `secret.identifier.serialize()`; we keep it in the\n * signature for source-level parity with the call sites.\n */\nfunction serializeRound2SecretPackage(\n secret: DkgRound2SecretPackage,\n _participantIndex: number,\n): Record<string, unknown> {\n const commitment = secret.commitment;\n const commitmentCoefficients = commitment.serialize().map((c: Uint8Array) => bytesToHex(c));\n const secretShare = bytesToHex(Ed25519Sha512.serializeScalar(secret.secretShare()));\n\n return {\n identifier: bytesToHex(secret.identifier.serialize()),\n commitment: commitmentCoefficients,\n secret_share: secretShare,\n min_signers: secret.minSigners,\n max_signers: secret.maxSigners,\n };\n}\n\n/**\n * Persist round 2 state to disk.\n *\n * Port of round 2 secret persistence from cmd/dkg/participant/round2.rs lines 229-251.\n */\nfunction persistRound2State(\n registryPath: string,\n groupId: ARID,\n round2Secret: DkgRound2SecretPackage,\n round1PackagesByXid: [XID, DkgRound1Package][],\n participantIndex: number,\n): string {\n const packagesDir = groupStateDir(registryPath, groupId.hex());\n fs.mkdirSync(packagesDir, { recursive: true });\n\n // Persist Round 2 secret\n const round2SecretPath = path.join(packagesDir, \"round2_secret.json\");\n const round2SecretJson = serializeRound2SecretPackage(round2Secret, participantIndex);\n fs.writeFileSync(round2SecretPath, JSON.stringify(round2SecretJson, null, 2));\n\n // Persist received Round 1 packages for finalize phase\n const round1PackagesPath = path.join(packagesDir, \"collected_round1.json\");\n const round1Json: Record<string, unknown> = {};\n for (const [xid, pkg] of round1PackagesByXid) {\n const packageJson = serde.round1PackageToJson(pkg);\n round1Json[xid.urString()] = packageJson;\n }\n fs.writeFileSync(round1PackagesPath, JSON.stringify(round1Json, null, 2));\n\n return round2SecretPath;\n}\n\n/**\n * Execute the DKG participant round 2 command.\n *\n * Responds to the Round 2 request from the coordinator, runs FROST DKG part2\n * to generate Round 2 packages, and posts the response back.\n *\n * Port of `CommandArgs::exec()` from cmd/dkg/participant/round2.rs lines 55-288.\n */\nexport async function round2(\n _client: StorageClient | undefined,\n options: DkgRound2Options,\n cwd: string,\n): Promise<DkgRound2Result> {\n if (options.storageSelection === undefined) {\n throw new Error(\"Hubert storage is required for round2\");\n }\n\n const registryPath = resolveRegistryPath(options.registryPath, cwd);\n const registry = Registry.load(registryPath);\n\n const owner = registry.owner();\n if (owner === undefined) {\n throw new Error(\"Registry owner is required\");\n }\n\n const groupId = parseAridUr(options.groupId);\n const groupRecord = registry.group(groupId);\n if (groupRecord === undefined) {\n throw new Error(\"Group not found in registry\");\n }\n\n // Get the ARID where we're listening for the Round 2 request\n const listeningAtArid = groupRecord.listeningAtArid();\n if (listeningAtArid === undefined) {\n throw new Error(\"No listening ARID for this group. Did you respond to the invite?\");\n }\n\n // Load our Round 1 secret\n const round1State = loadRound1State(registryPath, groupId);\n\n if (isVerbose() || options.verbose === true) {\n console.error(\"Fetching Round 2 request from Hubert...\");\n }\n\n const client = await createStorageClient(options.storageSelection);\n\n // Fetch the Round 2 request from where we're listening\n const requestEnvelope = await getWithIndicator(\n client,\n listeningAtArid,\n \"Round 2 request\",\n options.timeoutSeconds,\n options.verbose ?? false,\n );\n\n if (requestEnvelope === null || requestEnvelope === undefined) {\n throw new Error(\"Round 2 request not found in Hubert storage\");\n }\n\n // Decrypt and validate the request\n const ownerPrivateKeys = owner.xidDocument().inceptionPrivateKeys();\n if (ownerPrivateKeys === undefined) {\n throw new Error(\"Owner XID document has no private keys\");\n }\n\n const now = CborDate.now().datetime();\n const sealedRequest = SealedRequest.tryFromEnvelope(\n requestEnvelope,\n undefined,\n now,\n ownerPrivateKeys,\n );\n\n // Validate the request and extract response ARID\n const expectedCoordinator = groupRecord.coordinator().xid();\n const responseArid = validateRound2Request(sealedRequest, groupId, expectedCoordinator);\n\n // Extract Round 1 packages from the request\n const [round1Packages, round1PackagesByXid] = extractRound1Packages(\n sealedRequest,\n groupRecord,\n owner.xid(),\n );\n\n if (isVerbose() || options.verbose === true) {\n console.error(`Received ${round1Packages.size} Round 1 packages. Running DKG part2...`);\n }\n\n // Allocate next response ARID for the finalize phase\n const nextResponseArid = ARID.new();\n\n // Run FROST DKG part2\n // Convert Map<Identifier, Package> to Map<string, Package> for dkgPart2\n const round1PackagesHex = new Map<string, DkgRound1Package>();\n for (const [id, pkg] of round1Packages) {\n round1PackagesHex.set(identifierToHex(id), pkg);\n }\n\n const [round2Secret, round2Packages] = dkgPart2(round1State.secretPackage, round1PackagesHex);\n\n if (isVerbose() || options.verbose === true) {\n console.error(`Generated ${round2Packages.size} Round 2 packages.`);\n }\n\n // Convert round2Packages back to use Identifier keys for buildResponseBody\n const round2PackagesById = new Map<FrostIdentifier, unknown>();\n for (const [idHex, pkg] of round2Packages) {\n // Find the identifier that matches this hex\n for (const [id] of round1Packages) {\n if (identifierToHex(id) === idHex) {\n round2PackagesById.set(id, pkg);\n break;\n }\n }\n }\n\n // Build response with Round 2 packages\n const responseBody = buildResponseBody(\n groupId,\n owner.xid(),\n nextResponseArid,\n round2PackagesById,\n groupRecord,\n );\n\n const signerPrivateKeys = owner.xidDocument().inceptionPrivateKeys();\n if (signerPrivateKeys === undefined) {\n throw new Error(\"Owner XID document has no signing keys\");\n }\n\n // Get coordinator's XID document for encryption\n const coordinatorXid = groupRecord.coordinator().xid();\n const coordinatorRecord = registry.participant(coordinatorXid);\n let coordinatorDoc: XIDDocument;\n if (coordinatorRecord !== undefined) {\n coordinatorDoc = coordinatorRecord.xidDocument();\n } else {\n // Check if coordinator is the owner\n if (owner.xid().urString() === coordinatorXid.urString()) {\n coordinatorDoc = owner.xidDocument();\n } else {\n throw new Error(`Coordinator ${coordinatorXid.urString()} not found in registry`);\n }\n }\n\n // Get peer continuation from the request\n const peerContinuation = sealedRequest.peerContinuation();\n\n let sealed = SealedResponse.newSuccess(sealedRequest.id(), owner.xidDocument()).withResult(\n responseBody,\n );\n\n if (peerContinuation !== undefined) {\n sealed = sealed.withPeerContinuation(peerContinuation);\n }\n\n if (options.preview === true) {\n // Show the response envelope structure without encryption\n const unsealedEnvelope = sealed.toEnvelope(\n undefined, // No expiration for responses\n signerPrivateKeys,\n undefined,\n );\n const envelopeUr = unsealedEnvelope.urString();\n console.log(envelopeUr);\n\n return {\n listeningArid: nextResponseArid.urString(),\n envelopeUr,\n };\n }\n\n // Calculate participant index for serialization. Sort by XID byte\n // order (mirrors Rust `XID::cmp`) so the 1-indexed position matches\n // what the coordinator used when assigning FROST identifiers. The\n // earlier port sorted by UR string via `Array.sort()` (default JS\n // string compare), which diverges from Rust byte order for any\n // byte ≥ 0x80.\n const sortedParticipantXids: XID[] = groupRecord.participants().map((p) => p.xid());\n const ownerXid = owner.xid();\n const ownerXidStr = ownerXid.urString();\n if (!sortedParticipantXids.some((x) => x.urString() === ownerXidStr)) {\n sortedParticipantXids.push(ownerXid);\n }\n sortedParticipantXids.sort((a, b) => compareXidBytes(a.toData(), b.toData()));\n const participantIndex = sortedParticipantXids.findIndex((x) => x.urString() === ownerXidStr) + 1; // 1-indexed\n\n // Persist Round 2 secret and collected round1 packages\n const round2SecretPath = persistRound2State(\n registryPath,\n groupId,\n round2Secret,\n round1PackagesByXid,\n participantIndex,\n );\n\n const responseEnvelope = sealed.toEnvelope(\n undefined, // No expiration for responses\n signerPrivateKeys,\n coordinatorDoc,\n );\n\n // Post the response\n await putWithIndicator(\n client,\n responseArid,\n responseEnvelope,\n \"Round 2 Response\",\n options.verbose ?? false,\n );\n\n // Update contributions in registry\n const updatedGroupRecord = registry.group(groupId);\n if (updatedGroupRecord !== undefined) {\n const contributions = updatedGroupRecord.contributions();\n contributions.round2Secret = round2SecretPath;\n updatedGroupRecord.setContributions(contributions);\n // Set new listening ARID for finalize phase\n updatedGroupRecord.setListeningAtArid(nextResponseArid);\n registry.save(registryPath);\n }\n\n if (isVerbose() || options.verbose === true) {\n console.error(`Posted Round 2 response to ${responseArid.urString()}`);\n }\n\n return {\n listeningArid: nextResponseArid.urString(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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