chainlesschain 0.37.9 → 0.37.11
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 +309 -19
- package/bin/chainlesschain.js +4 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +374 -0
- package/src/commands/audit.js +286 -0
- package/src/commands/auth.js +387 -0
- package/src/commands/bi.js +240 -0
- package/src/commands/browse.js +184 -0
- package/src/commands/cowork.js +317 -0
- package/src/commands/did.js +376 -0
- package/src/commands/economy.js +375 -0
- package/src/commands/encrypt.js +233 -0
- package/src/commands/evolution.js +398 -0
- package/src/commands/export.js +125 -0
- package/src/commands/git.js +215 -0
- package/src/commands/hmemory.js +273 -0
- package/src/commands/hook.js +260 -0
- package/src/commands/import.js +259 -0
- package/src/commands/init.js +184 -0
- package/src/commands/instinct.js +202 -0
- package/src/commands/llm.js +155 -4
- package/src/commands/lowcode.js +320 -0
- package/src/commands/mcp.js +302 -0
- package/src/commands/memory.js +282 -0
- package/src/commands/note.js +187 -0
- package/src/commands/org.js +505 -0
- package/src/commands/p2p.js +274 -0
- package/src/commands/plugin.js +451 -0
- package/src/commands/sandbox.js +366 -0
- package/src/commands/search.js +237 -0
- package/src/commands/session.js +238 -0
- package/src/commands/skill.js +254 -201
- package/src/commands/sync.js +249 -0
- package/src/commands/tokens.js +214 -0
- package/src/commands/wallet.js +416 -0
- package/src/commands/workflow.js +359 -0
- package/src/commands/zkp.js +277 -0
- package/src/index.js +93 -1
- package/src/lib/a2a-protocol.js +371 -0
- package/src/lib/agent-coordinator.js +273 -0
- package/src/lib/agent-economy.js +369 -0
- package/src/lib/app-builder.js +377 -0
- package/src/lib/audit-logger.js +364 -0
- package/src/lib/bi-engine.js +299 -0
- package/src/lib/bm25-search.js +322 -0
- package/src/lib/browser-automation.js +216 -0
- package/src/lib/cowork/ab-comparator-cli.js +180 -0
- package/src/lib/cowork/code-knowledge-graph-cli.js +232 -0
- package/src/lib/cowork/debate-review-cli.js +144 -0
- package/src/lib/cowork/decision-kb-cli.js +153 -0
- package/src/lib/cowork/project-style-analyzer-cli.js +168 -0
- package/src/lib/cowork-adapter.js +106 -0
- package/src/lib/crypto-manager.js +246 -0
- package/src/lib/did-manager.js +270 -0
- package/src/lib/ensure-utf8.js +59 -0
- package/src/lib/evolution-system.js +508 -0
- package/src/lib/git-integration.js +220 -0
- package/src/lib/hierarchical-memory.js +471 -0
- package/src/lib/hook-manager.js +387 -0
- package/src/lib/instinct-manager.js +190 -0
- package/src/lib/knowledge-exporter.js +302 -0
- package/src/lib/knowledge-importer.js +293 -0
- package/src/lib/llm-providers.js +325 -0
- package/src/lib/mcp-client.js +413 -0
- package/src/lib/memory-manager.js +211 -0
- package/src/lib/note-versioning.js +244 -0
- package/src/lib/org-manager.js +424 -0
- package/src/lib/p2p-manager.js +317 -0
- package/src/lib/pdf-parser.js +96 -0
- package/src/lib/permission-engine.js +374 -0
- package/src/lib/plan-mode.js +333 -0
- package/src/lib/plugin-manager.js +430 -0
- package/src/lib/project-detector.js +53 -0
- package/src/lib/response-cache.js +156 -0
- package/src/lib/sandbox-v2.js +503 -0
- package/src/lib/service-container.js +183 -0
- package/src/lib/session-manager.js +189 -0
- package/src/lib/skill-loader.js +274 -0
- package/src/lib/sync-manager.js +347 -0
- package/src/lib/token-tracker.js +200 -0
- package/src/lib/wallet-manager.js +348 -0
- package/src/lib/workflow-engine.js +503 -0
- package/src/lib/zkp-engine.js +241 -0
- package/src/repl/agent-repl.js +259 -124
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZKP Engine — Zero-knowledge proof circuit compilation, proof generation,
|
|
3
|
+
* verification, and selective identity disclosure.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
|
|
8
|
+
/* ── In-memory stores ──────────────────────────────────────── */
|
|
9
|
+
const _circuits = new Map();
|
|
10
|
+
const _proofs = new Map();
|
|
11
|
+
const _verificationKeys = new Map();
|
|
12
|
+
|
|
13
|
+
const DEFAULT_SCHEME = "groth16";
|
|
14
|
+
|
|
15
|
+
/* ── Schema ────────────────────────────────────────────────── */
|
|
16
|
+
|
|
17
|
+
export function ensureZKPTables(db) {
|
|
18
|
+
db.exec(`
|
|
19
|
+
CREATE TABLE IF NOT EXISTS zkp_circuits (
|
|
20
|
+
id TEXT PRIMARY KEY,
|
|
21
|
+
name TEXT NOT NULL,
|
|
22
|
+
definition TEXT,
|
|
23
|
+
compiled TEXT,
|
|
24
|
+
verification_key TEXT,
|
|
25
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
26
|
+
)
|
|
27
|
+
`);
|
|
28
|
+
db.exec(`
|
|
29
|
+
CREATE TABLE IF NOT EXISTS zkp_proofs (
|
|
30
|
+
id TEXT PRIMARY KEY,
|
|
31
|
+
circuit_id TEXT NOT NULL,
|
|
32
|
+
proof TEXT,
|
|
33
|
+
public_inputs TEXT,
|
|
34
|
+
verified INTEGER DEFAULT 0,
|
|
35
|
+
scheme TEXT DEFAULT 'groth16',
|
|
36
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
37
|
+
)
|
|
38
|
+
`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* ── Circuit Compilation ───────────────────────────────────── */
|
|
42
|
+
|
|
43
|
+
export function compileCircuit(db, name, definition) {
|
|
44
|
+
const id = crypto.randomUUID();
|
|
45
|
+
const now = new Date().toISOString();
|
|
46
|
+
|
|
47
|
+
// Parse definition to extract constraints and I/O
|
|
48
|
+
let parsed;
|
|
49
|
+
if (typeof definition === "string") {
|
|
50
|
+
try {
|
|
51
|
+
parsed = JSON.parse(definition);
|
|
52
|
+
} catch (_err) {
|
|
53
|
+
parsed = { constraints: [], inputs: [], outputs: [] };
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
parsed = definition || {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const constraints = parsed.constraints || [];
|
|
60
|
+
const inputs = parsed.inputs || [];
|
|
61
|
+
const outputs = parsed.outputs || [];
|
|
62
|
+
|
|
63
|
+
// Generate verification key
|
|
64
|
+
const vkData = `${id}:${name}:${now}`;
|
|
65
|
+
const verificationKey = crypto
|
|
66
|
+
.createHash("sha256")
|
|
67
|
+
.update(vkData)
|
|
68
|
+
.digest("hex");
|
|
69
|
+
|
|
70
|
+
const compiled = {
|
|
71
|
+
bytecode: crypto.randomBytes(32).toString("hex"),
|
|
72
|
+
constraintCount: constraints.length || 1,
|
|
73
|
+
compiledAt: now,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const circuit = {
|
|
77
|
+
id,
|
|
78
|
+
name,
|
|
79
|
+
definition: parsed,
|
|
80
|
+
compiled,
|
|
81
|
+
constraints: constraints.length || 1,
|
|
82
|
+
inputs,
|
|
83
|
+
outputs,
|
|
84
|
+
verificationKey,
|
|
85
|
+
createdAt: now,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
_circuits.set(id, circuit);
|
|
89
|
+
_verificationKeys.set(id, verificationKey);
|
|
90
|
+
|
|
91
|
+
db.prepare(
|
|
92
|
+
`INSERT INTO zkp_circuits (id, name, definition, compiled, verification_key, created_at)
|
|
93
|
+
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
94
|
+
).run(
|
|
95
|
+
id,
|
|
96
|
+
name,
|
|
97
|
+
JSON.stringify(parsed),
|
|
98
|
+
JSON.stringify(compiled),
|
|
99
|
+
verificationKey,
|
|
100
|
+
now,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return circuit;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* ── Proof Generation ──────────────────────────────────────── */
|
|
107
|
+
|
|
108
|
+
export function generateProof(db, circuitId, privateInputs, publicInputs) {
|
|
109
|
+
const circuit = _circuits.get(circuitId);
|
|
110
|
+
if (!circuit) throw new Error(`Circuit not found: ${circuitId}`);
|
|
111
|
+
|
|
112
|
+
const id = crypto.randomUUID();
|
|
113
|
+
const now = new Date().toISOString();
|
|
114
|
+
|
|
115
|
+
// Mock zk-SNARK proof with {a, b, c} components (Groth16 structure)
|
|
116
|
+
const proofData = {
|
|
117
|
+
a: crypto.randomBytes(32).toString("hex"),
|
|
118
|
+
b: crypto.randomBytes(64).toString("hex"),
|
|
119
|
+
c: crypto.randomBytes(32).toString("hex"),
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const proof = {
|
|
123
|
+
id,
|
|
124
|
+
circuitId,
|
|
125
|
+
scheme: DEFAULT_SCHEME,
|
|
126
|
+
proof: proofData,
|
|
127
|
+
publicInputs: publicInputs || [],
|
|
128
|
+
verified: false,
|
|
129
|
+
createdAt: now,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
_proofs.set(id, proof);
|
|
133
|
+
|
|
134
|
+
db.prepare(
|
|
135
|
+
`INSERT INTO zkp_proofs (id, circuit_id, proof, public_inputs, verified, scheme, created_at)
|
|
136
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
137
|
+
).run(
|
|
138
|
+
id,
|
|
139
|
+
circuitId,
|
|
140
|
+
JSON.stringify(proofData),
|
|
141
|
+
JSON.stringify(publicInputs || []),
|
|
142
|
+
0,
|
|
143
|
+
DEFAULT_SCHEME,
|
|
144
|
+
now,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return proof;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* ── Proof Verification ────────────────────────────────────── */
|
|
151
|
+
|
|
152
|
+
export function verifyProof(db, proofId) {
|
|
153
|
+
const proof = _proofs.get(proofId);
|
|
154
|
+
if (!proof) throw new Error(`Proof not found: ${proofId}`);
|
|
155
|
+
|
|
156
|
+
const circuit = _circuits.get(proof.circuitId);
|
|
157
|
+
if (!circuit) throw new Error(`Circuit not found for proof: ${proofId}`);
|
|
158
|
+
|
|
159
|
+
// Mock verification — check proof structure is valid
|
|
160
|
+
const valid =
|
|
161
|
+
proof.proof &&
|
|
162
|
+
typeof proof.proof.a === "string" &&
|
|
163
|
+
typeof proof.proof.b === "string" &&
|
|
164
|
+
typeof proof.proof.c === "string" &&
|
|
165
|
+
_verificationKeys.has(proof.circuitId);
|
|
166
|
+
|
|
167
|
+
proof.verified = valid;
|
|
168
|
+
|
|
169
|
+
db.prepare(`UPDATE zkp_proofs SET verified = ? WHERE id = ?`).run(
|
|
170
|
+
valid ? 1 : 0,
|
|
171
|
+
proofId,
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return { valid, proofId, circuitId: proof.circuitId, scheme: proof.scheme };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* ── Identity Proof (Selective Disclosure) ─────────────────── */
|
|
178
|
+
|
|
179
|
+
export function createIdentityProof(claims, disclosedFields) {
|
|
180
|
+
if (!claims || typeof claims !== "object") {
|
|
181
|
+
throw new Error("Claims must be an object");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const allFields = Object.keys(claims);
|
|
185
|
+
const disclosed = {};
|
|
186
|
+
const hiddenFields = [];
|
|
187
|
+
|
|
188
|
+
for (const field of allFields) {
|
|
189
|
+
if (disclosedFields && disclosedFields.includes(field)) {
|
|
190
|
+
disclosed[field] = claims[field];
|
|
191
|
+
} else {
|
|
192
|
+
hiddenFields.push(field);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const commitment = crypto
|
|
197
|
+
.createHash("sha256")
|
|
198
|
+
.update(JSON.stringify(claims))
|
|
199
|
+
.digest("hex");
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
id: crypto.randomUUID(),
|
|
203
|
+
type: "selective-disclosure",
|
|
204
|
+
disclosed,
|
|
205
|
+
hiddenCount: hiddenFields.length,
|
|
206
|
+
commitment,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* ── Stats ─────────────────────────────────────────────────── */
|
|
211
|
+
|
|
212
|
+
export function getZKPStats() {
|
|
213
|
+
const proofList = [..._proofs.values()];
|
|
214
|
+
return {
|
|
215
|
+
circuits: _circuits.size,
|
|
216
|
+
proofs: proofList.length,
|
|
217
|
+
verifiedProofs: proofList.filter((p) => p.verified).length,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* ── Listing ───────────────────────────────────────────────── */
|
|
222
|
+
|
|
223
|
+
export function listCircuits(db) {
|
|
224
|
+
return [..._circuits.values()];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function listProofs(db, options) {
|
|
228
|
+
let proofs = [..._proofs.values()];
|
|
229
|
+
if (options && options.circuitId) {
|
|
230
|
+
proofs = proofs.filter((p) => p.circuitId === options.circuitId);
|
|
231
|
+
}
|
|
232
|
+
return proofs;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/* ── Reset (for testing) ───────────────────────────────────── */
|
|
236
|
+
|
|
237
|
+
export function _resetState() {
|
|
238
|
+
_circuits.clear();
|
|
239
|
+
_proofs.clear();
|
|
240
|
+
_verificationKeys.clear();
|
|
241
|
+
}
|