-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgate.mjs
More file actions
34 lines (29 loc) · 954 Bytes
/
gate.mjs
File metadata and controls
34 lines (29 loc) · 954 Bytes
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
// gate.mjs — Riverbraid-Core v1.5.0
import { createHash } from 'crypto';
import { readFileSync } from 'fs';
export const ANCHOR_PATH = new URL('.anchor', import.meta.url);
export const SNAPSHOT_PATH = new URL('constitution.snapshot.json', import.meta.url);
export const verifyLocal = () => {
try {
const ANCHOR = readFileSync(ANCHOR_PATH, 'utf8').trim();
const SNAPSHOT = JSON.parse(readFileSync(SNAPSHOT_PATH, 'utf8'));
const computed = createHash('sha256')
.update(JSON.stringify(SNAPSHOT, null, 2))
.digest('hex')
.slice(0, 6);
return computed === ANCHOR;
} catch (e) { return false; }
};
if (!verifyLocal()) {
console.error("[GATE FAIL] Invariant violation.");
process.exit(1);
}
export const startHeartbeat = () => {
setInterval(() => {
if (!verifyLocal()) {
console.error("[RUNTIME ALERT] Drift Detected.");
process.exit(1);
}
}, 60000);
};
export const GATE_PASSED = true;