memory-crystal 0.2.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.
- package/.env.example +20 -0
- package/CHANGELOG.md +6 -0
- package/LETTERS.md +22 -0
- package/LICENSE +21 -0
- package/README-ENTERPRISE.md +162 -0
- package/README-old.md +275 -0
- package/README.md +91 -0
- package/RELAY.md +88 -0
- package/TECHNICAL.md +379 -0
- package/ai/dev-updates/2026-02-25--cc-air--phase2-architecture-pivot.md +70 -0
- package/ai/dev-updates/2026-02-25--cc-air--phase2-worker-build.md +72 -0
- package/ai/dev-updates/2026-02-26--10-25-16--cc-mini--phase2-implementation.md +49 -0
- package/ai/dev-updates/2026-02-27--20-30-00--cc-mini--readme-overhaul-and-public-deploy.md +69 -0
- package/ai/notes/2026-02-26--cc-air--notes.md +412 -0
- package/ai/notes/2026-02-27--cc-mini--grok-feedback.md +44 -0
- package/ai/notes/2026-02-27--cc-mini--lesa-feedback.md +45 -0
- package/ai/notes/RESEARCH.md +1185 -0
- package/ai/notes/salience-research/README.md +29 -0
- package/ai/notes/salience-research/eurosla-salience-review.md +64 -0
- package/ai/notes/salience-research/full-research-summary.md +269 -0
- package/ai/notes/salience-research/salience-levels-diagram.png +0 -0
- package/ai/plan/2026-02-27--cc-mini--qr-pairing-spec.md +203 -0
- package/ai/plan/_archive/PLAN.md +194 -0
- package/ai/plan/_archive/PRD.md +1014 -0
- package/ai/plan/cc-plans-duplicates-from-dot-claude/2026-02-26--cc-mini--phase2-implementation-plan.md +245 -0
- package/ai/plan/dev-conventions-note.md +70 -0
- package/ai/plan/ldm-os-install-and-boot-architecture.md +285 -0
- package/ai/plan/memory-crystal-phase2-plan.md +192 -0
- package/ai/plan/memory-system-lay-of-the-land.md +214 -0
- package/ai/plan/phase2-ephemeral-relay.md +238 -0
- package/ai/plan/readme-first.md +68 -0
- package/ai/plan/roadmap.md +159 -0
- package/ai/todos/PUNCHLIST.md +44 -0
- package/ai/todos/README.md +31 -0
- package/ai/todos/inboxes/cc-air/2026-02-26--cc-air--post-relay-todos.md +85 -0
- package/ai/todos/inboxes/cc-mini/2026-02-26--cc-mini--phase2-status.md +100 -0
- package/ai/todos/inboxes/cc-mini/_archive/TODO.md +25 -0
- package/ai/todos/inboxes/parker/2026-02-25--cc-air--setup-checklist.md +139 -0
- package/ai/todos/inboxes/parker/2026-02-26--cc-mini--phase2-your-moves.md +72 -0
- package/dist/cc-hook.d.ts +1 -0
- package/dist/cc-hook.js +349 -0
- package/dist/chunk-3VFIJYS4.js +818 -0
- package/dist/chunk-52QE3YI3.js +1169 -0
- package/dist/chunk-AA3OPP4Z.js +432 -0
- package/dist/chunk-D3I3ZSE2.js +411 -0
- package/dist/chunk-EKSACBTJ.js +1070 -0
- package/dist/chunk-F3Y7EL7K.js +83 -0
- package/dist/chunk-JWZXYVET.js +1068 -0
- package/dist/chunk-KYVWO6ZM.js +1069 -0
- package/dist/chunk-L3VHARQH.js +413 -0
- package/dist/chunk-LOVAHSQV.js +411 -0
- package/dist/chunk-LQOYCAGG.js +446 -0
- package/dist/chunk-MK42FMEG.js +147 -0
- package/dist/chunk-NIJCVN3O.js +147 -0
- package/dist/chunk-O2UITJGH.js +465 -0
- package/dist/chunk-PEK6JH65.js +432 -0
- package/dist/chunk-PJ6FFKEX.js +77 -0
- package/dist/chunk-PLUBBZYR.js +800 -0
- package/dist/chunk-SGL6ISBJ.js +1061 -0
- package/dist/chunk-UNHVZB5G.js +411 -0
- package/dist/chunk-VAFTWSTE.js +1061 -0
- package/dist/chunk-XZ3S56RQ.js +1061 -0
- package/dist/chunk-Y72C7F6O.js +148 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +325 -0
- package/dist/core.d.ts +188 -0
- package/dist/core.js +12 -0
- package/dist/crypto.d.ts +16 -0
- package/dist/crypto.js +18 -0
- package/dist/dev-update-SZ2Z4WCQ.js +6 -0
- package/dist/ldm.d.ts +17 -0
- package/dist/ldm.js +12 -0
- package/dist/mcp-server.d.ts +1 -0
- package/dist/mcp-server.js +250 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +89 -0
- package/dist/mirror-sync.d.ts +1 -0
- package/dist/mirror-sync.js +130 -0
- package/dist/openclaw.d.ts +5 -0
- package/dist/openclaw.js +349 -0
- package/dist/poller.d.ts +1 -0
- package/dist/poller.js +272 -0
- package/dist/summarize.d.ts +19 -0
- package/dist/summarize.js +10 -0
- package/dist/worker.js +137 -0
- package/openclaw.plugin.json +11 -0
- package/package.json +40 -0
- package/scripts/migrate-lance-to-sqlite.mjs +217 -0
- package/skills/memory/SKILL.md +61 -0
- package/src/cc-hook.ts +447 -0
- package/src/cli.ts +356 -0
- package/src/core.ts +1472 -0
- package/src/crypto.ts +113 -0
- package/src/dev-update.ts +178 -0
- package/src/ldm.ts +117 -0
- package/src/mcp-server.ts +274 -0
- package/src/migrate.ts +104 -0
- package/src/mirror-sync.ts +175 -0
- package/src/openclaw.ts +250 -0
- package/src/poller.ts +345 -0
- package/src/summarize.ts +210 -0
- package/src/worker.ts +208 -0
- package/tsconfig.json +18 -0
- package/wrangler.toml +20 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/crypto.ts
|
|
2
|
+
import { readFileSync, existsSync } from "fs";
|
|
3
|
+
import { createCipheriv, createDecipheriv, createHmac, randomBytes, hkdfSync } from "crypto";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
var HOME = process.env.HOME || "";
|
|
7
|
+
var KEY_PATH = process.env.CRYSTAL_RELAY_KEY_PATH || join(HOME, ".openclaw", "secrets", "crystal-relay-key");
|
|
8
|
+
function loadRelayKey() {
|
|
9
|
+
if (!existsSync(KEY_PATH)) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Relay key not found at ${KEY_PATH}
|
|
12
|
+
Generate one: openssl rand -base64 32 > ${KEY_PATH} && chmod 600 ${KEY_PATH}
|
|
13
|
+
Copy the same key to all trusted machines.`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const raw = readFileSync(KEY_PATH, "utf-8").trim();
|
|
17
|
+
const key = Buffer.from(raw, "base64");
|
|
18
|
+
if (key.length !== 32) {
|
|
19
|
+
throw new Error(`Relay key must be 32 bytes (256 bits). Got ${key.length} bytes. Regenerate with: openssl rand -base64 32`);
|
|
20
|
+
}
|
|
21
|
+
return key;
|
|
22
|
+
}
|
|
23
|
+
function deriveSigningKey(masterKey) {
|
|
24
|
+
return Buffer.from(hkdfSync("sha256", masterKey, "", "crystal-relay-sign", 32));
|
|
25
|
+
}
|
|
26
|
+
function encrypt(plaintext, masterKey) {
|
|
27
|
+
const nonce = randomBytes(12);
|
|
28
|
+
const cipher = createCipheriv("aes-256-gcm", masterKey, nonce);
|
|
29
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
30
|
+
const tag = cipher.getAuthTag();
|
|
31
|
+
const signingKey = deriveSigningKey(masterKey);
|
|
32
|
+
const hmacData = Buffer.concat([nonce, ciphertext, tag]);
|
|
33
|
+
const hmac = createHmac("sha256", signingKey).update(hmacData).digest("hex");
|
|
34
|
+
return {
|
|
35
|
+
v: 1,
|
|
36
|
+
nonce: nonce.toString("base64"),
|
|
37
|
+
ciphertext: ciphertext.toString("base64"),
|
|
38
|
+
tag: tag.toString("base64"),
|
|
39
|
+
hmac
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function decrypt(payload, masterKey) {
|
|
43
|
+
if (payload.v !== 1) {
|
|
44
|
+
throw new Error(`Unknown payload version: ${payload.v}`);
|
|
45
|
+
}
|
|
46
|
+
const nonce = Buffer.from(payload.nonce, "base64");
|
|
47
|
+
const ciphertext = Buffer.from(payload.ciphertext, "base64");
|
|
48
|
+
const tag = Buffer.from(payload.tag, "base64");
|
|
49
|
+
const signingKey = deriveSigningKey(masterKey);
|
|
50
|
+
const hmacData = Buffer.concat([nonce, ciphertext, tag]);
|
|
51
|
+
const expectedHmac = createHmac("sha256", signingKey).update(hmacData).digest("hex");
|
|
52
|
+
if (payload.hmac !== expectedHmac) {
|
|
53
|
+
throw new Error("HMAC verification failed \u2014 blob rejected (tampered or wrong key)");
|
|
54
|
+
}
|
|
55
|
+
const decipher = createDecipheriv("aes-256-gcm", masterKey, nonce);
|
|
56
|
+
decipher.setAuthTag(tag);
|
|
57
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
58
|
+
}
|
|
59
|
+
function encryptJSON(data, masterKey) {
|
|
60
|
+
const plaintext = Buffer.from(JSON.stringify(data), "utf-8");
|
|
61
|
+
return encrypt(plaintext, masterKey);
|
|
62
|
+
}
|
|
63
|
+
function decryptJSON(payload, masterKey) {
|
|
64
|
+
const plaintext = decrypt(payload, masterKey);
|
|
65
|
+
return JSON.parse(plaintext.toString("utf-8"));
|
|
66
|
+
}
|
|
67
|
+
function encryptFile(filePath, masterKey) {
|
|
68
|
+
const plaintext = readFileSync(filePath);
|
|
69
|
+
return encrypt(plaintext, masterKey);
|
|
70
|
+
}
|
|
71
|
+
function hashBuffer(data) {
|
|
72
|
+
return createHash("sha256").update(data).digest("hex");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
loadRelayKey,
|
|
77
|
+
encrypt,
|
|
78
|
+
decrypt,
|
|
79
|
+
encryptJSON,
|
|
80
|
+
decryptJSON,
|
|
81
|
+
encryptFile,
|
|
82
|
+
hashBuffer
|
|
83
|
+
};
|