@mikeargento/bitgraph-verify 1.14.0 → 1.15.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.
Files changed (66) hide show
  1. package/dist/__tests__/carrier.test.js +19 -0
  2. package/dist/__tests__/carrier.test.js.map +1 -1
  3. package/dist/__tests__/carrier2.test.d.ts +2 -0
  4. package/dist/__tests__/carrier2.test.d.ts.map +1 -0
  5. package/dist/__tests__/carrier2.test.js +172 -0
  6. package/dist/__tests__/carrier2.test.js.map +1 -0
  7. package/dist/__tests__/settlement.test.d.ts +12 -0
  8. package/dist/__tests__/settlement.test.d.ts.map +1 -0
  9. package/dist/__tests__/settlement.test.js +185 -0
  10. package/dist/__tests__/settlement.test.js.map +1 -0
  11. package/dist/carrier-assemble.d.ts +33 -0
  12. package/dist/carrier-assemble.d.ts.map +1 -0
  13. package/dist/carrier-assemble.js +57 -0
  14. package/dist/carrier-assemble.js.map +1 -0
  15. package/dist/carrier-verify.d.ts +47 -1
  16. package/dist/carrier-verify.d.ts.map +1 -1
  17. package/dist/carrier-verify.js +292 -53
  18. package/dist/carrier-verify.js.map +1 -1
  19. package/dist/carrier.d.ts +93 -3
  20. package/dist/carrier.d.ts.map +1 -1
  21. package/dist/carrier.js +144 -19
  22. package/dist/carrier.js.map +1 -1
  23. package/dist/ceiling.js +2 -2
  24. package/dist/fuse-member.js +2 -2
  25. package/dist/fuse-member.js.map +1 -1
  26. package/dist/fuse-verify.js +3 -3
  27. package/dist/fuse-verify.js.map +1 -1
  28. package/dist/fuse.d.ts +34 -2
  29. package/dist/fuse.d.ts.map +1 -1
  30. package/dist/fuse.js +83 -6
  31. package/dist/fuse.js.map +1 -1
  32. package/dist/index.d.ts +10 -3
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +9 -2
  35. package/dist/index.js.map +1 -1
  36. package/dist/nitro.d.ts +128 -0
  37. package/dist/nitro.d.ts.map +1 -0
  38. package/dist/nitro.js +551 -0
  39. package/dist/nitro.js.map +1 -0
  40. package/dist/settlement.d.ts +114 -0
  41. package/dist/settlement.d.ts.map +1 -0
  42. package/dist/settlement.js +194 -0
  43. package/dist/settlement.js.map +1 -0
  44. package/package.json +1 -1
  45. package/src/__tests__/carrier.test.ts +18 -0
  46. package/src/__tests__/carrier2.test.ts +193 -0
  47. package/src/__tests__/fixtures/carrier2/ceiling-26088459.witness.json +1 -0
  48. package/src/__tests__/fixtures/carrier2/ceiling-4548.anchor.json +1 -0
  49. package/src/__tests__/fixtures/carrier2/demo4546.ceiling.json +106 -0
  50. package/src/__tests__/fixtures/carrier2/demo4546.proof.json +47 -0
  51. package/src/__tests__/fixtures/carrier2/demo4546.txt +29 -0
  52. package/src/__tests__/fixtures/carrier2/floor-26088457.witness.json +1 -0
  53. package/src/__tests__/fixtures/carrier2/floor-4542.anchor.json +1 -0
  54. package/src/__tests__/fixtures/settlement/pointer-51979918-tx1.json +39 -0
  55. package/src/__tests__/fixtures/settlement/pointer-51979918.json +69 -0
  56. package/src/__tests__/settlement.test.ts +215 -0
  57. package/src/carrier-assemble.ts +74 -0
  58. package/src/carrier-verify.ts +328 -47
  59. package/src/carrier.ts +174 -18
  60. package/src/ceiling.ts +2 -2
  61. package/src/fuse-member.ts +2 -2
  62. package/src/fuse-verify.ts +3 -3
  63. package/src/fuse.ts +93 -6
  64. package/src/index.ts +30 -2
  65. package/src/nitro.ts +602 -0
  66. package/src/settlement.ts +263 -0
@@ -0,0 +1,74 @@
1
+ // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
+
3
+ /**
4
+ * Assemble a bitgraph-carrier/2 payload from vetted parts. The caller has
5
+ * already verified every part (the anchors over their messages, the headers
6
+ * by hash, the Base sidecar with verifyCeiling); this lays them out, derives
7
+ * the attestation witness from the proof's own document, and declares the
8
+ * pins the file was made under. It computes nothing that a verifier would
9
+ * later trust: the witness is recomputed on read, the pins compared.
10
+ */
11
+
12
+ import { CARRIER_VERSION_2, encodeCarrierBlock, type CarrierPayload, type CarrierFloor, type CarrierCeiling, type CarrierCeilingInTime, type CarrierSettlement, type CarrierPins, type CarrierProof } from "./carrier.js";
13
+ import { attestationWitness } from "./nitro.js";
14
+ import { computeProofHash, computeSignedBodyHash } from "./proof-hash.js";
15
+ import { BITGRAPH_CEILING_WRITER, BASE_MAINNET_CHAIN_ID } from "./carrier-verify.js";
16
+ import type { BitGraphProof } from "./types.js";
17
+
18
+ export interface CarrierV2Parts {
19
+ proof: CarrierProof;
20
+ floor: CarrierFloor;
21
+ ceiling: CarrierCeiling;
22
+ ceilingInTime: CarrierCeilingInTime;
23
+ settlement?: CarrierSettlement;
24
+ /** Overrides for the declared pins; defaults to the proof's measurement, BitGraph's ceiling writer, Ethereum mainnet and Base mainnet. */
25
+ pins?: Partial<CarrierPins>;
26
+ /** Set false to leave the openssl witness out (a ZIP-family file whose block would pass the limit). Default true when the proof carries an aws-nitro attestation. */
27
+ withAttestationWitness?: boolean;
28
+ }
29
+
30
+ /**
31
+ * A ZIP-family file (docx, xlsx, pptx, zip) stops opening once the trailing
32
+ * block passes 65,535 bytes, because its end-of-archive record must sit within
33
+ * the last 64 KiB (measured 2026-09-30: Python and Spotlight fail at 65,536,
34
+ * QuickLook hangs; MP4 and MOV have no limit at all). Builders keep every
35
+ * block under this, dropping the attestation witness first (it is derivable
36
+ * from the proof) and refusing the carrier otherwise.
37
+ */
38
+ export const CARRIER_BLOCK_ZIP_LIMIT = 60_000;
39
+
40
+ export function assembleCarrierV2Payload(parts: CarrierV2Parts): CarrierPayload {
41
+ const proof = parts.proof as unknown as BitGraphProof;
42
+ const att = proof.environment?.attestation;
43
+ const wantWitness = parts.withAttestationWitness ?? (att?.format === "aws-nitro" && typeof att.reportB64 === "string");
44
+ const pins: CarrierPins = {
45
+ pcr0: proof.environment?.measurement,
46
+ ceilingWriter: BITGRAPH_CEILING_WRITER,
47
+ chains: { ethereum: 1, base: BASE_MAINNET_CHAIN_ID },
48
+ ...(parts.pins ?? {}),
49
+ };
50
+ const payload: CarrierPayload = {
51
+ carrier: CARRIER_VERSION_2,
52
+ proof: parts.proof,
53
+ floor: parts.floor,
54
+ ceiling: parts.ceiling,
55
+ ceilingInTime: parts.ceilingInTime,
56
+ ...(parts.settlement ? { settlement: parts.settlement } : {}),
57
+ pins,
58
+ };
59
+ if (wantWitness && att && typeof att.reportB64 === "string") {
60
+ const signedBodyHashB64 = computeSignedBodyHash(proof);
61
+ const proofHashB64 = computeProofHash(proof);
62
+ payload.attestation = attestationWitness(att.reportB64, {
63
+ pcr0: proof.environment.measurement,
64
+ signedBodyHashB64,
65
+ ...(proofHashB64 === signedBodyHashB64 ? { proofHashB64 } : {}),
66
+ }) as unknown as Record<string, unknown>;
67
+ }
68
+ return payload;
69
+ }
70
+
71
+ /** The size the block will have on disk for this payload. */
72
+ export function carrierBlockSize(payload: CarrierPayload): number {
73
+ return encodeCarrierBlock(payload).length;
74
+ }
@@ -1,101 +1,382 @@
1
1
  // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
- * verifyCarrier — the offline read path for a bitgraph-carrier/1 file.
4
+ * verifyCarrier — the offline read path for a BitGraphed file (bitgraph-carrier/1
5
+ * or /2), one result per claim, each saying what it rests on.
5
6
  *
6
- * Given a carrier and nothing else, it strips the block by structure, hands
7
- * the committed bytes and every embedded proof to the EXISTING bitgraph/1
8
- * verifier (verify(), never a second implementation), checks the floor
9
- * against the proof's own signed slotAnchor by identity, recomputes the
10
- * block-header witnesses locally, and states the window:
7
+ * Given the file and nothing else, it strips the block by structure and checks:
11
8
  *
12
- * TRUE every check passed. `bounds.notAfter` may still be null,
13
- * which means NOT FETCHED — a valid floor is never downgraded
14
- * because the ceiling has not been stamped in yet.
15
- * FALSE evidence contradicts a claim: wrong bytes, bad signature,
16
- * a floor that is not the signed one, a ceiling that does not
17
- * follow the commit.
18
- * UNDETERMINED the block is unreadable (corrupted, not forged), or the
19
- * bytes carry no block at all (`carrier: "none"`).
9
+ * the bytes SHA-256 of the committed bytes is the digest the proof names
10
+ * the proof Ed25519 signature, the position record and its bindings, the
11
+ * fused commitment rebuilt (bitgraph-fuse/1 or /2), proofHash
12
+ * the attestation ES384 signature, the certificate chain to the AWS Nitro root
13
+ * (641A0321…), validity at the document's own instant, PCR0 against
14
+ * the proof's measurement, user_data against the signed body; and,
15
+ * on a v2 block, the openssl-checkable witness against the document
16
+ * the floor the anchor proof named by the signed slotAnchor, verified over its
17
+ * own message, matched by identity; its Ethereum header recomputed
18
+ * the ceilings in position: the next anchor, same checks; in time (v2): the Base
19
+ * sidecar's whole chain of custody (verifyCeiling); settled (v2): the
20
+ * Ethereum block that committed the batch data (verifySettlementPointer)
21
+ * the pins what the file declares it was made under, against the verifier's own
20
22
  *
21
- * No network. Attestation depth (COSE, cert chain to the AWS root) is the
22
- * audit package's job, as it is for every other proof; this wrapper is the
23
- * verify()-level judgment plus the carrier bindings.
23
+ * Two LEVELS. Offline, every claim above holds by mathematics and the AWS root,
24
+ * with the two block headers taken as the ones matching their hashes. CONFIRMED
25
+ * needs one question answered by any node the caller names: is that header the
26
+ * chain's own block? The lookups are injected; this module never fetches.
27
+ *
28
+ * TRUE every carried claim passed. A claim not carried (no ceiling yet,
29
+ * no settlement yet) is stated as NOT_CARRIED, never as failure.
30
+ * FALSE evidence contradicts a claim: wrong bytes, a bad signature, a floor
31
+ * that is not the signed one, a ceiling that does not follow the commit.
32
+ * UNDETERMINED the block is unreadable (corrupted, not forged), the version is
33
+ * unknown, or the bytes carry no block at all.
34
+ *
35
+ * The reading is written HERE, from the results, never read from the file.
24
36
  */
25
37
 
26
- import { verify, createVerificationContext } from "./verifier.js";
38
+ import { verify, verifyProofIntegrity, createVerificationContext } from "./verifier.js";
39
+ import { verifyFuse } from "./fuse-verify.js";
40
+ import { readFuseAttribution } from "./fuse.js";
41
+ import { computeProofHash, computeSignedBodyHash } from "./proof-hash.js";
42
+ import { verifyNitroAttestation, witnessMatchesAttestation, awsNitroRootSha256, type AttestationWitness } from "./nitro.js";
43
+ import { verifyCeiling, checkCeilingOnline, type CeilingSidecar } from "./ceiling.js";
44
+ import { verifySettlementPointer, checkSettlementOnline, BASE_MAINNET_SETTLEMENT_PINS, type SettlementPointer, type SettlementPins } from "./settlement.js";
27
45
  import type { BitGraphProof } from "./types.js";
28
46
  import {
29
47
  parseCarrier, checkFloorBinding, checkCeilingBinding, anchorMessageBytes,
30
- verifyWitnessHeader, carrierBounds, innerDigestMatches,
48
+ verifyWitnessHeader, carrierBounds, innerDigestMatches, carrierVersionOf,
31
49
  type CarrierBounds, type CarrierPayload,
32
50
  } from "./carrier.js";
33
51
 
52
+ /** BitGraph's published ceiling writer on Base mainnet: the default pin a verifier compares with. */
53
+ export const BITGRAPH_CEILING_WRITER = "0xf3972408D853c975F86351C311f4310220bbF2a3";
54
+ export const BASE_MAINNET_CHAIN_ID = 8453;
55
+
56
+ export type ClaimResult = "TRUE" | "FALSE" | "UNDETERMINED" | "NOT_CARRIED";
57
+
58
+ export interface CarrierClaim {
59
+ /** Stable id, dotted: "bytes.digest", "proof.signature", "attestation.root", "floor.header", "ceiling.time.inclusion", "confirmed.floor" ... */
60
+ id: string;
61
+ /** One line a reader can print. */
62
+ name: string;
63
+ result: ClaimResult;
64
+ /** What the claim rests on when TRUE: "SHA-256", "Ed25519", "the AWS Nitro root (641A0321…)", "Ethereum block N, header as given", ... */
65
+ restsOn: string;
66
+ detail: string;
67
+ level: "offline" | "confirmed";
68
+ }
69
+
70
+ export interface CarrierLookups {
71
+ /** Ethereum mainnet: the chain's block hash at a height, or null. */
72
+ ethereumBlockHash?: (blockNumber: number) => Promise<string | null>;
73
+ /** Base mainnet: the chain's block hash at a height, or null. */
74
+ baseBlockHash?: (blockNumber: number) => Promise<string | null>;
75
+ }
76
+
77
+ export interface CarrierVerifyOptions {
78
+ /** The one online question per chain, answered by nodes the caller names. Without them the confirmed level is UNDETERMINED. */
79
+ lookups?: CarrierLookups;
80
+ /** The verifier's own pins. The file's declared pins are compared with these, never used as these. */
81
+ pins?: {
82
+ /** PCR0 values the verifier accepts. Without a list, the attestation's PCR0 is reported, not judged. */
83
+ pcr0?: string[];
84
+ ceilingWriter?: string;
85
+ baseChainId?: number;
86
+ settlement?: SettlementPins;
87
+ };
88
+ }
89
+
34
90
  export interface CarrierVerifyResult {
35
91
  verdict: "TRUE" | "FALSE" | "UNDETERMINED";
36
92
  /** "ok" | "none" | "corrupt" — whether the bytes carried a readable block at all. */
37
93
  carrier: "ok" | "none" | "corrupt";
94
+ version: 1 | 2 | null;
38
95
  /** Every failed or undetermined check, in the order met. Empty on a clean TRUE. */
39
96
  reasons: string[];
40
97
  /** Stated only when the block was readable. notAfter null = NOT FETCHED, in those words. */
41
98
  bounds: CarrierBounds | null;
42
99
  ceiling: "present" | "unfetched" | null;
100
+ claims: CarrierClaim[];
101
+ /** Plain language, written from the claims. */
102
+ reading: string;
43
103
  payload: CarrierPayload | null;
44
104
  /** The committed bytes, for callers that go on to placement or origin recovery. */
45
105
  inner: Uint8Array | null;
46
106
  }
47
107
 
48
- const FALSE_ = (carrier: "ok", reasons: string[], payload: CarrierPayload, inner: Uint8Array): CarrierVerifyResult => ({
49
- verdict: "FALSE", carrier, reasons, bounds: carrierBounds(payload), ceiling: payload.ceiling.status, payload, inner,
50
- });
51
-
52
- export async function verifyCarrier(bytes: Uint8Array): Promise<CarrierVerifyResult> {
108
+ export async function verifyCarrier(bytes: Uint8Array, opts: CarrierVerifyOptions = {}): Promise<CarrierVerifyResult> {
53
109
  const parsed = parseCarrier(bytes);
54
110
  if (parsed.kind === "none") {
55
- return { verdict: "UNDETERMINED", carrier: "none", reasons: ["no carrier block: these bytes do not carry a proof inside"], bounds: null, ceiling: null, payload: null, inner: null };
111
+ const claim: CarrierClaim = { id: "block", name: "A proof block at the end of the file", result: "UNDETERMINED", restsOn: "", detail: "no carrier block: these bytes do not carry a proof inside", level: "offline" };
112
+ return { verdict: "UNDETERMINED", carrier: "none", version: null, reasons: [claim.detail], bounds: null, ceiling: null, claims: [claim], reading: "These bytes carry no proof block.", payload: null, inner: null };
56
113
  }
57
114
  if (parsed.kind === "corrupt") {
58
- return { verdict: "UNDETERMINED", carrier: "corrupt", reasons: [`carrier block found but unreadable: ${parsed.reason}. A corrupted block, not a forgery.`], bounds: null, ceiling: null, payload: null, inner: null };
115
+ const detail = `carrier block found but unreadable: ${parsed.reason}. A corrupted block, not a forgery.`;
116
+ const claim: CarrierClaim = { id: "block", name: "A proof block at the end of the file", result: "UNDETERMINED", restsOn: "", detail, level: "offline" };
117
+ return { verdict: "UNDETERMINED", carrier: "corrupt", version: null, reasons: [detail], bounds: null, ceiling: null, claims: [claim], reading: "The file ends in a proof block this reader cannot read. That is a damaged or newer block, not a verdict on the file.", payload: null, inner: null };
59
118
  }
60
- const { inner, payload } = parsed;
61
- const reasons: string[] = [];
119
+ return verifyCarrierPayload(parsed.payload, parsed.inner, opts);
120
+ }
121
+
122
+ /**
123
+ * The same claims over a payload already in hand, with the committed bytes or
124
+ * without them. A proof page holds the payload's parts (the proof, the anchors,
125
+ * the headers, the Base sidecar) and often not the file, so with `inner` null the
126
+ * two claims that need the bytes (the digest, the fused commitment) are stated
127
+ * as not carried, and everything else is judged exactly as for a file.
128
+ */
129
+ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8Array | null, opts: CarrierVerifyOptions = {}): Promise<CarrierVerifyResult> {
130
+ const version = carrierVersionOf(payload);
131
+ const claims: CarrierClaim[] = [];
132
+ const add = (id: string, name: string, result: ClaimResult, restsOn: string, detail: string, level: "offline" | "confirmed" = "offline") =>
133
+ claims.push({ id, name, result, restsOn, detail, level });
134
+ const proof = payload.proof as unknown as BitGraphProof;
135
+ const pinnedWriter = opts.pins?.ceilingWriter ?? BITGRAPH_CEILING_WRITER;
136
+ const baseChainId = opts.pins?.baseChainId ?? BASE_MAINNET_CHAIN_ID;
137
+
138
+ if (inner !== null) add("block", "A proof block at the end of the file", "TRUE", "the block's own structure", `bitgraph-carrier/${version}, found from the end of the file and stripped exactly once`);
62
139
 
63
140
  // 1. The committed bytes are the ones the proof names.
64
- if (!innerDigestMatches(inner, payload)) {
65
- reasons.push("the committed bytes do not hash to the carried proof's artifact digest");
66
- return FALSE_("ok", reasons, payload, inner);
141
+ if (inner !== null) {
142
+ const digestOk = innerDigestMatches(inner, payload);
143
+ add("bytes.digest", "The committed bytes are the ones the proof names", digestOk ? "TRUE" : "FALSE", "SHA-256", digestOk ? "SHA-256 of the bytes before the block equals the proof's artifact digest" : "the committed bytes do not hash to the carried proof's artifact digest");
144
+ } else {
145
+ add("bytes.digest", "The committed bytes are the ones the proof names", "NOT_CARRIED", "", `the file is not in hand; the proof names SHA-256 ${String((proof.artifact as { digestB64?: string } | undefined)?.digestB64 ?? "")}`);
67
146
  }
68
147
 
69
148
  // 2. The proof itself, under the existing bitgraph/1 algorithm. A fresh
70
149
  // context: a carrier is judged alone, not against this process's history.
71
- const proofResult = await verify({ proof: payload.proof as unknown as BitGraphProof, bytes: inner, context: createVerificationContext() });
72
- if (!proofResult.valid) reasons.push(`the carried proof does not verify: ${proofResult.reason ?? "unspecified"}`);
150
+ // Without the bytes, the integrity half runs (verify() without bytes).
151
+ const proofResult = inner !== null
152
+ ? await verify({ proof, bytes: inner, context: createVerificationContext() })
153
+ : await verifyProofIntegrity({ proof, context: createVerificationContext() });
154
+ add("proof.signature", "The proof is signed and its position record is bound to it", proofResult.valid ? "TRUE" : "FALSE", "Ed25519", proofResult.valid ? "the enclave's Ed25519 signature over the canonical signed body verifies; the position record's own signature, its hash in the commit, the nonce and the counter order all agree" : `the carried proof does not verify: ${proofResult.reason ?? "unspecified"}`);
155
+
156
+ const ph = (payload.proof as { proofHash?: unknown }).proofHash;
157
+ if (typeof ph === "string") {
158
+ const ok = computeProofHash(proof) === ph;
159
+ add("proof.hash", "The ledger's proofHash is this proof's", ok ? "TRUE" : "FALSE", "SHA-256", ok ? "recomputed over the signed-body subset and equal" : "the proofHash field is not the hash of this proof's signed-body subset");
160
+ }
161
+
162
+ // 3. Fused: the commitment inside the bytes, rebuilt from the signed record (fuse/2: and the signed floor block).
163
+ const marker = readFuseAttribution(proof);
164
+ if (marker !== null && inner === null) {
165
+ add("proof.fused", "The bytes carry the position commitment", "NOT_CARRIED", "", `the file is not in hand; its bytes carry a bitgraph-fuse/${marker.version ?? 1} commitment to check`);
166
+ } else if (marker !== null && inner !== null) {
167
+ const f = await verifyFuse({ proof, bytes: inner });
168
+ const good = f.category === "FUSED_DIRECT" || f.category === "CARRIED_INLINE";
169
+ add("proof.fused", "The bytes carry the position commitment", good ? "TRUE" : "FALSE",
170
+ marker.version === 2 ? "SHA-256 over the signed position record, its nonce and the signed floor block hash" : "SHA-256 over the signed position record and its nonce",
171
+ good ? `${f.category}: ${marker.version === 2 ? "the commitment binds the floor block, so the bytes could not have been finished before that block existed" : "the commitment was made from the position record before the bytes were finished"}` : `${f.category}${f.reason ? `: ${f.reason}` : ""}`);
172
+ } else {
173
+ add("proof.fused", "The bytes carry the position commitment", "NOT_CARRIED", "", "an ordinary recording: the position was taken after the bytes existed, and no commitment is inside them");
174
+ }
175
+
176
+ // 4. The attestation: the hardware's word on which image signed, bound to this proof.
177
+ const att = proof.environment?.attestation;
178
+ if (att && att.format === "aws-nitro" && typeof att.reportB64 === "string") {
179
+ const n = verifyNitroAttestation(att.reportB64, { expectedPcr0: proof.environment.measurement, expectedUserDataB64: computeSignedBodyHash(proof) });
180
+ const byName = (prefix: string) => n.checks.find((c) => c.name.startsWith(prefix));
181
+ const sig = byName("AWS signature"), chain = byName("Certificate chain"), root = byName("Chains to") ?? byName("Trust root"), validity = byName("Certificate validity"), pcr0 = byName("PCR0"), bound = byName("Bound to this proof");
182
+ const r = (c: { pass: boolean } | undefined): ClaimResult => (c === undefined ? "UNDETERMINED" : c.pass ? "TRUE" : "FALSE");
183
+ add("attestation.signature", "AWS hardware signed the attestation", r(sig), "ES384 (P-384)", sig?.detail ?? "not reached");
184
+ add("attestation.chain", "The certificate chain holds together", r(chain), "ES384 (P-384)", chain?.detail ?? "not reached");
185
+ add("attestation.root", "The chain reaches the AWS Nitro root", r(root), `the AWS Nitro Enclaves Root CA G1 (${n.rootSha256.slice(0, 8)}…)`, root?.detail ?? "not reached");
186
+ add("attestation.validity", "Every certificate was valid at the document's own instant", r(validity), "the document's signed timestamp", validity?.detail ?? "not reached");
187
+ add("attestation.pcr0", "The attested image is the one the proof names", r(pcr0), "PCR0 inside the signed document", pcr0?.detail ?? "not reached");
188
+ add("attestation.binding", "The attestation is bound to this proof", r(bound), "user_data inside the signed document", bound?.detail ?? "not reached");
189
+ const measured = n.doc?.pcrs[0] ?? proof.environment.measurement;
190
+ if (opts.pins?.pcr0 && opts.pins.pcr0.length > 0) {
191
+ const ok = opts.pins.pcr0.map((x) => x.toLowerCase()).includes(measured.toLowerCase());
192
+ add("attestation.pins", "The image is one the verifier accepts", ok ? "TRUE" : "FALSE", "the verifier's own allowlist", ok ? `PCR0 ${measured.slice(0, 16)}… is on the verifier's list` : `PCR0 ${measured.slice(0, 16)}… is not on the verifier's list`);
193
+ } else {
194
+ add("attestation.pins", "The image is one the verifier accepts", "UNDETERMINED", "", `no allowlist given: PCR0 is ${measured}; compare it with the measurements BitGraph publishes and rebuild it from source to check`);
195
+ }
196
+ if (version === 2 && payload.attestation) {
197
+ const w = witnessMatchesAttestation(payload.attestation as unknown as AttestationWitness, att.reportB64);
198
+ add("attestation.witness", "The openssl witness is what the document decodes to", w.ok ? "TRUE" : "FALSE", "recomputed from the attestation document", w.detail);
199
+ }
200
+ } else {
201
+ add("attestation.signature", "AWS hardware signed the attestation", "NOT_CARRIED", "", "the proof carries no aws-nitro attestation");
202
+ }
73
203
 
74
- // 3. The floor: the anchor proof verifies over its own signed message, and
75
- // it is the anchor the enclave signed into the slot, matched by identity.
204
+ // 5. The floor: the anchor proof verifies over its own signed message, and
205
+ // it is the anchor the enclave fixed at allocation, matched by identity.
76
206
  const floorMsg = anchorMessageBytes(payload.floor.anchor);
77
- if (floorMsg.error !== null) reasons.push(`floor anchor: ${floorMsg.error}`);
207
+ if (floorMsg.error !== null) add("floor.anchor", "The floor anchor is a genuine anchor proof", "FALSE", "", `floor anchor: ${floorMsg.error}`);
78
208
  else {
79
209
  const floorResult = await verify({ proof: payload.floor.anchor as unknown as BitGraphProof, bytes: floorMsg.bytes, context: createVerificationContext() });
80
- if (!floorResult.valid) reasons.push(`the floor anchor proof does not verify: ${floorResult.reason ?? "unspecified"}`);
210
+ add("floor.anchor", "The floor anchor is a genuine anchor proof", floorResult.valid ? "TRUE" : "FALSE", "Ed25519", floorResult.valid ? "the anchor proof verifies over its own signed block-hash message, under the same key" : `the floor anchor proof does not verify: ${floorResult.reason ?? "unspecified"}`);
81
211
  }
82
- reasons.push(...checkFloorBinding(payload.proof, payload.floor));
212
+ const floorBind = checkFloorBinding(payload.proof, payload.floor);
213
+ add("floor.binding", "The floor is the anchor the enclave fixed for this position", floorBind.length === 0 ? "TRUE" : "FALSE", "the proof's signed commit.slotAnchor", floorBind.length === 0 ? "the anchor's counter, block number and block hash equal the signed slotAnchor" : floorBind.join("; "));
83
214
  const floorWitness = verifyWitnessHeader(payload.floor.witness);
84
- if (!floorWitness.ok) reasons.push(`floor witness: ${floorWitness.error}`);
215
+ add("floor.header", "The floor block's header is the one with that hash", floorWitness.ok ? "TRUE" : "FALSE", `Ethereum block ${payload.floor.witness.blockNumber}, header as given`, floorWitness.ok ? `keccak-256 of the header equals the signed block hash; its time is ${iso(floorWitness.timestamp)}` : `floor witness: ${floorWitness.error}`);
85
216
 
86
- // 4. The ceiling, only when the carrier claims one.
217
+ // 6. The ceiling in position, only when the carrier claims one.
87
218
  if (payload.ceiling.status === "present") {
88
219
  const ceilMsg = anchorMessageBytes(payload.ceiling.anchor);
89
- if (ceilMsg.error !== null) reasons.push(`ceiling anchor: ${ceilMsg.error}`);
220
+ if (ceilMsg.error !== null) add("ceiling.position.anchor", "The closing anchor is a genuine anchor proof", "FALSE", "", `ceiling anchor: ${ceilMsg.error}`);
90
221
  else {
91
222
  const ceilResult = await verify({ proof: payload.ceiling.anchor as unknown as BitGraphProof, bytes: ceilMsg.bytes, context: createVerificationContext() });
92
- if (!ceilResult.valid) reasons.push(`the ceiling anchor proof does not verify: ${ceilResult.reason ?? "unspecified"}`);
223
+ add("ceiling.position.anchor", "The closing anchor is a genuine anchor proof", ceilResult.valid ? "TRUE" : "FALSE", "Ed25519", ceilResult.valid ? "the anchor proof verifies over its own signed block-hash message, under the same key" : `the ceiling anchor proof does not verify: ${ceilResult.reason ?? "unspecified"}`);
224
+ }
225
+ const cb = checkCeilingBinding(payload.proof, payload.ceiling);
226
+ add("ceiling.position.binding", "The record was committed before the closing anchor", cb.length === 0 ? "TRUE" : "FALSE", "the enclave's counter order", cb.length === 0 ? "the anchor's counter follows the commit counter on the same chain, epoch and key: a bound in position, not a clock time" : cb.join("; "));
227
+ const cw = verifyWitnessHeader(payload.ceiling.witness);
228
+ add("ceiling.position.header", "The closing block's header is the one with that hash", cw.ok ? "TRUE" : "FALSE", `Ethereum block ${payload.ceiling.witness.blockNumber}, header as given`, cw.ok ? `keccak-256 of the header equals the anchor's block hash; its time is ${iso(cw.timestamp)}` : `ceiling witness: ${cw.error}`);
229
+ } else {
230
+ add("ceiling.position.binding", "The record was committed before the closing anchor", "NOT_CARRIED", "", "closing anchor not fetched: the floor stands on its own");
231
+ }
232
+
233
+ // 7. v2: the ceiling in time, the Base block the record existed by.
234
+ let ceilingTime: { blockNumber: number; blockHash: string; blockTimestamp: number; status: string } | null = null;
235
+ let sidecar: CeilingSidecar | null = null;
236
+ if (version === 2) {
237
+ const ct = payload.ceilingInTime;
238
+ if (ct && ct.status === "present") {
239
+ sidecar = ct.sidecar as unknown as CeilingSidecar;
240
+ const c = await verifyCeiling(proof, sidecar, { writerAddress: pinnedWriter, chainId: baseChainId, proofAlreadyVerified: proofResult.valid });
241
+ const byName = (n: string) => c.checks.find((x) => x.name === n);
242
+ const r = (x: { ok: boolean } | undefined): ClaimResult => (x === undefined ? "UNDETERMINED" : x.ok ? "TRUE" : "FALSE");
243
+ add("ceiling.time.record", "The record is under the root the ceiling names", r(byName("merkle")), "SHA-256 (RFC 9162 tree)", byName("merkle")?.detail ?? c.reason ?? "not reached");
244
+ add("ceiling.time.payload", "The transaction carries that root", r(byName("payload")), "the 84-byte BGC1 payload", byName("payload")?.detail ?? c.reason ?? "not reached");
245
+ add("ceiling.time.sender", "The transaction was signed by the ceiling writer", r(byName("sender")), `secp256k1; the writer pin ${pinnedWriter.slice(0, 8)}…`, byName("sender")?.detail ?? c.reason ?? "not reached");
246
+ add("ceiling.time.inclusion", "The transaction is in the Base block", r(byName("inclusion")), `Merkle-Patricia proof; Base block ${sidecar.anchor?.blockNumber ?? "?"}, header as given`, byName("inclusion")?.detail ?? c.reason ?? "not reached");
247
+ add("ceiling.time.floor", "The floor header the ceiling carries is the signed floor", r(byName("floor")), "the proof's signed commit.slotAnchor", byName("floor")?.detail ?? "the sidecar carries no floor header");
248
+ const win = c.ok ? c.window?.ceiling : undefined;
249
+ if (win) ceilingTime = { blockNumber: win.blockNumber, blockHash: win.blockHash, blockTimestamp: win.blockTimestamp, status: c.status ?? "included" };
250
+ if (!c.ok && c.reason) add("ceiling.time", "The ceiling in time holds together", "FALSE", "", c.reason);
251
+ add("ceiling.time.status", "How far Base had settled the block", "UNDETERMINED", "", `the sidecar says "${sidecar.status}", as BitGraph's Base node reported when the file was written; not proven by the file. Settlement below is the proof, when carried.`);
252
+ } else {
253
+ add("ceiling.time.record", "The record existed by a Base block", "NOT_CARRIED", "", ct?.status === "unfetched" ? "the ceiling in time was not fetched when this file was made" : "no ceiling in time is stated");
254
+ }
255
+
256
+ // 8. v2: settlement on Ethereum, when carried.
257
+ const st = payload.settlement;
258
+ if (st && st.status === "present") {
259
+ const pointer = st.pointer as unknown as SettlementPointer;
260
+ const sp = verifySettlementPointer(pointer, opts.pins?.settlement ?? BASE_MAINNET_SETTLEMENT_PINS);
261
+ const byName = (n: string) => sp.checks.find((x) => x.name === n);
262
+ const r = (x: { ok: boolean } | undefined): ClaimResult => (x === undefined ? "UNDETERMINED" : x.ok ? "TRUE" : "FALSE");
263
+ add("settlement.header", "The Ethereum block's header is the one with that hash", r(byName("header")), `Ethereum block ${pointer.l1?.blockNumber ?? "?"}, header as given`, byName("header")?.detail ?? sp.reason ?? "not reached");
264
+ add("settlement.inclusion", "Base's batch transaction is in that Ethereum block", r(byName("inclusion")), "Merkle-Patricia proof", byName("inclusion")?.detail ?? sp.reason ?? "not reached");
265
+ add("settlement.blobs", "The transaction lists the blobs that carry the batch", r(byName("blobs")), "secp256k1; the batcher and inbox pins; KZG versioned hashes", byName("blobs")?.detail ?? sp.reason ?? "not reached");
266
+ if (sidecar && pointer.baseBlockHash && sidecar.anchor && pointer.baseBlockHash.toLowerCase() !== sidecar.anchor.blockHash.toLowerCase()) {
267
+ add("settlement.base", "The settlement is for the ceiling's Base block", "FALSE", "", "the pointer names a different Base block than the ceiling");
268
+ }
269
+ add("settlement.blobs.decoded", "The ceiling transaction's bytes are in the blob data", "UNDETERMINED", "", "blob bytes are checked by bitgraph-audit with the blobs kept beside the package (KZG, channel decode); this reader holds only the pointer");
270
+ } else if (ceilingTime !== null) {
271
+ add("settlement.header", "The Base block's batch data is on Ethereum", "NOT_CARRIED", "", st?.status === "unfetched" ? "settlement not fetched when this file was made" : "no settlement is stated");
272
+ }
273
+
274
+ // 9. The declared pins, compared with the verifier's.
275
+ if (payload.pins) {
276
+ const notes: string[] = [];
277
+ if (payload.pins.pcr0 && payload.pins.pcr0.toLowerCase() !== proof.environment.measurement.toLowerCase()) notes.push("the declared PCR0 is not the proof's measurement");
278
+ if (payload.pins.ceilingWriter && payload.pins.ceilingWriter.toLowerCase() !== pinnedWriter.toLowerCase()) notes.push(`the declared ceiling writer ${payload.pins.ceilingWriter} is not the verifier's pin`);
279
+ if (payload.pins.chains?.base !== undefined && payload.pins.chains.base !== baseChainId) notes.push(`the declared Base chain ${payload.pins.chains.base} is not the verifier's`);
280
+ add("pins", "What the file says it was made under agrees with this verifier's pins", notes.length === 0 ? "TRUE" : "FALSE", "the verifier's own pins", notes.length === 0 ? "declared pins match; they were never used as authority" : notes.join("; "));
93
281
  }
94
- reasons.push(...checkCeilingBinding(payload.proof, payload.ceiling));
95
- const ceilWitness = verifyWitnessHeader(payload.ceiling.witness);
96
- if (!ceilWitness.ok) reasons.push(`ceiling witness: ${ceilWitness.error}`);
97
282
  }
98
283
 
99
- if (reasons.length > 0) return FALSE_("ok", reasons, payload, inner);
100
- return { verdict: "TRUE", carrier: "ok", reasons: [], bounds: carrierBounds(payload), ceiling: payload.ceiling.status, payload, inner };
284
+ // 10. Confirmed: the block hashes against nodes the caller named.
285
+ const lk = opts.lookups;
286
+ if (lk?.ethereumBlockHash) {
287
+ const h = (await safe(() => lk.ethereumBlockHash!(payload.floor.witness.blockNumber)))?.toLowerCase();
288
+ const ok = h === payload.floor.witness.blockHash.toLowerCase();
289
+ add("confirmed.floor", "The floor block is Ethereum's own", h ? (ok ? "TRUE" : "FALSE") : "UNDETERMINED", "the Ethereum node the caller named", h ? (ok ? `Ethereum block ${payload.floor.witness.blockNumber} matches the node` : `the node's block ${payload.floor.witness.blockNumber} is ${h}, not this header`) : "the node did not answer", "confirmed");
290
+ const pc = payload.ceiling;
291
+ if (pc.status === "present") {
292
+ const h2 = (await safe(() => lk.ethereumBlockHash!(pc.witness.blockNumber)))?.toLowerCase();
293
+ const ok2 = h2 === pc.witness.blockHash.toLowerCase();
294
+ add("confirmed.ceiling.position", "The closing block is Ethereum's own", h2 ? (ok2 ? "TRUE" : "FALSE") : "UNDETERMINED", "the Ethereum node the caller named", h2 ? (ok2 ? `Ethereum block ${pc.witness.blockNumber} matches the node` : `the node's block is ${h2}, not this header`) : "the node did not answer", "confirmed");
295
+ }
296
+ const st = payload.settlement;
297
+ if (st && st.status === "present") {
298
+ const r = await checkSettlementOnline(st.pointer as unknown as SettlementPointer, lk.ethereumBlockHash);
299
+ add("confirmed.settlement", "The settling Ethereum block is Ethereum's own", r.ok ? "TRUE" : "FALSE", "the Ethereum node the caller named", r.detail, "confirmed");
300
+ }
301
+ } else {
302
+ add("confirmed.floor", "The floor block is Ethereum's own", "UNDETERMINED", "", "no Ethereum node given: the header is taken as the one matching its hash; confirm block " + payload.floor.witness.blockNumber + " against any node or explorer", "confirmed");
303
+ }
304
+ if (sidecar) {
305
+ if (lk?.baseBlockHash) {
306
+ const r = await checkCeilingOnline(sidecar, lk.baseBlockHash);
307
+ add("confirmed.ceiling.time", "The ceiling block is Base's own", r.onChain === null ? "UNDETERMINED" : r.onChain ? "TRUE" : "FALSE", "the Base node the caller named", r.detail, "confirmed");
308
+ } else {
309
+ add("confirmed.ceiling.time", "The ceiling block is Base's own", "UNDETERMINED", "", `no Base node given: confirm block ${sidecar.anchor?.blockNumber ?? "?"} against any node or explorer`, "confirmed");
310
+ }
311
+ }
312
+
313
+ const reasons = claims.filter((c) => c.result === "FALSE").map((c) => `${c.name}: ${c.detail}`);
314
+ const verdict: CarrierVerifyResult["verdict"] = reasons.length > 0 ? "FALSE" : "TRUE";
315
+ const bounds = carrierBounds(payload);
316
+ return {
317
+ verdict,
318
+ carrier: "ok",
319
+ version,
320
+ reasons,
321
+ bounds,
322
+ ceiling: payload.ceiling.status,
323
+ claims,
324
+ reading: writeReading(verdict, claims, bounds, proof, ceilingTime, floorWitness.timestamp),
325
+ payload,
326
+ inner,
327
+ };
328
+ }
329
+
330
+ async function safe<T>(f: () => Promise<T>): Promise<T | null> {
331
+ try { return await f(); } catch { return null; }
332
+ }
333
+
334
+ function iso(ts: number | null): string {
335
+ return ts === null ? "unknown" : new Date(ts * 1000).toISOString().replace(".000Z", "Z");
336
+ }
337
+
338
+ /**
339
+ * The reading, from the results. It names what the file proves and what that
340
+ * rests on, and says what removes each reliance. Never stored in the file.
341
+ */
342
+ function writeReading(
343
+ verdict: CarrierVerifyResult["verdict"],
344
+ claims: CarrierClaim[],
345
+ bounds: CarrierBounds,
346
+ proof: BitGraphProof,
347
+ ceilingTime: { blockNumber: number; blockHash: string; blockTimestamp: number } | null,
348
+ floorTs: number | null,
349
+ ): string {
350
+ const get = (id: string) => claims.find((c) => c.id === id);
351
+ if (verdict === "FALSE") {
352
+ const failed = claims.filter((c) => c.result === "FALSE").map((c) => c.name.toLowerCase());
353
+ return `This file does not verify: ${failed.join("; ")}. Nothing here is a verdict on what the bytes say, only that the evidence does not hold together.`;
354
+ }
355
+ const position = proof.commit?.counter ?? "?";
356
+ const epoch = (proof.commit?.epochId ?? "").replace(/=+$/, "").slice(0, 8);
357
+ const fused = get("proof.fused");
358
+ const after = floorTs !== null ? `made after Ethereum block ${bounds.notBefore.blockNumber} (${iso(floorTs)})` : `made after Ethereum block ${bounds.notBefore.blockNumber}`;
359
+ const by = ceilingTime ? `, and existed by Base block ${ceilingTime.blockNumber} (${iso(ceilingTime.blockTimestamp)})` : "";
360
+ const settled = bounds.settledBy ? `, whose batch data Ethereum committed in block ${bounds.settledBy.blockNumber} (${iso(bounds.settledBy.timestamp)})` : "";
361
+ const before = bounds.notAfter ? `; committed before the anchoring of Ethereum block ${bounds.notAfter.blockNumber}, a bound in position` : "";
362
+ const digest = get("bytes.digest");
363
+ const subject = digest?.result !== "TRUE"
364
+ ? "The bytes this proof names were committed"
365
+ : fused?.result === "TRUE"
366
+ ? (fused.restsOn.includes("floor block") ? "These exact bytes were finished after the floor block existed" : "These exact bytes were finished after their position was opened")
367
+ : "These exact bytes were committed";
368
+ const att = get("attestation.root");
369
+ const rests: string[] = ["SHA-256", "Ed25519"];
370
+ if (att?.result === "TRUE") rests.push(`the AWS Nitro root (${awsNitroRootSha256().slice(0, 8)}…)`);
371
+ rests.push(`Ethereum block ${bounds.notBefore.blockNumber}`);
372
+ if (ceilingTime) rests.push(`Base block ${ceilingTime.blockNumber}`);
373
+ if (bounds.settledBy) rests.push(`Ethereum block ${bounds.settledBy.blockNumber}`);
374
+ const confirmed = claims.filter((c) => c.level === "confirmed");
375
+ const allConfirmed = confirmed.length > 0 && confirmed.every((c) => c.result === "TRUE");
376
+ const tail = allConfirmed
377
+ ? "Every block was confirmed against a node, so nothing here rests on a header taken as given."
378
+ : "Offline, the blocks are taken from their headers, each of which hashes to the hash the evidence names; confirm them against any node or explorer to remove that reliance.";
379
+ const pins = get("attestation.pins");
380
+ const pinLine = pins?.result === "TRUE" ? " The enclave image is one this verifier accepts." : pins?.result === "UNDETERMINED" ? ` The enclave image's PCR0 is ${proof.environment.measurement.slice(0, 16)}…; compare it with BitGraph's published measurements.` : "";
381
+ return `${subject}: ${after}${by}${settled}${before}. Position ${position} of epoch ${epoch}…. Rests on: ${rests.join(", ")}. ${tail}${pinLine}`;
101
382
  }