@eyeoverthink/sva-gate 2.0.2 → 2.1.1
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/LICENSE +201 -201
- package/README.md +219 -143
- package/bin/sva-gate.js +172 -172
- package/package.json +2 -2
- package/src/index.d.ts +142 -136
- package/src/index.js +49 -47
- package/src/lib/binder-induction.d.ts +7 -4
- package/src/lib/binder-induction.js +267 -204
- package/src/lib/membrane-core.js +40 -14
- package/src/lib/sentinel.js +103 -88
- package/src/lib/stream-guard.js +87 -25
- package/src/mcp-server.js +273 -268
- package/src/receipt.js +412 -412
- package/test/review-2026-12-04.test.js +84 -0
- package/test/sva-gate.test.js +268 -268
- package/test/trust.test.js +88 -88
- package/test/types.test.js +1 -1
package/bin/sva-gate.js
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// @eyeoverthink/sva-gate CLI — Zero-dependency 3-layer AI verification CLI & stdio MCP server.
|
|
3
|
-
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import {
|
|
6
|
-
mintSvaEr1,
|
|
7
|
-
verifyAnyReceipt,
|
|
8
|
-
evaluateOpeg1,
|
|
9
|
-
evaluateSvaJev1,
|
|
10
|
-
detect,
|
|
11
|
-
SealSession,
|
|
12
|
-
StreamSealGuard,
|
|
13
|
-
scanInjection,
|
|
14
|
-
induce,
|
|
15
|
-
leaveOneOut,
|
|
16
|
-
applySpec,
|
|
17
|
-
novelWording,
|
|
18
|
-
startStdioMcpServer,
|
|
19
|
-
JEV_SEMANTICS,
|
|
20
|
-
} from '../src/index.js';
|
|
21
|
-
|
|
22
|
-
const USAGE = `sva-gate v1.0.0 — Zero-dependency 3-layer AI verification CLI & MCP server
|
|
23
|
-
|
|
24
|
-
Commands:
|
|
25
|
-
sva-gate mcp Start stdio JSON-RPC 2.0 MCP server (6 tools)
|
|
26
|
-
sva-gate seal <text> Seal PII/secrets & scan for prompt injection
|
|
27
|
-
sva-gate stream-demo Demonstrate StreamSealGuard cross-token sealing
|
|
28
|
-
sva-gate mint <json-file | inline-json> Mint SVA-ER/1 receipt + OPEG/1 S4_COMMIT envelope
|
|
29
|
-
sva-gate verify <receipt.json> [deliverable] --key <hex> Verify SVA-ER/1 or
|
|
30
|
-
sva-gate gate <opeg-envelope.json> --key <hex> Evaluate OPEG/1 S4_COMMIT gate fail-closed
|
|
31
|
-
|
|
32
|
-
--key <hex> Ed25519 public key allowed to have signed (repeatable). Without it an intact
|
|
33
|
-
receipt is reported as integrity_only and the exit code is 1.
|
|
34
|
-
--allow-unpinned Accept any signer (1.x behaviour; demos and migration only).
|
|
35
|
-
sva-gate judge <jev-envelope.json> Evaluate SVA-JEV/1 epistemic judge gate
|
|
36
|
-
sva-gate self-test Run built-in 3-layer end-to-end verification check
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
// --key <hex> (repeatable): the Ed25519 key(s) allowed to have signed. --allow-unpinned: accept any signer (1.x behaviour).
|
|
40
|
-
function trustFlags(argv) {
|
|
41
|
-
const args = [], keys = [];
|
|
42
|
-
let allowUnpinned = false;
|
|
43
|
-
for (let i = 0; i < argv.length; i++) {
|
|
44
|
-
if (argv[i] === '--key') keys.push(argv[++i]);
|
|
45
|
-
else if (argv[i] === '--allow-unpinned') allowUnpinned = true;
|
|
46
|
-
else args.push(argv[i]);
|
|
47
|
-
}
|
|
48
|
-
return { args, trust: { expectedPublicKeys: keys.length ? keys : null, allowUnpinned } };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function readJsonArg(arg) {
|
|
52
|
-
if (!arg) throw new Error('Missing JSON argument or file path');
|
|
53
|
-
if (fs.existsSync(arg) && fs.statSync(arg).isFile()) {
|
|
54
|
-
return JSON.parse(fs.readFileSync(arg, 'utf8'));
|
|
55
|
-
}
|
|
56
|
-
return JSON.parse(arg);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const [cmd, ...rest] = process.argv.slice(2);
|
|
60
|
-
|
|
61
|
-
if (!cmd || cmd === '-h' || cmd === '--help') {
|
|
62
|
-
console.log(USAGE);
|
|
63
|
-
process.exit(0);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (cmd === 'mcp') {
|
|
67
|
-
startStdioMcpServer();
|
|
68
|
-
} else if (cmd === 'seal') {
|
|
69
|
-
const text = rest.join(' ');
|
|
70
|
-
const findings = detect(text);
|
|
71
|
-
const session = new SealSession();
|
|
72
|
-
const sealed = session.apply(text, findings);
|
|
73
|
-
console.log(JSON.stringify({ sealed, findingsCount: findings.length, audit: session.audit(sealed), injection: scanInjection(text) }, null, 2));
|
|
74
|
-
} else if (cmd === 'stream-demo') {
|
|
75
|
-
const chunks = ['Key sk-', 'ant-api03-abcdefghijklmnop1234567890 SSN 123-', '45-6789 mail elena@', 'northstar.org ok.'];
|
|
76
|
-
const sg = new StreamSealGuard();
|
|
77
|
-
const sealed = chunks.map((c) => sg.push(c)).join('') + sg.flush();
|
|
78
|
-
console.log(JSON.stringify({ chunks, sealed, audit: sg.session.audit(sealed) }, null, 2));
|
|
79
|
-
} else if (cmd === 'mint') {
|
|
80
|
-
const rSan = readJsonArg(rest[0]);
|
|
81
|
-
const res = mintSvaEr1({ rSan });
|
|
82
|
-
console.log(JSON.stringify(res, null, 2));
|
|
83
|
-
} else if (cmd === 'verify') {
|
|
84
|
-
const { args: pos, trust } = trustFlags(rest);
|
|
85
|
-
const receipt = readJsonArg(pos[0]);
|
|
86
|
-
let deliverable = null;
|
|
87
|
-
if (pos[1]) {
|
|
88
|
-
deliverable = fs.existsSync(pos[1]) ? fs.readFileSync(pos[1], 'utf8') : pos[1];
|
|
89
|
-
}
|
|
90
|
-
const res = verifyAnyReceipt(receipt, { deliverable, ...trust });
|
|
91
|
-
console.log(JSON.stringify(res, null, 2));
|
|
92
|
-
process.exit(res.ok ? 0 : 1);
|
|
93
|
-
} else if (cmd === 'gate') {
|
|
94
|
-
const { args: pos, trust } = trustFlags(rest);
|
|
95
|
-
const env = readJsonArg(pos[0]);
|
|
96
|
-
const res = evaluateOpeg1(env, trust);
|
|
97
|
-
console.log(JSON.stringify(res, null, 2));
|
|
98
|
-
process.exit(res.ok ? 0 : 1);
|
|
99
|
-
} else if (cmd === 'judge') {
|
|
100
|
-
const env = readJsonArg(rest[0]);
|
|
101
|
-
const res = evaluateSvaJev1(env);
|
|
102
|
-
console.log(JSON.stringify(res, null, 2));
|
|
103
|
-
process.exit(res.ok ? 0 : 1);
|
|
104
|
-
} else if (cmd === 'self-test') {
|
|
105
|
-
// 1. Layer 1 + 2: Mint SVA-ER/1 + OPEG/1, verify pass, verify tamper block
|
|
106
|
-
const minted = mintSvaEr1({ agencyName: 'sva-gate-selftest', missionId: 'ms_selftest', rSan: { answer: 42, unit: 'ms' } });
|
|
107
|
-
const pin = { expectedPublicKeys: [minted.publicKeyHex] };
|
|
108
|
-
const rOk = verifyAnyReceipt(minted.receipt, { deliverable: minted.deliverable, ...pin });
|
|
109
|
-
const gOk = evaluateOpeg1(minted.opegEnvelope, pin);
|
|
110
|
-
const badEnv = structuredClone(minted.opegEnvelope);
|
|
111
|
-
badEnv.sanitizer.rSan.answer = 999;
|
|
112
|
-
const gBad = evaluateOpeg1(badEnv, pin);
|
|
113
|
-
|
|
114
|
-
// 2. Layer 2: StreamSealGuard cross-token secret sealing
|
|
115
|
-
const sg = new StreamSealGuard();
|
|
116
|
-
const sOut = ['Token sk-', 'ant-api03-abcdefghijklmnop1234567890 done'].map((c) => sg.push(c)).join('') + sg.flush();
|
|
117
|
-
const sClean = sg.session.audit(sOut).clean && !sOut.includes('sk-ant-api03');
|
|
118
|
-
|
|
119
|
-
// 3. Layer 3: SVA-JEV/1 calibrated judge + planted fake + zero-LLM new_terms block
|
|
120
|
-
const jPass = evaluateSvaJev1({
|
|
121
|
-
spec: 'sva-jev/1', semantics: JEV_SEMANTICS, mode: 'calibration',
|
|
122
|
-
answered: 36, total: 36, right: 33, realFound: 12, realTotal: 12,
|
|
123
|
-
});
|
|
124
|
-
const jBlock = evaluateSvaJev1({
|
|
125
|
-
spec: 'sva-jev/1', semantics: JEV_SEMANTICS, mode: 'claim_trace',
|
|
126
|
-
ledgerTexts: ['[stage 1] Enforce 80% quorum via verify_run.'],
|
|
127
|
-
briefText: 'Enforce 80% quorum with 9999 retries via invented_helper_v2.',
|
|
128
|
-
plantedFakes: [{ id: 'fake-1', verdict: 'unsupported' }],
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// 4. Skill Crystallizer zero-LLM binder check
|
|
132
|
-
const skill = {
|
|
133
|
-
name: 'sequential_discount',
|
|
134
|
-
params: {
|
|
135
|
-
type: 'object',
|
|
136
|
-
properties: {
|
|
137
|
-
price: { type: 'number', description: 'original price' },
|
|
138
|
-
d1: { type: 'number', description: 'first discount as decimal fraction' },
|
|
139
|
-
d2: { type: 'number', description: 'second discount as decimal fraction' },
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
const pos = [
|
|
144
|
-
{ task: 'A $100 jacket is 20% off, then an extra 10% off. What is the final price?', input: { price: 100, d1: 0.2, d2: 0.1 } },
|
|
145
|
-
{ task: 'A $80 pair of shoes is 15% off, then an extra 20% off. What is the final price?', input: { price: 80, d1: 0.15, d2: 0.2 } },
|
|
146
|
-
{ task: 'A $150 backpack is 30% off, then an extra 5% off. What is the final price?', input: { price: 150, d1: 0.3, d2: 0.05 } },
|
|
147
|
-
];
|
|
148
|
-
const neg = [{ task: 'A $200 desk is 20% off, then 8% sales tax is added. What is the final price?' }];
|
|
149
|
-
const { spec } = induce(pos, neg, skill);
|
|
150
|
-
const looRows = leaveOneOut(pos, neg, skill);
|
|
151
|
-
const loo = { passed: looRows.filter((r) => r.ok).length, total: looRows.length, ok: looRows.every((r) => r.ok) };
|
|
152
|
-
const bound = spec ? applySpec(spec, 'A $240 coat is 25% off, then an extra 10% off. What is the final price?') : null;
|
|
153
|
-
const trapNovel = novelWording(pos, 'A $200 shoe is 10% off, then 8% sales tax is added. What is the final price?');
|
|
154
|
-
const trapBlocked = !applySpec(spec, 'A $200 shoe is 10% off, then 8% sales tax is added. What is the final price?') || trapNovel.length > 0;
|
|
155
|
-
|
|
156
|
-
const ok = Boolean(
|
|
157
|
-
rOk.ok && gOk.ok && !gBad.ok && sClean && jPass.ok && !jBlock.ok && loo.ok && bound?.price === 240 && trapBlocked
|
|
158
|
-
);
|
|
159
|
-
console.log(JSON.stringify({
|
|
160
|
-
ok,
|
|
161
|
-
layers: {
|
|
162
|
-
receiptAndOpeg: { verified: rOk.ok, gatePass: gOk.ok, tamperBlocked: !gBad.ok },
|
|
163
|
-
streamPrivacyMembrane: { clean: sClean, sealedPreview: sOut },
|
|
164
|
-
epistemicJudge: { calibrationPass: jPass.ok, inventedTermsBlocked: !jBlock.ok, newTerms: jBlock.newTerms },
|
|
165
|
-
skillCrystallizer: { leaveOneOut: loo, boundPrice: bound?.price ?? null, taxTrapRejected: trapBlocked },
|
|
166
|
-
},
|
|
167
|
-
}, null, 2));
|
|
168
|
-
process.exit(ok ? 0 : 1);
|
|
169
|
-
} else {
|
|
170
|
-
console.error(`Unknown command: ${cmd}\n\n${USAGE}`);
|
|
171
|
-
process.exit(1);
|
|
172
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @eyeoverthink/sva-gate CLI — Zero-dependency 3-layer AI verification CLI & stdio MCP server.
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import {
|
|
6
|
+
mintSvaEr1,
|
|
7
|
+
verifyAnyReceipt,
|
|
8
|
+
evaluateOpeg1,
|
|
9
|
+
evaluateSvaJev1,
|
|
10
|
+
detect,
|
|
11
|
+
SealSession,
|
|
12
|
+
StreamSealGuard,
|
|
13
|
+
scanInjection,
|
|
14
|
+
induce,
|
|
15
|
+
leaveOneOut,
|
|
16
|
+
applySpec,
|
|
17
|
+
novelWording,
|
|
18
|
+
startStdioMcpServer,
|
|
19
|
+
JEV_SEMANTICS,
|
|
20
|
+
} from '../src/index.js';
|
|
21
|
+
|
|
22
|
+
const USAGE = `sva-gate v1.0.0 — Zero-dependency 3-layer AI verification CLI & MCP server
|
|
23
|
+
|
|
24
|
+
Commands:
|
|
25
|
+
sva-gate mcp Start stdio JSON-RPC 2.0 MCP server (6 tools)
|
|
26
|
+
sva-gate seal <text> Seal PII/secrets & scan for prompt injection
|
|
27
|
+
sva-gate stream-demo Demonstrate StreamSealGuard cross-token sealing
|
|
28
|
+
sva-gate mint <json-file | inline-json> Mint SVA-ER/1 receipt + OPEG/1 S4_COMMIT envelope
|
|
29
|
+
sva-gate verify <receipt.json> [deliverable] --key <hex> Verify SVA-ER/1 or AER-1 v0.4 receipt offline
|
|
30
|
+
sva-gate gate <opeg-envelope.json> --key <hex> Evaluate OPEG/1 S4_COMMIT gate fail-closed
|
|
31
|
+
|
|
32
|
+
--key <hex> Ed25519 public key allowed to have signed (repeatable). Without it an intact
|
|
33
|
+
receipt is reported as integrity_only and the exit code is 1.
|
|
34
|
+
--allow-unpinned Accept any signer (1.x behaviour; demos and migration only).
|
|
35
|
+
sva-gate judge <jev-envelope.json> Evaluate SVA-JEV/1 epistemic judge gate
|
|
36
|
+
sva-gate self-test Run built-in 3-layer end-to-end verification check
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
// --key <hex> (repeatable): the Ed25519 key(s) allowed to have signed. --allow-unpinned: accept any signer (1.x behaviour).
|
|
40
|
+
function trustFlags(argv) {
|
|
41
|
+
const args = [], keys = [];
|
|
42
|
+
let allowUnpinned = false;
|
|
43
|
+
for (let i = 0; i < argv.length; i++) {
|
|
44
|
+
if (argv[i] === '--key') keys.push(argv[++i]);
|
|
45
|
+
else if (argv[i] === '--allow-unpinned') allowUnpinned = true;
|
|
46
|
+
else args.push(argv[i]);
|
|
47
|
+
}
|
|
48
|
+
return { args, trust: { expectedPublicKeys: keys.length ? keys : null, allowUnpinned } };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function readJsonArg(arg) {
|
|
52
|
+
if (!arg) throw new Error('Missing JSON argument or file path');
|
|
53
|
+
if (fs.existsSync(arg) && fs.statSync(arg).isFile()) {
|
|
54
|
+
return JSON.parse(fs.readFileSync(arg, 'utf8'));
|
|
55
|
+
}
|
|
56
|
+
return JSON.parse(arg);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
60
|
+
|
|
61
|
+
if (!cmd || cmd === '-h' || cmd === '--help') {
|
|
62
|
+
console.log(USAGE);
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (cmd === 'mcp') {
|
|
67
|
+
startStdioMcpServer();
|
|
68
|
+
} else if (cmd === 'seal') {
|
|
69
|
+
const text = rest.join(' ');
|
|
70
|
+
const findings = detect(text);
|
|
71
|
+
const session = new SealSession();
|
|
72
|
+
const sealed = session.apply(text, findings);
|
|
73
|
+
console.log(JSON.stringify({ sealed, findingsCount: findings.length, audit: session.audit(sealed), injection: scanInjection(text) }, null, 2));
|
|
74
|
+
} else if (cmd === 'stream-demo') {
|
|
75
|
+
const chunks = ['Key sk-', 'ant-api03-abcdefghijklmnop1234567890 SSN 123-', '45-6789 mail elena@', 'northstar.org ok.'];
|
|
76
|
+
const sg = new StreamSealGuard();
|
|
77
|
+
const sealed = chunks.map((c) => sg.push(c)).join('') + sg.flush();
|
|
78
|
+
console.log(JSON.stringify({ chunks, sealed, audit: sg.session.audit(sealed) }, null, 2));
|
|
79
|
+
} else if (cmd === 'mint') {
|
|
80
|
+
const rSan = readJsonArg(rest[0]);
|
|
81
|
+
const res = mintSvaEr1({ rSan });
|
|
82
|
+
console.log(JSON.stringify(res, null, 2));
|
|
83
|
+
} else if (cmd === 'verify') {
|
|
84
|
+
const { args: pos, trust } = trustFlags(rest);
|
|
85
|
+
const receipt = readJsonArg(pos[0]);
|
|
86
|
+
let deliverable = null;
|
|
87
|
+
if (pos[1]) {
|
|
88
|
+
deliverable = fs.existsSync(pos[1]) ? fs.readFileSync(pos[1], 'utf8') : pos[1];
|
|
89
|
+
}
|
|
90
|
+
const res = verifyAnyReceipt(receipt, { deliverable, ...trust });
|
|
91
|
+
console.log(JSON.stringify(res, null, 2));
|
|
92
|
+
process.exit(res.ok ? 0 : 1);
|
|
93
|
+
} else if (cmd === 'gate') {
|
|
94
|
+
const { args: pos, trust } = trustFlags(rest);
|
|
95
|
+
const env = readJsonArg(pos[0]);
|
|
96
|
+
const res = evaluateOpeg1(env, trust);
|
|
97
|
+
console.log(JSON.stringify(res, null, 2));
|
|
98
|
+
process.exit(res.ok ? 0 : 1);
|
|
99
|
+
} else if (cmd === 'judge') {
|
|
100
|
+
const env = readJsonArg(rest[0]);
|
|
101
|
+
const res = evaluateSvaJev1(env);
|
|
102
|
+
console.log(JSON.stringify(res, null, 2));
|
|
103
|
+
process.exit(res.ok ? 0 : 1);
|
|
104
|
+
} else if (cmd === 'self-test') {
|
|
105
|
+
// 1. Layer 1 + 2: Mint SVA-ER/1 + OPEG/1, verify pass, verify tamper block
|
|
106
|
+
const minted = mintSvaEr1({ agencyName: 'sva-gate-selftest', missionId: 'ms_selftest', rSan: { answer: 42, unit: 'ms' } });
|
|
107
|
+
const pin = { expectedPublicKeys: [minted.publicKeyHex] };
|
|
108
|
+
const rOk = verifyAnyReceipt(minted.receipt, { deliverable: minted.deliverable, ...pin });
|
|
109
|
+
const gOk = evaluateOpeg1(minted.opegEnvelope, pin);
|
|
110
|
+
const badEnv = structuredClone(minted.opegEnvelope);
|
|
111
|
+
badEnv.sanitizer.rSan.answer = 999;
|
|
112
|
+
const gBad = evaluateOpeg1(badEnv, pin);
|
|
113
|
+
|
|
114
|
+
// 2. Layer 2: StreamSealGuard cross-token secret sealing
|
|
115
|
+
const sg = new StreamSealGuard();
|
|
116
|
+
const sOut = ['Token sk-', 'ant-api03-abcdefghijklmnop1234567890 done'].map((c) => sg.push(c)).join('') + sg.flush();
|
|
117
|
+
const sClean = sg.session.audit(sOut).clean && !sOut.includes('sk-ant-api03');
|
|
118
|
+
|
|
119
|
+
// 3. Layer 3: SVA-JEV/1 calibrated judge + planted fake + zero-LLM new_terms block
|
|
120
|
+
const jPass = evaluateSvaJev1({
|
|
121
|
+
spec: 'sva-jev/1', semantics: JEV_SEMANTICS, mode: 'calibration',
|
|
122
|
+
answered: 36, total: 36, right: 33, realFound: 12, realTotal: 12,
|
|
123
|
+
});
|
|
124
|
+
const jBlock = evaluateSvaJev1({
|
|
125
|
+
spec: 'sva-jev/1', semantics: JEV_SEMANTICS, mode: 'claim_trace',
|
|
126
|
+
ledgerTexts: ['[stage 1] Enforce 80% quorum via verify_run.'],
|
|
127
|
+
briefText: 'Enforce 80% quorum with 9999 retries via invented_helper_v2.',
|
|
128
|
+
plantedFakes: [{ id: 'fake-1', verdict: 'unsupported' }],
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// 4. Skill Crystallizer zero-LLM binder check
|
|
132
|
+
const skill = {
|
|
133
|
+
name: 'sequential_discount',
|
|
134
|
+
params: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
price: { type: 'number', description: 'original price' },
|
|
138
|
+
d1: { type: 'number', description: 'first discount as decimal fraction' },
|
|
139
|
+
d2: { type: 'number', description: 'second discount as decimal fraction' },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
const pos = [
|
|
144
|
+
{ task: 'A $100 jacket is 20% off, then an extra 10% off. What is the final price?', input: { price: 100, d1: 0.2, d2: 0.1 } },
|
|
145
|
+
{ task: 'A $80 pair of shoes is 15% off, then an extra 20% off. What is the final price?', input: { price: 80, d1: 0.15, d2: 0.2 } },
|
|
146
|
+
{ task: 'A $150 backpack is 30% off, then an extra 5% off. What is the final price?', input: { price: 150, d1: 0.3, d2: 0.05 } },
|
|
147
|
+
];
|
|
148
|
+
const neg = [{ task: 'A $200 desk is 20% off, then 8% sales tax is added. What is the final price?' }];
|
|
149
|
+
const { spec } = induce(pos, neg, skill);
|
|
150
|
+
const looRows = leaveOneOut(pos, neg, skill);
|
|
151
|
+
const loo = { passed: looRows.filter((r) => r.ok).length, total: looRows.length, ok: looRows.every((r) => r.ok) };
|
|
152
|
+
const bound = spec ? applySpec(spec, 'A $240 coat is 25% off, then an extra 10% off. What is the final price?') : null;
|
|
153
|
+
const trapNovel = novelWording(pos, 'A $200 shoe is 10% off, then 8% sales tax is added. What is the final price?');
|
|
154
|
+
const trapBlocked = !applySpec(spec, 'A $200 shoe is 10% off, then 8% sales tax is added. What is the final price?') || trapNovel.length > 0;
|
|
155
|
+
|
|
156
|
+
const ok = Boolean(
|
|
157
|
+
rOk.ok && gOk.ok && !gBad.ok && sClean && jPass.ok && !jBlock.ok && loo.ok && bound?.price === 240 && trapBlocked
|
|
158
|
+
);
|
|
159
|
+
console.log(JSON.stringify({
|
|
160
|
+
ok,
|
|
161
|
+
layers: {
|
|
162
|
+
receiptAndOpeg: { verified: rOk.ok, gatePass: gOk.ok, tamperBlocked: !gBad.ok },
|
|
163
|
+
streamPrivacyMembrane: { clean: sClean, sealedPreview: sOut },
|
|
164
|
+
epistemicJudge: { calibrationPass: jPass.ok, inventedTermsBlocked: !jBlock.ok, newTerms: jBlock.newTerms },
|
|
165
|
+
skillCrystallizer: { leaveOneOut: loo, boundPrice: bound?.price ?? null, taxTrapRejected: trapBlocked },
|
|
166
|
+
},
|
|
167
|
+
}, null, 2));
|
|
168
|
+
process.exit(ok ? 0 : 1);
|
|
169
|
+
} else {
|
|
170
|
+
console.error(`Unknown command: ${cmd}\n\n${USAGE}`);
|
|
171
|
+
process.exit(1);
|
|
172
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eyeoverthink/sva-gate",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Zero-dependency 3-layer verification SDK, CLI, and stdio MCP server for AI agents: SVA-ER/1 &
|
|
5
|
+
"description": "Zero-dependency 3-layer verification SDK, CLI, and stdio MCP server for AI agents: SVA-ER/1 & AER-1 (draft-zambo-aer1) receipts, OPEG/1 execution gates, StreamSealGuard split-token privacy membrane, SVA-JEV/1 rule-based judge checks, and zero-LLM skill crystallization.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "./src/index.js",
|
|
8
8
|
"types": "./src/index.d.ts",
|
package/src/index.d.ts
CHANGED
|
@@ -1,136 +1,142 @@
|
|
|
1
|
-
export function canonical(value: unknown): string;
|
|
2
|
-
export function sha256Hex(data: string | Uint8Array): string;
|
|
3
|
-
export function isValidRfc3339(s: string): boolean;
|
|
4
|
-
|
|
5
|
-
export interface Ed25519Keypair {
|
|
6
|
-
publicKeyHex: string;
|
|
7
|
-
seedHex: string;
|
|
8
|
-
fxId: string;
|
|
9
|
-
privateKey: unknown;
|
|
10
|
-
publicKey: unknown;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function generateEd25519Keypair(): Ed25519Keypair;
|
|
14
|
-
export function keypairFromSeedHex(seedHex: string): Ed25519Keypair;
|
|
15
|
-
|
|
16
|
-
export interface MintOptions {
|
|
17
|
-
agencyName?: string;
|
|
18
|
-
missionId?: string;
|
|
19
|
-
rSan: Record<string, unknown>;
|
|
20
|
-
events?: Array<{ kind?: string; actor?: string; ts?: string; data?: Record<string, unknown> }>;
|
|
21
|
-
clockStatus?: 'attested' | 'drift' | 'unattested';
|
|
22
|
-
issuedAt?: string;
|
|
23
|
-
keypair?: Ed25519Keypair | null;
|
|
24
|
-
seedHex?: string | null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface MintResult {
|
|
28
|
-
receipt: Record<string, unknown>;
|
|
29
|
-
deliverable: string;
|
|
30
|
-
opegEnvelope: Record<string, unknown>;
|
|
31
|
-
publicKeyHex: string;
|
|
32
|
-
fxId: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function mintSvaEr1(opts: MintOptions): MintResult;
|
|
36
|
-
|
|
37
|
-
/** Whose signature counts. Without expectedPublicKeys an intact receipt is 'integrity_only' (ok: false). */
|
|
38
|
-
export interface TrustOptions {
|
|
39
|
-
/** Hex Ed25519 public key(s) allowed to have signed. */
|
|
40
|
-
expectedPublicKeys?: string | string[] | null;
|
|
41
|
-
/** Accept any signer (1.x behaviour). Demos and migration only. */
|
|
42
|
-
allowUnpinned?: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface SvaEr1Outcome {
|
|
46
|
-
ok: boolean;
|
|
47
|
-
outcome: 'verified' | 'verification_failed' | 'rejected_malformed' | 'integrity_only' | 'untrusted_signer';
|
|
48
|
-
deliverable: 'verified' | 'not_checked' | 'verification_failed';
|
|
49
|
-
clock: 'attested' | 'drift' | 'unattested' | 'verification_failed';
|
|
50
|
-
signer?: string;
|
|
51
|
-
trust?: 'pinned' | 'unpinned' | 'rejected';
|
|
52
|
-
merkleEncoding?: 'rfc6962' | 'legacy-hex-text';
|
|
53
|
-
reason?: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** True for the small-order Ed25519 public keys, which verify any message without a private key. */
|
|
57
|
-
export function isSmallOrderKey(publicKeyHex: string): boolean;
|
|
58
|
-
export function evaluateSvaEr1(input: { receipt: Record<string, unknown>; deliverable?: string | Record<string, unknown> | null } & TrustOptions): SvaEr1Outcome;
|
|
59
|
-
export function evaluateAer1V04(receipt: Record<string, unknown>, opts?: { allowUnpinned?: boolean }): {
|
|
60
|
-
ok: boolean;
|
|
61
|
-
outcome: 'verified' | 'verification_failed' | 'integrity_only';
|
|
62
|
-
clockAttestation: 'absent';
|
|
63
|
-
issuerKeyBinding: 'absent';
|
|
64
|
-
trust?: 'unsigned' | 'unpinned';
|
|
65
|
-
reason?: string;
|
|
66
|
-
payload?: Record<string, unknown>;
|
|
67
|
-
};
|
|
68
|
-
export function verifyAnyReceipt(receipt: Record<string, unknown>, opts?: { deliverable?: string | Record<string, unknown> | null } & TrustOptions): Record<string, unknown>;
|
|
69
|
-
export function evaluateOpeg1(doc: Record<string, unknown>, opts?: TrustOptions): {
|
|
70
|
-
ok: boolean;
|
|
71
|
-
gate: 'pass' | 'blocked' | 'integrity_only';
|
|
72
|
-
receiptFormat: string;
|
|
73
|
-
reason?: string;
|
|
74
|
-
receiptOutcome: Record<string, unknown> | null;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const JEV_SEMANTICS: 'stability-signal-not-correctness';
|
|
78
|
-
export const JEV_CHOICES: Set<'decide' | 'noise' | 'settled'>;
|
|
79
|
-
export function wilsonLower95(right: number, total: number, z?: number): number;
|
|
80
|
-
export function flatText(text: string): string;
|
|
81
|
-
export function extractFactualTerms(text: string): Set<string>;
|
|
82
|
-
export function evaluateSvaJev1(doc: Record<string, unknown>): { ok: boolean; mode: string; reason?: string; [k: string]: unknown };
|
|
83
|
-
|
|
84
|
-
export function detect(text: string, opts?: { terms?: string[] }): Array<{ type: string; value: string; start: number; end: number }>;
|
|
85
|
-
export class SealSession {
|
|
86
|
-
readonly size: number;
|
|
87
|
-
placeholder(type: string, value: string): string;
|
|
88
|
-
apply(text: string, findings: unknown[]): string;
|
|
89
|
-
values(): Array<{ type: string; value: string }>;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export const
|
|
99
|
-
export
|
|
100
|
-
export
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export function
|
|
108
|
-
export function
|
|
109
|
-
export function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
export function
|
|
133
|
-
|
|
134
|
-
export
|
|
135
|
-
|
|
136
|
-
|
|
1
|
+
export function canonical(value: unknown): string;
|
|
2
|
+
export function sha256Hex(data: string | Uint8Array): string;
|
|
3
|
+
export function isValidRfc3339(s: string): boolean;
|
|
4
|
+
|
|
5
|
+
export interface Ed25519Keypair {
|
|
6
|
+
publicKeyHex: string;
|
|
7
|
+
seedHex: string;
|
|
8
|
+
fxId: string;
|
|
9
|
+
privateKey: unknown;
|
|
10
|
+
publicKey: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function generateEd25519Keypair(): Ed25519Keypair;
|
|
14
|
+
export function keypairFromSeedHex(seedHex: string): Ed25519Keypair;
|
|
15
|
+
|
|
16
|
+
export interface MintOptions {
|
|
17
|
+
agencyName?: string;
|
|
18
|
+
missionId?: string;
|
|
19
|
+
rSan: Record<string, unknown>;
|
|
20
|
+
events?: Array<{ kind?: string; actor?: string; ts?: string; data?: Record<string, unknown> }>;
|
|
21
|
+
clockStatus?: 'attested' | 'drift' | 'unattested';
|
|
22
|
+
issuedAt?: string;
|
|
23
|
+
keypair?: Ed25519Keypair | null;
|
|
24
|
+
seedHex?: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface MintResult {
|
|
28
|
+
receipt: Record<string, unknown>;
|
|
29
|
+
deliverable: string;
|
|
30
|
+
opegEnvelope: Record<string, unknown>;
|
|
31
|
+
publicKeyHex: string;
|
|
32
|
+
fxId: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function mintSvaEr1(opts: MintOptions): MintResult;
|
|
36
|
+
|
|
37
|
+
/** Whose signature counts. Without expectedPublicKeys an intact receipt is 'integrity_only' (ok: false). */
|
|
38
|
+
export interface TrustOptions {
|
|
39
|
+
/** Hex Ed25519 public key(s) allowed to have signed. */
|
|
40
|
+
expectedPublicKeys?: string | string[] | null;
|
|
41
|
+
/** Accept any signer (1.x behaviour). Demos and migration only. */
|
|
42
|
+
allowUnpinned?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SvaEr1Outcome {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
outcome: 'verified' | 'verification_failed' | 'rejected_malformed' | 'integrity_only' | 'untrusted_signer';
|
|
48
|
+
deliverable: 'verified' | 'not_checked' | 'verification_failed';
|
|
49
|
+
clock: 'attested' | 'drift' | 'unattested' | 'verification_failed';
|
|
50
|
+
signer?: string;
|
|
51
|
+
trust?: 'pinned' | 'unpinned' | 'rejected';
|
|
52
|
+
merkleEncoding?: 'rfc6962' | 'legacy-hex-text';
|
|
53
|
+
reason?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** True for the small-order Ed25519 public keys, which verify any message without a private key. */
|
|
57
|
+
export function isSmallOrderKey(publicKeyHex: string): boolean;
|
|
58
|
+
export function evaluateSvaEr1(input: { receipt: Record<string, unknown>; deliverable?: string | Record<string, unknown> | null } & TrustOptions): SvaEr1Outcome;
|
|
59
|
+
export function evaluateAer1V04(receipt: Record<string, unknown>, opts?: { allowUnpinned?: boolean }): {
|
|
60
|
+
ok: boolean;
|
|
61
|
+
outcome: 'verified' | 'verification_failed' | 'integrity_only';
|
|
62
|
+
clockAttestation: 'absent';
|
|
63
|
+
issuerKeyBinding: 'absent';
|
|
64
|
+
trust?: 'unsigned' | 'unpinned';
|
|
65
|
+
reason?: string;
|
|
66
|
+
payload?: Record<string, unknown>;
|
|
67
|
+
};
|
|
68
|
+
export function verifyAnyReceipt(receipt: Record<string, unknown>, opts?: { deliverable?: string | Record<string, unknown> | null } & TrustOptions): Record<string, unknown>;
|
|
69
|
+
export function evaluateOpeg1(doc: Record<string, unknown>, opts?: TrustOptions): {
|
|
70
|
+
ok: boolean;
|
|
71
|
+
gate: 'pass' | 'blocked' | 'integrity_only';
|
|
72
|
+
receiptFormat: string;
|
|
73
|
+
reason?: string;
|
|
74
|
+
receiptOutcome: Record<string, unknown> | null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const JEV_SEMANTICS: 'stability-signal-not-correctness';
|
|
78
|
+
export const JEV_CHOICES: Set<'decide' | 'noise' | 'settled'>;
|
|
79
|
+
export function wilsonLower95(right: number, total: number, z?: number): number;
|
|
80
|
+
export function flatText(text: string): string;
|
|
81
|
+
export function extractFactualTerms(text: string): Set<string>;
|
|
82
|
+
export function evaluateSvaJev1(doc: Record<string, unknown>): { ok: boolean; mode: string; reason?: string; [k: string]: unknown };
|
|
83
|
+
|
|
84
|
+
export function detect(text: string, opts?: { terms?: string[] }): Array<{ type: string; value: string; start: number; end: number }>;
|
|
85
|
+
export class SealSession {
|
|
86
|
+
readonly size: number;
|
|
87
|
+
placeholder(type: string, value: string): string;
|
|
88
|
+
apply(text: string, findings: unknown[]): string;
|
|
89
|
+
values(): Array<{ type: string; value: string }>;
|
|
90
|
+
/** Lenient by default (also restores [EMAIL_1], <EMAIL_1>, bare EMAIL_1); strict restores only exact ⟦TYPE_n⟧ tokens issued by this session. */
|
|
91
|
+
unseal(text: string, opts?: { json?: boolean; strict?: boolean }): string;
|
|
92
|
+
audit(outbound: string): { clean: boolean; leaks: string[] };
|
|
93
|
+
}
|
|
94
|
+
export class MembraneLeak extends Error {
|
|
95
|
+
leaks: string[];
|
|
96
|
+
constructor(leaks: string[], message?: string | null);
|
|
97
|
+
}
|
|
98
|
+
export const MEMBRANE_NOTE: string;
|
|
99
|
+
export const SECRET_PREFIXES: string[];
|
|
100
|
+
export function tailHoldLength(text: string): number;
|
|
101
|
+
export class StreamSealGuard {
|
|
102
|
+
session: SealSession;
|
|
103
|
+
constructor(opts?: { session?: SealSession | null; mode?: 'seal' | 'redact'; maxBuffer?: number });
|
|
104
|
+
push(chunk: string): string;
|
|
105
|
+
flush(): string;
|
|
106
|
+
}
|
|
107
|
+
export function scanInjection(text: string): { score: number; flags: string[]; suspicious: boolean };
|
|
108
|
+
export function stripHidden(text: string): string;
|
|
109
|
+
export function redactSecrets(text: string): string;
|
|
110
|
+
export function wrapUntrusted(
|
|
111
|
+
source: string,
|
|
112
|
+
content: string,
|
|
113
|
+
evidence?: { sha256: string; bytes: number } | null,
|
|
114
|
+
): { text: string; scan: { score: number; flags: string[]; suspicious: boolean } };
|
|
115
|
+
export function screenGoal(goal: string): {
|
|
116
|
+
ok: boolean;
|
|
117
|
+
reason?: string;
|
|
118
|
+
notes?: string[];
|
|
119
|
+
scan?: { score: number; flags: string[]; suspicious: boolean };
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export function induce(
|
|
123
|
+
pos: Array<{ task: string; input: Record<string, unknown> }>,
|
|
124
|
+
neg: Array<{ task: string }>,
|
|
125
|
+
skill: { params?: { properties?: Record<string, unknown> } },
|
|
126
|
+
): { spec?: Record<string, unknown>; error?: string };
|
|
127
|
+
export function leaveOneOut(
|
|
128
|
+
pos: Array<{ task: string; input: Record<string, unknown> }>,
|
|
129
|
+
neg: Array<{ task: string }>,
|
|
130
|
+
skill: { params?: { properties?: Record<string, unknown> } },
|
|
131
|
+
): Array<{ ok: boolean; [k: string]: unknown }>;
|
|
132
|
+
export function applySpec(spec: Record<string, unknown>, task: string): Record<string, unknown> | null;
|
|
133
|
+
export function novelWording(pos: Array<{ task: string }>, task: string): string[];
|
|
134
|
+
export function explainApply(
|
|
135
|
+
spec: Record<string, unknown>,
|
|
136
|
+
task: string,
|
|
137
|
+
): { input: Record<string, unknown> | null; refused: null | 'shape' | 'block-word' | 'context-block' | 'modifier' | 'ambiguous' | 'missing'; detail: unknown };
|
|
138
|
+
export function modifierWords(task: string): string[];
|
|
139
|
+
|
|
140
|
+
export const MCP_TOOLS: Array<{ name: string; description: string; inputSchema: Record<string, unknown> }>;
|
|
141
|
+
export function createMcpHandler(): (req: Record<string, unknown>) => Record<string, unknown> | null;
|
|
142
|
+
export function startStdioMcpServer(): void;
|