@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uuaid/pillar",
3
- "version": "2.6.1",
3
+ "version": "2.7.1",
4
4
  "description": "Pillar (Protocol for Inter-agent Linked Ledger And Relay) — the secure delivery layer of UACP, the Universal Agent Communication Protocol. UACP = UUAID (identity) + Envelope (signed, encrypted container) + Pillar (relay, mailbox, routing, store-and-forward). Reference implementation of the UACP delivery layer; includes VDA-1 (IAASO-3901, in ballot) delivery attestation and a blind escrow for the Zilligon ZGN / EVM rails.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -14,7 +14,8 @@
14
14
  "pillar-directory": "bin/pillar-directory.mjs",
15
15
  "pillar-escrow": "bin/pillar-escrow.mjs",
16
16
  "pillar-group-v2": "bin/pillar-group-v2.mjs",
17
- "pillar-blob": "bin/pillar-blob.mjs"
17
+ "pillar-blob": "bin/pillar-blob.mjs",
18
+ "pillar-notify": "bin/pillar-notify.mjs"
18
19
  },
19
20
  "exports": {
20
21
  ".": "./src/index.mjs",
@@ -33,6 +34,7 @@
33
34
  "./blob/broker": "./src/blob/broker.mjs",
34
35
  "./refusals": "./src/net/refusals.mjs",
35
36
  "./groups-v2": "./src/groups-v2-admin.mjs",
37
+ "./vda": "./src/vda/core.mjs",
36
38
  "./package.json": "./package.json"
37
39
  },
38
40
  "files": [
@@ -53,32 +55,22 @@
53
55
  "postpublish": "node scripts/verify-publish.mjs"
54
56
  },
55
57
  "engines": {
56
- "node": ">=22"
58
+ "node": ">=20"
57
59
  },
58
60
  "dependencies": {
59
- "@chainsafe/libp2p-noise": "^17.0.0",
60
- "@noble/hashes": "^2.3.0",
61
- "@chainsafe/libp2p-yamux": "^8.0.1",
62
- "@libp2p/autonat": "^3.0.26",
63
- "@libp2p/bootstrap": "^12.0.29",
64
- "@libp2p/circuit-relay-v2": "^4.2.11",
65
- "@libp2p/crypto": "^5.1.22",
66
- "@libp2p/dcutr": "^3.0.26",
67
- "@libp2p/identify": "^4.1.12",
68
- "@libp2p/kad-dht": "^16.4.3",
69
- "@libp2p/peer-id": "^6.0.14",
70
- "@libp2p/ping": "^3.1.11",
71
- "@libp2p/tcp": "^11.0.26",
72
- "@libp2p/webrtc": "^6.0.29",
73
- "@libp2p/websockets": "^10.1.19",
74
- "@multiformats/multiaddr": "^13.0.3",
75
61
  "@noble/curves": "^2.3.0",
76
- "better-sqlite3": "^13.0.3",
77
- "it-pipe": "^3.0.1",
78
- "it-pushable": "^3.2.4",
79
- "libp2p": "^3.3.8",
80
- "multiformats": "^14.0.5",
81
- "uint8arrays": "^5.1.1",
62
+ "@noble/hashes": "^2.3.0",
82
63
  "ws": "^8.21.3"
64
+ },
65
+ "optionalDependencies": {
66
+ "better-sqlite3": "^13.0.3"
67
+ },
68
+ "peerDependencies": {
69
+ "@uuaid/pillar-p2p": "^2.7.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@uuaid/pillar-p2p": {
73
+ "optional": true
74
+ }
83
75
  }
84
76
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `--help` / `-h` for every bin: print usage to stdout and exit 0 before the
3
+ * bin opens a file, mints a key, listens or runs a command (2.7.0 R2).
4
+ */
5
+
6
+ /** True when the argument list holds `--help` or `-h` before any `--`. */
7
+ export function wantsHelp(args) {
8
+ for (const a of args) {
9
+ if (a === "--") return false;
10
+ if (a === "--help" || a === "-h") return true;
11
+ }
12
+ return false;
13
+ }
14
+
15
+ /**
16
+ * Write `text` to stdout, then exit 0. A bin awaits it at top level, so no
17
+ * later statement of the bin runs. The exit waits for the write: on macOS a
18
+ * pipe write is asynchronous, and an early exit would cut the text short.
19
+ */
20
+ export async function exitWithHelp(text) {
21
+ await new Promise((resolve) => process.stdout.write(text.endsWith("\n") ? text : `${text}\n`, resolve));
22
+ process.exit(0);
23
+ }
@@ -50,7 +50,7 @@ const newQueueId = () => `gq-${randomBytes(12).toString("hex")}`;
50
50
 
51
51
  function openMailbox(home) {
52
52
  const p = join(home, "mailbox.db");
53
- return existsSync(p) ? new Mailbox(p) : null;
53
+ return (existsSync(p) || existsSync(join(home, "mailbox"))) ? new Mailbox(p) : null;
54
54
  }
55
55
 
56
56
  /** A grp-<32 hex> id, or the id a unique name has in this mailbox; else null. */
@@ -25,13 +25,26 @@
25
25
  * Wire-frozen: this is a local, recipient-side decision only.
26
26
  */
27
27
  import { existsSync, readFileSync } from "node:fs";
28
- import { join } from "node:path";
28
+ import { dirname, join } from "node:path";
29
+ import { writeFileAtomic } from "../vnext/wave-a.mjs";
29
30
 
30
31
  export const POLICIES = ["open", "directory", "allowlist"];
32
+ export const DEFAULT_KNOCK_ACCEPT_SCOPE = ["message", "request", "reply", "ack"];
33
+
34
+ function normalizeScopes(raw) {
35
+ const out = {};
36
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return out;
37
+ for (const [uuaid, kinds] of Object.entries(raw)) {
38
+ if (typeof uuaid !== "string" || !Array.isArray(kinds)) continue;
39
+ const clean = kinds.filter((k) => typeof k === "string" && k.length > 0);
40
+ out[uuaid] = clean;
41
+ }
42
+ return out;
43
+ }
31
44
 
32
45
  export function loadTrustPolicy(home) {
33
46
  const p = join(home, "trust.json");
34
- if (!existsSync(p)) return { policy: "open", allow: [], block: [], path: p, exists: false };
47
+ if (!existsSync(p)) return { policy: "open", allow: [], block: [], allowScopes: {}, path: p, exists: false };
35
48
  let raw;
36
49
  try { raw = JSON.parse(readFileSync(p, "utf-8")); }
37
50
  catch (e) { throw new Error(`trust.json unparseable at ${p}: ${e.message}`); }
@@ -40,17 +53,70 @@ export function loadTrustPolicy(home) {
40
53
  throw new Error(`trust.json: unknown policy "${policy}" (expected ${POLICIES.join("|")})`);
41
54
  }
42
55
  const list = (v) => Array.isArray(v) ? v.filter(s => typeof s === "string") : [];
43
- return { policy, allow: list(raw.allow), block: list(raw.block), path: p, exists: true };
56
+ return {
57
+ policy,
58
+ allow: list(raw.allow),
59
+ block: list(raw.block),
60
+ allowScopes: normalizeScopes(raw.allowScopes),
61
+ path: p,
62
+ exists: true,
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Persist a trust policy object to `<home>/trust.json` (or `trust.path`) with mode 0600.
68
+ */
69
+ export function saveTrustPolicy(homeOrPath, trust) {
70
+ const p = trust?.path ?? (homeOrPath.endsWith(".json") ? homeOrPath : join(homeOrPath, "trust.json"));
71
+ const allowScopes = normalizeScopes(trust?.allowScopes);
72
+ const doc = {
73
+ policy: trust?.policy ?? "open",
74
+ allow: Array.isArray(trust?.allow) ? [...new Set(trust.allow.filter((s) => typeof s === "string"))] : [],
75
+ block: Array.isArray(trust?.block) ? [...new Set(trust.block.filter((s) => typeof s === "string"))] : [],
76
+ ...(Object.keys(allowScopes).length ? { allowScopes } : {}),
77
+ };
78
+ writeFileAtomic(p, `${JSON.stringify(doc, null, 2)}\n`, 0o600);
79
+ return { ...doc, allowScopes, path: p, exists: true };
80
+ }
81
+
82
+ /**
83
+ * Add `sender` to `trust.allow` (removing from `trust.block` if present) with an
84
+ * optional kind scope (defaulting to DEFAULT_KNOCK_ACCEPT_SCOPE), mutating `trust`
85
+ * in place and persisting `trust.json` (mode 0600) when a path/home is available.
86
+ */
87
+ export function allowSenderInTrust(trust, sender, { home = null, scope = DEFAULT_KNOCK_ACCEPT_SCOPE } = {}) {
88
+ const effectiveScope = Array.isArray(scope) && scope.length
89
+ ? [...new Set(scope.filter((s) => typeof s === "string" && s.length > 0))]
90
+ : [...DEFAULT_KNOCK_ACCEPT_SCOPE];
91
+ const target = trust ?? { policy: "open", allow: [], block: [], allowScopes: {}, path: home ? join(home, "trust.json") : null, exists: false };
92
+ if (!Array.isArray(target.allow)) target.allow = [];
93
+ if (!Array.isArray(target.block)) target.block = [];
94
+ if (!target.allowScopes || typeof target.allowScopes !== "object") target.allowScopes = {};
95
+ target.block = target.block.filter((u) => u !== sender);
96
+ if (!target.allow.includes(sender)) target.allow.push(sender);
97
+ target.allowScopes[sender] = effectiveScope;
98
+ const outPath = target.path ?? (home ? join(home, "trust.json") : null);
99
+ if (outPath) {
100
+ target.path = outPath;
101
+ target.exists = true;
102
+ saveTrustPolicy(dirname(outPath), target);
103
+ }
104
+ return target;
44
105
  }
45
106
 
46
107
  /**
47
108
  * Decide an envelope's fate. `knownSenders` is a Set of uuaids the recipient
48
109
  * already knows (address book / fleet.json / directory agents).
110
+ * Optional `opts.kind` enforces per-sender `allowScopes` when present.
49
111
  * Returns { deliver: true } or { deliver: false, reason }.
50
112
  */
51
- export function evaluateTrust(trust, sender, knownSenders) {
52
- if (trust.block.includes(sender)) return { deliver: false, reason: "blocked" };
53
- if (trust.allow.includes(sender)) return { deliver: true };
113
+ export function evaluateTrust(trust, sender, knownSenders, { kind = null } = {}) {
114
+ if (trust.block.includes(sender)) return { deliver: false, reason: "blocked" }; // @rule trust.blocked-first
115
+ if (trust.allow.includes(sender)) {
116
+ const scope = trust.allowScopes?.[sender];
117
+ if (kind && Array.isArray(scope) && !scope.includes("*") && !scope.includes(kind)) return { deliver: false, reason: "kind-not-allowed" }; // @rule trust.allow-scope-enforced
118
+ return { deliver: true };
119
+ }
54
120
  switch (trust.policy) {
55
121
  case "open": return { deliver: true };
56
122
  case "directory":