chainlesschain 0.47.8 → 0.49.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.
Files changed (86) hide show
  1. package/bin/chainlesschain.js +0 -0
  2. package/package.json +10 -8
  3. package/src/assets/web-panel/.build-hash +1 -1
  4. package/src/assets/web-panel/assets/{AppLayout-6SPt_8Y_.js → AppLayout-Rvi759IS.js} +1 -1
  5. package/src/assets/web-panel/assets/Dashboard-BS-tzGNj.css +1 -0
  6. package/src/assets/web-panel/assets/{Dashboard-Br7kCwKJ.js → Dashboard-DBhFxXYQ.js} +2 -2
  7. package/src/assets/web-panel/assets/{index-tN-8TosE.js → index-uL0cZ8N_.js} +2 -2
  8. package/src/assets/web-panel/index.html +2 -2
  9. package/src/commands/activitypub.js +533 -0
  10. package/src/commands/codegen.js +303 -0
  11. package/src/commands/collab.js +482 -0
  12. package/src/commands/compliance.js +597 -6
  13. package/src/commands/crosschain.js +382 -0
  14. package/src/commands/dbevo.js +388 -0
  15. package/src/commands/dev.js +411 -0
  16. package/src/commands/federation.js +427 -0
  17. package/src/commands/fusion.js +332 -0
  18. package/src/commands/governance.js +505 -0
  19. package/src/commands/hardening.js +110 -0
  20. package/src/commands/incentive.js +373 -0
  21. package/src/commands/inference.js +304 -0
  22. package/src/commands/infra.js +361 -0
  23. package/src/commands/kg.js +371 -0
  24. package/src/commands/marketplace.js +326 -0
  25. package/src/commands/matrix.js +283 -0
  26. package/src/commands/mcp.js +441 -18
  27. package/src/commands/nlprog.js +329 -0
  28. package/src/commands/nostr.js +196 -7
  29. package/src/commands/ops.js +408 -0
  30. package/src/commands/perception.js +385 -0
  31. package/src/commands/pqc.js +34 -0
  32. package/src/commands/privacy.js +345 -0
  33. package/src/commands/quantization.js +280 -0
  34. package/src/commands/recommend.js +336 -0
  35. package/src/commands/reputation.js +349 -0
  36. package/src/commands/runtime.js +500 -0
  37. package/src/commands/sla.js +352 -0
  38. package/src/commands/social.js +265 -0
  39. package/src/commands/stress.js +252 -0
  40. package/src/commands/tech.js +268 -0
  41. package/src/commands/tenant.js +576 -0
  42. package/src/commands/trust.js +366 -0
  43. package/src/harness/mcp-client.js +330 -54
  44. package/src/index.js +114 -0
  45. package/src/lib/activitypub-bridge.js +623 -0
  46. package/src/lib/aiops.js +523 -0
  47. package/src/lib/autonomous-developer.js +524 -0
  48. package/src/lib/code-agent.js +442 -0
  49. package/src/lib/collaboration-governance.js +556 -0
  50. package/src/lib/community-governance.js +649 -0
  51. package/src/lib/compliance-framework-reporter.js +600 -0
  52. package/src/lib/content-recommendation.js +600 -0
  53. package/src/lib/cross-chain.js +669 -0
  54. package/src/lib/dbevo.js +669 -0
  55. package/src/lib/decentral-infra.js +445 -0
  56. package/src/lib/federation-hardening.js +587 -0
  57. package/src/lib/hardening-manager.js +409 -0
  58. package/src/lib/inference-network.js +407 -0
  59. package/src/lib/knowledge-graph.js +530 -0
  60. package/src/lib/matrix-bridge.js +252 -0
  61. package/src/lib/mcp-client.js +3 -0
  62. package/src/lib/mcp-registry.js +347 -0
  63. package/src/lib/mcp-scaffold.js +385 -0
  64. package/src/lib/multimodal.js +698 -0
  65. package/src/lib/nl-programming.js +595 -0
  66. package/src/lib/nostr-bridge.js +214 -38
  67. package/src/lib/perception.js +500 -0
  68. package/src/lib/pqc-manager.js +141 -9
  69. package/src/lib/privacy-computing.js +575 -0
  70. package/src/lib/protocol-fusion.js +535 -0
  71. package/src/lib/quantization.js +362 -0
  72. package/src/lib/reputation-optimizer.js +509 -0
  73. package/src/lib/skill-marketplace.js +397 -0
  74. package/src/lib/sla-manager.js +484 -0
  75. package/src/lib/social-graph.js +408 -0
  76. package/src/lib/stix-parser.js +167 -0
  77. package/src/lib/stress-tester.js +383 -0
  78. package/src/lib/tech-learning-engine.js +651 -0
  79. package/src/lib/tenant-saas.js +831 -0
  80. package/src/lib/threat-intel.js +268 -0
  81. package/src/lib/token-incentive.js +513 -0
  82. package/src/lib/topic-classifier.js +400 -0
  83. package/src/lib/trust-security.js +473 -0
  84. package/src/lib/ueba.js +403 -0
  85. package/src/lib/universal-runtime.js +771 -0
  86. package/src/assets/web-panel/assets/Dashboard-CKeMmCoT.css +0 -1
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Threat Intelligence Store — SQLite-backed IoC (indicator of
3
+ * compromise) catalog. Imports STIX 2.1 bundles, deduplicates
4
+ * indicators by (type, value), and supports fast O(1) matching of
5
+ * an arbitrary observable against the stored feed.
6
+ *
7
+ * Designed to pair with `compliance-manager.js`: a compliance scan
8
+ * can call `matchObservable` to flag blocklisted artefacts during
9
+ * evidence ingestion.
10
+ */
11
+
12
+ import crypto from "crypto";
13
+ import fs from "fs";
14
+ import {
15
+ extractIndicatorsFromBundle,
16
+ classifyObservable,
17
+ IOC_TYPES,
18
+ } from "./stix-parser.js";
19
+
20
+ /* ── Schema ────────────────────────────────────────────────── */
21
+
22
+ export function ensureThreatIntelTables(db) {
23
+ db.exec(`
24
+ CREATE TABLE IF NOT EXISTS threat_intel_indicators (
25
+ id TEXT PRIMARY KEY,
26
+ type TEXT NOT NULL,
27
+ value TEXT NOT NULL,
28
+ labels TEXT,
29
+ confidence INTEGER,
30
+ source_id TEXT,
31
+ source_name TEXT,
32
+ valid_from TEXT,
33
+ valid_until TEXT,
34
+ first_seen_at TEXT DEFAULT (datetime('now')),
35
+ last_seen_at TEXT DEFAULT (datetime('now')),
36
+ UNIQUE(type, value)
37
+ )
38
+ `);
39
+ db.exec(
40
+ `CREATE INDEX IF NOT EXISTS idx_threat_intel_type ON threat_intel_indicators(type)`,
41
+ );
42
+ db.exec(
43
+ `CREATE INDEX IF NOT EXISTS idx_threat_intel_value ON threat_intel_indicators(value)`,
44
+ );
45
+ }
46
+
47
+ /* ── Import ────────────────────────────────────────────────── */
48
+
49
+ /**
50
+ * Import a parsed STIX bundle (or a loose array of STIX objects) into
51
+ * the store. Returns `{imported, updated, skipped, total}`.
52
+ *
53
+ * - `imported`: new (type,value) pairs inserted.
54
+ * - `updated`: existing pairs whose metadata was refreshed.
55
+ * - `skipped`: objects that yielded no usable indicator (unknown
56
+ * observable type, non-stix pattern_type, malformed pattern, etc.).
57
+ */
58
+ export function importStixBundle(db, bundle) {
59
+ if (!db) throw new Error("Database is required");
60
+ const iocs = extractIndicatorsFromBundle(bundle);
61
+ const total = Array.isArray(bundle?.objects)
62
+ ? bundle.objects.filter((o) => o?.type === "indicator").length
63
+ : Array.isArray(bundle)
64
+ ? bundle.filter((o) => o?.type === "indicator").length
65
+ : 0;
66
+
67
+ let imported = 0;
68
+ let updated = 0;
69
+
70
+ const insert = db.prepare(
71
+ `INSERT INTO threat_intel_indicators
72
+ (id, type, value, labels, confidence, source_id, source_name,
73
+ valid_from, valid_until, first_seen_at, last_seen_at)
74
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))`,
75
+ );
76
+ const update = db.prepare(
77
+ `UPDATE threat_intel_indicators
78
+ SET labels = ?,
79
+ confidence = ?,
80
+ source_id = ?,
81
+ source_name = ?,
82
+ valid_from = ?,
83
+ valid_until = ?,
84
+ last_seen_at = datetime('now')
85
+ WHERE type = ? AND value = ?`,
86
+ );
87
+ const selectExisting = db.prepare(
88
+ `SELECT id FROM threat_intel_indicators WHERE type = ? AND value = ?`,
89
+ );
90
+
91
+ for (const rawIoc of iocs) {
92
+ // File hashes are case-insensitive — normalize on write so that
93
+ // equality lookups in `matchObservable` don't depend on SQLite's
94
+ // COLLATE NOCASE (which the mock-db used in tests doesn't emulate).
95
+ const ioc = rawIoc.type.startsWith("file-")
96
+ ? { ...rawIoc, value: String(rawIoc.value).toLowerCase() }
97
+ : rawIoc;
98
+ const prior = selectExisting.get(ioc.type, ioc.value);
99
+ const labels = JSON.stringify(ioc.source?.labels || []);
100
+ const confidence = ioc.source?.confidence ?? null;
101
+ const sourceId = ioc.source?.indicatorId || null;
102
+ const sourceName = ioc.source?.name || null;
103
+ const validFrom = ioc.source?.validFrom || null;
104
+ const validUntil = ioc.source?.validUntil || null;
105
+
106
+ if (prior) {
107
+ update.run(
108
+ labels,
109
+ confidence,
110
+ sourceId,
111
+ sourceName,
112
+ validFrom,
113
+ validUntil,
114
+ ioc.type,
115
+ ioc.value,
116
+ );
117
+ updated += 1;
118
+ } else {
119
+ insert.run(
120
+ crypto.randomUUID(),
121
+ ioc.type,
122
+ ioc.value,
123
+ labels,
124
+ confidence,
125
+ sourceId,
126
+ sourceName,
127
+ validFrom,
128
+ validUntil,
129
+ );
130
+ imported += 1;
131
+ }
132
+ }
133
+ const skipped = Math.max(total - iocs.length, 0);
134
+ return { imported, updated, skipped, total };
135
+ }
136
+
137
+ /**
138
+ * Import a STIX bundle from a file path. Convenience wrapper over
139
+ * `importStixBundle` — reads the JSON, parses it, defers to the
140
+ * core importer.
141
+ */
142
+ export function importStixFile(db, filePath) {
143
+ const raw = fs.readFileSync(filePath, "utf-8");
144
+ let bundle;
145
+ try {
146
+ bundle = JSON.parse(raw);
147
+ } catch (err) {
148
+ throw new Error(`Invalid JSON in ${filePath}: ${err.message}`);
149
+ }
150
+ return importStixBundle(db, bundle);
151
+ }
152
+
153
+ /* ── Query ─────────────────────────────────────────────────── */
154
+
155
+ function _rowToIndicator(r) {
156
+ if (!r) return null;
157
+ let labels = [];
158
+ try {
159
+ labels = r.labels ? JSON.parse(r.labels) : [];
160
+ } catch {
161
+ labels = [];
162
+ }
163
+ return {
164
+ id: r.id,
165
+ type: r.type,
166
+ value: r.value,
167
+ labels,
168
+ confidence: r.confidence ?? null,
169
+ sourceId: r.source_id || null,
170
+ sourceName: r.source_name || null,
171
+ validFrom: r.valid_from || null,
172
+ validUntil: r.valid_until || null,
173
+ firstSeenAt: r.first_seen_at,
174
+ lastSeenAt: r.last_seen_at,
175
+ };
176
+ }
177
+
178
+ /**
179
+ * List indicators, optionally filtered by type. `limit` caps result
180
+ * size (default 100, 0 = unlimited).
181
+ */
182
+ export function listIndicators(db, options = {}) {
183
+ const { type, limit = 100 } = options;
184
+ if (type && !IOC_TYPES.includes(type)) {
185
+ throw new Error(
186
+ `Unknown IOC type: ${type}. Valid: ${IOC_TYPES.join(", ")}`,
187
+ );
188
+ }
189
+ let sql = `SELECT * FROM threat_intel_indicators`;
190
+ const params = [];
191
+ if (type) {
192
+ sql += ` WHERE type = ?`;
193
+ params.push(type);
194
+ }
195
+ sql += ` ORDER BY last_seen_at DESC`;
196
+ if (limit && limit > 0) {
197
+ sql += ` LIMIT ?`;
198
+ params.push(limit);
199
+ }
200
+ return db
201
+ .prepare(sql)
202
+ .all(...params)
203
+ .map(_rowToIndicator);
204
+ }
205
+
206
+ /**
207
+ * Match an arbitrary observable against the stored feed. Returns:
208
+ * {matched:true, type, indicator} on hit
209
+ * {matched:false, type} on miss (type still classified)
210
+ * {matched:false, type:"unknown"} if we can't classify the input
211
+ */
212
+ export function matchObservable(db, value) {
213
+ const type = classifyObservable(value);
214
+ if (type === "unknown") return { matched: false, type: "unknown" };
215
+
216
+ const trimmed = String(value).trim();
217
+ const normalized = type.startsWith("file-") ? trimmed.toLowerCase() : trimmed;
218
+
219
+ const row = db
220
+ .prepare(
221
+ `SELECT * FROM threat_intel_indicators
222
+ WHERE type = ? AND value = ?
223
+ LIMIT 1`,
224
+ )
225
+ .get(type, normalized);
226
+
227
+ if (!row) return { matched: false, type };
228
+ return { matched: true, type, indicator: _rowToIndicator(row) };
229
+ }
230
+
231
+ /**
232
+ * Aggregate stats — total indicators + counts per type.
233
+ */
234
+ export function getStats(db) {
235
+ const total =
236
+ db.prepare(`SELECT COUNT(*) AS n FROM threat_intel_indicators`).get()?.n ??
237
+ 0;
238
+ const rows = db
239
+ .prepare(
240
+ `SELECT type, COUNT(*) AS n
241
+ FROM threat_intel_indicators
242
+ GROUP BY type
243
+ ORDER BY n DESC`,
244
+ )
245
+ .all();
246
+ const byType = {};
247
+ for (const r of rows) byType[r.type] = r.n;
248
+ return { total, byType };
249
+ }
250
+
251
+ /**
252
+ * Remove a single indicator by (type, value). Returns true if a row
253
+ * was deleted.
254
+ */
255
+ export function removeIndicator(db, type, value) {
256
+ const info = db
257
+ .prepare(`DELETE FROM threat_intel_indicators WHERE type = ? AND value = ?`)
258
+ .run(type, value);
259
+ return info.changes > 0;
260
+ }
261
+
262
+ /**
263
+ * Drop every stored indicator. Returns the number of rows removed.
264
+ */
265
+ export function clearAll(db) {
266
+ const info = db.prepare(`DELETE FROM threat_intel_indicators`).run();
267
+ return info.changes;
268
+ }