@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/README.md
CHANGED
|
@@ -1,143 +1,219 @@
|
|
|
1
|
-
# `@eyeoverthink/sva-gate` (`
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
##
|
|
142
|
-
|
|
143
|
-
|
|
1
|
+
# `@eyeoverthink/sva-gate` (`v2.1.1`)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/eyeoverthink/sva-gate/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@eyeoverthink/sva-gate)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
**Redact streaming API keys & PII, block prompt injections, and sign/verify AI agent tool calls with pinned Ed25519 receipts — in 0 dependencies.**
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @eyeoverthink/sva-gate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 30-Second Quickstart: Catch Split-Token Secrets & Sign Agent Outputs
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { StreamSealGuard, mintSvaEr1, evaluateSvaEr1 } from '@eyeoverthink/sva-gate';
|
|
17
|
+
|
|
18
|
+
// 1. Catch secrets even when an LLM stream splits them across chunks ("sk-ant-" + "api03-...")
|
|
19
|
+
const guard = new StreamSealGuard();
|
|
20
|
+
const safeOut =
|
|
21
|
+
guard.push('Send token sk-ant-') +
|
|
22
|
+
guard.push('api03-secretkey1234567890abcdef to alice@example.com') +
|
|
23
|
+
guard.flush();
|
|
24
|
+
// -> "Send token ⟦SECRET_1⟧ to ⟦EMAIL_1⟧" (0 raw secrets leaked)
|
|
25
|
+
const restored = guard.session.unseal(safeOut, { strict: true });
|
|
26
|
+
|
|
27
|
+
// 2. Sign & verify an agent deliverable against a caller-pinned Ed25519 public key
|
|
28
|
+
const { receipt, deliverable, publicKeyHex } = mintSvaEr1({ rSan: { answer: 42 } });
|
|
29
|
+
const verdict = evaluateSvaEr1({ receipt, deliverable, expectedPublicKeys: [publicKeyHex] });
|
|
30
|
+
// -> { ok: true, outcome: 'verified', deliverable: 'verified', trust: 'pinned' }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Drop-In Framework Recipes
|
|
34
|
+
|
|
35
|
+
#### Streaming LLM Wrapper (OpenAI / Anthropic / Vercel AI SDK)
|
|
36
|
+
```js
|
|
37
|
+
import { StreamSealGuard } from '@eyeoverthink/sva-gate/membrane';
|
|
38
|
+
|
|
39
|
+
export async function* guardTextStream(textChunks) {
|
|
40
|
+
const guard = new StreamSealGuard();
|
|
41
|
+
for await (const chunk of textChunks) {
|
|
42
|
+
const out = guard.push(chunk);
|
|
43
|
+
if (out) yield out;
|
|
44
|
+
}
|
|
45
|
+
const tail = guard.flush();
|
|
46
|
+
if (tail) yield tail;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### HTTP / Express / Hono Receipt-Verification Middleware
|
|
51
|
+
```js
|
|
52
|
+
import { evaluateSvaEr1 } from '@eyeoverthink/sva-gate/receipt';
|
|
53
|
+
|
|
54
|
+
export function requirePinnedReceipt(trustedKeys) {
|
|
55
|
+
return (req, res, next) => {
|
|
56
|
+
const out = evaluateSvaEr1({
|
|
57
|
+
receipt: req.body?.receipt,
|
|
58
|
+
deliverable: req.body?.deliverable,
|
|
59
|
+
expectedPublicKeys: trustedKeys,
|
|
60
|
+
});
|
|
61
|
+
if (!out.ok) return res.status(403).json({ error: out.outcome, reason: out.reason });
|
|
62
|
+
req.verifiedReceipt = out;
|
|
63
|
+
next();
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
> **2.1.0 — privacy membrane and skill crystallizer fixes** (synced with `@eyeoverthink/privacy-membrane` 1.4.0 and
|
|
71
|
+
> `@eyeoverthink/skill-crystallizer` 1.3.0). `StreamSealGuard` no longer leaks a JWT, PEM key, email, password or
|
|
72
|
+
> titled name whose fragment arrives as its own chunk; `SealSession.unseal(text, { strict: true })` restores only the
|
|
73
|
+
> exact `⟦TYPE_n⟧` placeholders the session issued; detection is linear on adversarial input. The skill binder now
|
|
74
|
+
> refuses quantity and negation words its examples never used ("Two $240 coats…", "…is not 25% off…") and tasks on
|
|
75
|
+
> which two rules that both fit the examples disagree; `explainApply` says why. MCP `serverInfo.version` now reports
|
|
76
|
+
> the package version.
|
|
77
|
+
|
|
78
|
+
> **2.0.0 — breaking: verification now asks whose signature counts.** A receipt is `ok` only when it is intact
|
|
79
|
+
> **and** signed by a key you name in `expectedPublicKeys` (CLI: `--key <hex>`). Without it an intact receipt is
|
|
80
|
+
> `outcome: 'integrity_only'`, because anyone can mint an intact receipt with their own key. Small-order Ed25519
|
|
81
|
+
> keys (which verify any message with no private key) are refused. AER-1 v0.4 receipts carry no issuer signature and
|
|
82
|
+
> are reported as `integrity_only`; their deliverable is now checked against the outputs. The Merkle tree is now real
|
|
83
|
+
> RFC 6962 (raw digest bytes); receipts minted by 1.x still verify and report `merkleEncoding: 'legacy-hex-text'`.
|
|
84
|
+
> `allowUnpinned: true` (CLI `--allow-unpinned`) restores the 1.x behaviour for demos and migration.
|
|
85
|
+
|
|
86
|
+
Unifies the proven standards from [`eyeoverthink/sva-standard`](https://github.com/eyeoverthink/sva-standard) (`v1.7.0`, 106/106 tri-runtime conformance) and [`eyeoverthink/logic-chain-judge`](https://github.com/eyeoverthink/logic-chain-judge) (`v1.0.0`, 321 tests) into **one installable package** with **zero external runtime dependencies** (Node 22+ ESM with TypeScript `.d.ts` definitions + pure Python 3.10+ stdlib companion in `python/`).
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## 1. Drop Into Claude Code / Cursor / Codex / Any MCP Client (4 Lines)
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"mcpServers": {
|
|
95
|
+
"sva-gate": {
|
|
96
|
+
"command": "npx",
|
|
97
|
+
"args": ["-y", "@eyeoverthink/sva-gate", "mcp"]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Gives any agent **6 deterministic verification tools** over stdio JSON-RPC 2.0:
|
|
104
|
+
|
|
105
|
+
| MCP Tool | Layer | What It Enforces |
|
|
106
|
+
| --- | --- | --- |
|
|
107
|
+
| `sva_seal_text` | Layer 2 (`EMA/1`) | Seals PII/secrets (emails, SSNs, API keys, phones) into typed placeholders + `StreamSealGuard` cross-token split-secret sealing + keyword/zero-width prompt-injection scan |
|
|
108
|
+
| `sva_mint_receipt` | Layer 1 (`SVA-ER/1`) | Mints an Ed25519-signed, RFC 6962 `0x00`/`0x01` Merkle-proven receipt + matching `OPEG/1` `S4_COMMIT` envelope |
|
|
109
|
+
| `sva_verify_receipt` | Layer 1 (`SVA-ER/1` + `AER-1`) | Verifies **`SVA-ER/1`** receipts against a key you pin, and checks **`AER-1` v0.4** receipts (an individual Internet-Draft, `draft-zambo-aer1-26`, not an IETF standard) offline. AER-1 receipts carry no issuer signature, so they are reported as `integrity_only` |
|
|
110
|
+
| `sva_opeg_check` | Layer 2 (`OPEG/1`) | Fail-closed pre-commit gate: blocks `DIRECT_INFERENCE`, tampered `R_san` digests, and invalid receipts (`sva-er/1` or `aer-1`) |
|
|
111
|
+
| `sva_judge_audit` | Layer 3 (`SVA-JEV/1`) | Rule checks over judge results you supply (no model call): Wilson 95% CI > 2/3 on your counts, author self-vote exclusion, mandatory verbatim `>= 12`-char quotes, hidden planted-fake traps, and zero-LLM `new_terms` invention scanner |
|
|
112
|
+
| `sva_crystallize_skill` | Layer 1 (`VSC/1`) | Zero-LLM deterministic parameter binder induction with leave-one-out verification; refuses novel wording, unseen quantity/negation words and ambiguous rules (`testResult.refused` says why) |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 2. CLI Quick Start (10-Second Offline Self-Test)
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Run built-in 3-layer verification (receipts + OPEG tamper block + StreamSealGuard + SVA-JEV/1 + skill crystallizer)
|
|
120
|
+
npx @eyeoverthink/sva-gate self-test
|
|
121
|
+
|
|
122
|
+
# Seal secrets & scan for prompt injection
|
|
123
|
+
npx @eyeoverthink/sva-gate seal "Patient SSN 123-45-6789 key sk-ant-api03-abcdefghijklmnop1234567890"
|
|
124
|
+
|
|
125
|
+
# Demo cross-token split-secret streaming redaction
|
|
126
|
+
npx @eyeoverthink/sva-gate stream-demo
|
|
127
|
+
|
|
128
|
+
# Mint a signed SVA-ER/1 receipt + OPEG/1 envelope
|
|
129
|
+
npx @eyeoverthink/sva-gate mint '{"answer":42,"unit":"ms"}'
|
|
130
|
+
|
|
131
|
+
# Verify an SVA-ER/1 OR IETF AER-1 v0.4 receipt offline
|
|
132
|
+
npx @eyeoverthink/sva-gate verify receipt.json [deliverable.json]
|
|
133
|
+
|
|
134
|
+
# Evaluate an OPEG/1 gate or SVA-JEV/1 judge envelope fail-closed
|
|
135
|
+
npx @eyeoverthink/sva-gate gate opeg-envelope.json
|
|
136
|
+
npx @eyeoverthink/sva-gate judge jev-envelope.json
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 3. JS / TypeScript SDK (`0` Dependencies)
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
import {
|
|
145
|
+
mintSvaEr1,
|
|
146
|
+
verifyAnyReceipt,
|
|
147
|
+
evaluateOpeg1,
|
|
148
|
+
evaluateSvaJev1,
|
|
149
|
+
StreamSealGuard,
|
|
150
|
+
JEV_SEMANTICS,
|
|
151
|
+
} from '@eyeoverthink/sva-gate';
|
|
152
|
+
|
|
153
|
+
// 1. Mint & verify an SVA-ER/1 receipt + OPEG/1 S4_COMMIT envelope
|
|
154
|
+
const { receipt, deliverable, opegEnvelope, publicKeyHex } = mintSvaEr1({ rSan: { ok: true, value: 42 } });
|
|
155
|
+
// Name the key you trust. The verifier never trusts the key inside the receipt by itself.
|
|
156
|
+
const trust = { expectedPublicKeys: [publicKeyHex] };
|
|
157
|
+
console.log(verifyAnyReceipt(receipt, { deliverable, ...trust })); // { format: 'sva-er/1', ok: true, outcome: 'verified', trust: 'pinned', ... }
|
|
158
|
+
console.log(evaluateOpeg1(opegEnvelope, trust)); // { ok: true, gate: 'pass', ... }
|
|
159
|
+
console.log(verifyAnyReceipt(receipt, { deliverable })); // { ok: false, outcome: 'integrity_only', ... } — intact, signer not trusted
|
|
160
|
+
|
|
161
|
+
// 2. Seal split-token API keys across streaming chunks
|
|
162
|
+
const sg = new StreamSealGuard();
|
|
163
|
+
const safe = ['Key sk-', 'ant-api03-abcdefghijklmnop1234567890 ok'].map((c) => sg.push(c)).join('') + sg.flush();
|
|
164
|
+
// -> 'Key ⟦SECRET_1⟧ ok'. Put values back only in text a person you trust will read; strict ignores bare EMAIL_1 etc.
|
|
165
|
+
const restored = sg.session.unseal(modelReply, { strict: true });
|
|
166
|
+
|
|
167
|
+
// 3. Enforce SVA-JEV/1 epistemic judge gates
|
|
168
|
+
const verdict = evaluateSvaJev1({
|
|
169
|
+
spec: 'sva-jev/1',
|
|
170
|
+
semantics: JEV_SEMANTICS,
|
|
171
|
+
mode: 'claim_trace',
|
|
172
|
+
ledgerTexts: ['[stage 1] Enforce 80% quorum via verify_run.'],
|
|
173
|
+
briefText: 'Enforce 80% quorum with 9999 retries via invented_helper_v2.',
|
|
174
|
+
plantedFakes: [{ id: 'fake-1', verdict: 'unsupported' }],
|
|
175
|
+
});
|
|
176
|
+
// -> { ok: false, newTerms: ['9999', 'invented_helper_v2'], ... }
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 4. Pure Python 3.10+ Companion (`python/`)
|
|
182
|
+
|
|
183
|
+
Zero `pip` dependencies (standard library only):
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
pip install ./python
|
|
187
|
+
python -m unittest discover -s python/tests -v
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from sva_gate import JEV_SEMANTICS, evaluate_sva_jev1
|
|
192
|
+
res = evaluate_sva_jev1({
|
|
193
|
+
"spec": "sva-jev/1",
|
|
194
|
+
"semantics": JEV_SEMANTICS,
|
|
195
|
+
"mode": "calibration",
|
|
196
|
+
"answered": 36, "total": 36, "right": 33, "realFound": 12, "realTotal": 12,
|
|
197
|
+
})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Honest Limits
|
|
203
|
+
|
|
204
|
+
- **The privacy membrane is regex-based.** It misses IPv6 addresses, SSNs written without dashes and names without a title. Default (lenient) `unseal` also restores `[EMAIL_1]`, `<EMAIL_1>` and the bare word `EMAIL_1`, so any text that names a placeholder receives the real value; use `{ strict: true }` for text shown to others. The streaming guard emits each word when the next whitespace arrives, and only holds what a detector could recognise.
|
|
205
|
+
- **The skill binder gates a fixed list of quantity and negation words before numbers**, not every meaning-changing phrase; treat a routed answer as a draft for templated tasks only.
|
|
206
|
+
- **The prompt-injection scan is a keyword list.** Paraphrases, other languages and homoglyphs score 0.
|
|
207
|
+
|
|
208
|
+
- **Signatures prove post-signing integrity and key possession**, not that a compromised host didn't fabricate data prior to signing. Local unsynced clocks are explicitly labeled `unattested`.
|
|
209
|
+
- **`SVA-JEV/1` verdicts are stamped `stability-signal-not-correctness`** — multi-model consensus is never proof of truth.
|
|
210
|
+
- **Deterministic `new_terms` catches invented numbers and code identifiers**, not subtle semantic paraphrasing.
|
|
211
|
+
|
|
212
|
+
## Related Repositories & Live Offline Playgrounds
|
|
213
|
+
|
|
214
|
+
- **Open Standards & 5 Zero-Backend Browser Labs:** https://eyeoverthink.github.io/sva-standard/ (`eyeoverthink/sva-standard`)
|
|
215
|
+
- **Calibrated Epistemic Judge Pipeline:** https://github.com/eyeoverthink/logic-chain-judge
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|