@mikeargento/bitgraph-verify 1.13.0 → 1.14.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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/__tests__/ceiling.test.d.ts +8 -0
  3. package/dist/__tests__/ceiling.test.d.ts.map +1 -0
  4. package/dist/__tests__/ceiling.test.js +247 -0
  5. package/dist/__tests__/ceiling.test.js.map +1 -0
  6. package/dist/ceiling-evm.d.ts +49 -0
  7. package/dist/ceiling-evm.d.ts.map +1 -0
  8. package/dist/ceiling-evm.js +331 -0
  9. package/dist/ceiling-evm.js.map +1 -0
  10. package/dist/ceiling-trie.d.ts +9 -0
  11. package/dist/ceiling-trie.d.ts.map +1 -0
  12. package/dist/ceiling-trie.js +113 -0
  13. package/dist/ceiling-trie.js.map +1 -0
  14. package/dist/ceiling.d.ts +123 -0
  15. package/dist/ceiling.d.ts.map +1 -0
  16. package/dist/ceiling.js +247 -0
  17. package/dist/ceiling.js.map +1 -0
  18. package/dist/fuse-member.js +8 -8
  19. package/dist/fuse-member.js.map +1 -1
  20. package/dist/fuse-verify.js +4 -4
  21. package/dist/fuse-verify.js.map +1 -1
  22. package/dist/index.d.ts +5 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/verifier.js +4 -4
  27. package/dist/verifier.js.map +1 -1
  28. package/package.json +3 -2
  29. package/src/__tests__/ceiling.test.ts +281 -0
  30. package/src/__tests__/fixtures/ceiling/floor-26037892.header.hex +1 -0
  31. package/src/ceiling-evm.ts +326 -0
  32. package/src/ceiling-trie.ts +112 -0
  33. package/src/ceiling.ts +333 -0
  34. package/src/fuse-member.ts +8 -8
  35. package/src/fuse-verify.ts +4 -4
  36. package/src/index.ts +12 -0
  37. package/src/verifier.ts +4 -4
  38. package/dist/run.d.ts +0 -59
  39. package/dist/run.d.ts.map +0 -1
  40. package/dist/run.js +0 -147
  41. package/dist/run.js.map +0 -1
package/src/ceiling.ts ADDED
@@ -0,0 +1,333 @@
1
+ // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
+
3
+ /**
4
+ * A ceiling in TIME for a BitGraph, carried beside the proof, never inside it.
5
+ *
6
+ * Every BitGraph already has a floor in time (the Ethereum block fused in at
7
+ * slot allocation, `commit.slotAnchor`) and a ceiling in POSITION (the
8
+ * anchors that follow it in the chain). This adds the one thing a record
9
+ * cannot supply for itself: something outside the operator's control that
10
+ * depends on the record. After a commit, a writer puts a Merkle root over
11
+ * record hashes into a Base transaction. The block that includes it proves
12
+ * every record under that root existed by the block's timestamp.
13
+ *
14
+ * The sidecar (`bitgraph-ceiling/1`) is unsigned and trusted for nothing. Every
15
+ * value it states is recomputed here from bytes bound to a hash:
16
+ *
17
+ * proof ─computeProofHash→ leaf ─merklePath→ root
18
+ * root == payload.root, payload == tx.data, tx signed by the writer
19
+ * tx ─MPT proof→ header.transactionsRoot, keccak(header) == blockHash
20
+ * blockTimestamp read from the header, not from the sidecar's own field
21
+ *
22
+ * What stays OUTSIDE this function, and is reported, not assumed:
23
+ * - whether that header is really a Base block (check it against any Base
24
+ * RPC; see checkCeilingOnline), and
25
+ * - who the writer is (the caller names the address it trusts; BitGraph
26
+ * publishes its own on bitgraph.ing).
27
+ */
28
+
29
+ import { sha256 } from "@noble/hashes/sha256";
30
+ import { verifyProofIntegrity, createVerificationContext } from "./verifier.js";
31
+ import { computeProofHash } from "./proof-hash.js";
32
+ import { merkleLeafHash, merkleRootFromPath } from "./fuse-merkle.js";
33
+ import { base64ToBytes } from "./fuse.js";
34
+ import {
35
+ bytesEqual, bytesToHex, decodeEip1559, decodeHeader, hexToBytes, keccak256, mptVerify, txTrieKey,
36
+ } from "./ceiling-evm.js";
37
+ import type { BitGraphProof, VerificationPolicy } from "./types.js";
38
+
39
+ export const CEILING_VERSION = "bitgraph-ceiling/1";
40
+ export const CEILING_MAGIC = "BGC1";
41
+ export const CEILING_PAYLOAD_BYTES = 84;
42
+
43
+ export type CeilingStatus = "pending" | "included" | "safe" | "finalized";
44
+
45
+ export interface CeilingSidecar {
46
+ version: typeof CEILING_VERSION;
47
+ /** Standard base64, as the ledger stores it. */
48
+ proofHash: string;
49
+ leafIndex: number;
50
+ /** Tree size. RFC 9162 path checks need it; not in the build prompt's draft. */
51
+ leafCount: number;
52
+ /** Sibling hashes, leaf level up, 0x hex. */
53
+ merklePath: string[];
54
+ root: string;
55
+ anchor: {
56
+ chainId: number;
57
+ writer: string;
58
+ txHash: string;
59
+ rawTx: string;
60
+ payload: string;
61
+ blockNumber: number;
62
+ blockHash: string;
63
+ blockTimestamp: number;
64
+ blockHeader: string;
65
+ txIndex: number;
66
+ /** Trie nodes from transactionsRoot down to this transaction, 0x hex. */
67
+ txInclusionProof: string[];
68
+ } | null;
69
+ status: CeilingStatus;
70
+ statusObserved: { included: string | null; safe: string | null; finalized: string | null };
71
+ /**
72
+ * The floor block's header, so the window reads offline. Optional and
73
+ * unsigned: checked by keccak256 against the proof's SIGNED slotAnchor hash.
74
+ */
75
+ floor?: { blockNumber: number; blockHash: string; blockTimestamp: number; blockHeader: string } | null;
76
+ /** Reserved for v2: the Ethereum batch that settles this Base block. */
77
+ settlement: null;
78
+ }
79
+
80
+ // ── Payload ────────────────────────────────────────────────────────────────
81
+
82
+ export interface CeilingPayload {
83
+ root: Uint8Array;
84
+ prev: Uint8Array;
85
+ firstPos: bigint;
86
+ lastPos: bigint;
87
+ }
88
+
89
+ export function encodeCeilingPayload(p: CeilingPayload): Uint8Array {
90
+ if (p.root.length !== 32 || p.prev.length !== 32) throw new TypeError("root and prev are 32 bytes");
91
+ const out = new Uint8Array(CEILING_PAYLOAD_BYTES);
92
+ out.set(new TextEncoder().encode(CEILING_MAGIC), 0);
93
+ out.set(p.root, 4);
94
+ out.set(p.prev, 36);
95
+ const view = new DataView(out.buffer);
96
+ view.setBigUint64(68, p.firstPos);
97
+ view.setBigUint64(76, p.lastPos);
98
+ return out;
99
+ }
100
+
101
+ export function decodeCeilingPayload(bytes: Uint8Array): CeilingPayload {
102
+ if (bytes.length !== CEILING_PAYLOAD_BYTES) throw new TypeError(`payload is ${bytes.length} bytes, expected ${CEILING_PAYLOAD_BYTES}`);
103
+ const magic = new TextDecoder().decode(bytes.slice(0, 4));
104
+ if (magic !== CEILING_MAGIC) throw new TypeError(`payload magic is ${JSON.stringify(magic)}, expected ${CEILING_MAGIC}`);
105
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
106
+ return {
107
+ root: bytes.slice(4, 36),
108
+ prev: bytes.slice(36, 68),
109
+ firstPos: view.getBigUint64(68),
110
+ lastPos: view.getBigUint64(76),
111
+ };
112
+ }
113
+
114
+ /** SHA-256 of a payload: the next payload's `prev`, so the anchors chain. */
115
+ export function ceilingPayloadHash(payload: Uint8Array): Uint8Array {
116
+ return sha256(payload);
117
+ }
118
+
119
+ /** The leaf hash of one record: SHA256(0x00 || proofHash bytes). */
120
+ export function ceilingLeaf(proofHashB64: string): Uint8Array {
121
+ const raw = base64ToBytes(proofHashB64);
122
+ if (!raw || raw.length !== 32) throw new TypeError("proofHash must decode to 32 bytes");
123
+ return merkleLeafHash(raw);
124
+ }
125
+
126
+ // ── Verification ───────────────────────────────────────────────────────────
127
+
128
+ export interface CeilingCheck {
129
+ name: string;
130
+ ok: boolean;
131
+ detail?: string;
132
+ }
133
+
134
+ export interface CeilingVerifyResult {
135
+ /** True when every offline check passed. Says nothing about chain canonicality. */
136
+ ok: boolean;
137
+ reason?: string;
138
+ checks: CeilingCheck[];
139
+ status?: CeilingStatus;
140
+ window?: {
141
+ /** Floor: the proof's signed slotAnchor block. Time only if a checked header was carried. */
142
+ floor: { blockNumber: number; blockHash: string; blockTimestamp: number | null };
143
+ /** Ceiling: the Base block, time read from its header. */
144
+ ceiling: { chainId: number; blockNumber: number; blockHash: string; blockTimestamp: number };
145
+ widthSeconds: number | null;
146
+ };
147
+ /** One line for people. */
148
+ label?: string;
149
+ /** Offline, this is always false; checkCeilingOnline sets it. */
150
+ headerCheckedAgainstChain: boolean;
151
+ }
152
+
153
+ export interface CeilingVerifyOptions {
154
+ /** The declared writer address. A sidecar from any other sender is refused. */
155
+ writerAddress: string;
156
+ /** 8453 Base mainnet, 84532 Base Sepolia. */
157
+ chainId: number;
158
+ /** Skip the proof's own signature check (only when the caller already ran verify()). */
159
+ proofAlreadyVerified?: boolean;
160
+ /** Passed through to the proof's own check (measurement allowlist and so on). */
161
+ trustAnchors?: VerificationPolicy;
162
+ }
163
+
164
+ function hhmmss(unix: number): string {
165
+ return new Date(unix * 1000).toISOString().slice(11, 19);
166
+ }
167
+
168
+ export function ceilingLabel(status: CeilingStatus, blockNumber: number, blockTimestamp: number): string {
169
+ const at = `Base block ${blockNumber.toLocaleString("en-US")} at ${hhmmss(blockTimestamp)} UTC`;
170
+ if (status === "safe" || status === "finalized") return `Ceiling: ${at}, settled on Ethereum.`;
171
+ return `Ceiling: ${at}. Relies on Base's sequencer until settled on Ethereum.`;
172
+ }
173
+
174
+ /**
175
+ * Check a ceiling sidecar against its proof, offline. Every check runs and
176
+ * is reported; the first failure is the `reason`.
177
+ */
178
+ export async function verifyCeiling(
179
+ proof: BitGraphProof,
180
+ sidecar: CeilingSidecar,
181
+ opts: CeilingVerifyOptions,
182
+ ): Promise<CeilingVerifyResult> {
183
+ const checks: CeilingCheck[] = [];
184
+ const fail = (name: string, detail: string): CeilingVerifyResult => {
185
+ checks.push({ name, ok: false, detail });
186
+ return { ok: false, reason: `${name}: ${detail}`, checks, headerCheckedAgainstChain: false };
187
+ };
188
+ const pass = (name: string, detail?: string) => checks.push(detail === undefined ? { name, ok: true } : { name, ok: true, detail });
189
+
190
+ if (sidecar?.version !== CEILING_VERSION) return fail("format", `not a ${CEILING_VERSION} sidecar`);
191
+
192
+ // 0. The proof itself. The leaf covers the signed-body SUBSET (proofHash);
193
+ // the signature covers the rest, so an altered actor/policy fails here.
194
+ if (!opts.proofAlreadyVerified) {
195
+ const v = await verifyProofIntegrity({
196
+ proof,
197
+ context: createVerificationContext(),
198
+ ...(opts.trustAnchors ? { trustAnchors: opts.trustAnchors } : {}),
199
+ });
200
+ if (!v.valid) return fail("proof", `the proof does not verify (${v.reason ?? "invalid"})`);
201
+ pass("proof", "signature valid");
202
+ }
203
+
204
+ // 1. The record is under the root.
205
+ let proofHash: string;
206
+ try {
207
+ proofHash = computeProofHash(proof);
208
+ } catch (e) {
209
+ return fail("record", `cannot hash the proof (${(e as Error).message})`);
210
+ }
211
+ if (proofHash !== sidecar.proofHash) return fail("record", "this sidecar belongs to a different proof");
212
+ let computedRoot: Uint8Array | null;
213
+ try {
214
+ computedRoot = merkleRootFromPath(
215
+ ceilingLeaf(proofHash),
216
+ sidecar.leafIndex,
217
+ sidecar.leafCount,
218
+ sidecar.merklePath.map(hexToBytes),
219
+ );
220
+ } catch {
221
+ computedRoot = null;
222
+ }
223
+ if (!computedRoot) return fail("merkle", "the path does not fit the leaf index and tree size");
224
+ if (bytesToHex(computedRoot) !== sidecar.root.toLowerCase()) return fail("merkle", "the leaf and path do not reach the root");
225
+ pass("merkle", `leaf ${sidecar.leafIndex} of ${sidecar.leafCount} reaches the root`);
226
+
227
+ if (sidecar.status === "pending" || !sidecar.anchor) {
228
+ return { ok: false, reason: "ceiling pending: no transaction included yet", checks, status: "pending", headerCheckedAgainstChain: false };
229
+ }
230
+ const a = sidecar.anchor;
231
+
232
+ // 2. The payload carries that root.
233
+ let payloadBytes: Uint8Array;
234
+ try {
235
+ payloadBytes = hexToBytes(a.payload);
236
+ const p = decodeCeilingPayload(payloadBytes);
237
+ if (bytesToHex(p.root) !== sidecar.root.toLowerCase()) return fail("payload", "the payload's root is not this sidecar's root");
238
+ pass("payload", `${CEILING_MAGIC}, positions ${p.firstPos}-${p.lastPos}`);
239
+ } catch (e) {
240
+ return fail("payload", (e as Error).message);
241
+ }
242
+
243
+ // 3. The transaction: signed by the writer, to itself, carrying the payload.
244
+ let rawTx: Uint8Array;
245
+ try {
246
+ rawTx = hexToBytes(a.rawTx);
247
+ const tx = decodeEip1559(rawTx);
248
+ const writer = opts.writerAddress.toLowerCase();
249
+ if (tx.from !== writer) return fail("sender", `the transaction was signed by ${tx.from}, not the declared writer ${writer}`);
250
+ if (tx.to !== writer) return fail("sender", `the transaction is addressed to ${tx.to ?? "a contract creation"}, not to the writer`);
251
+ if (tx.chainId !== BigInt(opts.chainId)) return fail("chain", `the transaction is for chain ${tx.chainId}, expected ${opts.chainId}`);
252
+ if (a.chainId !== opts.chainId) return fail("chain", `the sidecar names chain ${a.chainId}, expected ${opts.chainId}`);
253
+ if (!bytesEqual(tx.data, payloadBytes)) return fail("payload", "the transaction's data is not the payload");
254
+ if (tx.hash !== a.txHash.toLowerCase()) return fail("transaction", "the raw transaction does not hash to txHash");
255
+ pass("sender", `signed by ${tx.from}`);
256
+ } catch (e) {
257
+ return fail("transaction", (e as Error).message);
258
+ }
259
+
260
+ // 4. The transaction is in the block, and the block is this header.
261
+ let header;
262
+ try {
263
+ header = decodeHeader(hexToBytes(a.blockHeader));
264
+ } catch (e) {
265
+ return fail("header", (e as Error).message);
266
+ }
267
+ if (header.hash !== a.blockHash.toLowerCase()) return fail("header", "the header does not hash to blockHash");
268
+ if (header.number !== a.blockNumber) return fail("header", `the header is block ${header.number}, the sidecar says ${a.blockNumber}`);
269
+ if (header.timestamp !== a.blockTimestamp) return fail("header", `the header's timestamp is ${header.timestamp}, the sidecar says ${a.blockTimestamp}`);
270
+ const inBlock = mptVerify(hexToBytes(header.transactionsRoot), txTrieKey(a.txIndex), a.txInclusionProof.map(hexToBytes));
271
+ if (!inBlock || !bytesEqual(inBlock, rawTx)) return fail("inclusion", "the transaction is not in this block");
272
+ pass("inclusion", `transaction ${a.txIndex} of block ${header.number}`);
273
+
274
+ // 5. The window. The floor is the proof's own signed slotAnchor.
275
+ const slotAnchor = proof.commit.slotAnchor;
276
+ let floor: { blockNumber: number; blockHash: string; blockTimestamp: number | null } | null = null;
277
+ if (slotAnchor) {
278
+ floor = { blockNumber: slotAnchor.blockNumber, blockHash: slotAnchor.blockHash, blockTimestamp: null };
279
+ const w = sidecar.floor;
280
+ if (w && w.blockHeader) {
281
+ try {
282
+ const fh = decodeHeader(hexToBytes(w.blockHeader));
283
+ if (fh.hash === slotAnchor.blockHash.toLowerCase() && fh.number === slotAnchor.blockNumber) {
284
+ floor.blockTimestamp = fh.timestamp;
285
+ pass("floor", `Ethereum block ${fh.number}, header checked against the signed hash`);
286
+ } else {
287
+ checks.push({ name: "floor", ok: false, detail: "the carried floor header does not match the proof's signed slotAnchor; ignored" });
288
+ }
289
+ } catch {
290
+ checks.push({ name: "floor", ok: false, detail: "the carried floor header does not decode; ignored" });
291
+ }
292
+ }
293
+ }
294
+ const width = floor?.blockTimestamp != null ? header.timestamp - floor.blockTimestamp : null;
295
+ const status = sidecar.status;
296
+ return {
297
+ ok: true,
298
+ checks,
299
+ status,
300
+ window: {
301
+ floor: floor ?? { blockNumber: 0, blockHash: "", blockTimestamp: null },
302
+ ceiling: { chainId: a.chainId, blockNumber: header.number, blockHash: header.hash, blockTimestamp: header.timestamp },
303
+ widthSeconds: width,
304
+ },
305
+ label: ceilingLabel(status, header.number, header.timestamp),
306
+ headerCheckedAgainstChain: false,
307
+ };
308
+ }
309
+
310
+ /**
311
+ * Ask a Base node whether the sidecar's block is on the chain. Returns a
312
+ * finding, never throws. Online is the only way to learn canonicality.
313
+ *
314
+ * The package makes no network calls of its own (the audit's zero-network
315
+ * guarantee covers it), so the caller supplies the one lookup:
316
+ * `getBlockHash(n)` returns the chain's hash at height n, or null.
317
+ */
318
+ export async function checkCeilingOnline(
319
+ sidecar: CeilingSidecar,
320
+ getBlockHash: (blockNumber: number) => Promise<string | null>,
321
+ ): Promise<{ onChain: boolean | null; detail: string }> {
322
+ if (!sidecar.anchor) return { onChain: null, detail: "no anchor to check" };
323
+ try {
324
+ const hash = (await getBlockHash(sidecar.anchor.blockNumber))?.toLowerCase();
325
+ if (!hash) return { onChain: null, detail: "the RPC did not return that block" };
326
+ if (hash === sidecar.anchor.blockHash.toLowerCase()) return { onChain: true, detail: `block ${sidecar.anchor.blockNumber} matches the chain` };
327
+ return { onChain: false, detail: `the chain's block ${sidecar.anchor.blockNumber} is ${hash}, not this header` };
328
+ } catch (e) {
329
+ return { onChain: null, detail: `header not checked against chain (${(e as Error).message})` };
330
+ }
331
+ }
332
+
333
+ export { keccak256 as ceilingKeccak256 };
@@ -289,7 +289,7 @@ function admit(bound: BoundSet, fusedBytes: Uint8Array, row: SetMember): Admitte
289
289
  return {
290
290
  category: "INVALID_SLOT_COMMITMENT",
291
291
  placement: placement.id,
292
- reason: "listed in the committed set manifest, but the bytes carry a commitment to a different slot; membership without the floor is not a member verdict",
292
+ reason: "listed in the committed set manifest, but the bytes carry a commitment to a different position; membership without the floor is not a member verdict",
293
293
  };
294
294
  }
295
295
  const embedded = located.originDigest ?? (located.originalBytes !== undefined ? sha256(located.originalBytes) : undefined);
@@ -306,19 +306,19 @@ function admit(bound: BoundSet, fusedBytes: Uint8Array, row: SetMember): Admitte
306
306
 
307
307
  /** The stray's two-part reason: made after the slot, yet not in the committed set. */
308
308
  function strayReason(span: FuseSpan | null, memberCount: number): string {
309
- const slot = span !== null ? `the slot allocated at position ${span.slotCounter}` : "its slot";
309
+ const slot = span !== null ? `position ${span.slotCounter}` : "its reserved position";
310
310
  const commit = span !== null ? `committed at position ${span.commitCounter}` : "at its commit";
311
- return `these bytes carry the commitment of ${slot}, so they were made after that slot existed, but their digest is not among the ${memberCount} members listed in the set manifest ${commit}; the set proof does not cover them`;
311
+ return `these bytes carry the position commitment of ${slot}, so they were made after that position existed, but their digest is not among the ${memberCount} members listed in the set manifest ${commit}; the set proof does not cover them`;
312
312
  }
313
313
 
314
314
  /** set/2: the two-part reason when the floor holds but no evidence, or evidence for another member, is in hand. */
315
315
  function unprovenReason(span: FuseSpan | null, memberCount: number, otherMember: boolean): string {
316
- const slot = span !== null ? `the slot allocated at position ${span.slotCounter}` : "its slot";
316
+ const slot = span !== null ? `position ${span.slotCounter}` : "its reserved position";
317
317
  const commit = span !== null ? `committed at position ${span.commitCounter}` : "at its commit";
318
318
  const shown = otherMember
319
319
  ? "the member evidence in hand describes a different member, so"
320
320
  : "no member evidence (row, index, path) is in hand, so";
321
- return `these bytes carry the commitment of ${slot}, so they were made after that slot existed, but ${shown} their place among the ${memberCount} members of the set ${commit} is not shown; a set/2 proof covers a member only with its path`;
321
+ return `these bytes carry the position commitment of ${slot}, so they were made after that position existed, but ${shown} their place among the ${memberCount} members of the set ${commit} is not shown; a set/2 proof covers a member only with its path`;
322
322
  }
323
323
 
324
324
  export async function verifyFuseMember(opts: FuseMemberOptions): Promise<FuseMemberResult> {
@@ -536,7 +536,7 @@ export async function verifyFuseMember(opts: FuseMemberOptions): Promise<FuseMem
536
536
  return base(
537
537
  "RECONSTRUCTION_MISMATCH",
538
538
  { ...withSet, placement: candidates[0] ?? null, originDigestB64: fileDigestB64 },
539
- `rebuilding ${candidates.join(" or ")} from this file and the proof's slot record does not reproduce the listed member digest`,
539
+ `rebuilding ${candidates.join(" or ")} from this file and the proof's position record does not reproduce the listed member digest`,
540
540
  );
541
541
  }
542
542
 
@@ -554,7 +554,7 @@ export async function verifyFuseMember(opts: FuseMemberOptions): Promise<FuseMem
554
554
  const other = bound.rows.length > 0;
555
555
  return base(other ? "INVALID_SET_PATH" : "SET_MEMBERSHIP_UNPROVEN", { ...withSet, placement: p.id, statements: [] }, unprovenReason(span, bound.count, other));
556
556
  }
557
- return base("NO_MATCH", withSet, "these bytes carry a commitment to a different slot; the proof proves nothing about them");
557
+ return base("NO_MATCH", withSet, "these bytes carry a commitment to a different position; the proof proves nothing about them");
558
558
  }
559
- return base("NO_MATCH", withSet, "this file is neither a listed member nor a listed original and carries no commitment to this slot; the proof proves nothing about it");
559
+ return base("NO_MATCH", withSet, "this file is neither a listed member nor a listed original and carries no commitment to this position; the proof proves nothing about it");
560
560
  }
@@ -126,7 +126,7 @@ export function spanOf(proof: BitGraphProof): FuseSpan | null {
126
126
 
127
127
  /** The floor sentence every fused verdict ends with: bounded below by the slot, above by the commit. */
128
128
  export function floorStatement(span: FuseSpan): string {
129
- return `The exact fused bytes could not feasibly have been finalized before their signed slot allocation at position ${span.slotCounter}, and were committed no later than position ${span.commitCounter}.`;
129
+ return `The exact fused bytes could not feasibly have been finalized before position ${span.slotCounter} was reserved and signed for them, and were committed no later than position ${span.commitCounter}.`;
130
130
  }
131
131
 
132
132
  function statements(category: FuseCategory, span: FuseSpan | null, originMatched: boolean): string[] {
@@ -163,8 +163,8 @@ function statements(category: FuseCategory, span: FuseSpan | null, originMatched
163
163
  function inlineStatements(span: FuseSpan | null, offset: number): string[] {
164
164
  if (span === null) return [];
165
165
  return [
166
- `The enclave signed the slot at position ${span.slotCounter} before this artifact's digest reached it.`,
167
- `These exact bytes contain that slot's commitment, first at byte ${offset}, so they were assembled after the slot existed and were committed at position ${span.commitCounter}.`,
166
+ `The enclave reserved and signed position ${span.slotCounter} before this artifact's digest reached it.`,
167
+ `These exact bytes contain that position's commitment, first at byte ${offset}, so they were assembled after position ${span.slotCounter} existed and were committed at position ${span.commitCounter}.`,
168
168
  ];
169
169
  }
170
170
 
@@ -341,7 +341,7 @@ export async function verifyFuse(opts: FuseVerifyOptions): Promise<FuseVerifyRes
341
341
  "RECONSTRUCTION_MISMATCH",
342
342
  { ...common, slotCommitmentB64, placement: declared?.id ?? null },
343
343
  declared !== undefined
344
- ? `rebuilding ${declared.id} from this file and the proof's slot record does not reproduce the committed artifact digest`
344
+ ? `rebuilding ${declared.id} from this file and the proof's position record does not reproduce the committed artifact digest`
345
345
  : "no registered byte-exact placement rebuilds the committed artifact digest from this file",
346
346
  );
347
347
  }
package/src/index.ts CHANGED
@@ -102,3 +102,15 @@ export type {
102
102
  } from "./carrier.js";
103
103
  export { verifyCarrier } from "./carrier-verify.js";
104
104
  export type { CarrierVerifyResult } from "./carrier-verify.js";
105
+
106
+ // Ceiling in time on Base (bitgraph-ceiling/1): a sidecar beside the proof, never inside it.
107
+ export {
108
+ CEILING_VERSION, CEILING_MAGIC, CEILING_PAYLOAD_BYTES,
109
+ encodeCeilingPayload, decodeCeilingPayload, ceilingPayloadHash, ceilingLeaf, ceilingLabel,
110
+ verifyCeiling, checkCeilingOnline,
111
+ } from "./ceiling.js";
112
+ export type { CeilingSidecar, CeilingStatus, CeilingPayload, CeilingCheck, CeilingVerifyResult, CeilingVerifyOptions } from "./ceiling.js";
113
+ export { rlpEncode, rlpDecode, decodeHeader, decodeEip1559, mptVerify, txTrieKey, keccak256,
114
+ hexToBytes as evmHexToBytes, bytesToHex as evmBytesToHex } from "./ceiling-evm.js";
115
+ export { txTrieProof } from "./ceiling-trie.js";
116
+ export type { RlpItem, DecodedHeader, DecodedTx } from "./ceiling-evm.js";
package/src/verifier.ts CHANGED
@@ -618,7 +618,7 @@ function checkPolicy(proof: BitGraphProof, policy: VerificationPolicy): string |
618
618
  // Slot allocation required (BitGraph causal ordering)
619
619
  if (policy.requireSlot === true) {
620
620
  if (proof.slotAllocation === undefined) {
621
- return "policy requires slotAllocation (BitGraph causal slot) but proof has none";
621
+ return "policy requires slotAllocation (the reserved position's record) but proof has none";
622
622
  }
623
623
  // Slot verification itself is handled in step 4c (before policy checks),
624
624
  // so by this point the slot has already been validated if present.
@@ -971,7 +971,7 @@ async function verifySlotAllocation(proof: BitGraphProof): Promise<string | null
971
971
  return "commit.slotHashB64 is not valid base64";
972
972
  }
973
973
  if (!constantTimeEqual(computedSlotHash, proofSlotHash)) {
974
- return "commit.slotHashB64 does not match SHA-256 of canonical slot body — slot binding broken";
974
+ return "commit.slotHashB64 does not match SHA-256 of the canonical position record: position binding broken";
975
975
  }
976
976
 
977
977
  // 5. Verify nonce binding: slot nonce === commit nonce
@@ -987,7 +987,7 @@ async function verifySlotAllocation(proof: BitGraphProof): Promise<string | null
987
987
  return "commit.slotCounter does not match slotAllocation.counter";
988
988
  }
989
989
  if (proof.commit.counter === undefined) {
990
- return "commit.counter must be present for slot ordering verification";
990
+ return "commit.counter must be present for position ordering verification";
991
991
  }
992
992
  try {
993
993
  const slotCounter = BigInt(slot.counter);
@@ -996,7 +996,7 @@ async function verifySlotAllocation(proof: BitGraphProof): Promise<string | null
996
996
  return `slotAllocation.counter (${slot.counter}) must be less than commit.counter (${proof.commit.counter})`;
997
997
  }
998
998
  } catch {
999
- return "could not parse slot or commit counter as integer";
999
+ return "could not parse the reserved or commit counter as an integer";
1000
1000
  }
1001
1001
 
1002
1002
  // 7. Verify same enclave: same public key
package/dist/run.d.ts DELETED
@@ -1,59 +0,0 @@
1
- import type { BitGraphProof, VerificationPolicy } from "./types.js";
2
- import { type FuseSpan } from "./fuse-verify.js";
3
- /** The signed profile id: attribution.name on a run proof. */
4
- export declare const RUN_PROFILE = "bitgraph-run/1";
5
- /**
6
- * The only encoding this build registers: the commitment as unpadded base64url
7
- * ASCII, the form a producer pastes into a prompt, a message or a header. It is
8
- * attribution.title on a run proof.
9
- */
10
- export declare const RUN_ENCODING_BASE64URL = "base64url";
11
- export type RunCategory = "RUN_CONFIRMED" | "COMMITMENT_ABSENT" | "INVALID_SLOT_COMMITMENT" | "INVALID_UNDERLYING_PROOF" | "UNDETERMINED_ENCODING" | "NOT_A_RUN";
12
- export interface RunMarker {
13
- /** attribution.title: how the commitment appears in the bytes. */
14
- encoding: string | null;
15
- /** attribution.message: the commitment the producer declared, as written. */
16
- declaredCommitment: string | null;
17
- }
18
- export interface RunVerifyResult {
19
- category: RunCategory;
20
- /** The underlying bitgraph/1 verification, reported on its own. */
21
- proof: {
22
- valid: boolean;
23
- reason?: string;
24
- };
25
- marker: RunMarker | null;
26
- /** Recomputed from the proof's slot record; null when the proof carries none. */
27
- slotCommitmentB64u: string | null;
28
- /** Byte offset of the first occurrence in the artifact, or null when absent. */
29
- offset: number | null;
30
- /** How many times it appears. One is the ordinary case; more is not an error. */
31
- occurrences: number;
32
- artifactDigestB64: string;
33
- fileDigestB64: string;
34
- span: FuseSpan | null;
35
- /** What this result establishes, bounded. */
36
- statements: string[];
37
- /** What it does not establish, stated so nothing has to be inferred. */
38
- limits: string[];
39
- reason: string | null;
40
- }
41
- export interface RunVerifyOptions {
42
- proof: BitGraphProof;
43
- bytes: Uint8Array;
44
- trustAnchors?: VerificationPolicy;
45
- }
46
- /** The marker a run proof carries, or null when it is not a run proof. */
47
- export declare function readRunAttribution(proof: BitGraphProof): RunMarker | null;
48
- /** The attribution a producer sends when committing a run. */
49
- export declare function runAttribution(commitment: Uint8Array | string): {
50
- name: string;
51
- title: string;
52
- message: string;
53
- };
54
- /**
55
- * Verify a bitgraph-run/1 artifact from its own bytes. Nothing here touches the
56
- * network, and nothing is rebuilt: a run has no original to rebuild from.
57
- */
58
- export declare function verifyRun(opts: RunVerifyOptions): Promise<RunVerifyResult>;
59
- //# sourceMappingURL=run.d.ts.map
package/dist/run.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGpE,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzD,8DAA8D;AAC9D,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAElD,MAAM,MAAM,WAAW,GACnB,eAAe,GACf,mBAAmB,GACnB,yBAAyB,GACzB,0BAA0B,GAC1B,uBAAuB,GACvB,WAAW,CAAC;AAEhB,MAAM,WAAW,SAAS;IACxB,kEAAkE;IAClE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,6EAA6E;IAC7E,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,WAAW,CAAC;IACtB,mEAAmE;IACnE,KAAK,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,iFAAiF;IACjF,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,gFAAgF;IAChF,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,EAAE,UAAU,CAAC;IAClB,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC;AAKD,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,CAOzE;AAED,8DAA8D;AAC9D,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAMhH;AA0BD;;;GAGG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CA8DhF"}