@verax-ai/proxy 0.4.2 → 0.4.4

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.
@@ -15,6 +15,12 @@ export type VerifyResult = {
15
15
  chainBreakAt: number | null;
16
16
  effectsBound: number;
17
17
  effectsOrphaned: number;
18
+ /**
19
+ * Refs of attested allows with no effect row that sit within the boundary
20
+ * allowance of the newest record: `boundary-deferred`, a warning. An older
21
+ * allow with no row is the problem `decision-without-effect <ref>`.
22
+ */
23
+ effectsDeferred: string[];
18
24
  trust: VerifyTrust;
19
25
  /** Which key answered for `self` effect rows. Same honesty rules as `trust`. */
20
26
  effectTrust: VerifyTrust;
@@ -34,8 +40,27 @@ export type VerifyResult = {
34
40
  tail: VerifyTail;
35
41
  /** Halt windows. A ledger with none says so; that sentence is not a violation. */
36
42
  control: VerifyControl;
43
+ /** Inputs rows checked against each record's signed `inputsHash`. */
44
+ inputs: VerifyInputs;
45
+ /** Transparency Service receipts for checkpoints, when the ledger holds any. */
46
+ anchors: VerifyAnchors;
37
47
  problems: string[];
38
48
  };
49
+ export type VerifyAnchors = {
50
+ line: string;
51
+ /** Receipts in `checkpoint-anchors.jsonl`. */
52
+ receipts: number;
53
+ /** Receipts that verified under the reader's key. Zero when no key was given. */
54
+ verified: number;
55
+ checked: boolean;
56
+ };
57
+ export type VerifyInputs = {
58
+ line: string;
59
+ /** Records whose inputs row was found and hashes to their `inputsHash`. */
60
+ matched: number;
61
+ missing: number;
62
+ mismatched: number;
63
+ };
39
64
  export type VerifyIndex = {
40
65
  present: boolean;
41
66
  /** Index refs that are not decisions in the ledger. */
@@ -63,9 +88,17 @@ export type VerifyOptions = {
63
88
  publicKeyPem?: string;
64
89
  /** Verify `self` effect rows against this key instead of the one those rows carry. */
65
90
  effectPublicKeyPem?: string;
91
+ /** Out-of-band pins only. Third-party resultHash is never attested by the extract. */
92
+ thirdPartyPublicKeyPems?: string[];
66
93
  /** Verify `same-org` effect rows against this key instead of the one those rows carry. */
67
94
  witnessPublicKeyPem?: string;
68
95
  /** Verify every checkpoint row against this key instead of one key taken from the file. */
69
96
  checkpointPublicKeyPem?: string;
97
+ /** The Transparency Service key that receipts in `checkpoint-anchors.jsonl` are checked under. */
98
+ anchorPublicKeyPem?: string;
99
+ /** How close to the newest record an allow with no effect row is deferred rather than named. */
100
+ boundaryAllowanceMs?: number;
70
101
  };
102
+ /** The core's default clock-skew allowance, which decision profile 6.1 applies unchanged. */
103
+ export declare const DEFAULT_BOUNDARY_ALLOWANCE_MS = 300000;
71
104
  export declare function verifyLedger(dir: string, opts?: VerifyOptions): Promise<VerifyResult>;
@@ -17,6 +17,13 @@
17
17
  * `{ ref, effectHash, witnessClass, resultHash }`, compared after
18
18
  * decode, and the receipt's effect (`body.effects[0]`, every
19
19
  * field the writer put there) must be that same row. A
20
+ * `third-party` row instead needs a one-row receipt verified
21
+ * under `thirdPartyPublicKeyPems` supplied by the reader, equal
22
+ * to the stored row and bound by ref and effectHash. No body
23
+ * attestation is required; its resultHash is unattested. Keys
24
+ * shared with record/effect/witness signers are refused. Without
25
+ * a third-party pin the row is named unchecked and is not bound.
26
+ * For self/same-org rows, a
20
27
  * thrown call relaxes only the hash, and only for the tool that
21
28
  * was allowed: some decision on that ref has `decision: "allow"`
22
29
  * and this row's class is exactly that decision's `effectClass`
@@ -51,6 +58,31 @@
51
58
  * that verified. A key taken from the file shows the checkpoints agree
52
59
  * with each other, not that the key was ever trusted.
53
60
  *
61
+ * Inputs are a further statement. The writer appends a call's inputs row
62
+ * before the record whose `inputsHash` commits to it, so a crash leaves at
63
+ * most an inputs row with no record, never the reverse. Each record that
64
+ * carries an `inputsHash` must find an inputs row under its ref whose
65
+ * canonical SHA-256 is that hash. A missing row is `inputs row missing`, a
66
+ * row under that ref with another hash is `inputs row does not match`, and
67
+ * either makes `ok` false: the approver block of an approval lives in that
68
+ * row, and an unbound row could be rewritten from a signed approval into an
69
+ * unsigned one. A row with no record is the crash case and is not named.
70
+ *
71
+ * Checkpoint counts are checked too. For every checkpoint that verified, its
72
+ * head must be a record the ledger holds, the verified records in its window
73
+ * up to that head must be its `receiptCount` ending at the head, and their
74
+ * allow, deny and defer counts must be its totals; a record appended later
75
+ * with a time in the window is not counted. Null totals (redacted) are not
76
+ * compared; the count still is.
77
+ *
78
+ * Anchors are the last statement. `checkpoint-anchors.jsonl` holds COSE
79
+ * Receipts from a Transparency Service for checkpoints `verax anchor`
80
+ * registered. A receipt names no key, so it is checked only under a key the
81
+ * reader supplies (`anchorPublicKeyPem`): each row must name a checkpoint that
82
+ * verified, its leaf entry must be the one the route defines, and the receipt
83
+ * must verify over the root its inclusion proof rebuilds. Without that key the
84
+ * receipts are counted and said to be unchecked; that is not a failure.
85
+ *
54
86
  * Control records are a further statement. An allow whose subject is
55
87
  * `verax.halt` opens a halt window; an allow whose subject is `verax.resume`
56
88
  * closes it. An allow whose subject does not start with `verax.` while a
@@ -68,14 +100,17 @@
68
100
  * copy they hold themselves.
69
101
  */
70
102
  import { createPublicKey } from "node:crypto";
103
+ import { samePublicKey, thirdPartyReceiptCoversRow } from "./third-party.js";
71
104
  import { existsSync, lstatSync, readFileSync } from "node:fs";
72
105
  import { join } from "node:path";
73
- import { findCheckpointChainBreak, verifyCheckpoint, verifyCheckpointUnderPin, } from "@cedulon/checkpoint";
106
+ import { checkpointHash, findCheckpointChainBreak, totalsFromDecisionRecords, verifyCheckpoint, verifyCheckpointUnderPin, } from "@cedulon/checkpoint";
74
107
  import { canonical, decisionRecordHash, findDecisionRecordChainBreak, verifyDecisionRecord } from "@cedulon/core";
75
108
  import { coseFromHex, decodeCoseSign1, verifyCoseSign1 } from "@cedulon/cose";
76
109
  import { verifyEffectExtract } from "@cedulon/effect-extract";
110
+ import { anchorEntryHash, readAnchors } from "./anchors.js";
77
111
  import { checkpointsPath, readCheckpointFile } from "./checkpoints.js";
78
112
  import { sha256Canonical } from "./hash.js";
113
+ import { verifyReceipt } from "./transparency-receipt.js";
79
114
  import { ledgerPiecePathProblem, readLedgerManifest, requireLedgerPiecePath, indexPath, manifestPath, parseIndexText, } from "./ledger-manifest.js";
80
115
  /**
81
116
  * A symbolic link is a named problem and is not read. Missing files are not
@@ -120,13 +155,17 @@ function takePieceFile(dir, rel, problems, read) {
120
155
  }
121
156
  return path;
122
157
  }
123
- /** Decision and effect files this directory holds, oldest piece first. Inputs are confined and not read. */
158
+ /**
159
+ * Decision, effect and inputs files this directory holds, oldest piece first.
160
+ * An inputs file the disk lacks is not named here: a record that needed a row
161
+ * from it is named when inputs are checked.
162
+ */
124
163
  function ledgerFiles(dir, problems) {
125
164
  const manifestFile = manifestPath(dir);
126
165
  const manifestLink = symbolicLinkProblem(manifestFile);
127
166
  if (manifestLink !== null) {
128
167
  problems.push(manifestLink);
129
- return { decisions: [], effects: [] };
168
+ return { decisions: [], effects: [], inputs: [] };
130
169
  }
131
170
  if (existsSync(manifestFile)) {
132
171
  try {
@@ -137,7 +176,7 @@ function ledgerFiles(dir, problems) {
137
176
  }
138
177
  catch (err) {
139
178
  problems.push(err instanceof Error ? err.message : "ledger-manifest-unreadable");
140
- return { decisions: [], effects: [] };
179
+ return { decisions: [], effects: [], inputs: [] };
141
180
  }
142
181
  }
143
182
  return legacyFiles(dir);
@@ -145,14 +184,17 @@ function ledgerFiles(dir, problems) {
145
184
  function legacyFiles(dir) {
146
185
  const decisionsPath = join(dir, "decisions.jsonl");
147
186
  const effectsPath = join(dir, "effects.jsonl");
187
+ const inputsPath = join(dir, "inputs.jsonl");
148
188
  return {
149
189
  decisions: existsSync(decisionsPath) ? [decisionsPath] : [],
150
190
  effects: existsSync(effectsPath) ? [effectsPath] : [],
191
+ inputs: existsSync(inputsPath) ? [inputsPath] : [],
151
192
  };
152
193
  }
153
194
  function pieceFiles(dir, pieces, problems) {
154
195
  const decisions = [];
155
196
  const effects = [];
197
+ const inputs = [];
156
198
  for (const p of pieces) {
157
199
  const decision = takePieceFile(dir, p.decisions, problems, true);
158
200
  if (decision)
@@ -160,9 +202,15 @@ function pieceFiles(dir, pieces, problems) {
160
202
  const effect = takePieceFile(dir, p.effects, problems, true);
161
203
  if (effect)
162
204
  effects.push(effect);
205
+ const before = problems.length;
163
206
  takePieceFile(dir, p.inputs, problems, false);
207
+ if (problems.length === before) {
208
+ const path = requireLedgerPiecePath(dir, p.inputs);
209
+ if (existsSync(path))
210
+ inputs.push(path);
211
+ }
164
212
  }
165
- return { decisions, effects };
213
+ return { decisions, effects, inputs };
166
214
  }
167
215
  /** Parses JSONL, reporting the line a bad row sits on rather than throwing. */
168
216
  function readJsonl(path, problems) {
@@ -304,7 +352,7 @@ function effectProblem(effect, ref) {
304
352
  }
305
353
  function firstReceiptKey(rows, sameOrg) {
306
354
  for (const row of rows) {
307
- if ((row.witnessClass === "same-org") !== sameOrg)
355
+ if (row.witnessClass !== (sameOrg ? "same-org" : "self"))
308
356
  continue;
309
357
  const pem = row.receipt?.publicKeyPem;
310
358
  if (isPublicKeyPem(pem))
@@ -520,7 +568,43 @@ function noteEffectCompleteness(effectRefs, bound, problems) {
520
568
  }
521
569
  return EFFECT_COMPLETENESS_CHECKED;
522
570
  }
523
- function tailStatement(dir, records, checkpointPublicKeyPem) {
571
+ /** The core's default clock-skew allowance, which decision profile 6.1 applies unchanged. */
572
+ export const DEFAULT_BOUNDARY_ALLOWANCE_MS = 300_000;
573
+ /**
574
+ * Every attested allow expects an effect row under its ref (decision profile
575
+ * 6.1). This reads the signed records and the rows, never `index.jsonl`,
576
+ * which is unsigned. A ref with a primary row, bound or not, is not this
577
+ * finding: a row that fails to bind is already named for what is wrong with
578
+ * it. The writer appends the row after the call returns, so an allow within
579
+ * the allowance of the newest attested record may still be in flight; that
580
+ * one is `boundary-deferred` and does not change `ok`. An older allow with no
581
+ * row is `decision-without-effect`.
582
+ */
583
+ function allowsWithoutEffect(attested, rowRefs, allowanceMs) {
584
+ let newest = -Infinity;
585
+ for (const r of attested) {
586
+ if (typeof r.claims.timestampMs === "number" && r.claims.timestampMs > newest)
587
+ newest = r.claims.timestampMs;
588
+ }
589
+ const findings = [];
590
+ const deferred = [];
591
+ const seen = new Set();
592
+ for (const r of attested) {
593
+ const ref = r.claims.ref;
594
+ if (r.claims.decision !== "allow" || typeof ref !== "string" || seen.has(ref))
595
+ continue;
596
+ seen.add(ref);
597
+ if (rowRefs.has(ref))
598
+ continue;
599
+ const t = r.claims.timestampMs;
600
+ if (typeof t === "number" && newest - t <= allowanceMs)
601
+ deferred.push(ref);
602
+ else
603
+ findings.push(ref);
604
+ }
605
+ return { findings, deferred };
606
+ }
607
+ function tailStatement(dir, records, checkpointPublicKeyPem, attested = records) {
524
608
  const checkpointFile = checkpointsPath(dir);
525
609
  const checkpointLink = symbolicLinkProblem(checkpointFile);
526
610
  if (checkpointLink !== null) {
@@ -529,6 +613,7 @@ function tailStatement(dir, records, checkpointPublicKeyPem) {
529
613
  tail: { line: TAIL_NONE, checkpoint: null },
530
614
  checkpointTrust: checkpointTrustOf(pinned, null, 0),
531
615
  problems: [checkpointLink],
616
+ verified: [],
532
617
  };
533
618
  }
534
619
  const loaded = readCheckpointFile(dir);
@@ -538,10 +623,22 @@ function tailStatement(dir, records, checkpointPublicKeyPem) {
538
623
  const key = pinned !== "" ? pinned : taken;
539
624
  const checkpointTrust = checkpointTrustOf(pinned, taken, rows.length);
540
625
  const problems = [...loaded.problems];
626
+ const verified = [];
541
627
  noteEd25519(key, problems);
542
628
  for (let i = 0; i < rows.length; i += 1) {
543
629
  if (!checkpointRowVerifies(rows[i], key)) {
544
630
  problems.push(`checkpoint signature does not verify: checkpoint ${i}`);
631
+ continue;
632
+ }
633
+ try {
634
+ const count = rows[i].claims.receiptCount;
635
+ verified.push({ hash: checkpointHash(rows[i]), receiptCount: typeof count === "number" ? count : null });
636
+ }
637
+ catch {
638
+ // A row that verified but cannot be hashed cannot be anchored either.
639
+ }
640
+ for (const problem of checkpointCountProblems(rows[i], records, attested)) {
641
+ problems.push(`${problem}: checkpoint ${i}`);
545
642
  }
546
643
  }
547
644
  let brk = null;
@@ -559,7 +656,7 @@ function tailStatement(dir, records, checkpointPublicKeyPem) {
559
656
  const covered = brk ? rows.slice(0, brk.index) : rows;
560
657
  const newest = covered.length > 0 ? covered[covered.length - 1] : null;
561
658
  if (!newest) {
562
- return { tail: { line: TAIL_NONE, checkpoint: null }, checkpointTrust, problems };
659
+ return { tail: { line: TAIL_NONE, checkpoint: null }, checkpointTrust, problems, verified };
563
660
  }
564
661
  const claims = newest.claims;
565
662
  const receiptCount = typeof claims.receiptCount === "number" ? claims.receiptCount : null;
@@ -589,8 +686,185 @@ function tailStatement(dir, records, checkpointPublicKeyPem) {
589
686
  tail: { line, checkpoint: { receiptCount, chainHeadHash, ledgerHoldsRecord } },
590
687
  checkpointTrust,
591
688
  problems,
689
+ verified,
592
690
  };
593
691
  }
692
+ const ANCHORS_NONE = {
693
+ line: "anchors: none (no checkpoint is registered with a transparency service)",
694
+ receipts: 0,
695
+ verified: 0,
696
+ checked: false,
697
+ };
698
+ function anchorStatement(dir, checkpoints, keyPem, problems) {
699
+ const read = readAnchors(dir);
700
+ if (!read.present)
701
+ return ANCHORS_NONE;
702
+ problems.push(...read.problems);
703
+ const receipts = read.rows.length;
704
+ const services = [...new Set(read.rows.map((r) => r.service))].join(", ");
705
+ if (keyPem === "") {
706
+ return {
707
+ line: `anchors: ${receipts} receipt(s) from ${services || "no service"}, not checked: pin the service key with --anchor-key`,
708
+ receipts,
709
+ verified: 0,
710
+ checked: false,
711
+ };
712
+ }
713
+ const byHash = new Map(checkpoints.map((c) => [c.hash, c]));
714
+ let verified = 0;
715
+ let newestCount = null;
716
+ for (const row of read.rows) {
717
+ const short = row.checkpointHash.slice(0, 12);
718
+ const checkpoint = byHash.get(row.checkpointHash);
719
+ if (!checkpoint) {
720
+ problems.push(`anchor names a checkpoint the ledger does not hold: ${short}`);
721
+ continue;
722
+ }
723
+ let entry;
724
+ try {
725
+ entry = anchorEntryHash(row.checkpointHash, row.route);
726
+ }
727
+ catch {
728
+ problems.push(`anchor route is not one this verifier reads: ${short}`);
729
+ continue;
730
+ }
731
+ if (entry !== row.entryHash) {
732
+ problems.push(`anchor entry hash is not the checkpoint's: ${short}`);
733
+ continue;
734
+ }
735
+ const check = verifyReceipt(Buffer.from(row.receiptB64, "base64"), Buffer.from(entry, "hex"), keyPem);
736
+ if (!check.ok) {
737
+ problems.push(`anchor receipt does not verify: ${short} (${check.stage}: ${check.reason})`);
738
+ continue;
739
+ }
740
+ if (check.treeSize !== row.treeSize || check.leafIndex !== row.leafIndex) {
741
+ problems.push(`anchor row disagrees with its receipt: ${short}`);
742
+ continue;
743
+ }
744
+ verified += 1;
745
+ if (checkpoint.receiptCount !== null && (newestCount === null || checkpoint.receiptCount > newestCount)) {
746
+ newestCount = checkpoint.receiptCount;
747
+ }
748
+ }
749
+ const covers = newestCount === null ? "" : `; the newest anchored checkpoint covers ${newestCount} record(s)`;
750
+ return {
751
+ line: verified === receipts
752
+ ? `anchors: ${receipts} receipt(s) from ${services} verify under the key you supplied${covers}`
753
+ : `anchors: ${verified} of ${receipts} receipt(s) verify under the key you supplied`,
754
+ receipts,
755
+ verified,
756
+ checked: true,
757
+ };
758
+ }
759
+ const INPUTS_UNCHECKED = { line: "inputs: not checked", matched: 0, missing: 0, mismatched: 0 };
760
+ /**
761
+ * Pairs each record that carries an `inputsHash` with an inputs row under its
762
+ * ref that hashes to it. Rows are used once. A ref can hold more rows than
763
+ * records (a crash after the row, a retry), so a record is matched against
764
+ * any unused row under its ref, not the k-th.
765
+ */
766
+ function inputsStatement(paths, records, problems) {
767
+ const rowsByRef = new Map();
768
+ for (const path of paths) {
769
+ for (const row of readJsonl(path, problems)) {
770
+ if (!row || typeof row !== "object" || Array.isArray(row))
771
+ continue;
772
+ const { ref, inputs } = row;
773
+ if (typeof ref !== "string" || inputs === undefined)
774
+ continue;
775
+ let hash;
776
+ try {
777
+ hash = sha256Canonical(inputs);
778
+ }
779
+ catch {
780
+ continue;
781
+ }
782
+ const list = rowsByRef.get(ref) ?? [];
783
+ list.push(hash);
784
+ rowsByRef.set(ref, list);
785
+ }
786
+ }
787
+ let matched = 0;
788
+ let missing = 0;
789
+ let mismatched = 0;
790
+ for (let i = 0; i < records.length; i += 1) {
791
+ const claims = records[i].claims;
792
+ const expected = claims?.inputsHash;
793
+ if (typeof expected !== "string")
794
+ continue;
795
+ const ref = typeof claims.ref === "string" ? claims.ref : null;
796
+ const rows = ref === null ? undefined : rowsByRef.get(ref);
797
+ if (!rows || rows.length === 0) {
798
+ missing += 1;
799
+ problems.push(`inputs row missing: record ${i} (ref ${ref ?? "?"})`);
800
+ continue;
801
+ }
802
+ const at = rows.indexOf(expected);
803
+ if (at < 0) {
804
+ mismatched += 1;
805
+ problems.push(`inputs row does not match its record's inputsHash: record ${i} (ref ${ref})`);
806
+ continue;
807
+ }
808
+ rows.splice(at, 1);
809
+ matched += 1;
810
+ }
811
+ const line = missing === 0 && mismatched === 0
812
+ ? `inputs: ${matched} record(s), each with its inputs row`
813
+ : `inputs: ${matched} match, ${missing} missing, ${mismatched} do not match their record`;
814
+ return { line, matched, missing, mismatched };
815
+ }
816
+ /**
817
+ * What a checkpoint counted is fixed by its head. The witness counts the
818
+ * records whose time falls in `[startMs, endMs)` and names the last of them
819
+ * as the head, so the attested records in that window up to and including
820
+ * the head must be `receiptCount` records ending at the head, and their
821
+ * allow, deny and defer counts must be the signed totals (decision profile
822
+ * 4.4). A record appended later with a time inside the window was never seen
823
+ * by the witness and is not counted. A head the ledger does not hold is named
824
+ * for every checkpoint, not only the newest. A null head means the witness
825
+ * counted nothing. Null totals were redacted; the count is still checked.
826
+ */
827
+ function checkpointCountProblems(row, records, attested) {
828
+ const claims = row.claims;
829
+ const { startMs, endMs, receiptCount } = claims;
830
+ if (typeof startMs !== "number" || typeof endMs !== "number")
831
+ return ["checkpoint has no window"];
832
+ const inWindow = (r) => r.claims.timestampMs >= startMs && r.claims.timestampMs < endMs;
833
+ let counted = [];
834
+ let headRecord = null;
835
+ if (typeof claims.chainHeadHash === "string") {
836
+ const at = records.findIndex((r) => {
837
+ try {
838
+ return decisionRecordHash(r) === claims.chainHeadHash;
839
+ }
840
+ catch {
841
+ return false;
842
+ }
843
+ });
844
+ if (at < 0)
845
+ return ["checkpoint names a head the ledger does not hold"];
846
+ headRecord = records[at];
847
+ const upTo = new Set(records.slice(0, at + 1));
848
+ counted = attested.filter((r) => upTo.has(r) && inWindow(r));
849
+ }
850
+ const problems = [];
851
+ const endsAtHead = headRecord === null ? counted.length === 0 : counted[counted.length - 1] === headRecord;
852
+ if (typeof receiptCount !== "number" || receiptCount !== counted.length || !endsAtHead) {
853
+ problems.push(`checkpoint covers ${String(receiptCount)} record(s) in its window; the ledger holds ${counted.length} there up to its head`);
854
+ }
855
+ if (claims.totals !== null && claims.totals !== undefined) {
856
+ let same = false;
857
+ try {
858
+ same = canonical(totalsFromDecisionRecords(counted)) === canonical(claims.totals);
859
+ }
860
+ catch {
861
+ // A totals value that does not canonicalise is not the map the profile defines.
862
+ }
863
+ if (!same)
864
+ problems.push("checkpoint totals do not match the records in its window");
865
+ }
866
+ return problems;
867
+ }
594
868
  function controlStatement(records) {
595
869
  let open = false;
596
870
  let windows = 0;
@@ -648,6 +922,7 @@ function unreadableResult(dir, problem) {
648
922
  chainBreakAt: null,
649
923
  effectsBound: 0,
650
924
  effectsOrphaned: 0,
925
+ effectsDeferred: [],
651
926
  trust,
652
927
  effectTrust: trust,
653
928
  witnessTrust: trust,
@@ -656,6 +931,8 @@ function unreadableResult(dir, problem) {
656
931
  effectCompleteness: EFFECT_COMPLETENESS_UNCHECKED,
657
932
  tail: { line: TAIL_NONE, checkpoint: null },
658
933
  control: CONTROL_UNCHECKED,
934
+ inputs: INPUTS_UNCHECKED,
935
+ anchors: ANCHORS_NONE,
659
936
  problems: [problem],
660
937
  };
661
938
  }
@@ -709,6 +986,7 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
709
986
  chainBreakAt: null,
710
987
  effectsBound: 0,
711
988
  effectsOrphaned: 0,
989
+ effectsDeferred: [],
712
990
  trust: { source: "none", publicKeyPem: null, note: "no records, so no key was used" },
713
991
  effectTrust: effectTrustOf(opts.effectPublicKeyPem?.trim() ?? "", null, 0),
714
992
  witnessTrust: witnessTrustOf(opts.witnessPublicKeyPem?.trim() ?? "", null, 0),
@@ -717,6 +995,8 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
717
995
  effectCompleteness,
718
996
  tail: emptyTail.tail,
719
997
  control: emptyControl.control,
998
+ inputs: INPUTS_UNCHECKED,
999
+ anchors: ANCHORS_NONE,
720
1000
  problems,
721
1001
  };
722
1002
  }
@@ -737,6 +1017,7 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
737
1017
  };
738
1018
  let signaturesValid = 0;
739
1019
  let signaturesInvalid = 0;
1020
+ const attested = [];
740
1021
  const recordRefused = ed25519Refusal(anahtar);
741
1022
  if (recordRefused)
742
1023
  problems.push(recordRefused);
@@ -751,6 +1032,7 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
751
1032
  }
752
1033
  if (gecerli) {
753
1034
  signaturesValid += 1;
1035
+ attested.push(rec);
754
1036
  }
755
1037
  else {
756
1038
  signaturesInvalid += 1;
@@ -816,8 +1098,27 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
816
1098
  const sameKeyTaken = firstReceiptKey(effectRows, true);
817
1099
  const effectKey = pinnedEffect !== "" ? pinnedEffect : selfKeyTaken;
818
1100
  const witnessKey = pinnedWitness !== "" ? pinnedWitness : sameKeyTaken;
819
- const selfCount = effectRows.filter((row) => row.witnessClass !== "same-org").length;
820
- const sameCount = effectRows.length - selfCount;
1101
+ const selfCount = effectRows.filter((row) => row.witnessClass === "self").length;
1102
+ const sameCount = effectRows.filter((row) => row.witnessClass === "same-org").length;
1103
+ const thirdPartyKeys = (opts.thirdPartyPublicKeyPems ?? []).filter((key) => {
1104
+ const roles = [
1105
+ ["record", [anahtar, ...records.map(r => r.publicKeyPem)]],
1106
+ ["effect", [effectKey, ...effectRows.filter(e => e.witnessClass === "self").map(e => e.receipt?.publicKeyPem)]],
1107
+ ["witness", [witnessKey, ...effectRows.filter(e => e.witnessClass === "same-org").map(e => e.receipt?.publicKeyPem)]],
1108
+ ];
1109
+ for (const [role, known] of roles) {
1110
+ if (known.some(pem => samePublicKey(key, pem))) {
1111
+ problems.push(`third-party key equals ${role} key; not accepted for third-party rows`);
1112
+ return false;
1113
+ }
1114
+ }
1115
+ const refusal = ed25519Refusal(key);
1116
+ if (refusal) {
1117
+ problems.push(`third-party key rejected: ${refusal}`);
1118
+ return false;
1119
+ }
1120
+ return true;
1121
+ });
821
1122
  const effectTrust = effectTrustOf(pinnedEffect, selfKeyTaken, selfCount);
822
1123
  const witnessTrust = witnessTrustOf(pinnedWitness, sameKeyTaken, sameCount);
823
1124
  if (pinnedEffect !== "" && pinnedWitness === "" && sameCount > 0) {
@@ -839,6 +1140,12 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
839
1140
  const effectHash = typeof e.row?.effectHash === "string" ? e.row.effectHash : null;
840
1141
  const effectClass = typeof e.row?.effectClass === "string" ? e.row.effectClass : "";
841
1142
  if (effectClass === "duplicate-effect") {
1143
+ // Duplicate refusals are body observations, never downstream receipts.
1144
+ if (e.witnessClass === "third-party") {
1145
+ effectsOrphaned += 1;
1146
+ problems.push(`third-party row ${ref ?? "(missing)"} cannot be a duplicate-effect refusal`);
1147
+ continue;
1148
+ }
842
1149
  const sig = typeof e.attestation?.coseHex === "string" ? e.attestation.coseHex : "";
843
1150
  const dupKey = `${ref ?? ""}\0${sig}`;
844
1151
  if (sig !== "" && duplicateSeen.has(dupKey)) {
@@ -872,7 +1179,7 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
872
1179
  primarySeen.add(ref);
873
1180
  const hashes = ref === null ? undefined : hashesByRef.get(ref);
874
1181
  const hashMatch = effectHash !== null && hashes?.has(effectHash) === true;
875
- if (effectClass.endsWith(":threw")) {
1182
+ if (e.witnessClass !== "third-party" && effectClass.endsWith(":threw")) {
876
1183
  const allowed = ref === null ? undefined : allowedClassesByRef.get(ref);
877
1184
  let thrownOk = false;
878
1185
  if (allowed) {
@@ -896,7 +1203,17 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
896
1203
  : `effect hash does not match its decision: ref ${ref}`);
897
1204
  continue;
898
1205
  }
899
- if (!effectSignatureCoversRow(e, e.witnessClass === "same-org" ? witnessKey : effectKey)) {
1206
+ if (e.witnessClass === "third-party") {
1207
+ if (!thirdPartyKeys.some(key => thirdPartyReceiptCoversRow(e.receipt, e.row, key))) {
1208
+ effectsOrphaned += 1;
1209
+ problems.push((opts.thirdPartyPublicKeyPems?.length ?? 0) === 0
1210
+ ? `third-party row ${ref ?? "(missing)"} unchecked: no pinned third-party key`
1211
+ : `third-party row ${ref ?? "(missing)"} receipt does not cover the row under an accepted pinned third-party key`);
1212
+ continue;
1213
+ }
1214
+ // Only the effect row is signed; resultHash has no third-party attestation.
1215
+ }
1216
+ else if (!effectSignatureCoversRow(e, e.witnessClass === "same-org" ? witnessKey : effectKey)) {
900
1217
  effectsOrphaned += 1;
901
1218
  problems.push(effectProblem(e, ref));
902
1219
  continue;
@@ -905,12 +1222,16 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
905
1222
  if (ref !== null)
906
1223
  boundPrimaryRefs.add(ref);
907
1224
  }
1225
+ const unbound = allowsWithoutEffect(attested, primarySeen, opts.boundaryAllowanceMs ?? DEFAULT_BOUNDARY_ALLOWANCE_MS);
1226
+ problems.push(...unbound.findings.map((ref) => `decision-without-effect ${ref}`));
908
1227
  const indexed = indexStatement(dir, refler);
909
1228
  const effectCompleteness = noteEffectCompleteness(indexed.effectRefs, boundPrimaryRefs, problems);
910
- const tailed = tailStatement(dir, records, opts.checkpointPublicKeyPem ?? "");
1229
+ const inputs = inputsStatement(files.inputs, records, problems);
1230
+ const tailed = tailStatement(dir, records, opts.checkpointPublicKeyPem ?? "", attested);
911
1231
  problems.push(...indexed.problems, ...tailed.problems);
912
1232
  const stated = controlStatement(records);
913
1233
  problems.push(...stated.violations);
1234
+ const anchors = anchorStatement(dir, tailed.verified, opts.anchorPublicKeyPem?.trim() ?? "", problems);
914
1235
  const ok = problems.length === 0 && signaturesInvalid === 0 && chainBreakAt === null && effectsOrphaned === 0;
915
1236
  return {
916
1237
  ok,
@@ -922,6 +1243,7 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
922
1243
  chainBreakAt,
923
1244
  effectsBound,
924
1245
  effectsOrphaned,
1246
+ effectsDeferred: unbound.deferred,
925
1247
  trust,
926
1248
  effectTrust,
927
1249
  witnessTrust,
@@ -930,6 +1252,8 @@ async function verifyLedgerUnchecked(dir, opts = {}) {
930
1252
  effectCompleteness,
931
1253
  tail: tailed.tail,
932
1254
  control: stated.control,
1255
+ inputs,
1256
+ anchors,
933
1257
  problems,
934
1258
  };
935
1259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verax-ai/proxy",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {