@bcts/frost-hubert 1.0.0-alpha.23 → 1.0.0-beta.1

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.
Files changed (165) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/frost.cjs +344 -72
  3. package/dist/bin/frost.cjs.map +1 -1
  4. package/dist/bin/frost.mjs +344 -71
  5. package/dist/bin/frost.mjs.map +1 -1
  6. package/dist/busy-B_h0bNAJ.cjs +38 -0
  7. package/dist/busy-B_h0bNAJ.cjs.map +1 -0
  8. package/dist/busy-BlU8_pS2.mjs +27 -0
  9. package/dist/busy-BlU8_pS2.mjs.map +1 -0
  10. package/dist/cmd/index.cjs +27 -22
  11. package/dist/cmd/index.d.cts +2 -2
  12. package/dist/cmd/index.d.mts +2 -2
  13. package/dist/cmd/index.mjs +6 -3
  14. package/dist/cmd-CCVhHzG7.cjs +129 -0
  15. package/dist/cmd-CCVhHzG7.cjs.map +1 -0
  16. package/dist/cmd-DNsHd19v.mjs +112 -0
  17. package/dist/cmd-DNsHd19v.mjs.map +1 -0
  18. package/dist/common-7-BOgaTt.cjs +113 -0
  19. package/dist/common-7-BOgaTt.cjs.map +1 -0
  20. package/dist/common-Cf1UvJaP.mjs +282 -0
  21. package/dist/common-Cf1UvJaP.mjs.map +1 -0
  22. package/dist/common-CnvAUC2b.cjs +372 -0
  23. package/dist/common-CnvAUC2b.cjs.map +1 -0
  24. package/dist/common-DNrD_-EI.mjs +96 -0
  25. package/dist/common-DNrD_-EI.mjs.map +1 -0
  26. package/dist/dkg/index.cjs +6 -103
  27. package/dist/dkg/index.cjs.map +1 -1
  28. package/dist/dkg/index.d.cts +2 -2
  29. package/dist/dkg/index.d.mts +2 -2
  30. package/dist/dkg/index.mjs +4 -101
  31. package/dist/dkg/index.mjs.map +1 -1
  32. package/dist/finalize-BpC0rz93.mjs +389 -0
  33. package/dist/finalize-BpC0rz93.mjs.map +1 -0
  34. package/dist/finalize-Cb0obTSo.cjs +402 -0
  35. package/dist/finalize-Cb0obTSo.cjs.map +1 -0
  36. package/dist/finalize-DHEnKobp.cjs +303 -0
  37. package/dist/finalize-DHEnKobp.cjs.map +1 -0
  38. package/dist/finalize-DQ0VGUHO.cjs +265 -0
  39. package/dist/finalize-DQ0VGUHO.cjs.map +1 -0
  40. package/dist/finalize-DtRxHZ7H.mjs +290 -0
  41. package/dist/finalize-DtRxHZ7H.mjs.map +1 -0
  42. package/dist/finalize-T83Ko8nG.mjs +252 -0
  43. package/dist/finalize-T83Ko8nG.mjs.map +1 -0
  44. package/dist/frost/index.cjs +1 -1
  45. package/dist/frost/index.cjs.map +1 -1
  46. package/dist/frost/index.d.cts.map +1 -1
  47. package/dist/frost/index.d.mts.map +1 -1
  48. package/dist/frost/index.mjs +1 -1
  49. package/dist/frost/index.mjs.map +1 -1
  50. package/dist/{index-BJlwbPYu.d.cts → index-BErX9AZF.d.cts} +101 -79
  51. package/dist/index-BErX9AZF.d.cts.map +1 -0
  52. package/dist/{index-BkqLimZT.d.mts → index-BaUVw4b1.d.mts} +25 -2
  53. package/dist/index-BaUVw4b1.d.mts.map +1 -0
  54. package/dist/{index-BMbPgH0W.d.cts → index-CD50Qtgw.d.cts} +46 -2
  55. package/dist/index-CD50Qtgw.d.cts.map +1 -0
  56. package/dist/{index-DoV5HFvV.d.mts → index-CD50Qtgw.d.mts} +46 -2
  57. package/dist/index-CD50Qtgw.d.mts.map +1 -0
  58. package/dist/{index-Dzm1v4_4.d.mts → index-Drklne-Y.d.mts} +101 -79
  59. package/dist/index-Drklne-Y.d.mts.map +1 -0
  60. package/dist/{index-DmxfT59Y.d.cts → index-gkmZzEuD.d.cts} +25 -2
  61. package/dist/index-gkmZzEuD.d.cts.map +1 -0
  62. package/dist/index.cjs +30 -23
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +4 -4
  65. package/dist/index.d.cts.map +1 -1
  66. package/dist/index.d.mts +4 -4
  67. package/dist/index.d.mts.map +1 -1
  68. package/dist/index.mjs +8 -4
  69. package/dist/index.mjs.map +1 -1
  70. package/dist/invite-1tzg0B0P.cjs +274 -0
  71. package/dist/invite-1tzg0B0P.cjs.map +1 -0
  72. package/dist/invite-BLwtexAu.cjs +109 -0
  73. package/dist/invite-BLwtexAu.cjs.map +1 -0
  74. package/dist/invite-Be2v2SVc.mjs +96 -0
  75. package/dist/invite-Be2v2SVc.mjs.map +1 -0
  76. package/dist/invite-D8mQSnFz.mjs +219 -0
  77. package/dist/invite-D8mQSnFz.mjs.map +1 -0
  78. package/dist/parallel-PZiwHZT8.mjs +235 -0
  79. package/dist/parallel-PZiwHZT8.mjs.map +1 -0
  80. package/dist/parallel-szwYx-bi.cjs +318 -0
  81. package/dist/parallel-szwYx-bi.cjs.map +1 -0
  82. package/dist/proposed-participant-BvHNnpcZ.cjs +140 -0
  83. package/dist/proposed-participant-BvHNnpcZ.cjs.map +1 -0
  84. package/dist/proposed-participant-Detb823_.mjs +129 -0
  85. package/dist/proposed-participant-Detb823_.mjs.map +1 -0
  86. package/dist/receive-BR-knnGv.cjs +213 -0
  87. package/dist/receive-BR-knnGv.cjs.map +1 -0
  88. package/dist/receive-D_r4Mryr.cjs +190 -0
  89. package/dist/receive-D_r4Mryr.cjs.map +1 -0
  90. package/dist/receive-dkSCSGpl.mjs +188 -0
  91. package/dist/receive-dkSCSGpl.mjs.map +1 -0
  92. package/dist/receive-g8EhZF2Y.mjs +177 -0
  93. package/dist/receive-g8EhZF2Y.mjs.map +1 -0
  94. package/dist/registry/index.cjs +86 -11
  95. package/dist/registry/index.cjs.map +1 -1
  96. package/dist/registry/index.d.cts +1 -1
  97. package/dist/registry/index.d.mts +1 -1
  98. package/dist/registry/index.mjs +85 -10
  99. package/dist/registry/index.mjs.map +1 -1
  100. package/dist/{registry-loI1_Mh1.cjs → registry-CkIbA7nt.cjs} +79 -2
  101. package/dist/registry-CkIbA7nt.cjs.map +1 -0
  102. package/dist/{registry-CgrCZ4En.mjs → registry-DGjs4qDK.mjs} +74 -3
  103. package/dist/registry-DGjs4qDK.mjs.map +1 -0
  104. package/dist/round1-9FAqFvL5.cjs +465 -0
  105. package/dist/round1-9FAqFvL5.cjs.map +1 -0
  106. package/dist/round1-B8haiMM8.mjs +208 -0
  107. package/dist/round1-B8haiMM8.mjs.map +1 -0
  108. package/dist/round1-BOIE1E4O.mjs +452 -0
  109. package/dist/round1-BOIE1E4O.mjs.map +1 -0
  110. package/dist/round1-Bq0vweyQ.cjs +422 -0
  111. package/dist/round1-Bq0vweyQ.cjs.map +1 -0
  112. package/dist/round1-CXkXoVQU.cjs +208 -0
  113. package/dist/round1-CXkXoVQU.cjs.map +1 -0
  114. package/dist/round1-D8t7EzIo.mjs +373 -0
  115. package/dist/round1-D8t7EzIo.mjs.map +1 -0
  116. package/dist/round1-DriPu15x.cjs +221 -0
  117. package/dist/round1-DriPu15x.cjs.map +1 -0
  118. package/dist/round1-Y2kcVwnR.mjs +195 -0
  119. package/dist/round1-Y2kcVwnR.mjs.map +1 -0
  120. package/dist/round2-AMDYMUIg.cjs +305 -0
  121. package/dist/round2-AMDYMUIg.cjs.map +1 -0
  122. package/dist/round2-BHQKVJFo.cjs +410 -0
  123. package/dist/round2-BHQKVJFo.cjs.map +1 -0
  124. package/dist/round2-BfetYacV.mjs +450 -0
  125. package/dist/round2-BfetYacV.mjs.map +1 -0
  126. package/dist/round2-Cf5CJc_8.mjs +397 -0
  127. package/dist/round2-Cf5CJc_8.mjs.map +1 -0
  128. package/dist/round2-CvrmylN1.cjs +293 -0
  129. package/dist/round2-CvrmylN1.cjs.map +1 -0
  130. package/dist/round2-Dk_w97nl.cjs +499 -0
  131. package/dist/round2-Dk_w97nl.cjs.map +1 -0
  132. package/dist/round2-Z2JhMwxc.mjs +292 -0
  133. package/dist/round2-Z2JhMwxc.mjs.map +1 -0
  134. package/dist/round2-mF6UlkT-.mjs +280 -0
  135. package/dist/round2-mF6UlkT-.mjs.map +1 -0
  136. package/package.json +14 -14
  137. package/src/bin/frost.ts +849 -128
  138. package/src/cmd/common.ts +19 -1
  139. package/src/cmd/dkg/common.ts +97 -10
  140. package/src/cmd/dkg/coordinator/invite.ts +5 -2
  141. package/src/cmd/dkg/participant/finalize.ts +51 -17
  142. package/src/cmd/dkg/participant/round1.ts +39 -38
  143. package/src/cmd/dkg/participant/round2.ts +60 -26
  144. package/src/cmd/sign/coordinator/round2.ts +5 -1
  145. package/src/cmd/sign/participant/finalize.ts +6 -2
  146. package/src/cmd/sign/participant/receive.ts +5 -2
  147. package/src/dkg/group-invite.ts +12 -2
  148. package/src/dkg/proposed-participant.ts +32 -3
  149. package/src/registry/owner-record.ts +12 -0
  150. package/src/registry/participant-record.ts +35 -2
  151. package/src/registry/registry-impl.ts +74 -18
  152. package/dist/cmd-5yLeC_QL.mjs +0 -4708
  153. package/dist/cmd-5yLeC_QL.mjs.map +0 -1
  154. package/dist/cmd-BfZjC3Uh.cjs +0 -4847
  155. package/dist/cmd-BfZjC3Uh.cjs.map +0 -1
  156. package/dist/index-BJlwbPYu.d.cts.map +0 -1
  157. package/dist/index-BMbPgH0W.d.cts.map +0 -1
  158. package/dist/index-BkqLimZT.d.mts.map +0 -1
  159. package/dist/index-DmxfT59Y.d.cts.map +0 -1
  160. package/dist/index-DoV5HFvV.d.mts.map +0 -1
  161. package/dist/index-Dzm1v4_4.d.mts.map +0 -1
  162. package/dist/registry-CgrCZ4En.mjs.map +0 -1
  163. package/dist/registry-loI1_Mh1.cjs.map +0 -1
  164. /package/dist/{chunk-CZWwpsFl.cjs → chunk-DakpK96I.cjs} +0 -0
  165. /package/dist/{chunk-CjcI7cDX.mjs → chunk-z9aeyW2b.mjs} +0 -0
@@ -0,0 +1,282 @@
1
+ import { n as __require } from "./chunk-z9aeyW2b.mjs";
2
+ import { n as compareXidBytes } from "./proposed-participant-Detb823_.mjs";
3
+ import { GroupParticipant } from "./registry/index.mjs";
4
+ import { UR } from "@bcts/uniform-resources";
5
+ import * as path from "node:path";
6
+ //#region src/cmd/dkg/common.ts
7
+ /**
8
+ * Copyright © 2023-2026 Blockchain Commons, LLC
9
+ * Copyright © 2025-2026 Parity Technologies
10
+ *
11
+ *
12
+ * Common utilities for DKG commands.
13
+ *
14
+ * Port of cmd/dkg/common.rs from frost-hubert-rust.
15
+ *
16
+ * @module
17
+ */
18
+ /**
19
+ * Parse an ARID from a UR string.
20
+ *
21
+ * Mirrors Rust `parse_arid_ur` (`cmd/common.rs:27-43`):
22
+ *
23
+ * 1. Trim and reject empty input.
24
+ * 2. Parse as a UR; require `ur_type` of `"arid"`.
25
+ * 3. Try `ARID::try_from(cbor)` (the tagged-CBOR form).
26
+ * 4. If that fails, fall back to interpreting the CBOR as a bare
27
+ * byte string and constructing the ARID from those bytes via
28
+ * `ARID::from_data_ref`.
29
+ *
30
+ * The earlier port only accepted the tagged form; this matches Rust
31
+ * by accepting the byte-string fallback too.
32
+ */
33
+ function parseAridUr(urString) {
34
+ const trimmed = urString.trim();
35
+ if (trimmed.length === 0) throw new Error("ARID is required");
36
+ const ur = UR.fromURString(trimmed);
37
+ if (ur.urTypeStr() !== "arid") throw new Error(`Expected a ur:arid, found ur:${ur.urTypeStr()}`);
38
+ const { ARID: ARIDClass } = __require("@bcts/components");
39
+ const cbor = ur.cbor();
40
+ try {
41
+ return ARIDClass.fromTaggedCbor(cbor);
42
+ } catch {
43
+ const bytes = cbor.asByteString?.();
44
+ if (bytes === void 0) throw new Error("Invalid ARID payload");
45
+ return ARIDClass.fromData(bytes);
46
+ }
47
+ }
48
+ /**
49
+ * Parse an envelope from a UR string.
50
+ *
51
+ * Port of `parse_envelope_ur()` from cmd/dkg/common.rs.
52
+ */
53
+ function parseEnvelopeUr(urString) {
54
+ const ur = UR.fromURString(urString.trim());
55
+ if (ur.urTypeStr() !== "envelope") throw new Error(`Expected ur:envelope, found ur:${ur.urTypeStr()}`);
56
+ const { Envelope: EnvelopeClass } = __require("@bcts/envelope");
57
+ return EnvelopeClass.fromCbor(ur.cbor());
58
+ }
59
+ /**
60
+ * Resolve the registry owner's XID document.
61
+ *
62
+ * The earlier port called this `resolveSender(registry)`, but its
63
+ * behaviour — "give me the owner" — has nothing in common with Rust's
64
+ * `resolve_sender(registry, input)` (which resolves an arbitrary
65
+ * named sender). This helper is renamed to its actual behaviour;
66
+ * the Rust-equivalent `resolveSender(registry, input)` lives below.
67
+ */
68
+ function resolveOwnerXidDocument(registry) {
69
+ const owner = registry.owner();
70
+ if (!owner) throw new Error("No owner set in registry. Run 'registry owner set' first.");
71
+ return owner.xidDocument();
72
+ }
73
+ /**
74
+ * Resolve a sender XID document from the registry by UR or pet name.
75
+ *
76
+ * Mirrors Rust `resolve_sender(registry, input)`
77
+ * (`cmd/dkg/common.rs:76-94`):
78
+ *
79
+ * 1. Trim and reject empty input.
80
+ * 2. Try parsing the input as a `ur:xid`. If that succeeds, look it
81
+ * up via `registry.participant(xid)`; if no record is found,
82
+ * error with `Sender with XID {ur} not found`.
83
+ * 3. Otherwise look it up by pet name via
84
+ * `registry.participantByPetName(name)`; if no record is found,
85
+ * error with `Sender with pet name '{name}' not found`.
86
+ *
87
+ * Note Rust does NOT check the owner here — only the participants
88
+ * map. The earlier inline duplicate in `participant/round1.ts` did
89
+ * an extra owner-check fallback which is removed to match Rust.
90
+ */
91
+ function resolveSender(registry, input) {
92
+ const trimmed = input.trim();
93
+ if (trimmed.length === 0) throw new Error("Sender is required");
94
+ let xid;
95
+ try {
96
+ const { XID: XIDClass } = __require("@bcts/components");
97
+ xid = XIDClass.fromURString(trimmed);
98
+ } catch {
99
+ xid = void 0;
100
+ }
101
+ if (xid !== void 0) {
102
+ const record = registry.participant(xid);
103
+ if (record !== void 0) return record.xidDocument();
104
+ throw new Error(`Sender with XID ${xid.urString()} not found`);
105
+ }
106
+ const result = registry.participantByPetName(trimmed);
107
+ if (result !== void 0) {
108
+ const [, record] = result;
109
+ return record.xidDocument();
110
+ }
111
+ throw new Error(`Sender with pet name '${trimmed}' not found`);
112
+ }
113
+ /**
114
+ * Resolve participant identifiers (XID URs or pet names) to records.
115
+ *
116
+ * Port of `resolve_participants()` from cmd/dkg/common.rs lines 29-74.
117
+ */
118
+ function resolveParticipants(registry, inputs) {
119
+ const seenArgs = /* @__PURE__ */ new Set();
120
+ const seenXids = /* @__PURE__ */ new Set();
121
+ const resolved = [];
122
+ for (const raw of inputs) {
123
+ const trimmed = raw.trim();
124
+ if (trimmed === "") throw new Error("Participant identifier cannot be empty");
125
+ if (seenArgs.has(trimmed)) throw new Error(`Duplicate participant argument: ${trimmed}`);
126
+ seenArgs.add(trimmed);
127
+ let xid;
128
+ let record;
129
+ try {
130
+ const { XID: XIDClass } = __require("@bcts/components");
131
+ xid = XIDClass.fromURString(trimmed);
132
+ const foundRecord = registry.participant(xid);
133
+ if (!foundRecord) throw new Error(`Participant with XID ${xid.urString()} not found in registry`);
134
+ record = foundRecord;
135
+ } catch {
136
+ const result = registry.participantByPetName(trimmed);
137
+ if (!result) throw new Error(`Participant with pet name '${trimmed}' not found`);
138
+ [xid, record] = result;
139
+ }
140
+ const xidUr = xid.urString();
141
+ if (seenXids.has(xidUr)) throw new Error(`Duplicate participant specified; multiple inputs resolve to ${xidUr}`);
142
+ seenXids.add(xidUr);
143
+ resolved.push([xid, record]);
144
+ }
145
+ return resolved;
146
+ }
147
+ /**
148
+ * Get display name for sender from registry.
149
+ *
150
+ * Port of `resolve_sender_name()` from cmd/dkg/common.rs lines 96-116.
151
+ */
152
+ function resolveSenderName(registry, sender) {
153
+ const owner = registry.owner();
154
+ const senderXid = sender.xid();
155
+ if (owner?.xidDocument().xid().urString() === senderXid.urString()) return formatNameWithOwnerMarker(owner.petName() ?? senderXid.urString(), true);
156
+ const record = registry.participant(senderXid);
157
+ if (record) return formatNameWithOwnerMarker(record.petName() ?? record.xid().urString(), false);
158
+ }
159
+ /**
160
+ * Build GroupParticipant[] from XIDDocuments using registry lookups.
161
+ *
162
+ * Port of `build_group_participants()` from cmd/dkg/common.rs lines 122-131.
163
+ */
164
+ function buildGroupParticipants(registry, owner, participants) {
165
+ return participants.map((doc) => groupParticipantFromRegistry(registry, owner, doc));
166
+ }
167
+ /**
168
+ * Create a GroupParticipant from a XIDDocument, validating against the registry.
169
+ *
170
+ * Port of `group_participant_from_registry()` from cmd/dkg/common.rs lines 133-149.
171
+ */
172
+ function groupParticipantFromRegistry(registry, owner, document) {
173
+ const xid = document.xid();
174
+ if (xid.urString() === owner.xid().urString()) return new GroupParticipant(xid);
175
+ if (!registry.participant(xid)) throw new Error(`Invite participant not found in registry: ${xid.urString()}`);
176
+ return new GroupParticipant(xid);
177
+ }
178
+ /**
179
+ * Format a participant name with owner marker if applicable.
180
+ *
181
+ * Port of `format_name_with_owner_marker()` from cmd/dkg/common.rs lines 155-157.
182
+ */
183
+ function formatNameWithOwnerMarker(name, isOwner) {
184
+ return isOwner ? `* ${name}` : name;
185
+ }
186
+ /**
187
+ * Get display names for participants, sorted by XID, with owner marked.
188
+ *
189
+ * Port of `participant_names_from_registry()` from cmd/dkg/common.rs lines 159-191.
190
+ */
191
+ function participantNamesFromRegistry(registry, participants, ownerXid, ownerPetName) {
192
+ return [...participants].sort((a, b) => compareXidBytes(a.xid().toData(), b.xid().toData())).map((document) => {
193
+ const xid = document.xid();
194
+ const isOwner = xid.urString() === ownerXid.urString();
195
+ let name;
196
+ if (isOwner) name = ownerPetName ?? xid.urString();
197
+ else {
198
+ const record = registry.participant(xid);
199
+ if (!record) throw new Error(`Invite participant not found in registry: ${xid.urString()}`);
200
+ name = record.petName() ?? xid.urString();
201
+ }
202
+ return formatNameWithOwnerMarker(name, isOwner);
203
+ });
204
+ }
205
+ /**
206
+ * Get the DKG state directory for a given registry path and group ID.
207
+ *
208
+ * Port of `dkg_state_dir()` from cmd/dkg/common.rs.
209
+ */
210
+ function dkgStateDir(registryPath, groupIdHex) {
211
+ const base = path.dirname(registryPath);
212
+ return path.join(base, "group-state", groupIdHex, "dkg");
213
+ }
214
+ /**
215
+ * Convert a verifying key bytes to a SigningPublicKey.
216
+ *
217
+ * Port of `signing_key_from_verifying()` from cmd/dkg/common.rs.
218
+ */
219
+ function signingKeyFromVerifying(verifyingKeyBytes) {
220
+ const { SigningPublicKey: SigningPublicKeyClass } = __require("@bcts/components");
221
+ return SigningPublicKeyClass.fromBytes(verifyingKeyBytes);
222
+ }
223
+ //#endregion
224
+ //#region src/cmd/common.ts
225
+ /**
226
+ * Copyright © 2023-2026 Blockchain Commons, LLC
227
+ * Copyright © 2025-2026 Parity Technologies
228
+ *
229
+ *
230
+ * Common utilities for commands.
231
+ *
232
+ * Port of `cmd/common.rs` from `frost-hubert-rust`.
233
+ *
234
+ * Rust's `cmd::common` exports four cross-cutting helpers used by
235
+ * both the DKG and signing subcommand trees:
236
+ *
237
+ * - `parse_arid_ur` / `signing_key_from_verifying` — re-exported
238
+ * here so the TS module layout matches Rust. The implementations
239
+ * live alongside their other DKG-specific siblings in
240
+ * `cmd/dkg/common.ts` so callers in either tree can keep using
241
+ * them; this file just surfaces them at the parallel-to-Rust
242
+ * import path (`@bcts/frost-hubert/cmd/common`).
243
+ * - `group_state_dir` and the verbose-flag helpers are TS-native here.
244
+ *
245
+ * `OptionalStorageSelector` is intentionally not ported: it's a
246
+ * `clap`-specific argument struct and the TS port surfaces the same
247
+ * effect via the `StorageSelection` string-literal union — see the
248
+ * `parity audit` for context.
249
+ *
250
+ * @module
251
+ */
252
+ /**
253
+ * Get the group state directory for a given registry path and group ID.
254
+ *
255
+ * Port of `group_state_dir()` from cmd/common.rs.
256
+ */
257
+ function groupStateDir(registryPath, groupIdHex) {
258
+ const base = path.dirname(registryPath);
259
+ return path.join(base, "group-state", groupIdHex);
260
+ }
261
+ /**
262
+ * Global verbose flag.
263
+ */
264
+ let verboseFlag = false;
265
+ /**
266
+ * Set the verbose flag.
267
+ */
268
+ function setVerbose(value) {
269
+ verboseFlag = value;
270
+ }
271
+ /**
272
+ * Check if verbose mode is enabled.
273
+ *
274
+ * Port of `is_verbose()` from cmd/common.rs.
275
+ */
276
+ function isVerbose() {
277
+ return verboseFlag;
278
+ }
279
+ //#endregion
280
+ export { dkgStateDir as a, parseAridUr as c, resolveOwnerXidDocument as d, resolveParticipants as f, signingKeyFromVerifying as h, buildGroupParticipants as i, parseEnvelopeUr as l, resolveSenderName as m, isVerbose as n, formatNameWithOwnerMarker as o, resolveSender as p, setVerbose as r, groupParticipantFromRegistry as s, groupStateDir as t, participantNamesFromRegistry as u };
281
+
282
+ //# sourceMappingURL=common-Cf1UvJaP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-Cf1UvJaP.mjs","names":[],"sources":["../src/cmd/dkg/common.ts","../src/cmd/common.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Common utilities for DKG commands.\n *\n * Port of cmd/dkg/common.rs from frost-hubert-rust.\n *\n * @module\n */\n\nimport * as path from \"node:path\";\n\nimport { type ARID, type XID } from \"@bcts/components\";\nimport { compareXidBytes } from \"../../dkg/proposed-participant.js\";\nimport { type Envelope } from \"@bcts/envelope\";\nimport { UR } from \"@bcts/uniform-resources\";\nimport { type XIDDocument } from \"@bcts/xid\";\n\nimport {\n GroupParticipant,\n type OwnerRecord,\n type ParticipantRecord,\n type Registry,\n} from \"../../registry/index.js\";\n\n// Re-export cross-cutting utilities for convenience\nexport { groupStateDir } from \"../common.js\";\n\n/**\n * Parse an ARID from a UR string.\n *\n * Mirrors Rust `parse_arid_ur` (`cmd/common.rs:27-43`):\n *\n * 1. Trim and reject empty input.\n * 2. Parse as a UR; require `ur_type` of `\"arid\"`.\n * 3. Try `ARID::try_from(cbor)` (the tagged-CBOR form).\n * 4. If that fails, fall back to interpreting the CBOR as a bare\n * byte string and constructing the ARID from those bytes via\n * `ARID::from_data_ref`.\n *\n * The earlier port only accepted the tagged form; this matches Rust\n * by accepting the byte-string fallback too.\n */\nexport function parseAridUr(urString: string): ARID {\n const trimmed = urString.trim();\n if (trimmed.length === 0) {\n throw new Error(\"ARID is required\");\n }\n const ur = UR.fromURString(trimmed);\n\n if (ur.urTypeStr() !== \"arid\") {\n throw new Error(`Expected a ur:arid, found ur:${ur.urTypeStr()}`);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports, no-undef\n const { ARID: ARIDClass } = require(\"@bcts/components\");\n const cbor = ur.cbor();\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access\n return ARIDClass.fromTaggedCbor(cbor);\n } catch {\n // Fall back to a bare byte string payload, mirroring Rust's\n // `CBOR::try_into_byte_string(cbor) → ARID::from_data_ref(bytes)`.\n const bytes = (cbor as { asByteString(): Uint8Array | undefined }).asByteString?.();\n if (bytes === undefined) {\n throw new Error(\"Invalid ARID payload\");\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access\n return ARIDClass.fromData(bytes);\n }\n}\n\n/**\n * Parse an envelope from a UR string.\n *\n * Port of `parse_envelope_ur()` from cmd/dkg/common.rs.\n */\nexport function parseEnvelopeUr(urString: string): Envelope {\n const ur = UR.fromURString(urString.trim());\n\n if (ur.urTypeStr() !== \"envelope\") {\n throw new Error(`Expected ur:envelope, found ur:${ur.urTypeStr()}`);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports, no-undef\n const { Envelope: EnvelopeClass } = require(\"@bcts/envelope\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access\n return EnvelopeClass.fromCbor(ur.cbor());\n}\n\n/**\n * Resolve the registry owner's XID document.\n *\n * The earlier port called this `resolveSender(registry)`, but its\n * behaviour — \"give me the owner\" — has nothing in common with Rust's\n * `resolve_sender(registry, input)` (which resolves an arbitrary\n * named sender). This helper is renamed to its actual behaviour;\n * the Rust-equivalent `resolveSender(registry, input)` lives below.\n */\nexport function resolveOwnerXidDocument(registry: Registry): XIDDocument {\n const owner = registry.owner();\n\n if (!owner) {\n throw new Error(\"No owner set in registry. Run 'registry owner set' first.\");\n }\n\n return owner.xidDocument();\n}\n\n/**\n * Resolve a sender XID document from the registry by UR or pet name.\n *\n * Mirrors Rust `resolve_sender(registry, input)`\n * (`cmd/dkg/common.rs:76-94`):\n *\n * 1. Trim and reject empty input.\n * 2. Try parsing the input as a `ur:xid`. If that succeeds, look it\n * up via `registry.participant(xid)`; if no record is found,\n * error with `Sender with XID {ur} not found`.\n * 3. Otherwise look it up by pet name via\n * `registry.participantByPetName(name)`; if no record is found,\n * error with `Sender with pet name '{name}' not found`.\n *\n * Note Rust does NOT check the owner here — only the participants\n * map. The earlier inline duplicate in `participant/round1.ts` did\n * an extra owner-check fallback which is removed to match Rust.\n */\nexport function resolveSender(registry: Registry, input: string): XIDDocument {\n const trimmed = input.trim();\n if (trimmed.length === 0) {\n throw new Error(\"Sender is required\");\n }\n\n // Try parsing as an XID UR string first. `XID.fromURString` throws\n // when the input isn't a `ur:xid`; that's the signal to fall back\n // to pet-name lookup.\n let xid: XID | undefined;\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports, no-undef\n const { XID: XIDClass } = require(\"@bcts/components\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access\n xid = XIDClass.fromURString(trimmed) as XID;\n } catch {\n xid = undefined;\n }\n\n if (xid !== undefined) {\n const record = registry.participant(xid);\n if (record !== undefined) {\n return record.xidDocument();\n }\n throw new Error(`Sender with XID ${xid.urString()} not found`);\n }\n\n const result = registry.participantByPetName(trimmed);\n if (result !== undefined) {\n const [, record] = result;\n return record.xidDocument();\n }\n throw new Error(`Sender with pet name '${trimmed}' not found`);\n}\n\n// -----------------------------------------------------------------------------\n// Participant resolution\n// -----------------------------------------------------------------------------\n\n/**\n * Resolve participant identifiers (XID URs or pet names) to records.\n *\n * Port of `resolve_participants()` from cmd/dkg/common.rs lines 29-74.\n */\nexport function resolveParticipants(\n registry: Registry,\n inputs: string[],\n): [XID, ParticipantRecord][] {\n const seenArgs = new Set<string>();\n const seenXids = new Set<string>();\n const resolved: [XID, ParticipantRecord][] = [];\n\n for (const raw of inputs) {\n const trimmed = raw.trim();\n if (trimmed === \"\") {\n throw new Error(\"Participant identifier cannot be empty\");\n }\n if (seenArgs.has(trimmed)) {\n throw new Error(`Duplicate participant argument: ${trimmed}`);\n }\n seenArgs.add(trimmed);\n\n let xid: XID;\n let record: ParticipantRecord;\n\n // Try parsing as XID UR first\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports, no-undef\n const { XID: XIDClass } = require(\"@bcts/components\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access\n xid = XIDClass.fromURString(trimmed) as XID;\n\n const foundRecord = registry.participant(xid);\n if (!foundRecord) {\n throw new Error(`Participant with XID ${xid.urString()} not found in registry`);\n }\n record = foundRecord;\n } catch {\n // Try looking up by pet name\n const result = registry.participantByPetName(trimmed);\n if (!result) {\n throw new Error(`Participant with pet name '${trimmed}' not found`);\n }\n [xid, record] = result;\n }\n\n const xidUr = xid.urString();\n if (seenXids.has(xidUr)) {\n throw new Error(`Duplicate participant specified; multiple inputs resolve to ${xidUr}`);\n }\n seenXids.add(xidUr);\n\n resolved.push([xid, record]);\n }\n\n return resolved;\n}\n\n/**\n * Get display name for sender from registry.\n *\n * Port of `resolve_sender_name()` from cmd/dkg/common.rs lines 96-116.\n */\nexport function resolveSenderName(registry: Registry, sender: XIDDocument): string | undefined {\n const owner = registry.owner();\n const senderXid = sender.xid();\n\n // Check if sender is the owner\n if (owner?.xidDocument().xid().urString() === senderXid.urString()) {\n const name = owner.petName() ?? senderXid.urString();\n return formatNameWithOwnerMarker(name, true);\n }\n\n // Look up in participants\n const record = registry.participant(senderXid);\n if (record) {\n const name = record.petName() ?? record.xid().urString();\n return formatNameWithOwnerMarker(name, false);\n }\n\n return undefined;\n}\n\n// -----------------------------------------------------------------------------\n// Group participant building\n// -----------------------------------------------------------------------------\n\n/**\n * Build GroupParticipant[] from XIDDocuments using registry lookups.\n *\n * Port of `build_group_participants()` from cmd/dkg/common.rs lines 122-131.\n */\nexport function buildGroupParticipants(\n registry: Registry,\n owner: OwnerRecord,\n participants: XIDDocument[],\n): GroupParticipant[] {\n return participants.map((doc) => groupParticipantFromRegistry(registry, owner, doc));\n}\n\n/**\n * Create a GroupParticipant from a XIDDocument, validating against the registry.\n *\n * Port of `group_participant_from_registry()` from cmd/dkg/common.rs lines 133-149.\n */\nexport function groupParticipantFromRegistry(\n registry: Registry,\n owner: OwnerRecord,\n document: XIDDocument,\n): GroupParticipant {\n const xid = document.xid();\n\n // If the document is the owner, allow it\n if (xid.urString() === owner.xid().urString()) {\n return new GroupParticipant(xid);\n }\n\n // Otherwise, verify the participant is in the registry\n if (!registry.participant(xid)) {\n throw new Error(`Invite participant not found in registry: ${xid.urString()}`);\n }\n\n return new GroupParticipant(xid);\n}\n\n// -----------------------------------------------------------------------------\n// Name formatting\n// -----------------------------------------------------------------------------\n\n/**\n * Format a participant name with owner marker if applicable.\n *\n * Port of `format_name_with_owner_marker()` from cmd/dkg/common.rs lines 155-157.\n */\nexport function formatNameWithOwnerMarker(name: string, isOwner: boolean): string {\n return isOwner ? `* ${name}` : name;\n}\n\n/**\n * Get display names for participants, sorted by XID, with owner marked.\n *\n * Port of `participant_names_from_registry()` from cmd/dkg/common.rs lines 159-191.\n */\nexport function participantNamesFromRegistry(\n registry: Registry,\n participants: XIDDocument[],\n ownerXid: XID,\n ownerPetName: string | undefined,\n): string[] {\n // Sort by XID byte order — mirrors Rust `XID::cmp` (raw 32-byte\n // lex compare). The earlier port used\n // `urString().localeCompare(...)`, which diverges from byte order\n // for bytes ≥ 0x80 and is locale-aware.\n const sorted = [...participants].sort((a, b) =>\n compareXidBytes(a.xid().toData(), b.xid().toData()),\n );\n\n return sorted.map((document) => {\n const xid = document.xid();\n const isOwner = xid.urString() === ownerXid.urString();\n\n let name: string;\n if (isOwner) {\n name = ownerPetName ?? xid.urString();\n } else {\n const record = registry.participant(xid);\n if (!record) {\n throw new Error(`Invite participant not found in registry: ${xid.urString()}`);\n }\n name = record.petName() ?? xid.urString();\n }\n\n return formatNameWithOwnerMarker(name, isOwner);\n });\n}\n\n/**\n * Get the DKG state directory for a given registry path and group ID.\n *\n * Port of `dkg_state_dir()` from cmd/dkg/common.rs.\n */\nexport function dkgStateDir(registryPath: string, groupIdHex: string): string {\n const base = path.dirname(registryPath);\n return path.join(base, \"group-state\", groupIdHex, \"dkg\");\n}\n\n/**\n * Convert a verifying key bytes to a SigningPublicKey.\n *\n * Port of `signing_key_from_verifying()` from cmd/dkg/common.rs.\n */\nexport function signingKeyFromVerifying(verifyingKeyBytes: Uint8Array): unknown {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports, no-undef\n const { SigningPublicKey: SigningPublicKeyClass } = require(\"@bcts/components\");\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access\n return SigningPublicKeyClass.fromBytes(verifyingKeyBytes);\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Common utilities for commands.\n *\n * Port of `cmd/common.rs` from `frost-hubert-rust`.\n *\n * Rust's `cmd::common` exports four cross-cutting helpers used by\n * both the DKG and signing subcommand trees:\n *\n * - `parse_arid_ur` / `signing_key_from_verifying` — re-exported\n * here so the TS module layout matches Rust. The implementations\n * live alongside their other DKG-specific siblings in\n * `cmd/dkg/common.ts` so callers in either tree can keep using\n * them; this file just surfaces them at the parallel-to-Rust\n * import path (`@bcts/frost-hubert/cmd/common`).\n * - `group_state_dir` and the verbose-flag helpers are TS-native here.\n *\n * `OptionalStorageSelector` is intentionally not ported: it's a\n * `clap`-specific argument struct and the TS port surfaces the same\n * effect via the `StorageSelection` string-literal union — see the\n * `parity audit` for context.\n *\n * @module\n */\n\nimport * as path from \"node:path\";\n\nexport { parseAridUr, signingKeyFromVerifying } from \"./dkg/common.js\";\n\n/**\n * Get the group state directory for a given registry path and group ID.\n *\n * Port of `group_state_dir()` from cmd/common.rs.\n */\nexport function groupStateDir(registryPath: string, groupIdHex: string): string {\n const base = path.dirname(registryPath);\n return path.join(base, \"group-state\", groupIdHex);\n}\n\n/**\n * Global verbose flag.\n */\nlet verboseFlag = false;\n\n/**\n * Set the verbose flag.\n */\nexport function setVerbose(value: boolean): void {\n verboseFlag = value;\n}\n\n/**\n * Check if verbose mode is enabled.\n *\n * Port of `is_verbose()` from cmd/common.rs.\n */\nexport function isVerbose(): boolean {\n return verboseFlag;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,YAAY,UAAwB;CAClD,MAAM,UAAU,SAAS,KAAK;CAC9B,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,kBAAkB;CAEpC,MAAM,KAAK,GAAG,aAAa,OAAO;CAElC,IAAI,GAAG,UAAU,MAAM,QACrB,MAAM,IAAI,MAAM,gCAAgC,GAAG,UAAU,GAAG;CAIlE,MAAM,EAAE,MAAM,cAAA,UAAsB,kBAAkB;CACtD,MAAM,OAAO,GAAG,KAAK;CACrB,IAAI;EAEF,OAAO,UAAU,eAAe,IAAI;CACtC,QAAQ;EAGN,MAAM,QAAS,KAAoD,eAAe;EAClF,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MAAM,sBAAsB;EAGxC,OAAO,UAAU,SAAS,KAAK;CACjC;AACF;;;;;;AAOA,SAAgB,gBAAgB,UAA4B;CAC1D,MAAM,KAAK,GAAG,aAAa,SAAS,KAAK,CAAC;CAE1C,IAAI,GAAG,UAAU,MAAM,YACrB,MAAM,IAAI,MAAM,kCAAkC,GAAG,UAAU,GAAG;CAIpE,MAAM,EAAE,UAAU,kBAA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@ -0,0 +1,372 @@
1
+ const require_chunk = require("./chunk-DakpK96I.cjs");
2
+ const require_proposed_participant = require("./proposed-participant-BvHNnpcZ.cjs");
3
+ const require_registry_index = require("./registry/index.cjs");
4
+ let _bcts_uniform_resources = require("@bcts/uniform-resources");
5
+ let node_path = require("node:path");
6
+ node_path = require_chunk.__toESM(node_path, 1);
7
+ //#region src/cmd/dkg/common.ts
8
+ /**
9
+ * Copyright © 2023-2026 Blockchain Commons, LLC
10
+ * Copyright © 2025-2026 Parity Technologies
11
+ *
12
+ *
13
+ * Common utilities for DKG commands.
14
+ *
15
+ * Port of cmd/dkg/common.rs from frost-hubert-rust.
16
+ *
17
+ * @module
18
+ */
19
+ /**
20
+ * Parse an ARID from a UR string.
21
+ *
22
+ * Mirrors Rust `parse_arid_ur` (`cmd/common.rs:27-43`):
23
+ *
24
+ * 1. Trim and reject empty input.
25
+ * 2. Parse as a UR; require `ur_type` of `"arid"`.
26
+ * 3. Try `ARID::try_from(cbor)` (the tagged-CBOR form).
27
+ * 4. If that fails, fall back to interpreting the CBOR as a bare
28
+ * byte string and constructing the ARID from those bytes via
29
+ * `ARID::from_data_ref`.
30
+ *
31
+ * The earlier port only accepted the tagged form; this matches Rust
32
+ * by accepting the byte-string fallback too.
33
+ */
34
+ function parseAridUr(urString) {
35
+ const trimmed = urString.trim();
36
+ if (trimmed.length === 0) throw new Error("ARID is required");
37
+ const ur = _bcts_uniform_resources.UR.fromURString(trimmed);
38
+ if (ur.urTypeStr() !== "arid") throw new Error(`Expected a ur:arid, found ur:${ur.urTypeStr()}`);
39
+ const { ARID: ARIDClass } = require("@bcts/components");
40
+ const cbor = ur.cbor();
41
+ try {
42
+ return ARIDClass.fromTaggedCbor(cbor);
43
+ } catch {
44
+ const bytes = cbor.asByteString?.();
45
+ if (bytes === void 0) throw new Error("Invalid ARID payload");
46
+ return ARIDClass.fromData(bytes);
47
+ }
48
+ }
49
+ /**
50
+ * Parse an envelope from a UR string.
51
+ *
52
+ * Port of `parse_envelope_ur()` from cmd/dkg/common.rs.
53
+ */
54
+ function parseEnvelopeUr(urString) {
55
+ const ur = _bcts_uniform_resources.UR.fromURString(urString.trim());
56
+ if (ur.urTypeStr() !== "envelope") throw new Error(`Expected ur:envelope, found ur:${ur.urTypeStr()}`);
57
+ const { Envelope: EnvelopeClass } = require("@bcts/envelope");
58
+ return EnvelopeClass.fromCbor(ur.cbor());
59
+ }
60
+ /**
61
+ * Resolve the registry owner's XID document.
62
+ *
63
+ * The earlier port called this `resolveSender(registry)`, but its
64
+ * behaviour — "give me the owner" — has nothing in common with Rust's
65
+ * `resolve_sender(registry, input)` (which resolves an arbitrary
66
+ * named sender). This helper is renamed to its actual behaviour;
67
+ * the Rust-equivalent `resolveSender(registry, input)` lives below.
68
+ */
69
+ function resolveOwnerXidDocument(registry) {
70
+ const owner = registry.owner();
71
+ if (!owner) throw new Error("No owner set in registry. Run 'registry owner set' first.");
72
+ return owner.xidDocument();
73
+ }
74
+ /**
75
+ * Resolve a sender XID document from the registry by UR or pet name.
76
+ *
77
+ * Mirrors Rust `resolve_sender(registry, input)`
78
+ * (`cmd/dkg/common.rs:76-94`):
79
+ *
80
+ * 1. Trim and reject empty input.
81
+ * 2. Try parsing the input as a `ur:xid`. If that succeeds, look it
82
+ * up via `registry.participant(xid)`; if no record is found,
83
+ * error with `Sender with XID {ur} not found`.
84
+ * 3. Otherwise look it up by pet name via
85
+ * `registry.participantByPetName(name)`; if no record is found,
86
+ * error with `Sender with pet name '{name}' not found`.
87
+ *
88
+ * Note Rust does NOT check the owner here — only the participants
89
+ * map. The earlier inline duplicate in `participant/round1.ts` did
90
+ * an extra owner-check fallback which is removed to match Rust.
91
+ */
92
+ function resolveSender(registry, input) {
93
+ const trimmed = input.trim();
94
+ if (trimmed.length === 0) throw new Error("Sender is required");
95
+ let xid;
96
+ try {
97
+ const { XID: XIDClass } = require("@bcts/components");
98
+ xid = XIDClass.fromURString(trimmed);
99
+ } catch {
100
+ xid = void 0;
101
+ }
102
+ if (xid !== void 0) {
103
+ const record = registry.participant(xid);
104
+ if (record !== void 0) return record.xidDocument();
105
+ throw new Error(`Sender with XID ${xid.urString()} not found`);
106
+ }
107
+ const result = registry.participantByPetName(trimmed);
108
+ if (result !== void 0) {
109
+ const [, record] = result;
110
+ return record.xidDocument();
111
+ }
112
+ throw new Error(`Sender with pet name '${trimmed}' not found`);
113
+ }
114
+ /**
115
+ * Resolve participant identifiers (XID URs or pet names) to records.
116
+ *
117
+ * Port of `resolve_participants()` from cmd/dkg/common.rs lines 29-74.
118
+ */
119
+ function resolveParticipants(registry, inputs) {
120
+ const seenArgs = /* @__PURE__ */ new Set();
121
+ const seenXids = /* @__PURE__ */ new Set();
122
+ const resolved = [];
123
+ for (const raw of inputs) {
124
+ const trimmed = raw.trim();
125
+ if (trimmed === "") throw new Error("Participant identifier cannot be empty");
126
+ if (seenArgs.has(trimmed)) throw new Error(`Duplicate participant argument: ${trimmed}`);
127
+ seenArgs.add(trimmed);
128
+ let xid;
129
+ let record;
130
+ try {
131
+ const { XID: XIDClass } = require("@bcts/components");
132
+ xid = XIDClass.fromURString(trimmed);
133
+ const foundRecord = registry.participant(xid);
134
+ if (!foundRecord) throw new Error(`Participant with XID ${xid.urString()} not found in registry`);
135
+ record = foundRecord;
136
+ } catch {
137
+ const result = registry.participantByPetName(trimmed);
138
+ if (!result) throw new Error(`Participant with pet name '${trimmed}' not found`);
139
+ [xid, record] = result;
140
+ }
141
+ const xidUr = xid.urString();
142
+ if (seenXids.has(xidUr)) throw new Error(`Duplicate participant specified; multiple inputs resolve to ${xidUr}`);
143
+ seenXids.add(xidUr);
144
+ resolved.push([xid, record]);
145
+ }
146
+ return resolved;
147
+ }
148
+ /**
149
+ * Get display name for sender from registry.
150
+ *
151
+ * Port of `resolve_sender_name()` from cmd/dkg/common.rs lines 96-116.
152
+ */
153
+ function resolveSenderName(registry, sender) {
154
+ const owner = registry.owner();
155
+ const senderXid = sender.xid();
156
+ if (owner?.xidDocument().xid().urString() === senderXid.urString()) return formatNameWithOwnerMarker(owner.petName() ?? senderXid.urString(), true);
157
+ const record = registry.participant(senderXid);
158
+ if (record) return formatNameWithOwnerMarker(record.petName() ?? record.xid().urString(), false);
159
+ }
160
+ /**
161
+ * Build GroupParticipant[] from XIDDocuments using registry lookups.
162
+ *
163
+ * Port of `build_group_participants()` from cmd/dkg/common.rs lines 122-131.
164
+ */
165
+ function buildGroupParticipants(registry, owner, participants) {
166
+ return participants.map((doc) => groupParticipantFromRegistry(registry, owner, doc));
167
+ }
168
+ /**
169
+ * Create a GroupParticipant from a XIDDocument, validating against the registry.
170
+ *
171
+ * Port of `group_participant_from_registry()` from cmd/dkg/common.rs lines 133-149.
172
+ */
173
+ function groupParticipantFromRegistry(registry, owner, document) {
174
+ const xid = document.xid();
175
+ if (xid.urString() === owner.xid().urString()) return new require_registry_index.GroupParticipant(xid);
176
+ if (!registry.participant(xid)) throw new Error(`Invite participant not found in registry: ${xid.urString()}`);
177
+ return new require_registry_index.GroupParticipant(xid);
178
+ }
179
+ /**
180
+ * Format a participant name with owner marker if applicable.
181
+ *
182
+ * Port of `format_name_with_owner_marker()` from cmd/dkg/common.rs lines 155-157.
183
+ */
184
+ function formatNameWithOwnerMarker(name, isOwner) {
185
+ return isOwner ? `* ${name}` : name;
186
+ }
187
+ /**
188
+ * Get display names for participants, sorted by XID, with owner marked.
189
+ *
190
+ * Port of `participant_names_from_registry()` from cmd/dkg/common.rs lines 159-191.
191
+ */
192
+ function participantNamesFromRegistry(registry, participants, ownerXid, ownerPetName) {
193
+ return [...participants].sort((a, b) => require_proposed_participant.compareXidBytes(a.xid().toData(), b.xid().toData())).map((document) => {
194
+ const xid = document.xid();
195
+ const isOwner = xid.urString() === ownerXid.urString();
196
+ let name;
197
+ if (isOwner) name = ownerPetName ?? xid.urString();
198
+ else {
199
+ const record = registry.participant(xid);
200
+ if (!record) throw new Error(`Invite participant not found in registry: ${xid.urString()}`);
201
+ name = record.petName() ?? xid.urString();
202
+ }
203
+ return formatNameWithOwnerMarker(name, isOwner);
204
+ });
205
+ }
206
+ /**
207
+ * Get the DKG state directory for a given registry path and group ID.
208
+ *
209
+ * Port of `dkg_state_dir()` from cmd/dkg/common.rs.
210
+ */
211
+ function dkgStateDir(registryPath, groupIdHex) {
212
+ const base = node_path.dirname(registryPath);
213
+ return node_path.join(base, "group-state", groupIdHex, "dkg");
214
+ }
215
+ /**
216
+ * Convert a verifying key bytes to a SigningPublicKey.
217
+ *
218
+ * Port of `signing_key_from_verifying()` from cmd/dkg/common.rs.
219
+ */
220
+ function signingKeyFromVerifying(verifyingKeyBytes) {
221
+ const { SigningPublicKey: SigningPublicKeyClass } = require("@bcts/components");
222
+ return SigningPublicKeyClass.fromBytes(verifyingKeyBytes);
223
+ }
224
+ //#endregion
225
+ //#region src/cmd/common.ts
226
+ /**
227
+ * Copyright © 2023-2026 Blockchain Commons, LLC
228
+ * Copyright © 2025-2026 Parity Technologies
229
+ *
230
+ *
231
+ * Common utilities for commands.
232
+ *
233
+ * Port of `cmd/common.rs` from `frost-hubert-rust`.
234
+ *
235
+ * Rust's `cmd::common` exports four cross-cutting helpers used by
236
+ * both the DKG and signing subcommand trees:
237
+ *
238
+ * - `parse_arid_ur` / `signing_key_from_verifying` — re-exported
239
+ * here so the TS module layout matches Rust. The implementations
240
+ * live alongside their other DKG-specific siblings in
241
+ * `cmd/dkg/common.ts` so callers in either tree can keep using
242
+ * them; this file just surfaces them at the parallel-to-Rust
243
+ * import path (`@bcts/frost-hubert/cmd/common`).
244
+ * - `group_state_dir` and the verbose-flag helpers are TS-native here.
245
+ *
246
+ * `OptionalStorageSelector` is intentionally not ported: it's a
247
+ * `clap`-specific argument struct and the TS port surfaces the same
248
+ * effect via the `StorageSelection` string-literal union — see the
249
+ * `parity audit` for context.
250
+ *
251
+ * @module
252
+ */
253
+ /**
254
+ * Get the group state directory for a given registry path and group ID.
255
+ *
256
+ * Port of `group_state_dir()` from cmd/common.rs.
257
+ */
258
+ function groupStateDir(registryPath, groupIdHex) {
259
+ const base = node_path.dirname(registryPath);
260
+ return node_path.join(base, "group-state", groupIdHex);
261
+ }
262
+ /**
263
+ * Global verbose flag.
264
+ */
265
+ let verboseFlag = false;
266
+ /**
267
+ * Set the verbose flag.
268
+ */
269
+ function setVerbose(value) {
270
+ verboseFlag = value;
271
+ }
272
+ /**
273
+ * Check if verbose mode is enabled.
274
+ *
275
+ * Port of `is_verbose()` from cmd/common.rs.
276
+ */
277
+ function isVerbose() {
278
+ return verboseFlag;
279
+ }
280
+ //#endregion
281
+ Object.defineProperty(exports, "buildGroupParticipants", {
282
+ enumerable: true,
283
+ get: function() {
284
+ return buildGroupParticipants;
285
+ }
286
+ });
287
+ Object.defineProperty(exports, "dkgStateDir", {
288
+ enumerable: true,
289
+ get: function() {
290
+ return dkgStateDir;
291
+ }
292
+ });
293
+ Object.defineProperty(exports, "formatNameWithOwnerMarker", {
294
+ enumerable: true,
295
+ get: function() {
296
+ return formatNameWithOwnerMarker;
297
+ }
298
+ });
299
+ Object.defineProperty(exports, "groupParticipantFromRegistry", {
300
+ enumerable: true,
301
+ get: function() {
302
+ return groupParticipantFromRegistry;
303
+ }
304
+ });
305
+ Object.defineProperty(exports, "groupStateDir", {
306
+ enumerable: true,
307
+ get: function() {
308
+ return groupStateDir;
309
+ }
310
+ });
311
+ Object.defineProperty(exports, "isVerbose", {
312
+ enumerable: true,
313
+ get: function() {
314
+ return isVerbose;
315
+ }
316
+ });
317
+ Object.defineProperty(exports, "parseAridUr", {
318
+ enumerable: true,
319
+ get: function() {
320
+ return parseAridUr;
321
+ }
322
+ });
323
+ Object.defineProperty(exports, "parseEnvelopeUr", {
324
+ enumerable: true,
325
+ get: function() {
326
+ return parseEnvelopeUr;
327
+ }
328
+ });
329
+ Object.defineProperty(exports, "participantNamesFromRegistry", {
330
+ enumerable: true,
331
+ get: function() {
332
+ return participantNamesFromRegistry;
333
+ }
334
+ });
335
+ Object.defineProperty(exports, "resolveOwnerXidDocument", {
336
+ enumerable: true,
337
+ get: function() {
338
+ return resolveOwnerXidDocument;
339
+ }
340
+ });
341
+ Object.defineProperty(exports, "resolveParticipants", {
342
+ enumerable: true,
343
+ get: function() {
344
+ return resolveParticipants;
345
+ }
346
+ });
347
+ Object.defineProperty(exports, "resolveSender", {
348
+ enumerable: true,
349
+ get: function() {
350
+ return resolveSender;
351
+ }
352
+ });
353
+ Object.defineProperty(exports, "resolveSenderName", {
354
+ enumerable: true,
355
+ get: function() {
356
+ return resolveSenderName;
357
+ }
358
+ });
359
+ Object.defineProperty(exports, "setVerbose", {
360
+ enumerable: true,
361
+ get: function() {
362
+ return setVerbose;
363
+ }
364
+ });
365
+ Object.defineProperty(exports, "signingKeyFromVerifying", {
366
+ enumerable: true,
367
+ get: function() {
368
+ return signingKeyFromVerifying;
369
+ }
370
+ });
371
+
372
+ //# sourceMappingURL=common-CnvAUC2b.cjs.map