@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.
- package/README.md +325 -7
- package/bin/carrier.mjs +21 -0
- package/bin/pillar-ask.mjs +4 -1
- package/bin/pillar-blob.mjs +6 -0
- package/bin/pillar-directory.mjs +282 -16
- package/bin/pillar-escrow.mjs +4 -1
- package/bin/pillar-group-v2.mjs +6 -0
- package/bin/pillar-notify.mjs +13 -0
- package/bin/pillar-responder.mjs +266 -23
- package/bin/pillar.mjs +512 -257
- package/package.json +17 -25
- package/src/cli-help.mjs +23 -0
- package/src/group-v2-cli.mjs +1 -1
- package/src/identity/trust.mjs +72 -6
- package/src/mailbox/mailbox.mjs +313 -12
- package/src/net/carrier-server.mjs +34 -2
- package/src/net/refusals.mjs +2 -0
- package/src/net/seed-registry.mjs +2 -1
- package/src/net/transport.mjs +320 -91
- package/src/node-check.mjs +29 -8
- package/src/notify-events.mjs +148 -0
- package/src/notify-log.mjs +124 -0
- package/src/notify-runner.mjs +372 -0
- package/src/notify-store.mjs +736 -0
- package/src/notify.mjs +350 -0
- package/src/pillar.mjs +382 -27
- package/src/readers.mjs +2 -2
- package/src/registry/federation.mjs +3056 -0
- package/src/registry/gossip.mjs +294 -0
- package/src/registry/heartbeats.mjs +205 -0
- package/src/registry/lineage-verifier.mjs +972 -0
- package/src/registry/lineage.mjs +984 -0
- package/src/registry/listings.mjs +612 -0
- package/src/registry/resolve.mjs +376 -0
- package/src/registry/stats.mjs +508 -0
- package/src/sqlite-loader.mjs +40 -0
- package/src/vendor/pillar-core.mjs +22 -0
- package/src/vendor/uuaid-soul.mjs +2246 -0
- package/src/vnext/a6b-common.mjs +270 -0
- package/src/vnext/b1-cli.mjs +970 -0
- package/src/vnext/card-cli.mjs +370 -0
- package/src/vnext/greeter-operator.mjs +160 -0
- package/src/vnext/greeter-suggest.mjs +318 -0
- package/src/vnext/greeter.mjs +571 -0
- package/src/vnext/homes.mjs +48 -0
- package/src/vnext/init-cli.mjs +489 -0
- package/src/vnext/intro-cli.mjs +81 -0
- package/src/vnext/json-dir-mailbox.mjs +304 -0
- package/src/vnext/jsonl-mailbox.mjs +1132 -0
- package/src/vnext/knock-answer.mjs +162 -0
- package/src/vnext/knock-cli.mjs +520 -0
- package/src/vnext/knock-lane.mjs +312 -0
- package/src/vnext/knock-responder.mjs +344 -0
- package/src/vnext/lineage-cli.mjs +653 -0
- package/src/vnext/listing-cli.mjs +323 -0
- package/src/vnext/resolve-cli.mjs +104 -0
- package/src/vnext/soul-cli.mjs +666 -0
- package/src/vnext/verify-cli.mjs +333 -0
- package/src/vnext/w4-redirect.mjs +178 -0
- package/src/vnext/wave-a.mjs +193 -0
- package/src/vnext/witness-cli.mjs +547 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for `@uuaid/pillar` 2.7.0 Row A6b CLI verbs
|
|
3
|
+
* (`card`, `knock`, `knocks`, `answer`, `intro`, `resolve`, `listing`).
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { Keychain } from "../identity/keychain.mjs";
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_CARD_CARRIER,
|
|
11
|
+
DEFAULT_CARD_HOME,
|
|
12
|
+
DEFAULT_STAMP_BITS,
|
|
13
|
+
buildCard,
|
|
14
|
+
eventDigest,
|
|
15
|
+
hexToBytes,
|
|
16
|
+
identityFromSeed,
|
|
17
|
+
parseUuaid,
|
|
18
|
+
verifyLineage,
|
|
19
|
+
} from "../vendor/pillar-core.mjs";
|
|
20
|
+
import { isValidUuaid } from "./knock-lane.mjs";
|
|
21
|
+
import { CARD_KEY, LINEAGE_LOG_KEY, nowIsoSeconds, seedHexFromKeychainIdentity } from "./wave-a.mjs";
|
|
22
|
+
|
|
23
|
+
export const INTENT_TAG_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
24
|
+
export const HEX64_RE = /^[0-9a-f]{64}$/;
|
|
25
|
+
|
|
26
|
+
export function resolveHome(opts) {
|
|
27
|
+
return opts?.home || process.env.PILLAR_HOME || join(homedir(), ".pillar");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function failCli(errOut, msg, exitCode = 1) {
|
|
31
|
+
errOut(`${msg}\n`);
|
|
32
|
+
return { exitCode };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isHttpsUrl(value) {
|
|
36
|
+
let parsed = null;
|
|
37
|
+
try { parsed = typeof value === "string" ? new URL(value) : null; } catch { parsed = null; }
|
|
38
|
+
if (!parsed || parsed.protocol !== "https:" || !parsed.hostname) return false; // @rule a6b.https-url
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isLoopbackHostname(hostname) {
|
|
43
|
+
const h = String(hostname ?? "").toLowerCase();
|
|
44
|
+
return h === "localhost" || h === "::1" || h === "[::1]" || /^127(?:\.\d{1,3}){3}$/.test(h);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isRegistryUrl(value) {
|
|
48
|
+
if (typeof value !== "string" || value.length === 0) return false;
|
|
49
|
+
if (isHttpsUrl(value)) return true;
|
|
50
|
+
let parsed;
|
|
51
|
+
try { parsed = new URL(value); } catch { return false; }
|
|
52
|
+
if (parsed.protocol !== "http:") return false; // @rule a6b.registry-http-only
|
|
53
|
+
if (!isLoopbackHostname(parsed.hostname)) return false; // @rule a6b.registry-loopback-only
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isCarrierUrl(value) {
|
|
58
|
+
if (typeof value !== "string" || value.length === 0) return false;
|
|
59
|
+
let parsed;
|
|
60
|
+
try { parsed = new URL(value); } catch { return false; }
|
|
61
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return false; // @rule a6b.carrier-url-scheme
|
|
62
|
+
return Boolean(parsed.hostname);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function parseDecimalInt(raw, { min, max, label }) {
|
|
66
|
+
if (typeof raw !== "string" || !/^\d+$/.test(raw)) { return { ok: false, error: `${label} must be a base-10 integer (${min}..${max}), got "${raw}"` }; } // @rule a6b.int-decimal
|
|
67
|
+
const n = Number(raw);
|
|
68
|
+
if (!Number.isSafeInteger(n) || n < min || n > max) { return { ok: false, error: `${label} must be an integer in ${min}..${max}, got "${raw}"` }; } // @rule a6b.int-range
|
|
69
|
+
return { ok: true, value: n };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Strict CLI flag parser for A6b verbs:
|
|
74
|
+
* - Rejects unknown flags, short flags, `--bool=val`, missing values, and
|
|
75
|
+
* flag-shaped values (next token starting with `-`, except `-`).
|
|
76
|
+
* - Supports repeatable value flags via `repeatValueFlags`.
|
|
77
|
+
*/
|
|
78
|
+
export function parseStrictFlags(rawArgs, {
|
|
79
|
+
boolFlags = new Set(),
|
|
80
|
+
valueFlags = new Set(),
|
|
81
|
+
repeatValueFlags = new Set(),
|
|
82
|
+
cmdName = "pillar",
|
|
83
|
+
} = {}) {
|
|
84
|
+
const args = Array.isArray(rawArgs) ? rawArgs : [];
|
|
85
|
+
const positionals = [];
|
|
86
|
+
const opts = {};
|
|
87
|
+
for (const k of boolFlags) opts[k] = false;
|
|
88
|
+
for (const k of repeatValueFlags) opts[k] = [];
|
|
89
|
+
let endOfFlags = false;
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < args.length; i++) {
|
|
92
|
+
const tok = args[i];
|
|
93
|
+
if (!endOfFlags && tok === "--") {
|
|
94
|
+
endOfFlags = true;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!endOfFlags && typeof tok === "string" && tok.startsWith("-") && tok !== "-") {
|
|
98
|
+
const isLong = tok.startsWith("--");
|
|
99
|
+
const eq = isLong ? tok.indexOf("=") : -1;
|
|
100
|
+
const key = isLong ? (eq === -1 ? tok.slice(2) : tok.slice(2, eq)) : "";
|
|
101
|
+
const hasEq = eq !== -1;
|
|
102
|
+
|
|
103
|
+
if (isLong && boolFlags.has(key)) {
|
|
104
|
+
if (hasEq) { return { ok: false, exitCode: 64, error: `${cmdName}: --${key} does not take a value` }; } // @rule a6b.flag-bool-no-value
|
|
105
|
+
opts[key] = true;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const isRepeat = isLong && repeatValueFlags.has(key);
|
|
110
|
+
if (!isLong || (!valueFlags.has(key) && !isRepeat)) { return { ok: false, exitCode: 64, error: `${cmdName}: unknown flag ${tok}` }; } // @rule a6b.flag-unknown
|
|
111
|
+
|
|
112
|
+
let val;
|
|
113
|
+
if (hasEq) {
|
|
114
|
+
val = tok.slice(eq + 1);
|
|
115
|
+
} else {
|
|
116
|
+
if (i + 1 >= args.length) { return { ok: false, exitCode: 64, error: `${cmdName}: --${key} requires a value` }; } // @rule a6b.flag-value-required
|
|
117
|
+
if (typeof args[i + 1] === "string" && args[i + 1].startsWith("-") && args[i + 1] !== "-") { return { ok: false, exitCode: 64, error: `${cmdName}: --${key} requires a value` }; } // @rule a6b.flag-value-not-flag
|
|
118
|
+
val = args[++i];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (isRepeat) opts[key].push(val);
|
|
122
|
+
else opts[key] = val;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
positionals.push(tok);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { ok: true, positionals, opts };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function loadHomeConfig(home) {
|
|
132
|
+
const cfgPath = join(home, "config.json");
|
|
133
|
+
if (!existsSync(cfgPath)) return {};
|
|
134
|
+
return JSON.parse(readFileSync(cfgPath, "utf8"));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function loadHomeLineage(home) {
|
|
138
|
+
const logPath = join(home, LINEAGE_LOG_KEY);
|
|
139
|
+
if (!existsSync(logPath)) return { exists: false, log: null, lineage: null, head: null };
|
|
140
|
+
const log = JSON.parse(readFileSync(logPath, "utf8"));
|
|
141
|
+
if (!Array.isArray(log) || log.length === 0) {
|
|
142
|
+
throw new Error(`${logPath} is not a valid lineage event array`);
|
|
143
|
+
}
|
|
144
|
+
const tip = log[log.length - 1];
|
|
145
|
+
const lineage = typeof log[0]?.lineage === "string" ? log[0].lineage : null;
|
|
146
|
+
let head = null;
|
|
147
|
+
if (tip && typeof tip === "object" && !Array.isArray(tip)) {
|
|
148
|
+
try { head = `sha256:${eventDigest(tip)}`; } catch { head = null; }
|
|
149
|
+
}
|
|
150
|
+
return { exists: true, log, lineage, head };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function loadHomeIdentity(home, passphrase = "") {
|
|
154
|
+
const kcPath = join(home, "keychain.json");
|
|
155
|
+
if (existsSync(kcPath)) {
|
|
156
|
+
const kc = new Keychain(kcPath);
|
|
157
|
+
const id = kc.load({ passphrase });
|
|
158
|
+
const seedHex = seedHexFromKeychainIdentity(id);
|
|
159
|
+
const parsed = parseUuaid(id.uuaid);
|
|
160
|
+
const namespace = parsed?.namespace ?? "pillar";
|
|
161
|
+
const objectType = parsed?.objectType ?? "agent";
|
|
162
|
+
const coreId = identityFromSeed(hexToBytes(seedHex), { namespace, objectType });
|
|
163
|
+
return {
|
|
164
|
+
keychain: kc,
|
|
165
|
+
identity: id,
|
|
166
|
+
coreId,
|
|
167
|
+
uuaid: id.uuaid,
|
|
168
|
+
publicKeyHex: id.publicKeyHex,
|
|
169
|
+
seedHex,
|
|
170
|
+
namespace,
|
|
171
|
+
objectType,
|
|
172
|
+
isJsonDir: false,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const seedPath = join(home, "identity", "agent.seed");
|
|
176
|
+
if (existsSync(seedPath)) {
|
|
177
|
+
const seedHex = readFileSync(seedPath, "utf8").trim().toLowerCase();
|
|
178
|
+
if (!HEX64_RE.test(seedHex)) throw new Error(`invalid Ed25519 seed at ${seedPath}`);
|
|
179
|
+
let namespace = "pillar";
|
|
180
|
+
let objectType = "agent";
|
|
181
|
+
const metaPath = join(home, "identity", "agent-meta.json");
|
|
182
|
+
if (existsSync(metaPath)) {
|
|
183
|
+
try {
|
|
184
|
+
const meta = JSON.parse(readFileSync(metaPath, "utf8"));
|
|
185
|
+
const parsed = typeof meta?.uuaid === "string" ? parseUuaid(meta.uuaid) : null;
|
|
186
|
+
if (parsed) {
|
|
187
|
+
namespace = parsed.namespace;
|
|
188
|
+
objectType = parsed.objectType;
|
|
189
|
+
}
|
|
190
|
+
} catch { /* fallback to default namespace */ }
|
|
191
|
+
}
|
|
192
|
+
const coreId = identityFromSeed(hexToBytes(seedHex), { namespace, objectType });
|
|
193
|
+
return {
|
|
194
|
+
keychain: null,
|
|
195
|
+
identity: null,
|
|
196
|
+
coreId,
|
|
197
|
+
uuaid: coreId.uuaid,
|
|
198
|
+
publicKeyHex: coreId.publicKeyHex,
|
|
199
|
+
seedHex,
|
|
200
|
+
namespace,
|
|
201
|
+
objectType,
|
|
202
|
+
isJsonDir: true,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
throw new Error(`no pillar identity found at ${home}; run: pillar init`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function loadHomeCard(home, expectedUuaid = null) {
|
|
209
|
+
const cardPath = join(home, CARD_KEY);
|
|
210
|
+
if (!existsSync(cardPath)) return null;
|
|
211
|
+
const parsed = JSON.parse(readFileSync(cardPath, "utf8"));
|
|
212
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || parsed.v !== "pillar-card/1") {
|
|
213
|
+
throw new Error(`${cardPath} is not a valid pillar-card/1 document`);
|
|
214
|
+
}
|
|
215
|
+
if (expectedUuaid && parsed.uuaid !== expectedUuaid) return null;
|
|
216
|
+
return parsed;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function resolveCarriers(optCarriers, cfg) {
|
|
220
|
+
if (Array.isArray(optCarriers) && optCarriers.length > 0) {
|
|
221
|
+
return optCarriers.flatMap((c) => String(c).split(",").map((s) => s.trim()).filter(Boolean));
|
|
222
|
+
}
|
|
223
|
+
if (process.env.PILLAR_CARRIERS) {
|
|
224
|
+
return process.env.PILLAR_CARRIERS.split(",").map((s) => s.trim()).filter(Boolean);
|
|
225
|
+
}
|
|
226
|
+
return Array.isArray(cfg?.carriers) ? cfg.carriers.filter((c) => typeof c === "string" && c.length > 0) : [];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Load this home's stored `card/card.json` (matching the active UUAID) or
|
|
231
|
+
* synthesize a valid signed in-memory `pillar-card/1` so `knock` / `answer`
|
|
232
|
+
* work on fresh `pillar init` homes before `pillar card build` is run.
|
|
233
|
+
*/
|
|
234
|
+
export function ensureHomeCard(home, homeId, { carriers = [], cfg = {}, now = nowIsoSeconds() } = {}) {
|
|
235
|
+
try {
|
|
236
|
+
const stored = loadHomeCard(home, homeId.uuaid);
|
|
237
|
+
if (stored) return stored;
|
|
238
|
+
} catch { /* ignore malformed card when synthesizing fallback only if needed? No, rethrow */
|
|
239
|
+
throw new Error(`stored card at ${join(home, CARD_KEY)} is malformed`);
|
|
240
|
+
}
|
|
241
|
+
const lin = loadHomeLineage(home);
|
|
242
|
+
let lineage = homeId.uuaid;
|
|
243
|
+
let lineageHead;
|
|
244
|
+
if (lin.exists && lin.log) {
|
|
245
|
+
const v = verifyLineage(lin.log, { now });
|
|
246
|
+
if (v.verdict === "valid" && v.facts?.current === homeId.uuaid) {
|
|
247
|
+
lineage = lin.lineage ?? homeId.uuaid;
|
|
248
|
+
lineageHead = v.facts?.head ?? lin.head ?? undefined;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const httpsCarriers = carriers.filter((c) => isHttpsUrl(c));
|
|
252
|
+
const knockCfg = cfg?.knock ?? {};
|
|
253
|
+
const knock = {
|
|
254
|
+
pow: Number.isInteger(knockCfg.requiredBits ?? knockCfg.pow) ? (knockCfg.requiredBits ?? knockCfg.pow) : DEFAULT_STAMP_BITS,
|
|
255
|
+
...(typeof knockCfg.introductions === "boolean" ? { introductions: knockCfg.introductions } : {}),
|
|
256
|
+
...(Number.isInteger(knockCfg.maxBytes) ? { maxBytes: knockCfg.maxBytes } : {}),
|
|
257
|
+
};
|
|
258
|
+
return buildCard(homeId.coreId, {
|
|
259
|
+
name: `pillar-${homeId.uuaid.slice(-12)}`,
|
|
260
|
+
lineage,
|
|
261
|
+
...(lineageHead ? { lineageHead } : {}),
|
|
262
|
+
carriers: httpsCarriers.length > 0 ? httpsCarriers : [DEFAULT_CARD_CARRIER],
|
|
263
|
+
homes: [DEFAULT_CARD_HOME],
|
|
264
|
+
knock,
|
|
265
|
+
updatedAt: now,
|
|
266
|
+
namespace: homeId.namespace,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export { isValidUuaid };
|