-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-vectors.cjs
More file actions
executable file
·71 lines (65 loc) · 2.63 KB
/
run-vectors.cjs
File metadata and controls
executable file
·71 lines (65 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const GOVERNED = [
"Riverbraid-Core", "Riverbraid-Golds", "Riverbraid-Crypto-Gold",
"Riverbraid-Judicial-Gold", "Riverbraid-Memory-Gold", "Riverbraid-Integration-Gold",
"Riverbraid-Refusal-Gold", "Riverbraid-Cognition", "Riverbraid-Harness-Gold",
"Riverbraid-Temporal-Gold", "Riverbraid-Action-Gold", "Riverbraid-Audio-Gold",
"Riverbraid-Vision-Gold", "Riverbraid-Lite", "Riverbraid-Interface-Gold"
];
const SNAPSHOT = "constitution.snapshot.json";
const sha256 = (b) => crypto.createHash("sha256").update(b).digest("hex");
function checkFloor(buf, label) {
if (buf.length === 0 || buf[buf.length-1] !== 0x0a) throw new Error(`LF_VIOLATION:${label}`);
if (buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) throw new Error(`BOM_VIOLATION:${label}`);
for (let i = 0; i < buf.length; i++) {
const b = buf[i];
if (b === 0x0d || b === 0x00 || b < 0x09 || (b > 0x0a && b < 0x20) || b > 0x7e)
throw new Error(`ILLEGAL_BYTE:${label}:${i}`);
}
}
function getSnapshot() {
const hashes = {};
const rootDir = path.dirname(process.cwd());
GOVERNED.forEach(repo => {
const dir = repo === "Riverbraid-Core" ? process.cwd() : path.join(rootDir, repo);
if (!fs.existsSync(dir)) return;
const files = [];
function walk(d) {
fs.readdirSync(d, { withFileTypes: true }).forEach(entry => {
const full = path.join(d, entry.name);
const rel = path.relative(rootDir, full).split(path.sep).join("/");
if (entry.name === ".git" || entry.name === "node_modules" || entry.name === "__pycache__") return;
if (entry.isDirectory()) walk(full);
else if (entry.isFile()) {
const buf = fs.readFileSync(full);
checkFloor(buf, rel);
files.push({path: rel, sha256: sha256(buf)});
}
});
}
walk(dir);
hashes[repo] = files.sort((a,b) => a.path.localeCompare(b.path));
});
const payload = JSON.stringify(hashes, null, 0) + "\n";
return {
version: "1.5.0",
sha256: sha256(Buffer.from(payload)),
files: hashes
};
}
const cmd = process.argv[2];
if (cmd === "snapshot") {
fs.writeFileSync(SNAPSHOT, JSON.stringify(getSnapshot(), null, 0) + "\n");
console.log(" Snapshot Generated.");
} else if (cmd === "verify") {
const snap = JSON.parse(fs.readFileSync(SNAPSHOT));
const current = getSnapshot();
if (current.sha256 !== snap.sha256) throw new Error("CRITICAL: State Drift Detected.");
console.log(" VERIFIED: Floor is Stationary.");
} else {
console.log("Usage: node run-vectors.cjs [snapshot|verify]");
process.exit(1);
}