@uuaid/pillar 2.6.1 → 2.7.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 (61) hide show
  1. package/README.md +325 -7
  2. package/bin/carrier.mjs +21 -0
  3. package/bin/pillar-ask.mjs +4 -1
  4. package/bin/pillar-blob.mjs +6 -0
  5. package/bin/pillar-directory.mjs +282 -16
  6. package/bin/pillar-escrow.mjs +4 -1
  7. package/bin/pillar-group-v2.mjs +6 -0
  8. package/bin/pillar-notify.mjs +13 -0
  9. package/bin/pillar-responder.mjs +266 -23
  10. package/bin/pillar.mjs +512 -257
  11. package/package.json +17 -25
  12. package/src/cli-help.mjs +23 -0
  13. package/src/group-v2-cli.mjs +1 -1
  14. package/src/identity/trust.mjs +72 -6
  15. package/src/mailbox/mailbox.mjs +313 -12
  16. package/src/net/carrier-server.mjs +34 -2
  17. package/src/net/refusals.mjs +2 -0
  18. package/src/net/seed-registry.mjs +2 -1
  19. package/src/net/transport.mjs +320 -91
  20. package/src/node-check.mjs +29 -8
  21. package/src/notify-events.mjs +148 -0
  22. package/src/notify-log.mjs +124 -0
  23. package/src/notify-runner.mjs +372 -0
  24. package/src/notify-store.mjs +736 -0
  25. package/src/notify.mjs +350 -0
  26. package/src/pillar.mjs +382 -27
  27. package/src/readers.mjs +2 -2
  28. package/src/registry/federation.mjs +3056 -0
  29. package/src/registry/gossip.mjs +294 -0
  30. package/src/registry/heartbeats.mjs +205 -0
  31. package/src/registry/lineage-verifier.mjs +972 -0
  32. package/src/registry/lineage.mjs +984 -0
  33. package/src/registry/listings.mjs +612 -0
  34. package/src/registry/resolve.mjs +376 -0
  35. package/src/registry/stats.mjs +508 -0
  36. package/src/sqlite-loader.mjs +40 -0
  37. package/src/vendor/pillar-core.mjs +22 -0
  38. package/src/vendor/uuaid-soul.mjs +2246 -0
  39. package/src/vnext/a6b-common.mjs +270 -0
  40. package/src/vnext/b1-cli.mjs +970 -0
  41. package/src/vnext/card-cli.mjs +370 -0
  42. package/src/vnext/greeter-operator.mjs +160 -0
  43. package/src/vnext/greeter-suggest.mjs +318 -0
  44. package/src/vnext/greeter.mjs +571 -0
  45. package/src/vnext/homes.mjs +48 -0
  46. package/src/vnext/init-cli.mjs +489 -0
  47. package/src/vnext/intro-cli.mjs +81 -0
  48. package/src/vnext/json-dir-mailbox.mjs +304 -0
  49. package/src/vnext/jsonl-mailbox.mjs +1132 -0
  50. package/src/vnext/knock-answer.mjs +162 -0
  51. package/src/vnext/knock-cli.mjs +520 -0
  52. package/src/vnext/knock-lane.mjs +312 -0
  53. package/src/vnext/knock-responder.mjs +344 -0
  54. package/src/vnext/lineage-cli.mjs +653 -0
  55. package/src/vnext/listing-cli.mjs +323 -0
  56. package/src/vnext/resolve-cli.mjs +104 -0
  57. package/src/vnext/soul-cli.mjs +666 -0
  58. package/src/vnext/verify-cli.mjs +333 -0
  59. package/src/vnext/w4-redirect.mjs +178 -0
  60. package/src/vnext/wave-a.mjs +193 -0
  61. package/src/vnext/witness-cli.mjs +547 -0
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Shared Wave A helpers for `@uuaid/pillar` 2.7.0 vNext CLI verbs.
3
+ *
4
+ * Uses the byte-pinned vendored core (`../vendor/pillar-core.mjs`).
5
+ * Enforces owner decision #23 (Wave A): zero witnesses, zero homes,
6
+ * refusal identical to `open()` before any keygen, signing, or disk write.
7
+ */
8
+ import { createPrivateKey, createPublicKey } from "node:crypto";
9
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
10
+ import { dirname } from "node:path";
11
+ import {
12
+ CARD_KEY,
13
+ LINEAGE_LOG_KEY,
14
+ WAVE_A_WITNESS_HOME_REFUSAL_CODE,
15
+ WaveARefusalError,
16
+ assertWaveANoWitnessesOrHomes,
17
+ eventDigest,
18
+ } from "../vendor/pillar-core.mjs";
19
+
20
+ export {
21
+ CARD_KEY,
22
+ LINEAGE_LOG_KEY,
23
+ WAVE_A_WITNESS_HOME_REFUSAL_CODE,
24
+ WaveARefusalError,
25
+ assertWaveANoWitnessesOrHomes,
26
+ eventDigest,
27
+ };
28
+
29
+ const PKCS8_ED25519_PREFIX = Buffer.from("302e020100300506032b657004220420", "hex");
30
+ const STRICT_ISO_DT_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(Z|[+-](\d{2}):(\d{2}))$/;
31
+ const DAYS_IN_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
32
+
33
+ const WITNESS_FLAGS = new Set([
34
+ "witness",
35
+ "witnesses",
36
+ "add-witness",
37
+ "remove-witness",
38
+ "set-witnesses",
39
+ ]);
40
+
41
+ const HOME_REGISTRY_FLAGS = new Set([
42
+ "homes",
43
+ "home-registry",
44
+ "home-registries",
45
+ "lineage-home",
46
+ "lineage-homes",
47
+ "add-home",
48
+ "remove-home",
49
+ "set-homes",
50
+ ]);
51
+
52
+ const THRESHOLD_FLAGS = new Set(["witness-threshold"]);
53
+ const M_FLAGS = new Set(["m"]);
54
+
55
+ export function nowIsoSeconds() {
56
+ return new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
57
+ }
58
+
59
+ export function isStrictIsoDateTime(value) {
60
+ if (typeof value !== "string") return false;
61
+ const m = STRICT_ISO_DT_RE.exec(value);
62
+ if (!m) return false;
63
+ const year = +m[1];
64
+ const month = +m[2];
65
+ const day = +m[3];
66
+ const hr = +m[4];
67
+ const min = +m[5];
68
+ const sec = +m[6];
69
+ const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
70
+ const maxDay = month === 2 && leap ? 29 : (DAYS_IN_MONTH[month] ?? 0);
71
+ if (month < 1 || month > 12 || day < 1 || day > maxDay) return false;
72
+ if (hr > 23 || min > 59 || sec > 59 || (m[7] !== "Z" && (+m[8] > 23 || +m[9] > 59))) return false;
73
+ return Number.isFinite(Date.parse(value));
74
+ }
75
+
76
+ function normalizeFlagName(rawKey) {
77
+ return rawKey
78
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
79
+ .replace(/_/g, "-")
80
+ .toLowerCase();
81
+ }
82
+
83
+ /**
84
+ * Scan raw CLI argv tokens (after the command/subcommand) for any witness,
85
+ * lineage-home, or witness-threshold option. Note: `--home` (singular) is
86
+ * pillar's local data directory path and is NOT a lineage home registry option.
87
+ *
88
+ * Returns an object suitable for `assertWaveANoWitnessesOrHomes(opts)`.
89
+ */
90
+ export function extractWaveAWitnessHomeOpts(rawArgs) {
91
+ const out = {};
92
+ const list = Array.isArray(rawArgs) ? rawArgs : [];
93
+ const witnesses = [];
94
+ const homes = [];
95
+ let sawWitness = false;
96
+ let sawHome = false;
97
+
98
+ for (let i = 0; i < list.length; i++) {
99
+ const token = list[i];
100
+ if (typeof token !== "string" || token === "--") continue;
101
+ if (/^-m\d/.test(token)) { out.m = token.slice(2); continue; } // @rule vnext.wave-a-glued-m
102
+ if (token === "-m" || token.startsWith("-m=")) {
103
+ const val = token.startsWith("-m=")
104
+ ? token.slice(3)
105
+ : (i + 1 < list.length && typeof list[i + 1] === "string" && !list[i + 1].startsWith("-") ? list[++i] : true);
106
+ out.m = val;
107
+ continue;
108
+ }
109
+ if (!token.startsWith("--") || token.length <= 2) continue;
110
+ const eq = token.indexOf("=");
111
+ const rawKey = eq === -1 ? token.slice(2) : token.slice(2, eq);
112
+ const key = normalizeFlagName(rawKey);
113
+ const hasEq = eq !== -1;
114
+ let val;
115
+ if (hasEq) {
116
+ val = token.slice(eq + 1);
117
+ } else if (i + 1 < list.length && typeof list[i + 1] === "string" && !list[i + 1].startsWith("-")) {
118
+ val = list[i + 1];
119
+ } else {
120
+ val = true;
121
+ }
122
+
123
+ if (WITNESS_FLAGS.has(key)) {
124
+ sawWitness = true;
125
+ if (typeof val === "string" && val.trim().length > 0) {
126
+ witnesses.push(...val.split(",").map((s) => s.trim()).filter(Boolean));
127
+ }
128
+ } else if (HOME_REGISTRY_FLAGS.has(key)) {
129
+ sawHome = true;
130
+ if (typeof val === "string" && val.trim().length > 0) {
131
+ homes.push(...val.split(",").map((s) => s.trim()).filter(Boolean));
132
+ }
133
+ } else if (THRESHOLD_FLAGS.has(key)) {
134
+ out.witnessThreshold = val;
135
+ } else if (M_FLAGS.has(key)) {
136
+ out.m = val;
137
+ }
138
+ }
139
+
140
+ if (sawWitness) {
141
+ out.witnesses = witnesses.length > 0 ? witnesses : ["<named>"];
142
+ }
143
+ if (sawHome) {
144
+ out.homes = homes.length > 0 ? homes : ["<named>"];
145
+ }
146
+ return out;
147
+ }
148
+
149
+ /** Convert a 32-byte Ed25519 seed hex + UUAID into a Keychain-saveable identity object. */
150
+ export function keychainIdentityFromSeedHex(seedHex, uuaid, createdAt) {
151
+ const seed = Buffer.from(seedHex, "hex");
152
+ const privateKey = createPrivateKey({
153
+ key: Buffer.concat([PKCS8_ED25519_PREFIX, seed]),
154
+ format: "der",
155
+ type: "pkcs8",
156
+ });
157
+ const publicKey = createPublicKey(privateKey);
158
+ const pubDer = publicKey.export({ type: "spki", format: "der" });
159
+ const rawPub = pubDer.subarray(pubDer.length - 32);
160
+ return {
161
+ uuaid,
162
+ publicKey,
163
+ privateKey,
164
+ publicKeyHex: Buffer.from(rawPub).toString("hex"),
165
+ createdAt: createdAt ?? nowIsoSeconds(),
166
+ };
167
+ }
168
+
169
+ /** Extract the 32-byte Ed25519 seed hex from a loaded Keychain identity object. */
170
+ export function seedHexFromKeychainIdentity(identity) {
171
+ const der = identity.privateKey.export({ type: "pkcs8", format: "der" });
172
+ return Buffer.from(der.subarray(der.length - 32)).toString("hex");
173
+ }
174
+
175
+ /** Write a file atomically via sibling temp file + rename. */
176
+ export function writeFileAtomic(filePath, content, mode = 0o600) {
177
+ mkdirSync(dirname(filePath), { recursive: true });
178
+ const tmp = `${filePath}.tmp-${process.pid}-${Math.random().toString(16).slice(2, 10)}`;
179
+ writeFileSync(tmp, content, { mode });
180
+ renameSync(tmp, filePath);
181
+ }
182
+
183
+ /** Read recovery sheet words from `--recovery-sheet` or `--recovery-sheet-file`. */
184
+ export function readRecoverySheetWords(opts) {
185
+ if (typeof opts.recoverySheet === "string") {
186
+ return opts.recoverySheet.trim().split(/\s+/).filter(Boolean);
187
+ }
188
+ if (typeof opts.recoverySheetFile === "string") {
189
+ const text = readFileSync(opts.recoverySheetFile, "utf8");
190
+ return text.trim().split(/\s+/).filter(Boolean);
191
+ }
192
+ return null;
193
+ }