@verax-ai/proxy 0.6.1 → 0.8.0
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/dist/approvals.d.ts +30 -1
- package/dist/approvals.js +71 -14
- package/dist/control-sync.js +7 -1
- package/dist/data-classes.d.ts +36 -0
- package/dist/data-classes.js +412 -0
- package/dist/explain.js +128 -16
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/inputs.d.ts +4 -0
- package/dist/inputs.js +41 -0
- package/dist/ledger-manifest.d.ts +2 -0
- package/dist/ledger-manifest.js +1 -0
- package/dist/ledger.d.ts +2 -0
- package/dist/ledger.js +4 -0
- package/dist/policy.d.ts +12 -2
- package/dist/policy.js +208 -7
- package/dist/process-halt.d.ts +9 -0
- package/dist/process-halt.js +68 -0
- package/dist/proxy.js +215 -47
- package/dist/reconcile.d.ts +10 -1
- package/dist/reconcile.js +89 -14
- package/dist/result-classes.d.ts +35 -0
- package/dist/result-classes.js +485 -0
- package/dist/types.d.ts +64 -7
- package/dist/types.js +6 -1
- package/dist/verify-ledger.d.ts +7 -0
- package/dist/verify-ledger.js +180 -17
- package/package.json +3 -2
package/dist/verify-ledger.js
CHANGED
|
@@ -24,11 +24,16 @@
|
|
|
24
24
|
* shared with record/effect/witness signers are refused. Without
|
|
25
25
|
* a third-party pin the row is named unchecked and is not bound.
|
|
26
26
|
* For self/same-org rows, a
|
|
27
|
-
* thrown call relaxes only the hash, and only for the
|
|
28
|
-
* was allowed: some decision on that ref has
|
|
29
|
-
* and this row's class is exactly that
|
|
30
|
-
* plus `:threw`. A
|
|
31
|
-
* not
|
|
27
|
+
* thrown call relaxes only the hash, and only for the
|
|
28
|
+
* tool that was allowed: some decision on that ref has
|
|
29
|
+
* `decision: "allow"` and this row's class is exactly that
|
|
30
|
+
* decision's `effectClass` plus `:threw`. A halted call does
|
|
31
|
+
* not relax the hash: the same allow must have matching `ref`,
|
|
32
|
+
* matching `effectHash`, and this row's class is exactly that
|
|
33
|
+
* allow's `effectClass` plus `:halted`. The allow class is
|
|
34
|
+
* explicit and non-empty; `subject` is not a fallback. A deny,
|
|
35
|
+
* or an allow of a different tool, does not bind. The signature
|
|
36
|
+
* is still required. A
|
|
32
37
|
* `duplicate-effect` row is bound to the decision by ref and to
|
|
33
38
|
* the fixed refusal hash the writer stores, not to the
|
|
34
39
|
* decision's effectHash; the signature is still required.
|
|
@@ -585,7 +590,7 @@ export const DEFAULT_BOUNDARY_ALLOWANCE_MS = 300_000;
|
|
|
585
590
|
* one is `boundary-deferred` and does not change `ok`. An older allow with no
|
|
586
591
|
* row is `decision-without-effect`.
|
|
587
592
|
*/
|
|
588
|
-
function allowsWithoutEffect(attested, rowRefs, allowanceMs) {
|
|
593
|
+
function allowsWithoutEffect(attested, rowRefs, allowanceMs, resultRefs = new Set()) {
|
|
589
594
|
let newest = -Infinity;
|
|
590
595
|
for (const r of attested) {
|
|
591
596
|
if (typeof r.claims.timestampMs === "number" && r.claims.timestampMs > newest)
|
|
@@ -599,6 +604,8 @@ function allowsWithoutEffect(attested, rowRefs, allowanceMs) {
|
|
|
599
604
|
if (r.claims.decision !== "allow" || typeof ref !== "string" || seen.has(ref))
|
|
600
605
|
continue;
|
|
601
606
|
seen.add(ref);
|
|
607
|
+
if (resultRefs.has(ref))
|
|
608
|
+
continue;
|
|
602
609
|
if (rowRefs.has(ref))
|
|
603
610
|
continue;
|
|
604
611
|
const t = r.claims.timestampMs;
|
|
@@ -609,6 +616,91 @@ function allowsWithoutEffect(attested, rowRefs, allowanceMs) {
|
|
|
609
616
|
}
|
|
610
617
|
return { findings, deferred };
|
|
611
618
|
}
|
|
619
|
+
/** The same checks verifyLedger applies to a result record. */
|
|
620
|
+
export function resultRecordIsMismatch(rec, meta, resultHashByRef, effectClassByRef, namedCount) {
|
|
621
|
+
const expected = resultHashByRef.get(meta.resultOf);
|
|
622
|
+
const decision = rec.claims.decision;
|
|
623
|
+
const effectOk = decision === "allow"
|
|
624
|
+
? rec.claims.effectHash === rec.claims.requestHash
|
|
625
|
+
: decision === "deny"
|
|
626
|
+
? rec.claims.effectHash === null
|
|
627
|
+
: false;
|
|
628
|
+
return (expected === undefined ||
|
|
629
|
+
rec.claims.requestHash !== expected ||
|
|
630
|
+
!effectOk ||
|
|
631
|
+
!resultClassesShapeOk(meta.resultClasses) ||
|
|
632
|
+
!subjectMatchesNamedCall(rec.claims.subject, effectClassByRef.get(meta.resultOf)) ||
|
|
633
|
+
namedCount > 1);
|
|
634
|
+
}
|
|
635
|
+
/** Decisions whose inputs say they are about a result, not a new allow. */
|
|
636
|
+
function resultRecordMetaByRef(paths, records, problems) {
|
|
637
|
+
const rowsByRef = new Map();
|
|
638
|
+
for (const path of paths) {
|
|
639
|
+
for (const row of readJsonl(path, problems)) {
|
|
640
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
641
|
+
continue;
|
|
642
|
+
const { ref, inputs } = row;
|
|
643
|
+
if (typeof ref !== "string" || inputs === null || typeof inputs !== "object" || Array.isArray(inputs)) {
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
const resultOf = inputs.resultOf;
|
|
647
|
+
if (typeof resultOf !== "string")
|
|
648
|
+
continue;
|
|
649
|
+
let hash;
|
|
650
|
+
try {
|
|
651
|
+
hash = sha256Canonical(inputs);
|
|
652
|
+
}
|
|
653
|
+
catch {
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
const list = rowsByRef.get(ref) ?? [];
|
|
657
|
+
list.push({ hash, resultOf, resultClasses: inputs.resultClasses });
|
|
658
|
+
rowsByRef.set(ref, list);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
const map = new Map();
|
|
662
|
+
for (const rec of records) {
|
|
663
|
+
const ref = rec.claims.ref;
|
|
664
|
+
const expected = rec.claims.inputsHash;
|
|
665
|
+
if (typeof ref !== "string" || typeof expected !== "string")
|
|
666
|
+
continue;
|
|
667
|
+
const rows = rowsByRef.get(ref);
|
|
668
|
+
if (!rows)
|
|
669
|
+
continue;
|
|
670
|
+
const hit = rows.find((row) => row.hash === expected);
|
|
671
|
+
if (!hit)
|
|
672
|
+
continue;
|
|
673
|
+
map.set(ref, { resultOf: hit.resultOf, resultClasses: hit.resultClasses });
|
|
674
|
+
}
|
|
675
|
+
return map;
|
|
676
|
+
}
|
|
677
|
+
function positiveIntMap(raw) {
|
|
678
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw))
|
|
679
|
+
return false;
|
|
680
|
+
for (const n of Object.values(raw)) {
|
|
681
|
+
if (typeof n !== "number" || !Number.isInteger(n) || n <= 0)
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
return true;
|
|
685
|
+
}
|
|
686
|
+
function resultClassesShapeOk(raw) {
|
|
687
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw))
|
|
688
|
+
return false;
|
|
689
|
+
const o = raw;
|
|
690
|
+
if (typeof o.returnedHash !== "string" || !/^[0-9a-f]{64}$/.test(o.returnedHash))
|
|
691
|
+
return false;
|
|
692
|
+
if (!positiveIntMap(o.masked) || !positiveIntMap(o.withheld))
|
|
693
|
+
return false;
|
|
694
|
+
if (typeof o.transcribed !== "number" || !Number.isInteger(o.transcribed) || o.transcribed < 0) {
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
function subjectMatchesNamedCall(subject, effectClass) {
|
|
700
|
+
if (typeof subject !== "string" || effectClass === undefined)
|
|
701
|
+
return false;
|
|
702
|
+
return subject === effectClass || `${subject}:threw` === effectClass;
|
|
703
|
+
}
|
|
612
704
|
function tailStatement(dir, records, checkpointPublicKeyPem, attested = records) {
|
|
613
705
|
const checkpointFile = checkpointsPath(dir);
|
|
614
706
|
const checkpointLink = symbolicLinkProblem(checkpointFile);
|
|
@@ -987,6 +1079,25 @@ function isDecisionRow(row) {
|
|
|
987
1079
|
const claims = row.claims;
|
|
988
1080
|
return claims !== null && typeof claims === "object";
|
|
989
1081
|
}
|
|
1082
|
+
function isThrownEffectClass(effectClass) {
|
|
1083
|
+
return effectClass.endsWith(":threw");
|
|
1084
|
+
}
|
|
1085
|
+
function haltedBindsToSameAllow(ref, effectHash, effectClass, records) {
|
|
1086
|
+
if (ref === null || effectHash === null)
|
|
1087
|
+
return false;
|
|
1088
|
+
for (const r of records) {
|
|
1089
|
+
if (r.claims.ref !== ref || r.claims.decision !== "allow")
|
|
1090
|
+
continue;
|
|
1091
|
+
const cls = r.claims.effectClass;
|
|
1092
|
+
if (typeof cls !== "string" || cls === "")
|
|
1093
|
+
continue;
|
|
1094
|
+
if (r.claims.effectHash !== effectHash)
|
|
1095
|
+
continue;
|
|
1096
|
+
if (effectClass === `${cls}:halted`)
|
|
1097
|
+
return true;
|
|
1098
|
+
}
|
|
1099
|
+
return false;
|
|
1100
|
+
}
|
|
990
1101
|
export async function verifyLedger(dir, opts = {}) {
|
|
991
1102
|
try {
|
|
992
1103
|
return await verifyLedgerUnchecked(dir, opts);
|
|
@@ -1102,12 +1213,15 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
|
|
|
1102
1213
|
// An effect is bound only when a decision with that ref records the same
|
|
1103
1214
|
// effectHash. A `:threw` row relaxes the hash and nothing else: it binds
|
|
1104
1215
|
// only when some decision on that ref is an allow and the row's class is
|
|
1105
|
-
// exactly that decision's effectClass plus `:threw`. A
|
|
1106
|
-
//
|
|
1107
|
-
//
|
|
1108
|
-
//
|
|
1109
|
-
//
|
|
1110
|
-
//
|
|
1216
|
+
// exactly that decision's effectClass plus `:threw`. A `:halted` row keeps
|
|
1217
|
+
// the hash: the same allow must match ref, effectHash, and class plus
|
|
1218
|
+
// `:halted`. A deny did not throw or halt, and an allow of a different tool
|
|
1219
|
+
// is not this class. A
|
|
1220
|
+
// `duplicate-effect` row must carry the writer's fixed refusal hash. The
|
|
1221
|
+
// attestation plus receipt still verify under one effect key. A mismatch is
|
|
1222
|
+
// named and counts as orphaned. A second primary row for a ref that already
|
|
1223
|
+
// has one is named and is not bound, even when the first row itself did not
|
|
1224
|
+
// bind.
|
|
1111
1225
|
const refler = new Set();
|
|
1112
1226
|
const hashesByRef = new Map();
|
|
1113
1227
|
const allowedClassesByRef = new Map();
|
|
@@ -1224,23 +1338,34 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
|
|
|
1224
1338
|
primarySeen.add(ref);
|
|
1225
1339
|
const hashes = ref === null ? undefined : hashesByRef.get(ref);
|
|
1226
1340
|
const hashMatch = effectHash !== null && hashes?.has(effectHash) === true;
|
|
1227
|
-
if (e.witnessClass !== "third-party" && effectClass
|
|
1341
|
+
if (e.witnessClass !== "third-party" && isThrownEffectClass(effectClass)) {
|
|
1228
1342
|
const allowed = ref === null ? undefined : allowedClassesByRef.get(ref);
|
|
1229
|
-
let
|
|
1343
|
+
let threwOk = false;
|
|
1230
1344
|
if (allowed) {
|
|
1231
1345
|
for (const cls of allowed) {
|
|
1232
1346
|
if (`${cls}:threw` === effectClass) {
|
|
1233
|
-
|
|
1347
|
+
threwOk = true;
|
|
1234
1348
|
break;
|
|
1235
1349
|
}
|
|
1236
1350
|
}
|
|
1237
1351
|
}
|
|
1238
|
-
if (!
|
|
1352
|
+
if (!threwOk) {
|
|
1239
1353
|
effectsOrphaned += 1;
|
|
1240
1354
|
problems.push(`thrown effect does not match an allowed decision: ref ${ref ?? "(missing)"}`);
|
|
1241
1355
|
continue;
|
|
1242
1356
|
}
|
|
1243
1357
|
}
|
|
1358
|
+
else if (e.witnessClass !== "third-party" && effectClass.endsWith(":halted")) {
|
|
1359
|
+
if (!haltedBindsToSameAllow(ref, effectHash, effectClass, records)) {
|
|
1360
|
+
effectsOrphaned += 1;
|
|
1361
|
+
const stem = effectClass.slice(0, -":halted".length);
|
|
1362
|
+
const classWouldMatch = ref !== null && (allowedClassesByRef.get(ref)?.has(stem) ?? false);
|
|
1363
|
+
problems.push(classWouldMatch && ref !== null
|
|
1364
|
+
? `effect hash does not match its decision: ref ${ref}`
|
|
1365
|
+
: `halted effect does not match an allowed decision: ref ${ref ?? "(missing)"}`);
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1244
1369
|
else if (!hashMatch) {
|
|
1245
1370
|
effectsOrphaned += 1;
|
|
1246
1371
|
problems.push(ref === null || !refler.has(ref)
|
|
@@ -1267,8 +1392,46 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
|
|
|
1267
1392
|
if (ref !== null)
|
|
1268
1393
|
boundPrimaryRefs.add(ref);
|
|
1269
1394
|
}
|
|
1270
|
-
const
|
|
1395
|
+
const resultMeta = resultRecordMetaByRef(files.inputs, records, problems);
|
|
1396
|
+
const unbound = allowsWithoutEffect(attested, primarySeen, opts.boundaryAllowanceMs ?? DEFAULT_BOUNDARY_ALLOWANCE_MS, new Set(resultMeta.keys()));
|
|
1271
1397
|
problems.push(...unbound.findings.map((ref) => `decision-without-effect ${ref}`));
|
|
1398
|
+
const resultHashByRef = new Map();
|
|
1399
|
+
const effectClassByRef = new Map();
|
|
1400
|
+
for (const e of effectRows) {
|
|
1401
|
+
if (typeof e.row?.ref !== "string")
|
|
1402
|
+
continue;
|
|
1403
|
+
if (e.row.effectClass === "duplicate-effect")
|
|
1404
|
+
continue;
|
|
1405
|
+
if (typeof e.resultHash === "string")
|
|
1406
|
+
resultHashByRef.set(e.row.ref, e.resultHash);
|
|
1407
|
+
if (typeof e.row.effectClass === "string") {
|
|
1408
|
+
effectClassByRef.set(e.row.ref, e.row.effectClass);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
// A result record is a statement about a call, not an allow that needs its
|
|
1412
|
+
// own effect row. Besides resultOf / requestHash, the decision is allow or
|
|
1413
|
+
// deny, an allow repeats that hash as effectHash, a deny carries none,
|
|
1414
|
+
// returnedHash is 64 lowercase hex, counts are integers (masked/withheld
|
|
1415
|
+
// positive, transcribed ≥ 0), subject matches the named call's effectClass
|
|
1416
|
+
// (`:threw` allowed), and at most one result record names a call. Any of
|
|
1417
|
+
// those failing is `result-record-mismatch <ref>`.
|
|
1418
|
+
const namedByCall = new Map();
|
|
1419
|
+
for (const [ref, meta] of resultMeta) {
|
|
1420
|
+
const list = namedByCall.get(meta.resultOf) ?? [];
|
|
1421
|
+
list.push(ref);
|
|
1422
|
+
namedByCall.set(meta.resultOf, list);
|
|
1423
|
+
}
|
|
1424
|
+
for (const rec of attested) {
|
|
1425
|
+
const ref = rec.claims.ref;
|
|
1426
|
+
if (typeof ref !== "string")
|
|
1427
|
+
continue;
|
|
1428
|
+
const meta = resultMeta.get(ref);
|
|
1429
|
+
if (meta === undefined)
|
|
1430
|
+
continue;
|
|
1431
|
+
if (resultRecordIsMismatch(rec, meta, resultHashByRef, effectClassByRef, (namedByCall.get(meta.resultOf) ?? []).length)) {
|
|
1432
|
+
problems.push(`result-record-mismatch ${ref}`);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1272
1435
|
const indexed = indexStatement(dir, refler);
|
|
1273
1436
|
const effectCompleteness = noteEffectCompleteness(indexed.effectRefs, boundPrimaryRefs, problems);
|
|
1274
1437
|
const inputs = inputsStatement(files.inputs, records, problems);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verax-ai/proxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"@cedulon/core": "0.13.1",
|
|
25
25
|
"@cedulon/cose": "0.13.1",
|
|
26
26
|
"@cedulon/effect-extract": "0.13.1",
|
|
27
|
-
"@cedulon/x402-adapter": "0.13.1"
|
|
27
|
+
"@cedulon/x402-adapter": "0.13.1",
|
|
28
|
+
"@conarium-ai/mask": "0.3.5"
|
|
28
29
|
},
|
|
29
30
|
"description": "The decision proxy behind VERAX: policy, signed decision records, and the ledger they live in.",
|
|
30
31
|
"homepage": "https://verax-ai.com",
|