-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-binding.js
More file actions
80 lines (62 loc) · 2.4 KB
/
runtime-binding.js
File metadata and controls
80 lines (62 loc) · 2.4 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
72
73
74
75
76
77
78
79
80
// Riverbraid-Harness-Gold/runtime-binding.js
// Bounded runtime coupling surface.
// Claim boundary: local runtime validation only, not external audit or production hardening.
const path = require('path');
const fs = require('fs');
const { execFileSync } = require('child_process');
const verifyPath = path.resolve(__dirname, '../bin/verify-swarm.cjs');
const shieldPath = path.resolve(__dirname, '../riverbraid-shield.js');
const { verifySwarm, getCurrentRoot } = require(verifyPath);
const shield = require(shieldPath);
function verifyGpgSignature(sigPath, anchorPath) {
execFileSync('gpg', ['--verify', sigPath, anchorPath], { stdio: 'ignore' });
}
function enforceCoreValidator(context) {
const root = getCurrentRoot();
const anchorPath = path.join(process.cwd(), '.anchor');
const sigPath = path.join(process.cwd(), '.anchor.asc');
if (!fs.existsSync(anchorPath) || !fs.existsSync(sigPath)) {
console.error(`${context}: Missing GPG-signed .anchor or .anchor.asc`);
process.exit(1);
}
try {
verifyGpgSignature(sigPath, anchorPath);
console.log(`${context}: GPG signature verified`);
} catch {
console.error(`${context}: GPG signature verification failed`);
process.exit(1);
}
const anchoredRoot = fs.readFileSync(anchorPath, 'utf8').trim();
if (anchoredRoot !== root) {
console.error(`${context}: Anchor content mismatch`);
process.exit(1);
}
if (!verifySwarm(root)) {
console.error(`${context}: verifySwarm failed`);
process.exit(1);
}
shield.logAttestation(context, root);
console.log(`Riverbraid Core validator passed for ${context} (root: ${root})`);
}
function bindP5(p5Instance) {
const originalSetup = p5Instance.setup || function () {};
p5Instance.setup = function () {
enforceCoreValidator('p5-setup');
originalSetup.call(this);
};
const originalDraw = p5Instance.draw || function () {};
p5Instance.draw = function () {
enforceCoreValidator('p5-draw');
originalDraw.call(this);
};
console.log('p5.js coupled to Riverbraid-Core runtime validator');
}
function bindHydra(hydraSynth) {
const originalEval = hydraSynth.eval || function () {};
hydraSynth.eval = function (code) {
enforceCoreValidator('hydra-eval');
return originalEval.call(this, code);
};
console.log('Hydra coupled to Riverbraid-Core runtime validator');
}
module.exports = { bindP5, bindHydra, enforceCoreValidator, verifyGpgSignature };