@verax-ai/proxy 0.7.0 → 0.8.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/dist/approvals.d.ts +30 -1
- package/dist/approvals.js +69 -13
- package/dist/data-classes.d.ts +36 -0
- package/dist/data-classes.js +412 -0
- package/dist/explain.js +63 -13
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -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/proxy.js +149 -20
- package/dist/reconcile.d.ts +10 -1
- package/dist/reconcile.js +79 -14
- package/dist/result-classes.d.ts +35 -0
- package/dist/result-classes.js +485 -0
- package/dist/types.d.ts +59 -5
- package/dist/types.js +6 -1
- package/dist/verify-ledger.d.ts +7 -0
- package/dist/verify-ledger.js +127 -2
- package/package.json +3 -2
package/dist/verify-ledger.js
CHANGED
|
@@ -590,7 +590,7 @@ export const DEFAULT_BOUNDARY_ALLOWANCE_MS = 300_000;
|
|
|
590
590
|
* one is `boundary-deferred` and does not change `ok`. An older allow with no
|
|
591
591
|
* row is `decision-without-effect`.
|
|
592
592
|
*/
|
|
593
|
-
function allowsWithoutEffect(attested, rowRefs, allowanceMs) {
|
|
593
|
+
function allowsWithoutEffect(attested, rowRefs, allowanceMs, resultRefs = new Set()) {
|
|
594
594
|
let newest = -Infinity;
|
|
595
595
|
for (const r of attested) {
|
|
596
596
|
if (typeof r.claims.timestampMs === "number" && r.claims.timestampMs > newest)
|
|
@@ -604,6 +604,8 @@ function allowsWithoutEffect(attested, rowRefs, allowanceMs) {
|
|
|
604
604
|
if (r.claims.decision !== "allow" || typeof ref !== "string" || seen.has(ref))
|
|
605
605
|
continue;
|
|
606
606
|
seen.add(ref);
|
|
607
|
+
if (resultRefs.has(ref))
|
|
608
|
+
continue;
|
|
607
609
|
if (rowRefs.has(ref))
|
|
608
610
|
continue;
|
|
609
611
|
const t = r.claims.timestampMs;
|
|
@@ -614,6 +616,91 @@ function allowsWithoutEffect(attested, rowRefs, allowanceMs) {
|
|
|
614
616
|
}
|
|
615
617
|
return { findings, deferred };
|
|
616
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
|
+
}
|
|
617
704
|
function tailStatement(dir, records, checkpointPublicKeyPem, attested = records) {
|
|
618
705
|
const checkpointFile = checkpointsPath(dir);
|
|
619
706
|
const checkpointLink = symbolicLinkProblem(checkpointFile);
|
|
@@ -1305,8 +1392,46 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
|
|
|
1305
1392
|
if (ref !== null)
|
|
1306
1393
|
boundPrimaryRefs.add(ref);
|
|
1307
1394
|
}
|
|
1308
|
-
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()));
|
|
1309
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
|
+
}
|
|
1310
1435
|
const indexed = indexStatement(dir, refler);
|
|
1311
1436
|
const effectCompleteness = noteEffectCompleteness(indexed.effectRefs, boundPrimaryRefs, problems);
|
|
1312
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.1",
|
|
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",
|