@bcts/frost-hubert 1.0.0-alpha.23 → 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 +345 -71
- package/dist/bin/frost.cjs.map +1 -1
- package/dist/bin/frost.mjs +345 -71
- 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/cmd/index.cjs +28 -22
- package/dist/cmd/index.d.cts +2 -2
- package/dist/cmd/index.d.mts +2 -2
- package/dist/cmd/index.mjs +7 -3
- 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 +6 -102
- package/dist/dkg/index.cjs.map +1 -1
- package/dist/dkg/index.d.cts +2 -2
- package/dist/dkg/index.d.mts +2 -2
- package/dist/dkg/index.mjs +4 -101
- package/dist/dkg/index.mjs.map +1 -1
- 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/{index-BkqLimZT.d.mts → index-B3c-80VS.d.cts} +26 -3
- package/dist/index-B3c-80VS.d.cts.map +1 -0
- package/dist/{index-BJlwbPYu.d.cts → index-BgbSGpxn.d.mts} +102 -80
- package/dist/index-BgbSGpxn.d.mts.map +1 -0
- package/dist/{index-BMbPgH0W.d.cts → index-C8QeHNwa.d.cts} +46 -2
- package/dist/{index-BMbPgH0W.d.cts.map → index-C8QeHNwa.d.cts.map} +1 -1
- package/dist/{index-DmxfT59Y.d.cts → index-D3QTWkEm.d.mts} +26 -3
- package/dist/index-D3QTWkEm.d.mts.map +1 -0
- package/dist/{index-DoV5HFvV.d.mts → index-DVbWyOs7.d.mts} +46 -2
- package/dist/{index-DoV5HFvV.d.mts.map → index-DVbWyOs7.d.mts.map} +1 -1
- package/dist/{index-Dzm1v4_4.d.mts → index-F1iNEAJR.d.cts} +102 -80
- package/dist/index-F1iNEAJR.d.cts.map +1 -0
- package/dist/index.cjs +31 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +9 -4
- 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 +85 -10
- package/dist/registry/index.cjs.map +1 -1
- package/dist/registry/index.d.cts +1 -1
- package/dist/registry/index.d.mts +1 -1
- package/dist/registry/index.mjs +85 -10
- package/dist/registry/index.mjs.map +1 -1
- package/dist/{registry-loI1_Mh1.cjs → registry-9puTaRrD.cjs} +1 -1
- package/dist/{registry-loI1_Mh1.cjs.map → registry-9puTaRrD.cjs.map} +1 -1
- package/dist/{registry-CgrCZ4En.mjs → registry-BpCwtrRt.mjs} +1 -1
- package/dist/{registry-CgrCZ4En.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 +10 -10
- 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 +51 -17
- 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 +32 -3
- package/src/registry/owner-record.ts +12 -0
- package/src/registry/participant-record.ts +35 -2
- package/src/registry/registry-impl.ts +74 -18
- package/dist/cmd-5yLeC_QL.mjs +0 -4708
- package/dist/cmd-5yLeC_QL.mjs.map +0 -1
- package/dist/cmd-BfZjC3Uh.cjs +0 -4847
- package/dist/cmd-BfZjC3Uh.cjs.map +0 -1
- package/dist/index-BJlwbPYu.d.cts.map +0 -1
- package/dist/index-BkqLimZT.d.mts.map +0 -1
- package/dist/index-DmxfT59Y.d.cts.map +0 -1
- package/dist/index-Dzm1v4_4.d.mts.map +0 -1
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
|
+
const require_registry_index = require("./registry/index.cjs");
|
|
3
|
+
const require_common = require("./common-lKP5EzHy.cjs");
|
|
4
|
+
const require_busy = require("./busy-EZU7EKr6.cjs");
|
|
5
|
+
const require_parallel = require("./parallel-D1R6ZGlY.cjs");
|
|
6
|
+
let _bcts_components = require("@bcts/components");
|
|
7
|
+
let _bcts_dcbor = require("@bcts/dcbor");
|
|
8
|
+
let _bcts_envelope = require("@bcts/envelope");
|
|
9
|
+
let _bcts_gstp = require("@bcts/gstp");
|
|
10
|
+
let node_fs = require("node:fs");
|
|
11
|
+
node_fs = require_chunk.__toESM(node_fs, 1);
|
|
12
|
+
let node_path = require("node:path");
|
|
13
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
14
|
+
let _frosts_ed25519 = require("@frosts/ed25519");
|
|
15
|
+
//#region src/cmd/dkg/coordinator/round1.ts
|
|
16
|
+
/**
|
|
17
|
+
* Copyright © 2023-2026 Blockchain Commons, LLC
|
|
18
|
+
* Copyright © 2025-2026 Parity Technologies
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
* DKG coordinator round 1 command.
|
|
22
|
+
*
|
|
23
|
+
* Port of cmd/dkg/coordinator/round1.rs from frost-hubert-rust.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
var round1_exports = /* @__PURE__ */ require_chunk.__exportAll({ round1: () => round1 });
|
|
28
|
+
/**
|
|
29
|
+
* Validate that the owner is the coordinator for this group.
|
|
30
|
+
*
|
|
31
|
+
* Port of `validate_coordinator()` from cmd/dkg/coordinator/round1.rs lines 201-214.
|
|
32
|
+
*/
|
|
33
|
+
function validateCoordinator(groupRecord, owner) {
|
|
34
|
+
if (groupRecord.coordinator().xid().urString() !== owner.xid().urString()) throw new Error(`Only the coordinator can collect and send Round 2 requests. Coordinator: ${groupRecord.coordinator().xid().urString()}, Owner: ${owner.xid().urString()}`);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetch a single round 1 response from storage.
|
|
38
|
+
*
|
|
39
|
+
* Port of `fetch_and_validate_response()` from cmd/dkg/coordinator/round1.rs lines 512-566.
|
|
40
|
+
*/
|
|
41
|
+
async function fetchRound1Response(client, responseArid, timeout, coordinator, expectedGroupId, participantName) {
|
|
42
|
+
const envelope = await require_busy.getWithIndicator(client, responseArid, participantName, timeout, require_common.isVerbose());
|
|
43
|
+
if (envelope === void 0) throw new Error("Response not found in Hubert storage");
|
|
44
|
+
const coordinatorPrivateKeys = coordinator.inceptionPrivateKeys();
|
|
45
|
+
if (coordinatorPrivateKeys === void 0) throw new Error("Coordinator XID document has no inception private keys");
|
|
46
|
+
const now = _bcts_dcbor.CborDate.now().datetime();
|
|
47
|
+
const sealedResponse = _bcts_gstp.SealedResponse.tryFromEncryptedEnvelope(envelope, void 0, now, coordinatorPrivateKeys);
|
|
48
|
+
if (sealedResponse.isErr()) {
|
|
49
|
+
const reasonEnvelope = sealedResponse.error().objectForPredicate("reason");
|
|
50
|
+
const reason = reasonEnvelope !== void 0 ? reasonEnvelope.extractSubject((cbor) => cbor.toText()) : "unknown reason";
|
|
51
|
+
throw new Error(`Participant rejected invite: ${reason}`);
|
|
52
|
+
}
|
|
53
|
+
const result = sealedResponse.result();
|
|
54
|
+
validateRound1Response(result, expectedGroupId);
|
|
55
|
+
const nextResponseArid = result.tryObjectForPredicate("response_arid", (cbor) => {
|
|
56
|
+
return _bcts_components.ARID.fromTaggedCbor(cbor);
|
|
57
|
+
});
|
|
58
|
+
return [extractRound1Package(result), nextResponseArid];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Validate a round 1 response envelope.
|
|
62
|
+
*
|
|
63
|
+
* Port of `validate_round1_response()` from cmd/dkg/coordinator/round1.rs lines 568-586.
|
|
64
|
+
*/
|
|
65
|
+
function validateRound1Response(result, expectedGroupId) {
|
|
66
|
+
result.checkSubjectUnit();
|
|
67
|
+
result.checkType("dkgRound1Response");
|
|
68
|
+
const groupId = result.tryObjectForPredicate("group", (cbor) => {
|
|
69
|
+
return _bcts_components.ARID.fromTaggedCbor(cbor);
|
|
70
|
+
});
|
|
71
|
+
if (groupId.urString() !== expectedGroupId.urString()) throw new Error(`Response group ID ${groupId.urString()} does not match expected ${expectedGroupId.urString()}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Extract a round 1 package from a response envelope.
|
|
75
|
+
*
|
|
76
|
+
* Port of `extract_round1_package()` from cmd/dkg/coordinator/round1.rs lines 588-598.
|
|
77
|
+
*/
|
|
78
|
+
function extractRound1Package(result) {
|
|
79
|
+
const round1Envelope = result.objectForPredicate("round1_package");
|
|
80
|
+
if (round1Envelope === void 0) throw new Error("round1_package missing from response");
|
|
81
|
+
const round1Json = round1Envelope.extractSubject((cbor) => {
|
|
82
|
+
return _bcts_components.JSON.fromTaggedCbor(cbor);
|
|
83
|
+
});
|
|
84
|
+
const jsonStr = new TextDecoder().decode(round1Json.asBytes());
|
|
85
|
+
const jsonObj = globalThis.JSON.parse(jsonStr);
|
|
86
|
+
return _frosts_ed25519.serde.round1PackageFromJson(jsonObj);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Validate and extract data from a round 1 response (for parallel fetch).
|
|
90
|
+
*
|
|
91
|
+
* Port of `validate_and_extract_round1_response()` from cmd/dkg/coordinator/round1.rs lines 674-707.
|
|
92
|
+
*/
|
|
93
|
+
function validateAndExtractRound1Response(envelope, coordinatorKeys, expectedGroupId) {
|
|
94
|
+
const now = _bcts_dcbor.CborDate.now().datetime();
|
|
95
|
+
const sealedResponse = _bcts_gstp.SealedResponse.tryFromEncryptedEnvelope(envelope, void 0, now, coordinatorKeys);
|
|
96
|
+
if (sealedResponse.isErr()) {
|
|
97
|
+
const reasonEnvelope = sealedResponse.error().objectForPredicate("reason");
|
|
98
|
+
return { rejected: `Participant rejected invite: ${reasonEnvelope !== void 0 ? reasonEnvelope.extractSubject((cbor) => cbor.toText()) : "unknown reason"}` };
|
|
99
|
+
}
|
|
100
|
+
const result = sealedResponse.result();
|
|
101
|
+
validateRound1Response(result, expectedGroupId);
|
|
102
|
+
const nextResponseArid = result.tryObjectForPredicate("response_arid", (cbor) => {
|
|
103
|
+
return _bcts_components.ARID.fromTaggedCbor(cbor);
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
package: extractRound1Package(result),
|
|
107
|
+
nextResponseArid
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Collect Round 1 responses in parallel with progress display.
|
|
112
|
+
*
|
|
113
|
+
* Port of `collect_round1_responses_parallel()` from cmd/dkg/coordinator/round1.rs lines 636-671.
|
|
114
|
+
*/
|
|
115
|
+
async function collectRound1Parallel(client, registry, pendingRequests, coordinator, expectedGroupId, timeout) {
|
|
116
|
+
const requests = [];
|
|
117
|
+
for (const [xid, arid] of pendingRequests.iterCollect()) {
|
|
118
|
+
const name = registry.participant(xid)?.petName() ?? xid.urString();
|
|
119
|
+
requests.push([
|
|
120
|
+
xid,
|
|
121
|
+
arid,
|
|
122
|
+
name
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
const coordinatorKeys = coordinator.inceptionPrivateKeys();
|
|
126
|
+
if (coordinatorKeys === void 0) throw new Error("Missing coordinator private keys");
|
|
127
|
+
const config = { timeoutSeconds: timeout };
|
|
128
|
+
const groupId = expectedGroupId;
|
|
129
|
+
return require_parallel.parallelFetch(client, requests, (envelope, _xid) => {
|
|
130
|
+
return validateAndExtractRound1Response(envelope, coordinatorKeys, groupId);
|
|
131
|
+
}, config);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build a Round 2 request for a single participant.
|
|
135
|
+
*
|
|
136
|
+
* Port of `build_round2_request_for_participant()` from cmd/dkg/coordinator/round1.rs lines 604-623.
|
|
137
|
+
*/
|
|
138
|
+
function buildRound2RequestForParticipant(sender, groupId, round1Packages, responseArid) {
|
|
139
|
+
let request = _bcts_gstp.SealedRequest.new("dkgRound2", _bcts_components.ARID.new(), sender).withParameter("group", groupId).withParameter("responseArid", responseArid);
|
|
140
|
+
for (const [xid, pkg] of round1Packages) {
|
|
141
|
+
const packageJson = _frosts_ed25519.serde.round1PackageToJson(pkg);
|
|
142
|
+
const jsonStr = globalThis.JSON.stringify(packageJson);
|
|
143
|
+
const jsonBytes = new TextEncoder().encode(jsonStr);
|
|
144
|
+
const jsonWrapper = _bcts_components.JSON.fromData(jsonBytes);
|
|
145
|
+
const packageEnvelope = _bcts_envelope.Envelope.new(jsonWrapper).addAssertion("participant", xid);
|
|
146
|
+
request = request.withParameter("round1Package", packageEnvelope);
|
|
147
|
+
}
|
|
148
|
+
return request;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Dispatch Round 2 requests in parallel.
|
|
152
|
+
*
|
|
153
|
+
* Port of `dispatch_round2_requests_parallel()` from cmd/dkg/coordinator/round1.rs lines 729-844.
|
|
154
|
+
*/
|
|
155
|
+
async function dispatchRound2RequestsParallel(client, registry, registryPath, coordinator, groupId, successes, preview) {
|
|
156
|
+
const signerPrivateKeys = coordinator.inceptionPrivateKeys();
|
|
157
|
+
if (signerPrivateKeys === void 0) throw new Error("Coordinator XID document has no signing keys");
|
|
158
|
+
const validUntil = new Date(Date.now() + 3600 * 1e3);
|
|
159
|
+
const round1Packages = successes.map(([xid, data]) => [xid, data.package]);
|
|
160
|
+
const messages = [];
|
|
161
|
+
const collectArids = [];
|
|
162
|
+
let previewOutput;
|
|
163
|
+
for (const [xid, data] of successes) {
|
|
164
|
+
const participant = registry.participant(xid);
|
|
165
|
+
if (participant === void 0) throw new Error(`Participant ${xid.urString()} not found in registry`);
|
|
166
|
+
const recipientDoc = participant.xidDocument();
|
|
167
|
+
const participantName = participant.petName() ?? xid.urString();
|
|
168
|
+
const collectFromArid = _bcts_components.ARID.new();
|
|
169
|
+
collectArids.push([xid, collectFromArid]);
|
|
170
|
+
const request = buildRound2RequestForParticipant(coordinator, groupId, round1Packages, collectFromArid);
|
|
171
|
+
if (preview && previewOutput === void 0) previewOutput = [participantName, request.toEnvelope(validUntil, signerPrivateKeys, void 0).urString()];
|
|
172
|
+
const sealedEnvelope = request.toEnvelope(validUntil, signerPrivateKeys, recipientDoc);
|
|
173
|
+
messages.push([
|
|
174
|
+
xid,
|
|
175
|
+
data.nextResponseArid,
|
|
176
|
+
sealedEnvelope,
|
|
177
|
+
participantName
|
|
178
|
+
]);
|
|
179
|
+
}
|
|
180
|
+
console.error();
|
|
181
|
+
const sendResults = await require_parallel.parallelSend(client, messages, require_common.isVerbose());
|
|
182
|
+
const failures = [];
|
|
183
|
+
for (const [xid, err] of sendResults) if (err !== null) failures.push([xid, err.message]);
|
|
184
|
+
if (failures.length > 0) {
|
|
185
|
+
for (const [xid, error] of failures) console.error(`Failed to send to ${xid.urString()}: ${error}`);
|
|
186
|
+
throw new Error(`Failed to send Round 2 requests to ${failures.length} participants`);
|
|
187
|
+
}
|
|
188
|
+
const newPendingRequests = new require_registry_index.PendingRequests();
|
|
189
|
+
for (const [xid, collectFromArid] of collectArids) newPendingRequests.addCollectOnly(xid, collectFromArid);
|
|
190
|
+
const groupRecord = registry.groupMut(groupId);
|
|
191
|
+
if (groupRecord === void 0) throw new Error("Group not found in registry");
|
|
192
|
+
groupRecord.setPendingRequests(newPendingRequests);
|
|
193
|
+
registry.save(registryPath);
|
|
194
|
+
return previewOutput;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Update pending requests from parallel collection results.
|
|
198
|
+
*
|
|
199
|
+
* Port of `update_pending_for_round2_from_collection()` from cmd/dkg/coordinator/round1.rs lines 710-726.
|
|
200
|
+
*/
|
|
201
|
+
function updatePendingForRound2FromCollection(registry, registryPath, groupId, successes) {
|
|
202
|
+
const newPending = new require_registry_index.PendingRequests();
|
|
203
|
+
for (const [xid, data] of successes) newPending.addSendOnly(xid, data.nextResponseArid);
|
|
204
|
+
const groupRecord = registry.groupMut(groupId);
|
|
205
|
+
if (groupRecord === void 0) throw new Error("Group not found in registry");
|
|
206
|
+
groupRecord.setPendingRequests(newPending);
|
|
207
|
+
registry.save(registryPath);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Persist collected round 1 packages to disk.
|
|
211
|
+
*
|
|
212
|
+
* Port of `persist_round1_packages()` from cmd/dkg/coordinator/round1.rs lines 301-340.
|
|
213
|
+
*/
|
|
214
|
+
function persistRound1Packages(registryPath, groupId, packages) {
|
|
215
|
+
const packagesDir = require_common.groupStateDir(registryPath, groupId.hex());
|
|
216
|
+
node_fs.mkdirSync(packagesDir, { recursive: true });
|
|
217
|
+
const round1PackagesPath = node_path.join(packagesDir, "collected_round1.json");
|
|
218
|
+
const packagesJson = {};
|
|
219
|
+
for (const [xid, pkg] of packages) packagesJson[xid.urString()] = _frosts_ed25519.serde.round1PackageToJson(pkg);
|
|
220
|
+
node_fs.writeFileSync(round1PackagesPath, globalThis.JSON.stringify(packagesJson, null, 2));
|
|
221
|
+
const cwd = process.cwd();
|
|
222
|
+
if (round1PackagesPath.startsWith(cwd)) return round1PackagesPath.slice(cwd.length + 1);
|
|
223
|
+
return round1PackagesPath;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Fetch all round 1 packages sequentially.
|
|
227
|
+
*
|
|
228
|
+
* Port of `fetch_all_round1_packages()` from cmd/dkg/coordinator/round1.rs lines 243-299.
|
|
229
|
+
*/
|
|
230
|
+
async function fetchAllRound1Packages(ctx, pendingRequests, timeout) {
|
|
231
|
+
const round1Packages = [];
|
|
232
|
+
const nextResponseArids = [];
|
|
233
|
+
const errors = [];
|
|
234
|
+
for (const [participantXid, collectFromArid] of pendingRequests.iterCollect()) {
|
|
235
|
+
const participantName = ctx.registry.participant(participantXid)?.petName() ?? participantXid.urString();
|
|
236
|
+
try {
|
|
237
|
+
const [pkg, nextArid] = await fetchRound1Response(ctx.client, collectFromArid, timeout, ctx.ownerDoc, ctx.groupId, participantName);
|
|
238
|
+
round1Packages.push([participantXid, pkg]);
|
|
239
|
+
nextResponseArids.push([participantXid, nextArid]);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
errors.push([participantXid, e instanceof Error ? e.message : String(e)]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (errors.length > 0) {
|
|
245
|
+
if (require_common.isVerbose()) {
|
|
246
|
+
console.error();
|
|
247
|
+
console.error(`Failed to collect from ${errors.length} participants:`);
|
|
248
|
+
}
|
|
249
|
+
for (const [xid, error] of errors) console.error(` ${xid.urString()}: ${error}`);
|
|
250
|
+
throw new Error(`Round 1 collection incomplete: ${errors.length} of ${pendingRequests.len()} responses failed`);
|
|
251
|
+
}
|
|
252
|
+
return [round1Packages, nextResponseArids];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Collect round 1 responses sequentially.
|
|
256
|
+
*
|
|
257
|
+
* Port of `collect_round1_responses()` from cmd/dkg/coordinator/round1.rs lines 220-241.
|
|
258
|
+
*/
|
|
259
|
+
async function collectRound1Responses(ctx, pendingRequests, timeout) {
|
|
260
|
+
if (require_common.isVerbose()) console.error(`Collecting Round 1 responses from ${pendingRequests.len()} participants...`);
|
|
261
|
+
const [packages, nextResponseArids] = await fetchAllRound1Packages(ctx, pendingRequests, timeout);
|
|
262
|
+
const displayPath = persistRound1Packages(ctx.registryPath, ctx.groupId, packages);
|
|
263
|
+
updatePendingForRound2(ctx, nextResponseArids);
|
|
264
|
+
return {
|
|
265
|
+
packages,
|
|
266
|
+
nextResponseArids,
|
|
267
|
+
displayPath
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Update pending requests for round 2 (sequential path).
|
|
272
|
+
*
|
|
273
|
+
* Port of `update_pending_for_round2()` from cmd/dkg/coordinator/round1.rs lines 342-357.
|
|
274
|
+
*/
|
|
275
|
+
function updatePendingForRound2(ctx, nextResponseArids) {
|
|
276
|
+
const newPending = new require_registry_index.PendingRequests();
|
|
277
|
+
for (const [xid, sendToArid] of nextResponseArids) newPending.addSendOnly(xid, sendToArid);
|
|
278
|
+
const groupRecord = ctx.registry.groupMut(ctx.groupId);
|
|
279
|
+
if (groupRecord === void 0) throw new Error("Group not found in registry");
|
|
280
|
+
groupRecord.setPendingRequests(newPending);
|
|
281
|
+
ctx.registry.save(ctx.registryPath);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Build participant info for round 2 dispatch.
|
|
285
|
+
*
|
|
286
|
+
* Port of `build_round2_participant_info()` from cmd/dkg/coordinator/round1.rs lines 438-458.
|
|
287
|
+
*/
|
|
288
|
+
function buildRound2ParticipantInfo(registry, nextResponseArids) {
|
|
289
|
+
return nextResponseArids.map(([xid, sendToArid]) => {
|
|
290
|
+
const participant = registry.participant(xid);
|
|
291
|
+
if (participant === void 0) throw new Error(`Participant ${xid.urString()} not found in registry`);
|
|
292
|
+
return [
|
|
293
|
+
xid,
|
|
294
|
+
participant.xidDocument(),
|
|
295
|
+
sendToArid,
|
|
296
|
+
_bcts_components.ARID.new()
|
|
297
|
+
];
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Update pending for round 2 collection (sequential path).
|
|
302
|
+
*
|
|
303
|
+
* Port of `update_pending_for_round2_collection()` from cmd/dkg/coordinator/round1.rs lines 460-475.
|
|
304
|
+
*/
|
|
305
|
+
function updatePendingForRound2Collection(ctx, participantInfo) {
|
|
306
|
+
const newPendingRequests = new require_registry_index.PendingRequests();
|
|
307
|
+
for (const [xid, , , collectFromArid] of participantInfo) newPendingRequests.addCollectOnly(xid, collectFromArid);
|
|
308
|
+
const groupRecord = ctx.registry.groupMut(ctx.groupId);
|
|
309
|
+
if (groupRecord === void 0) throw new Error("Group not found in registry");
|
|
310
|
+
groupRecord.setPendingRequests(newPendingRequests);
|
|
311
|
+
ctx.registry.save(ctx.registryPath);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Dispatch Round 2 requests sequentially.
|
|
315
|
+
*
|
|
316
|
+
* Port of `dispatch_round2_requests()` from cmd/dkg/coordinator/round1.rs lines 363-436.
|
|
317
|
+
*/
|
|
318
|
+
async function dispatchRound2Requests(ctx, collection, preview) {
|
|
319
|
+
const signerPrivateKeys = ctx.ownerDoc.inceptionPrivateKeys();
|
|
320
|
+
if (signerPrivateKeys === void 0) throw new Error("Coordinator XID document has no signing keys");
|
|
321
|
+
const validUntil = new Date(Date.now() + 3600 * 1e3);
|
|
322
|
+
const participantInfo = buildRound2ParticipantInfo(ctx.registry, collection.nextResponseArids);
|
|
323
|
+
if (require_common.isVerbose()) console.error(`Sending Round 2 requests to ${participantInfo.length} participants...`);
|
|
324
|
+
else console.error();
|
|
325
|
+
let previewOutput;
|
|
326
|
+
for (const [xid, recipientDoc, sendToArid, collectFromArid] of participantInfo) {
|
|
327
|
+
const participantName = ctx.registry.participant(xid)?.petName() ?? xid.urString();
|
|
328
|
+
const request = buildRound2RequestForParticipant(ctx.ownerDoc, ctx.groupId, collection.packages, collectFromArid);
|
|
329
|
+
if (preview && previewOutput === void 0) previewOutput = [participantName, request.toEnvelope(validUntil, signerPrivateKeys, void 0).urString()];
|
|
330
|
+
const sealedEnvelope = request.toEnvelope(validUntil, signerPrivateKeys, recipientDoc);
|
|
331
|
+
await require_busy.putWithIndicator(ctx.client, sendToArid, sealedEnvelope, participantName, require_common.isVerbose());
|
|
332
|
+
}
|
|
333
|
+
updatePendingForRound2Collection(ctx, participantInfo);
|
|
334
|
+
return previewOutput;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Print summary for sequential collection.
|
|
338
|
+
*
|
|
339
|
+
* Port of `print_summary()` from cmd/dkg/coordinator/round1.rs lines 481-506.
|
|
340
|
+
*/
|
|
341
|
+
function printSummary(collection, preview) {
|
|
342
|
+
if (preview !== void 0) {
|
|
343
|
+
const [participantName, ur] = preview;
|
|
344
|
+
if (require_common.isVerbose()) {
|
|
345
|
+
console.error(`# Round 2 preview for ${participantName}`);
|
|
346
|
+
console.error();
|
|
347
|
+
}
|
|
348
|
+
console.error(`Collected ${collection.packages.length} Round 1 packages to ${collection.displayPath} and sent ${collection.nextResponseArids.length} Round 2 requests.`);
|
|
349
|
+
console.log(ur);
|
|
350
|
+
} else if (require_common.isVerbose()) {
|
|
351
|
+
console.error();
|
|
352
|
+
console.error(`Collected ${collection.packages.length} Round 1 packages to ${collection.displayPath} and sent ${collection.nextResponseArids.length} Round 2 requests.`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Print summary for parallel collection.
|
|
357
|
+
*
|
|
358
|
+
* Port of `print_summary_parallel()` from cmd/dkg/coordinator/round1.rs lines 847-901.
|
|
359
|
+
*/
|
|
360
|
+
function printSummaryParallel(collection, displayPath, preview) {
|
|
361
|
+
if (collection.rejections.length > 0) {
|
|
362
|
+
console.error();
|
|
363
|
+
console.error("Rejections:");
|
|
364
|
+
for (const [xid, reason] of collection.rejections) console.error(` ${xid.urString()}: ${reason}`);
|
|
365
|
+
}
|
|
366
|
+
if (collection.errors.length > 0) {
|
|
367
|
+
console.error();
|
|
368
|
+
console.error("Errors:");
|
|
369
|
+
for (const [xid, error] of collection.errors) console.error(` ${xid.urString()}: ${error}`);
|
|
370
|
+
}
|
|
371
|
+
if (collection.timeouts.length > 0) {
|
|
372
|
+
console.error();
|
|
373
|
+
console.error("Timeouts:");
|
|
374
|
+
for (const xid of collection.timeouts) console.error(` ${xid.urString()}`);
|
|
375
|
+
}
|
|
376
|
+
if (!collection.allSucceeded()) {
|
|
377
|
+
console.error();
|
|
378
|
+
bailWithCollectionSummary(collection);
|
|
379
|
+
}
|
|
380
|
+
if (preview !== void 0) {
|
|
381
|
+
const [participantName, ur] = preview;
|
|
382
|
+
if (require_common.isVerbose()) {
|
|
383
|
+
console.error(`# Round 2 preview for ${participantName}`);
|
|
384
|
+
console.error();
|
|
385
|
+
}
|
|
386
|
+
console.error(`Collected ${collection.successes.length} Round 1 packages to ${displayPath} and sent ${collection.successes.length} Round 2 requests.`);
|
|
387
|
+
console.log(ur);
|
|
388
|
+
} else if (require_common.isVerbose()) {
|
|
389
|
+
console.error();
|
|
390
|
+
console.error(`Collected ${collection.successes.length} Round 1 packages to ${displayPath} and sent ${collection.successes.length} Round 2 requests.`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Print collection summary and throw error.
|
|
395
|
+
*
|
|
396
|
+
* Port of `bail_with_collection_summary()` from cmd/dkg/coordinator/round1.rs lines 903-913.
|
|
397
|
+
*/
|
|
398
|
+
function bailWithCollectionSummary(collection) {
|
|
399
|
+
const msg = `Round 1 collection incomplete: ${collection.successes.length} succeeded, ${collection.rejections.length} rejected, ${collection.errors.length} errors, ${collection.timeouts.length} timeouts`;
|
|
400
|
+
console.error(msg);
|
|
401
|
+
throw new Error(msg);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Execute the DKG coordinator round 1 command.
|
|
405
|
+
*
|
|
406
|
+
* Collects commitment packages from participants.
|
|
407
|
+
*
|
|
408
|
+
* Port of `CommandArgs::exec()` from cmd/dkg/coordinator/round1.rs lines 59-173.
|
|
409
|
+
*/
|
|
410
|
+
async function round1(client, options, cwd) {
|
|
411
|
+
const registryPath = require_registry_index.resolveRegistryPath(options.registryPath, cwd);
|
|
412
|
+
const registry = require_registry_index.Registry.load(registryPath);
|
|
413
|
+
const owner = registry.owner();
|
|
414
|
+
if (owner === void 0) throw new Error("Registry owner is required");
|
|
415
|
+
const ownerDoc = owner.xidDocument();
|
|
416
|
+
const groupId = require_common.parseAridUr(options.groupId);
|
|
417
|
+
const groupRecord = registry.group(groupId);
|
|
418
|
+
if (groupRecord === void 0) throw new Error(`Group ${options.groupId} not found in registry`);
|
|
419
|
+
validateCoordinator(groupRecord, owner);
|
|
420
|
+
const pendingRequests = groupRecord.pendingRequests();
|
|
421
|
+
if (pendingRequests.isEmpty()) throw new Error("No pending requests for this group. Round 1 may already be collected.");
|
|
422
|
+
if (options.parallel === true) {
|
|
423
|
+
const collection = await collectRound1Parallel(client, registry, pendingRequests, ownerDoc, groupId, options.timeoutSeconds);
|
|
424
|
+
const displayPath = persistRound1Packages(registryPath, groupId, collection.successes.map(([xid, data]) => [xid, data.package]));
|
|
425
|
+
updatePendingForRound2FromCollection(registry, registryPath, groupId, collection.successes);
|
|
426
|
+
printSummaryParallel(collection, displayPath, await dispatchRound2RequestsParallel(client, registry, registryPath, ownerDoc, groupId, collection.successes, options.preview ?? false));
|
|
427
|
+
return {
|
|
428
|
+
accepted: collection.successes.length,
|
|
429
|
+
rejected: collection.rejections.length,
|
|
430
|
+
errors: collection.errors.length,
|
|
431
|
+
timeouts: collection.timeouts.length
|
|
432
|
+
};
|
|
433
|
+
} else {
|
|
434
|
+
const ctx = {
|
|
435
|
+
client,
|
|
436
|
+
registryPath,
|
|
437
|
+
registry,
|
|
438
|
+
ownerDoc,
|
|
439
|
+
groupId
|
|
440
|
+
};
|
|
441
|
+
const collection = await collectRound1Responses(ctx, pendingRequests, options.timeoutSeconds);
|
|
442
|
+
printSummary(collection, await dispatchRound2Requests(ctx, collection, options.preview ?? false));
|
|
443
|
+
return {
|
|
444
|
+
accepted: collection.packages.length,
|
|
445
|
+
rejected: 0,
|
|
446
|
+
errors: 0,
|
|
447
|
+
timeouts: 0
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
//#endregion
|
|
452
|
+
Object.defineProperty(exports, "round1", {
|
|
453
|
+
enumerable: true,
|
|
454
|
+
get: function() {
|
|
455
|
+
return round1;
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
Object.defineProperty(exports, "round1_exports", {
|
|
459
|
+
enumerable: true,
|
|
460
|
+
get: function() {
|
|
461
|
+
return round1_exports;
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
//# sourceMappingURL=round1-BHBjru1m.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round1-BHBjru1m.cjs","names":["getWithIndicator","isVerbose","CborDate","SealedResponse","ARID","JSONWrapper","serde","parallelFetch","SealedRequest","Envelope","parallelSend","PendingRequests","groupStateDir","path","putWithIndicator","resolveRegistryPath","Registry","parseAridUr"],"sources":["../src/cmd/dkg/coordinator/round1.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * DKG coordinator round 1 command.\n *\n * Port of cmd/dkg/coordinator/round1.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, type PrivateKeys, type XID } from \"@bcts/components\";\nimport { CborDate } from \"@bcts/dcbor\";\nimport { Envelope } from \"@bcts/envelope\";\nimport { SealedRequest, SealedResponse } from \"@bcts/gstp\";\nimport type { XIDDocument } from \"@bcts/xid\";\n\nimport {\n type GroupRecord,\n type OwnerRecord,\n PendingRequests,\n Registry,\n resolveRegistryPath,\n} from \"../../../registry/index.js\";\nimport { getWithIndicator, putWithIndicator } from \"../../busy.js\";\nimport { groupStateDir, isVerbose } from \"../../common.js\";\nimport {\n type CollectionResult,\n parallelFetch,\n parallelSend,\n type ParallelFetchConfig,\n} from \"../../parallel.js\";\nimport { type StorageClient } from \"../../storage.js\";\nimport { parseAridUr } from \"../common.js\";\nimport { type DkgRound1Package } from \"../../../frost/index.js\";\nimport { serde } from \"@frosts/ed25519\";\n\n/**\n * Options for the DKG round1 command.\n */\nexport interface DkgRound1Options {\n registryPath?: string;\n groupId: string;\n parallel?: boolean;\n timeoutSeconds?: number;\n preview?: boolean;\n verbose?: boolean;\n}\n\n/**\n * Result of the DKG round1 command.\n */\nexport interface DkgRound1Result {\n accepted: number;\n rejected: number;\n errors: number;\n timeouts: number;\n}\n\n// -----------------------------------------------------------------------------\n// Context and result types\n// -----------------------------------------------------------------------------\n\n/**\n * Context for round 1 collection operations.\n */\ninterface Round1Context {\n client: StorageClient;\n registryPath: string;\n registry: Registry;\n ownerDoc: XIDDocument;\n groupId: ARID;\n}\n\n/**\n * Type alias for a round 1 package entry.\n */\ntype Round1Package = [XID, DkgRound1Package];\n\n/**\n * Type alias for next response ARID entry.\n */\ntype NextResponseArid = [XID, ARID];\n\n/**\n * Result of collecting round 1 responses.\n */\ninterface Round1Collection {\n packages: Round1Package[];\n nextResponseArids: NextResponseArid[];\n displayPath: string;\n}\n\n/**\n * Data extracted from a successful Round 1 response.\n */\ninterface Round1ResponseData {\n package: DkgRound1Package;\n nextResponseArid: ARID;\n}\n\n// -----------------------------------------------------------------------------\n// Validation\n// -----------------------------------------------------------------------------\n\n/**\n * Validate that the owner is the coordinator for this group.\n *\n * Port of `validate_coordinator()` from cmd/dkg/coordinator/round1.rs lines 201-214.\n */\nfunction validateCoordinator(groupRecord: GroupRecord, owner: OwnerRecord): void {\n if (groupRecord.coordinator().xid().urString() !== owner.xid().urString()) {\n throw new Error(\n `Only the coordinator can collect and send Round 2 requests. ` +\n `Coordinator: ${groupRecord.coordinator().xid().urString()}, ` +\n `Owner: ${owner.xid().urString()}`,\n );\n }\n}\n\n// -----------------------------------------------------------------------------\n// Sequential fetch implementation\n// -----------------------------------------------------------------------------\n\n/**\n * Fetch a single round 1 response from storage.\n *\n * Port of `fetch_and_validate_response()` from cmd/dkg/coordinator/round1.rs lines 512-566.\n */\nasync function fetchRound1Response(\n client: StorageClient,\n responseArid: ARID,\n timeout: number | undefined,\n coordinator: XIDDocument,\n expectedGroupId: ARID,\n participantName: string,\n): Promise<[DkgRound1Package, ARID]> {\n const envelope = await getWithIndicator(\n client,\n responseArid,\n participantName,\n timeout,\n isVerbose(),\n );\n\n if (envelope === undefined) {\n throw new Error(\"Response not found in Hubert storage\");\n }\n\n const coordinatorPrivateKeys = coordinator.inceptionPrivateKeys();\n if (coordinatorPrivateKeys === undefined) {\n throw new Error(\"Coordinator XID document has no inception private keys\");\n }\n\n const now = CborDate.now().datetime();\n const sealedResponse = SealedResponse.tryFromEncryptedEnvelope(\n envelope,\n undefined,\n now,\n coordinatorPrivateKeys,\n );\n\n if (sealedResponse.isErr()) {\n const error = sealedResponse.error();\n const reasonEnvelope = error.objectForPredicate(\"reason\");\n const reason =\n reasonEnvelope !== undefined\n ? reasonEnvelope.extractSubject((cbor) => cbor.toText())\n : \"unknown reason\";\n throw new Error(`Participant rejected invite: ${reason}`);\n }\n\n const result = sealedResponse.result();\n validateRound1Response(result, expectedGroupId);\n\n const nextResponseArid = result.tryObjectForPredicate<ARID>(\"response_arid\", (cbor) => {\n return ARID.fromTaggedCbor(cbor);\n });\n\n const round1Package = extractRound1Package(result);\n\n return [round1Package, nextResponseArid];\n}\n\n/**\n * Validate a round 1 response envelope.\n *\n * Port of `validate_round1_response()` from cmd/dkg/coordinator/round1.rs lines 568-586.\n */\nfunction validateRound1Response(result: Envelope, expectedGroupId: ARID): void {\n result.checkSubjectUnit();\n result.checkType(\"dkgRound1Response\");\n\n const groupId = result.tryObjectForPredicate<ARID>(\"group\", (cbor) => {\n return ARID.fromTaggedCbor(cbor);\n });\n\n if (groupId.urString() !== expectedGroupId.urString()) {\n throw new Error(\n `Response group ID ${groupId.urString()} does not match expected ${expectedGroupId.urString()}`,\n );\n }\n}\n\n/**\n * Extract a round 1 package from a response envelope.\n *\n * Port of `extract_round1_package()` from cmd/dkg/coordinator/round1.rs lines 588-598.\n */\nfunction extractRound1Package(result: Envelope): DkgRound1Package {\n const round1Envelope = result.objectForPredicate(\"round1_package\");\n if (round1Envelope === undefined) {\n throw new Error(\"round1_package missing from response\");\n }\n\n const round1Json = round1Envelope.extractSubject<JSONWrapper>((cbor) => {\n return JSONWrapper.fromTaggedCbor(cbor);\n });\n\n const jsonStr = new TextDecoder().decode(round1Json.asBytes());\n const jsonObj = globalThis.JSON.parse(jsonStr) as Record<string, unknown>;\n return serde.round1PackageFromJson(jsonObj);\n}\n\n/**\n * Validate and extract data from a round 1 response (for parallel fetch).\n *\n * Port of `validate_and_extract_round1_response()` from cmd/dkg/coordinator/round1.rs lines 674-707.\n */\nfunction validateAndExtractRound1Response(\n envelope: Envelope,\n coordinatorKeys: PrivateKeys,\n expectedGroupId: ARID,\n): Round1ResponseData | { rejected: string } {\n const now = CborDate.now().datetime();\n const sealedResponse = SealedResponse.tryFromEncryptedEnvelope(\n envelope,\n undefined,\n now,\n coordinatorKeys,\n );\n\n if (sealedResponse.isErr()) {\n const error = sealedResponse.error();\n const reasonEnvelope = error.objectForPredicate(\"reason\");\n const reason =\n reasonEnvelope !== undefined\n ? reasonEnvelope.extractSubject((cbor) => cbor.toText())\n : \"unknown reason\";\n return { rejected: `Participant rejected invite: ${reason}` };\n }\n\n const result = sealedResponse.result();\n validateRound1Response(result, expectedGroupId);\n\n const nextResponseArid = result.tryObjectForPredicate<ARID>(\"response_arid\", (cbor) => {\n return ARID.fromTaggedCbor(cbor);\n });\n\n const pkg = extractRound1Package(result);\n\n return { package: pkg, nextResponseArid };\n}\n\n// -----------------------------------------------------------------------------\n// Parallel collection\n// -----------------------------------------------------------------------------\n\n/**\n * Collect Round 1 responses in parallel with progress display.\n *\n * Port of `collect_round1_responses_parallel()` from cmd/dkg/coordinator/round1.rs lines 636-671.\n */\nasync function collectRound1Parallel(\n client: StorageClient,\n registry: Registry,\n pendingRequests: PendingRequests,\n coordinator: XIDDocument,\n expectedGroupId: ARID,\n timeout: number | undefined,\n): Promise<CollectionResult<Round1ResponseData>> {\n const requests: [XID, ARID, string][] = [];\n for (const [xid, arid] of pendingRequests.iterCollect()) {\n const participant = registry.participant(xid);\n const name = participant?.petName() ?? xid.urString();\n requests.push([xid, arid, name]);\n }\n\n const coordinatorKeys = coordinator.inceptionPrivateKeys();\n if (coordinatorKeys === undefined) {\n throw new Error(\"Missing coordinator private keys\");\n }\n\n const config: ParallelFetchConfig = { timeoutSeconds: timeout };\n const groupId = expectedGroupId;\n\n return parallelFetch(\n client,\n requests,\n (envelope: Envelope, _xid: XID) => {\n return validateAndExtractRound1Response(envelope, coordinatorKeys, groupId);\n },\n config,\n );\n}\n\n// -----------------------------------------------------------------------------\n// Round 2 request building\n// -----------------------------------------------------------------------------\n\n/**\n * Build a Round 2 request for a single participant.\n *\n * Port of `build_round2_request_for_participant()` from cmd/dkg/coordinator/round1.rs lines 604-623.\n */\nfunction buildRound2RequestForParticipant(\n sender: XIDDocument,\n groupId: ARID,\n round1Packages: Round1Package[],\n responseArid: ARID,\n): SealedRequest {\n let request = SealedRequest.new(\"dkgRound2\", ARID.new(), sender)\n .withParameter(\"group\", groupId)\n .withParameter(\"responseArid\", responseArid);\n\n for (const [xid, pkg] of round1Packages) {\n const packageJson = serde.round1PackageToJson(pkg);\n const jsonStr = globalThis.JSON.stringify(packageJson);\n const jsonBytes = new TextEncoder().encode(jsonStr);\n const jsonWrapper = JSONWrapper.fromData(jsonBytes);\n const packageEnvelope = Envelope.new(jsonWrapper).addAssertion(\"participant\", xid);\n request = request.withParameter(\"round1Package\", packageEnvelope);\n }\n\n return request;\n}\n\n/**\n * Dispatch Round 2 requests in parallel.\n *\n * Port of `dispatch_round2_requests_parallel()` from cmd/dkg/coordinator/round1.rs lines 729-844.\n */\nasync function dispatchRound2RequestsParallel(\n client: StorageClient,\n registry: Registry,\n registryPath: string,\n coordinator: XIDDocument,\n groupId: ARID,\n successes: [XID, Round1ResponseData][],\n preview: boolean,\n): Promise<[string, string] | undefined> {\n const signerPrivateKeys = coordinator.inceptionPrivateKeys();\n if (signerPrivateKeys === undefined) {\n throw new Error(\"Coordinator XID document has no signing keys\");\n }\n\n const validUntil = new Date(Date.now() + 60 * 60 * 1000); // 1 hour from now\n\n // Build round1 packages list for request building\n const round1Packages: Round1Package[] = successes.map(([xid, data]) => [xid, data.package]);\n\n // Build participant info and messages\n const messages: [XID, ARID, Envelope, string][] = [];\n const collectArids: [XID, ARID][] = [];\n let previewOutput: [string, string] | undefined;\n\n for (const [xid, data] of successes) {\n const participant = registry.participant(xid);\n if (participant === undefined) {\n throw new Error(`Participant ${xid.urString()} not found in registry`);\n }\n const recipientDoc = participant.xidDocument();\n const participantName = participant.petName() ?? xid.urString();\n\n const collectFromArid = ARID.new();\n collectArids.push([xid, collectFromArid]);\n\n const request = buildRound2RequestForParticipant(\n coordinator,\n groupId,\n round1Packages,\n collectFromArid,\n );\n\n if (preview && previewOutput === undefined) {\n const unsealedEnvelope = request.toEnvelope(validUntil, signerPrivateKeys, undefined);\n previewOutput = [participantName, unsealedEnvelope.urString()];\n }\n\n const sealedEnvelope = request.toEnvelope(validUntil, signerPrivateKeys, recipientDoc);\n\n messages.push([xid, data.nextResponseArid, sealedEnvelope, participantName]);\n }\n\n // Blank line to separate get phase from put phase\n console.error();\n\n // Send all messages in parallel\n const sendResults = await parallelSend(client, messages, isVerbose());\n\n // Check for send failures\n const failures: [XID, string][] = [];\n for (const [xid, err] of sendResults) {\n if (err !== null) {\n failures.push([xid, err.message]);\n }\n }\n\n if (failures.length > 0) {\n for (const [xid, error] of failures) {\n console.error(`Failed to send to ${xid.urString()}: ${error}`);\n }\n throw new Error(`Failed to send Round 2 requests to ${failures.length} participants`);\n }\n\n // Update pending requests for Round 2 collection\n const newPendingRequests = new PendingRequests();\n for (const [xid, collectFromArid] of collectArids) {\n newPendingRequests.addCollectOnly(xid, collectFromArid);\n }\n const groupRecord = registry.groupMut(groupId);\n if (groupRecord === undefined) {\n throw new Error(\"Group not found in registry\");\n }\n groupRecord.setPendingRequests(newPendingRequests);\n registry.save(registryPath);\n\n return previewOutput;\n}\n\n// -----------------------------------------------------------------------------\n// Pending request updates\n// -----------------------------------------------------------------------------\n\n/**\n * Update pending requests from parallel collection results.\n *\n * Port of `update_pending_for_round2_from_collection()` from cmd/dkg/coordinator/round1.rs lines 710-726.\n */\nfunction updatePendingForRound2FromCollection(\n registry: Registry,\n registryPath: string,\n groupId: ARID,\n successes: [XID, Round1ResponseData][],\n): void {\n const newPending = new PendingRequests();\n for (const [xid, data] of successes) {\n newPending.addSendOnly(xid, data.nextResponseArid);\n }\n const groupRecord = registry.groupMut(groupId);\n if (groupRecord === undefined) {\n throw new Error(\"Group not found in registry\");\n }\n groupRecord.setPendingRequests(newPending);\n registry.save(registryPath);\n}\n\n// -----------------------------------------------------------------------------\n// Persistence\n// -----------------------------------------------------------------------------\n\n/**\n * Persist collected round 1 packages to disk.\n *\n * Port of `persist_round1_packages()` from cmd/dkg/coordinator/round1.rs lines 301-340.\n */\nfunction persistRound1Packages(\n registryPath: string,\n groupId: ARID,\n packages: Round1Package[],\n): string {\n const packagesDir = groupStateDir(registryPath, groupId.hex());\n fs.mkdirSync(packagesDir, { recursive: true });\n\n const round1PackagesPath = path.join(packagesDir, \"collected_round1.json\");\n const packagesJson: Record<string, unknown> = {};\n\n for (const [xid, pkg] of packages) {\n packagesJson[xid.urString()] = serde.round1PackageToJson(pkg);\n }\n\n fs.writeFileSync(round1PackagesPath, globalThis.JSON.stringify(packagesJson, null, 2));\n\n // Return display path (relative to cwd if possible)\n const cwd = process.cwd();\n if (round1PackagesPath.startsWith(cwd)) {\n return round1PackagesPath.slice(cwd.length + 1);\n }\n return round1PackagesPath;\n}\n\n// -----------------------------------------------------------------------------\n// Sequential collection\n// -----------------------------------------------------------------------------\n\n/**\n * Fetch all round 1 packages sequentially.\n *\n * Port of `fetch_all_round1_packages()` from cmd/dkg/coordinator/round1.rs lines 243-299.\n */\nasync function fetchAllRound1Packages(\n ctx: Round1Context,\n pendingRequests: PendingRequests,\n timeout: number | undefined,\n): Promise<[Round1Package[], NextResponseArid[]]> {\n const round1Packages: Round1Package[] = [];\n const nextResponseArids: NextResponseArid[] = [];\n const errors: [XID, string][] = [];\n\n for (const [participantXid, collectFromArid] of pendingRequests.iterCollect()) {\n const participant = ctx.registry.participant(participantXid);\n const participantName = participant?.petName() ?? participantXid.urString();\n\n try {\n const [pkg, nextArid] = await fetchRound1Response(\n ctx.client,\n collectFromArid,\n timeout,\n ctx.ownerDoc,\n ctx.groupId,\n participantName,\n );\n round1Packages.push([participantXid, pkg]);\n nextResponseArids.push([participantXid, nextArid]);\n } catch (e) {\n errors.push([participantXid, e instanceof Error ? e.message : String(e)]);\n }\n }\n\n if (errors.length > 0) {\n if (isVerbose()) {\n console.error();\n console.error(`Failed to collect from ${errors.length} participants:`);\n }\n for (const [xid, error] of errors) {\n console.error(` ${xid.urString()}: ${error}`);\n }\n throw new Error(\n `Round 1 collection incomplete: ${errors.length} of ${pendingRequests.len()} responses failed`,\n );\n }\n\n return [round1Packages, nextResponseArids];\n}\n\n/**\n * Collect round 1 responses sequentially.\n *\n * Port of `collect_round1_responses()` from cmd/dkg/coordinator/round1.rs lines 220-241.\n */\nasync function collectRound1Responses(\n ctx: Round1Context,\n pendingRequests: PendingRequests,\n timeout: number | undefined,\n): Promise<Round1Collection> {\n if (isVerbose()) {\n console.error(`Collecting Round 1 responses from ${pendingRequests.len()} participants...`);\n }\n\n const [packages, nextResponseArids] = await fetchAllRound1Packages(ctx, pendingRequests, timeout);\n\n const displayPath = persistRound1Packages(ctx.registryPath, ctx.groupId, packages);\n\n updatePendingForRound2(ctx, nextResponseArids);\n\n return { packages, nextResponseArids, displayPath };\n}\n\n/**\n * Update pending requests for round 2 (sequential path).\n *\n * Port of `update_pending_for_round2()` from cmd/dkg/coordinator/round1.rs lines 342-357.\n */\nfunction updatePendingForRound2(ctx: Round1Context, nextResponseArids: NextResponseArid[]): void {\n const newPending = new PendingRequests();\n for (const [xid, sendToArid] of nextResponseArids) {\n newPending.addSendOnly(xid, sendToArid);\n }\n const groupRecord = ctx.registry.groupMut(ctx.groupId);\n if (groupRecord === undefined) {\n throw new Error(\"Group not found in registry\");\n }\n groupRecord.setPendingRequests(newPending);\n ctx.registry.save(ctx.registryPath);\n}\n\n// -----------------------------------------------------------------------------\n// Round 2 dispatch (sequential)\n// -----------------------------------------------------------------------------\n\n/**\n * Build participant info for round 2 dispatch.\n *\n * Port of `build_round2_participant_info()` from cmd/dkg/coordinator/round1.rs lines 438-458.\n */\nfunction buildRound2ParticipantInfo(\n registry: Registry,\n nextResponseArids: NextResponseArid[],\n): [XID, XIDDocument, ARID, ARID][] {\n return nextResponseArids.map(([xid, sendToArid]) => {\n const participant = registry.participant(xid);\n if (participant === undefined) {\n throw new Error(`Participant ${xid.urString()} not found in registry`);\n }\n const doc = participant.xidDocument();\n const collectFromArid = ARID.new();\n return [xid, doc, sendToArid, collectFromArid];\n });\n}\n\n/**\n * Update pending for round 2 collection (sequential path).\n *\n * Port of `update_pending_for_round2_collection()` from cmd/dkg/coordinator/round1.rs lines 460-475.\n */\nfunction updatePendingForRound2Collection(\n ctx: Round1Context,\n participantInfo: [XID, XIDDocument, ARID, ARID][],\n): void {\n const newPendingRequests = new PendingRequests();\n for (const [xid, , , collectFromArid] of participantInfo) {\n newPendingRequests.addCollectOnly(xid, collectFromArid);\n }\n const groupRecord = ctx.registry.groupMut(ctx.groupId);\n if (groupRecord === undefined) {\n throw new Error(\"Group not found in registry\");\n }\n groupRecord.setPendingRequests(newPendingRequests);\n ctx.registry.save(ctx.registryPath);\n}\n\n/**\n * Dispatch Round 2 requests sequentially.\n *\n * Port of `dispatch_round2_requests()` from cmd/dkg/coordinator/round1.rs lines 363-436.\n */\nasync function dispatchRound2Requests(\n ctx: Round1Context,\n collection: Round1Collection,\n preview: boolean,\n): Promise<[string, string] | undefined> {\n const signerPrivateKeys = ctx.ownerDoc.inceptionPrivateKeys();\n if (signerPrivateKeys === undefined) {\n throw new Error(\"Coordinator XID document has no signing keys\");\n }\n\n const validUntil = new Date(Date.now() + 60 * 60 * 1000); // 1 hour from now\n\n const participantInfo = buildRound2ParticipantInfo(ctx.registry, collection.nextResponseArids);\n\n if (isVerbose()) {\n console.error(`Sending Round 2 requests to ${participantInfo.length} participants...`);\n } else {\n // Blank line to separate get phase from put phase\n console.error();\n }\n\n let previewOutput: [string, string] | undefined;\n\n for (const [xid, recipientDoc, sendToArid, collectFromArid] of participantInfo) {\n const participant = ctx.registry.participant(xid);\n const participantName = participant?.petName() ?? xid.urString();\n\n const request = buildRound2RequestForParticipant(\n ctx.ownerDoc,\n ctx.groupId,\n collection.packages,\n collectFromArid,\n );\n\n if (preview && previewOutput === undefined) {\n const unsealedEnvelope = request.toEnvelope(validUntil, signerPrivateKeys, undefined);\n previewOutput = [participantName, unsealedEnvelope.urString()];\n }\n\n const sealedEnvelope = request.toEnvelope(validUntil, signerPrivateKeys, recipientDoc);\n\n await putWithIndicator(ctx.client, sendToArid, sealedEnvelope, participantName, isVerbose());\n }\n\n updatePendingForRound2Collection(ctx, participantInfo);\n\n return previewOutput;\n}\n\n// -----------------------------------------------------------------------------\n// Output\n// -----------------------------------------------------------------------------\n\n/**\n * Print summary for sequential collection.\n *\n * Port of `print_summary()` from cmd/dkg/coordinator/round1.rs lines 481-506.\n */\nfunction printSummary(collection: Round1Collection, preview: [string, string] | undefined): void {\n if (preview !== undefined) {\n const [participantName, ur] = preview;\n if (isVerbose()) {\n console.error(`# Round 2 preview for ${participantName}`);\n console.error();\n }\n console.error(\n `Collected ${collection.packages.length} Round 1 packages to ${collection.displayPath} ` +\n `and sent ${collection.nextResponseArids.length} Round 2 requests.`,\n );\n console.log(ur);\n } else if (isVerbose()) {\n console.error();\n console.error(\n `Collected ${collection.packages.length} Round 1 packages to ${collection.displayPath} ` +\n `and sent ${collection.nextResponseArids.length} Round 2 requests.`,\n );\n }\n}\n\n/**\n * Print summary for parallel collection.\n *\n * Port of `print_summary_parallel()` from cmd/dkg/coordinator/round1.rs lines 847-901.\n */\nfunction printSummaryParallel(\n collection: CollectionResult<Round1ResponseData>,\n displayPath: string,\n preview: [string, string] | undefined,\n): void {\n // Report any failures\n if (collection.rejections.length > 0) {\n console.error();\n console.error(\"Rejections:\");\n for (const [xid, reason] of collection.rejections) {\n console.error(` ${xid.urString()}: ${reason}`);\n }\n }\n if (collection.errors.length > 0) {\n console.error();\n console.error(\"Errors:\");\n for (const [xid, error] of collection.errors) {\n console.error(` ${xid.urString()}: ${error}`);\n }\n }\n if (collection.timeouts.length > 0) {\n console.error();\n console.error(\"Timeouts:\");\n for (const xid of collection.timeouts) {\n console.error(` ${xid.urString()}`);\n }\n }\n\n if (!collection.allSucceeded()) {\n console.error();\n bailWithCollectionSummary(collection);\n }\n\n if (preview !== undefined) {\n const [participantName, ur] = preview;\n if (isVerbose()) {\n console.error(`# Round 2 preview for ${participantName}`);\n console.error();\n }\n console.error(\n `Collected ${collection.successes.length} Round 1 packages to ${displayPath} ` +\n `and sent ${collection.successes.length} Round 2 requests.`,\n );\n console.log(ur);\n } else if (isVerbose()) {\n console.error();\n console.error(\n `Collected ${collection.successes.length} Round 1 packages to ${displayPath} ` +\n `and sent ${collection.successes.length} Round 2 requests.`,\n );\n }\n}\n\n/**\n * Print collection summary and throw error.\n *\n * Port of `bail_with_collection_summary()` from cmd/dkg/coordinator/round1.rs lines 903-913.\n */\nfunction bailWithCollectionSummary(collection: CollectionResult<Round1ResponseData>): never {\n const msg =\n `Round 1 collection incomplete: ${collection.successes.length} succeeded, ` +\n `${collection.rejections.length} rejected, ${collection.errors.length} errors, ` +\n `${collection.timeouts.length} timeouts`;\n console.error(msg);\n throw new Error(msg);\n}\n\n// -----------------------------------------------------------------------------\n// Main entry point\n// -----------------------------------------------------------------------------\n\n/**\n * Execute the DKG coordinator round 1 command.\n *\n * Collects commitment packages from participants.\n *\n * Port of `CommandArgs::exec()` from cmd/dkg/coordinator/round1.rs lines 59-173.\n */\nexport async function round1(\n client: StorageClient,\n options: DkgRound1Options,\n cwd: string,\n): Promise<DkgRound1Result> {\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 const ownerDoc = owner.xidDocument();\n\n const groupId = parseAridUr(options.groupId);\n const groupRecord = registry.group(groupId);\n\n if (groupRecord === undefined) {\n throw new Error(`Group ${options.groupId} not found in registry`);\n }\n\n validateCoordinator(groupRecord, owner);\n\n const pendingRequests = groupRecord.pendingRequests();\n if (pendingRequests.isEmpty()) {\n throw new Error(\"No pending requests for this group. Round 1 may already be collected.\");\n }\n\n if (options.parallel === true) {\n // Parallel path with progress display\n const collection = await collectRound1Parallel(\n client,\n registry,\n pendingRequests,\n ownerDoc,\n groupId,\n options.timeoutSeconds,\n );\n\n // Extract packages for persistence\n const packages: Round1Package[] = collection.successes.map(([xid, data]) => [\n xid,\n data.package,\n ]);\n\n const displayPath = persistRound1Packages(registryPath, groupId, packages);\n\n updatePendingForRound2FromCollection(registry, registryPath, groupId, collection.successes);\n\n const preview = await dispatchRound2RequestsParallel(\n client,\n registry,\n registryPath,\n ownerDoc,\n groupId,\n collection.successes,\n options.preview ?? false,\n );\n\n printSummaryParallel(collection, displayPath, preview);\n\n return {\n accepted: collection.successes.length,\n rejected: collection.rejections.length,\n errors: collection.errors.length,\n timeouts: collection.timeouts.length,\n };\n } else {\n // Sequential path (original behavior)\n const ctx: Round1Context = {\n client,\n registryPath,\n registry,\n ownerDoc,\n groupId,\n };\n\n const collection = await collectRound1Responses(ctx, pendingRequests, options.timeoutSeconds);\n\n const preview = await dispatchRound2Requests(ctx, collection, options.preview ?? false);\n\n printSummary(collection, preview);\n\n return {\n accepted: collection.packages.length,\n rejected: 0,\n errors: 0,\n timeouts: 0,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHA,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