@mikeargento/bitgraph-verify 1.24.0 → 1.26.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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/__tests__/carrier2.test.js +1 -1
  3. package/dist/__tests__/carrier2.test.js.map +1 -1
  4. package/dist/__tests__/carrier5.test.d.ts +9 -0
  5. package/dist/__tests__/carrier5.test.d.ts.map +1 -0
  6. package/dist/__tests__/carrier5.test.js +62 -0
  7. package/dist/__tests__/carrier5.test.js.map +1 -0
  8. package/dist/__tests__/epoch-genesis.test.d.ts +7 -0
  9. package/dist/__tests__/epoch-genesis.test.d.ts.map +1 -0
  10. package/dist/__tests__/epoch-genesis.test.js +61 -0
  11. package/dist/__tests__/epoch-genesis.test.js.map +1 -0
  12. package/dist/carrier-verify.d.ts +1 -1
  13. package/dist/carrier-verify.d.ts.map +1 -1
  14. package/dist/carrier-verify.js +5 -1
  15. package/dist/carrier-verify.js.map +1 -1
  16. package/dist/carrier.d.ts +10 -2
  17. package/dist/carrier.d.ts.map +1 -1
  18. package/dist/carrier.js +20 -1
  19. package/dist/carrier.js.map +1 -1
  20. package/dist/carrier5.d.ts +24 -0
  21. package/dist/carrier5.d.ts.map +1 -0
  22. package/dist/carrier5.js +93 -0
  23. package/dist/carrier5.js.map +1 -0
  24. package/dist/epoch-genesis.d.ts +61 -0
  25. package/dist/epoch-genesis.d.ts.map +1 -0
  26. package/dist/epoch-genesis.js +171 -0
  27. package/dist/epoch-genesis.js.map +1 -0
  28. package/dist/index.d.ts +5 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +6 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/tree-member.d.ts +22 -0
  33. package/dist/tree-member.d.ts.map +1 -1
  34. package/dist/tree-member.js +27 -0
  35. package/dist/tree-member.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/__tests__/carrier2.test.ts +1 -1
  38. package/src/__tests__/carrier5.test.ts +65 -0
  39. package/src/__tests__/epoch-genesis.test.ts +71 -0
  40. package/src/__tests__/fixtures/carrier5/ceiling.json +95 -0
  41. package/src/__tests__/fixtures/carrier5/proof.json +53 -0
  42. package/src/__tests__/fixtures/carrier5/single.txt +1 -0
  43. package/src/carrier-verify.ts +6 -3
  44. package/src/carrier.ts +19 -3
  45. package/src/carrier5.ts +105 -0
  46. package/src/epoch-genesis.ts +184 -0
  47. package/src/index.ts +7 -0
  48. package/src/tree-member.ts +26 -1
@@ -0,0 +1,105 @@
1
+ // Copyright (c) Argento Computing Inc. All rights reserved. See LICENSE.
2
+
3
+ /**
4
+ * The BitGraphed file, version 5 (2026-10-20): a file that carries its own proof, for proofs made in one atomic action
5
+ * (enclave v11 on). The bytes are the file exactly as it was bound, then the block (carrier.ts framing) holding:
6
+ *
7
+ * { carrier: "bitgraph-carrier/5", proof, ceilingInTime }
8
+ *
9
+ * proof the bitgraph/1 proof as the ledger serves it for these bytes. For a file of a tree (every drop on
10
+ * bitgraph.ing from 2026-10-20) it carries, in its unsigned metadata, the file's bitgraph-tree-member/1
11
+ * block: its path to the bound root, and the tree's floor leaf, base-block.json (the latest Base block
12
+ * read just before the bind).
13
+ * ceilingInTime the proof's Base ceiling (bitgraph-ceiling/1: the batch transaction, its block header, the trie and
14
+ * Merkle paths), or "unfetched".
15
+ *
16
+ * Checked offline, in this order: the bytes before the block are the bound bytes (directly, or as the member the tree
17
+ * names); the proof is BitGraph's (verifyAttested: signature, atomic counts, AWS Nitro attestation, published image);
18
+ * the floor block is a leaf of the very tree the proof binds, and the attested bind time is after its timestamp; the
19
+ * ceiling's batch holds this proof and its transaction is in the Base block it names. Whether those two Base blocks are
20
+ * on Base's canonical chain is a check against Base (Basescan), not one a file can carry.
21
+ */
22
+
23
+ import { sha256 } from "@noble/hashes/sha256";
24
+ import { CARRIER_VERSION_5, buildCarrier, type CarrierPayload, type CarrierBounds } from "./carrier.js";
25
+ import { verifyAttested } from "./attested.js";
26
+ import { verifyCeiling, type CeilingSidecar } from "./ceiling.js";
27
+ import { checkTreeFloor, treeMemberOf } from "./tree-member.js";
28
+ import type { BitGraphProof } from "./types.js";
29
+ import type { CarrierClaim, CarrierVerifyResult, ClaimResult } from "./carrier-verify.js";
30
+
31
+ export const BITGRAPH_CEILING_WRITER_V5 = "0xf3972408D853c975F86351C311f4310220bbF2a3";
32
+ const BASE_CHAIN_ID = 8453;
33
+
34
+ export interface CarrierV5Payload {
35
+ carrier: typeof CARRIER_VERSION_5;
36
+ proof: Record<string, unknown>;
37
+ ceilingInTime: { status: "unfetched" } | { status: "present"; sidecar: Record<string, unknown> };
38
+ }
39
+
40
+ /** The v5 payload for a proof (as the ledger serves it for these bytes) and its ceiling sidecar, if written yet. */
41
+ export function assembleCarrierV5Payload(proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null): CarrierV5Payload {
42
+ return { carrier: CARRIER_VERSION_5, proof, ceilingInTime: ceilingSidecar ? { status: "present", sidecar: ceilingSidecar } : { status: "unfetched" } };
43
+ }
44
+
45
+ /** The BitGraphed file: the bound bytes, unchanged, followed by the v5 block. */
46
+ export function buildBitGraphedFileV5(bytes: Uint8Array, proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null): Uint8Array {
47
+ return buildCarrier(bytes, assembleCarrierV5Payload(proof, ceilingSidecar) as unknown as CarrierPayload);
48
+ }
49
+
50
+ const hex = (b: Uint8Array) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
51
+ const iso = (s: number) => new Date(s * 1000).toISOString().replace(".000Z", "Z");
52
+
53
+ export async function verifyCarrierV5(payloadIn: CarrierPayload, inner: Uint8Array | null, opts: { pcr0?: readonly string[]; rootDer?: Uint8Array } = {}): Promise<CarrierVerifyResult> {
54
+ const payload = payloadIn as unknown as CarrierV5Payload;
55
+ const proof = payload.proof as unknown as BitGraphProof;
56
+ const claims: CarrierClaim[] = [];
57
+ const add = (id: string, name: string, result: ClaimResult, restsOn: string, detail: string) => claims.push({ id, name, result, restsOn, detail, level: "offline" });
58
+ const member = treeMemberOf(proof);
59
+
60
+ // 1 + 2. The bytes, and the proof: verifyAttested walks a member's hash up its path first, then checks the proof
61
+ // against the root text it signs; plain bytes are checked against the proof's digest.
62
+ const r = await verifyAttested({ proof, ...(inner ? { bytes: inner } : {}), ...(opts.pcr0 ? { pcr0: opts.pcr0 } : {}), ...(opts.rootDer ? { rootDer: opts.rootDer } : {}) });
63
+ if (!inner) add("bytes.digest", "The file is the bound bytes", "NOT_CARRIED", "SHA-256", "no file in hand");
64
+ else if (member) add("tree.member", "The file is in the tree the proof binds", r.treeMember ? "TRUE" : "FALSE", "SHA-256", r.treeMember ? `file ${r.treeMember.index + 1} of ${r.treeMember.files}: its hash walks up the tree to the root the proof binds` : (r.reason ?? "its hash does not reach the root"));
65
+ else add("bytes.digest", "The file is the bound bytes", r.valid || !/digest/.test(r.reason ?? "") ? "TRUE" : "FALSE", "SHA-256", "the bytes before the block hash to the proof's digest");
66
+ for (const c of r.checks) add(`attestation.${c.name.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`, c.name, c.pass ? "TRUE" : "FALSE", "the AWS Nitro attestation", c.detail);
67
+ add("attestation.pins", "The image is one BitGraph published", r.image ? "TRUE" : "FALSE", "BitGraph's published enclave images", r.image ? `PCR0 ${String(r.pcr0).slice(0, 16)}… is the ${r.image.version} image` : `PCR0 ${String(r.pcr0 ?? "").slice(0, 16)}… is not one of BitGraph's`);
68
+ add("proof.signature", "The signature, the nonce's record and the two consecutive counts", r.valid ? "TRUE" : "FALSE", "Ed25519", r.valid ? "the enclave's key signed this body" : (r.reason ?? "did not verify"));
69
+
70
+ // 3. The floor: a leaf of the very tree the proof binds, and before the attested bind time.
71
+ let notBefore: CarrierBounds["notBefore"] | null = null;
72
+ if (member?.floor) {
73
+ const f = checkTreeFloor(proof, member);
74
+ const after = f !== null && r.attestedAtMs !== null && r.attestedAtMs >= f.timestamp * 1000;
75
+ add("floor.leaf", "The floor block is a leaf of the tree the proof binds", f ? "TRUE" : "FALSE", "SHA-256", f ? `Base block ${f.number} (${f.hash.slice(0, 12)}…): base-block.json walks up the tree to the bound root, so the bind came after this block existed` : "base-block.json does not reach the bound root");
76
+ if (f) {
77
+ add("floor.time", "The bind came after the floor block's time", after ? "TRUE" : "FALSE", "the AWS Nitro attestation's time", after ? `bound ${iso(Math.floor(r.attestedAtMs! / 1000))}, block ${iso(f.timestamp)}` : "the attested bind time is not after the block's time");
78
+ notBefore = { chain: "base", blockNumber: f.number, blockHash: f.hash, timestamp: f.timestamp };
79
+ }
80
+ }
81
+
82
+ // 4. The ceiling: this proof's hash is in the batch the Base transaction carries, and that transaction is in its block.
83
+ let existedBy: CarrierBounds["existedBy"] = null;
84
+ if (payload.ceilingInTime.status === "present") {
85
+ const c = await verifyCeiling(proof, payload.ceilingInTime.sidecar as unknown as CeilingSidecar, { writerAddress: BITGRAPH_CEILING_WRITER_V5, chainId: BASE_CHAIN_ID, proofAlreadyVerified: r.valid });
86
+ const w = c.window?.ceiling;
87
+ add("ceiling.time", "Written to Base, in a batch from BitGraph's writer", c.ok ? "TRUE" : "FALSE", "Base: the batch root, the transaction and the block header", c.ok && w ? `Base block ${w.blockNumber} (${iso(w.blockTimestamp)}): the proof existed by then` : (c.reason ?? "the ceiling does not verify"));
88
+ if (c.ok && w) existedBy = { chain: "base", blockNumber: w.blockNumber, blockHash: w.blockHash, timestamp: w.blockTimestamp };
89
+ } else add("ceiling.time", "Written to Base", "NOT_CARRIED", "", "this file was made before the Base write landed; the ceiling can be looked up by the proof's hash");
90
+
91
+ const failed = claims.filter((c) => c.result === "FALSE");
92
+ const verdict: CarrierVerifyResult["verdict"] = failed.length > 0 ? "FALSE" : r.valid ? "TRUE" : "UNDETERMINED";
93
+ const where = member ? `file ${member.index + 1} of a tree of ${member.files}` : "these exact bytes";
94
+ const reading = verdict === "TRUE"
95
+ ? `BitGraph #${proof.commit?.counter}: ${where}, bound by BitGraph's published enclave image ${r.image?.version ?? ""}${notBefore ? ` after Base block ${notBefore.blockNumber}` : ""}${existedBy ? ` and written to Base by block ${existedBy.blockNumber}` : ""}. Check those blocks on Base to place it in real time.`
96
+ : `This BitGraphed file does not check: ${failed.map((c) => c.detail).join("; ") || "the proof did not verify"}.`;
97
+ return {
98
+ verdict, carrier: "ok", version: 5, reasons: claims.filter((c) => c.result !== "TRUE" && c.result !== "NOT_CARRIED").map((c) => c.detail),
99
+ bounds: notBefore ? { notBefore, notAfter: null, existedBy, settledBy: null } : null,
100
+ ceiling: null, claims, reading, payload: payloadIn, inner,
101
+ };
102
+ }
103
+
104
+ /** The bound bytes' SHA-256 as hex (for callers printing the envelope rule). */
105
+ export const innerHex = (inner: Uint8Array) => hex(sha256(inner));
@@ -0,0 +1,184 @@
1
+ // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
+
3
+ /**
4
+ * bitgraph-epoch-genesis/1: an epoch opens with a write to Base, not a read of it.
5
+ *
6
+ * A block read bound as an epoch's first BitGraph proves the epoch began after that block, but the host chooses
7
+ * the block, so an old one makes the floor loose, and nothing in the proofs says how old. With a genesis
8
+ * transaction the choice is gone. The host puts the new epoch's id in a Base transaction from the ceiling writer's
9
+ * address, waits for it to be mined, and binds a record of the mined transaction as the epoch's first BitGraph.
10
+ *
11
+ * - The transaction carries the epoch id, which is derived from the epoch's key, so the transaction could not be
12
+ * made before the key existed: the key is older than the block that holds the transaction.
13
+ * - BitGraph 1 binds the mined transaction, so it could not be made before that block: every BitGraph of the
14
+ * epoch is younger than that block.
15
+ *
16
+ * Epochs therefore order by their genesis blocks on Base alone, and the transactions are a public list of every
17
+ * epoch the writer opened. Calldata is "BGE1" followed by the 32 raw bytes of the epoch id. The record is a small
18
+ * JSON file whose SHA-256 BitGraph 1 binds; this module makes, parses and checks it.
19
+ */
20
+
21
+ import { sha256 } from "@noble/hashes/sha256";
22
+ import type { BitGraphProof } from "./types.js";
23
+
24
+ export const EPOCH_GENESIS_FORMAT = "bitgraph-epoch-genesis/1" as const;
25
+ export const EPOCH_GENESIS_REQUEST_FORMAT = "bitgraph-epoch-genesis-request/1" as const;
26
+ export const EPOCH_GENESIS_MAGIC = "BGE1";
27
+
28
+ export interface EpochGenesisFile {
29
+ format: typeof EPOCH_GENESIS_FORMAT;
30
+ epochId: string;
31
+ chain: "base-mainnet" | "base-sepolia";
32
+ chainId: 8453 | 84532;
33
+ /** The sending (and receiving) address, lowercase 0x hex: the ceiling writer's. */
34
+ writer: string;
35
+ txHash: string;
36
+ blockNumber: number;
37
+ blockHash: string;
38
+ blockTimestamp: number;
39
+ note: string;
40
+ }
41
+
42
+ const enc = new TextEncoder();
43
+
44
+ function b64ToBytes(s: string): Uint8Array | null {
45
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(s) || s.length % 4 !== 0) return null;
46
+ const bin = typeof atob === "function" ? atob(s) : Buffer.from(s, "base64").toString("binary");
47
+ const out = new Uint8Array(bin.length);
48
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
49
+ return out;
50
+ }
51
+
52
+ function bytesToB64(u: Uint8Array): string {
53
+ let bin = "";
54
+ for (const x of u) bin += String.fromCharCode(x);
55
+ return typeof btoa === "function" ? btoa(bin) : Buffer.from(bin, "binary").toString("base64");
56
+ }
57
+
58
+ const hex = (u: Uint8Array): string => Array.from(u, (b) => b.toString(16).padStart(2, "0")).join("");
59
+
60
+ /** "BGE1" || the 32 raw bytes of the epoch id: what the genesis transaction carries. */
61
+ export function epochGenesisCalldata(epochId: string): Uint8Array {
62
+ const id = b64ToBytes(epochId);
63
+ if (id === null || id.length !== 32) throw new TypeError("an epoch id is 32 bytes in standard base64");
64
+ const out = new Uint8Array(4 + 32);
65
+ out.set(enc.encode(EPOCH_GENESIS_MAGIC), 0);
66
+ out.set(id, 4);
67
+ return out;
68
+ }
69
+
70
+ /** The calldata as 0x hex, as a node reports a transaction's input. */
71
+ export function epochGenesisCalldataHex(epochId: string): string {
72
+ return "0x" + hex(epochGenesisCalldata(epochId));
73
+ }
74
+
75
+ /** The epoch id carried by calldata, or null when the bytes are not a genesis. */
76
+ export function epochIdOfCalldata(input: string | Uint8Array): string | null {
77
+ let bytes: Uint8Array;
78
+ if (typeof input === "string") {
79
+ const h = input.startsWith("0x") ? input.slice(2) : input;
80
+ if (!/^[0-9a-fA-F]*$/.test(h) || h.length % 2 !== 0) return null;
81
+ bytes = new Uint8Array(h.length / 2);
82
+ for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
83
+ } else bytes = input;
84
+ if (bytes.length !== 36) return null;
85
+ for (let i = 0; i < 4; i++) if (bytes[i] !== EPOCH_GENESIS_MAGIC.charCodeAt(i)) return null;
86
+ return bytesToB64(bytes.slice(4));
87
+ }
88
+
89
+ const CHAIN_NAMES = { 8453: "base-mainnet", 84532: "base-sepolia" } as const;
90
+
91
+ /** The file's text, byte for byte, as the writer makes it and the epoch's first BitGraph binds it. */
92
+ export function epochGenesisFileText(f: Omit<EpochGenesisFile, "format" | "chain" | "note">): string {
93
+ const chain = CHAIN_NAMES[f.chainId];
94
+ const body: EpochGenesisFile = {
95
+ format: EPOCH_GENESIS_FORMAT,
96
+ epochId: f.epochId,
97
+ chain,
98
+ chainId: f.chainId,
99
+ writer: f.writer.toLowerCase(),
100
+ txHash: f.txHash.toLowerCase(),
101
+ blockNumber: f.blockNumber,
102
+ blockHash: f.blockHash.toLowerCase(),
103
+ blockTimestamp: f.blockTimestamp,
104
+ note: `The first BitGraph of this epoch. Base transaction ${f.txHash.toLowerCase()} carries this epoch's id and was mined in block ${f.blockNumber}, so this epoch's key existed before that block and every BitGraph of this epoch was made after it.`,
105
+ };
106
+ return JSON.stringify(body, null, 2) + "\n";
107
+ }
108
+
109
+ /** Strict: the format, a 32-byte epoch id, a known chain, hex hashes, integers. Null otherwise. */
110
+ export function parseEpochGenesisFile(text: string): EpochGenesisFile | null {
111
+ let o: Record<string, unknown>;
112
+ try { o = JSON.parse(text) as Record<string, unknown>; } catch { return null; }
113
+ if (!o || typeof o !== "object" || o["format"] !== EPOCH_GENESIS_FORMAT) return null;
114
+ const epochId = o["epochId"];
115
+ if (typeof epochId !== "string" || b64ToBytes(epochId)?.length !== 32) return null;
116
+ const chainId = o["chainId"];
117
+ if (chainId !== 8453 && chainId !== 84532) return null;
118
+ if (o["chain"] !== CHAIN_NAMES[chainId]) return null;
119
+ const writer = o["writer"], txHash = o["txHash"], blockHash = o["blockHash"];
120
+ if (typeof writer !== "string" || !/^0x[0-9a-f]{40}$/.test(writer)) return null;
121
+ if (typeof txHash !== "string" || !/^0x[0-9a-f]{64}$/.test(txHash)) return null;
122
+ if (typeof blockHash !== "string" || !/^0x[0-9a-f]{64}$/.test(blockHash)) return null;
123
+ const blockNumber = o["blockNumber"], blockTimestamp = o["blockTimestamp"];
124
+ if (!Number.isSafeInteger(blockNumber) || (blockNumber as number) < 0) return null;
125
+ if (!Number.isSafeInteger(blockTimestamp) || (blockTimestamp as number) < 0) return null;
126
+ const note = typeof o["note"] === "string" ? o["note"] : "";
127
+ return { format: EPOCH_GENESIS_FORMAT, epochId, chain: CHAIN_NAMES[chainId], chainId, writer, txHash, blockNumber: blockNumber as number, blockHash, blockTimestamp: blockTimestamp as number, note };
128
+ }
129
+
130
+ /** What a node says about the transaction, from eth_getTransactionByHash. */
131
+ export interface EpochGenesisTx {
132
+ from: string;
133
+ to: string | null;
134
+ input: string;
135
+ blockHash: string | null;
136
+ blockNumber: number | null;
137
+ }
138
+
139
+ /** What a node says about the block, from eth_getBlockByHash. */
140
+ export interface EpochGenesisBlock {
141
+ hash: string;
142
+ number: number;
143
+ timestamp: number;
144
+ }
145
+
146
+ export interface EpochGenesisCheck {
147
+ ok: boolean;
148
+ reasons: string[];
149
+ genesis: EpochGenesisFile | null;
150
+ }
151
+
152
+ /**
153
+ * Check a genesis record against the epoch's first BitGraph and, when given, against what Base says.
154
+ *
155
+ * The file must hash to the proof's digest; the proof must be the epoch's first (counts 1 and 2) and name the
156
+ * file's epoch; the transaction, when supplied, must be the writer's self-addressed transaction carrying this
157
+ * epoch's id, mined in the block the file names; the block, when supplied, must be that block with that time.
158
+ * Without `tx` and `block` only the file and the proof are checked (offline).
159
+ */
160
+ export function checkEpochGenesis(args: { file: string; proof: BitGraphProof; tx?: EpochGenesisTx | null; block?: EpochGenesisBlock | null }): EpochGenesisCheck {
161
+ const reasons: string[] = [];
162
+ const genesis = parseEpochGenesisFile(args.file);
163
+ if (!genesis) return { ok: false, reasons: ["the file is not a bitgraph-epoch-genesis/1 record"], genesis: null };
164
+ const digest = bytesToB64(sha256(enc.encode(args.file)));
165
+ if (digest !== args.proof.artifact?.digestB64) reasons.push("the file does not hash to the proof's digest");
166
+ const commit = args.proof.commit as { counter?: string; slotCounter?: string; epochId?: string };
167
+ if (commit.epochId !== genesis.epochId) reasons.push("the proof is not of the epoch the file names");
168
+ if (commit.slotCounter !== "1" || commit.counter !== "2") reasons.push("the proof is not the epoch's first BitGraph (counts 1 and 2)");
169
+ if (args.tx) {
170
+ const t = args.tx;
171
+ if (t.from.toLowerCase() !== genesis.writer) reasons.push("the transaction was not sent by the writer the file names");
172
+ if ((t.to ?? "").toLowerCase() !== genesis.writer) reasons.push("the transaction is not self-addressed to the writer");
173
+ if (t.input.toLowerCase() !== epochGenesisCalldataHex(genesis.epochId)) reasons.push("the transaction does not carry this epoch's id");
174
+ if ((t.blockHash ?? "").toLowerCase() !== genesis.blockHash) reasons.push("the transaction is not in the block the file names");
175
+ if (t.blockNumber !== null && t.blockNumber !== genesis.blockNumber) reasons.push("the transaction's block number is not the one the file names");
176
+ }
177
+ if (args.block) {
178
+ const b = args.block;
179
+ if (b.hash.toLowerCase() !== genesis.blockHash) reasons.push("Base's block hash differs from the file's");
180
+ if (b.number !== genesis.blockNumber) reasons.push("Base's block number differs from the file's");
181
+ if (b.timestamp !== genesis.blockTimestamp) reasons.push("Base's block time differs from the file's");
182
+ }
183
+ return { ok: reasons.length === 0, reasons, genesis };
184
+ }
package/src/index.ts CHANGED
@@ -149,6 +149,10 @@ export type { CarrierV3Parts } from "./carrier-assemble.js";
149
149
 
150
150
  /* bitgraph-carrier/4 (2026-10-11): one member of a tree/1 BitGraph carries its own proof: the bytes are the leaf's, the block walks them to the signed root document. */
151
151
  export { CARRIER_VERSION_4, memberArtifactDigest } from "./carrier.js";
152
+ // The BitGraphed file for atomic proofs: the proof (with its tree path and floor leaf) and its Base ceiling (2026-10-20).
153
+ export { CARRIER_VERSION_5 } from "./carrier.js";
154
+ export { assembleCarrierV5Payload, buildBitGraphedFileV5, verifyCarrierV5, type CarrierV5Payload } from "./carrier5.js";
155
+ export { checkTreeFloor, BASE_BLOCK_FORMAT, type TreeFloor, type TreeFloorBlock } from "./tree-member.js";
152
156
  export type { CarrierTree } from "./carrier.js";
153
157
  export { assembleCarrierV4Payload } from "./carrier-assemble.js";
154
158
  export type { CarrierV4Parts } from "./carrier-assemble.js";
@@ -203,3 +207,6 @@ export type { RpcBlockHeader } from "./ceiling.js";
203
207
  export { PUBLISHED_ENCLAVE_MEASUREMENTS, PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
204
208
  export type { PublishedMeasurement } from "./measurements.js";
205
209
  export type { BitGraphExport, ExportClaim, ExportClaimResult, ExportLookups, ExportVerifyOptions, ExportVerifyResult } from "./export.js";
210
+ /* bitgraph-epoch-genesis/1 (2026-10-23): an epoch opens with a Base write carrying its id; the epoch's first BitGraph binds the mined transaction's record. */
211
+ export { EPOCH_GENESIS_FORMAT, EPOCH_GENESIS_REQUEST_FORMAT, EPOCH_GENESIS_MAGIC, epochGenesisCalldata, epochGenesisCalldataHex, epochIdOfCalldata, epochGenesisFileText, parseEpochGenesisFile, checkEpochGenesis } from "./epoch-genesis.js";
212
+ export type { EpochGenesisFile, EpochGenesisTx, EpochGenesisBlock, EpochGenesisCheck } from "./epoch-genesis.js";
@@ -21,7 +21,12 @@
21
21
  import { sha256 } from "@noble/hashes/sha256";
22
22
 
23
23
  export const TREE_MEMBER_METADATA_KEY = "bitgraph-tree-member/1" as const;
24
- export interface TreeMemberBlock { format: typeof TREE_MEMBER_METADATA_KEY; files: number; index: number; path: string; rootText: string }
24
+ /** The tree's floor (bitgraph.ing, 2026-10-20): base-block.json, the latest Base block read just before the bind, as the
25
+ * tree's first leaf; `file` is its exact text, `index` and `path` place it in the same tree. */
26
+ export interface TreeFloor { file: string; index: number; path: string }
27
+ export interface TreeMemberBlock { format: typeof TREE_MEMBER_METADATA_KEY; files: number; index: number; path: string; rootText: string; floor?: TreeFloor }
28
+ export const BASE_BLOCK_FORMAT = "bitgraph-base-block/1" as const;
29
+ export interface TreeFloorBlock { chain: string; chainId: number; number: number; hash: string; timestamp: number }
25
30
 
26
31
  const enc = new TextEncoder();
27
32
  const HEX = "0123456789abcdef";
@@ -96,5 +101,25 @@ export function checkTreeMember(proof: unknown, fileDigest: Uint8Array | string,
96
101
  return treeRootFromPath(sha256(cat(new Uint8Array([0]), d)), block.index, block.files, path) === parsed.root;
97
102
  }
98
103
 
104
+ /**
105
+ * The tree's floor block, when the member carries one and base-block.json is in the very tree the proof binds (its hash
106
+ * walks up its path to the root rootText names, and SHA-256(rootText) is what the proof signs). Null otherwise. That the
107
+ * block exists on Base with that hash and time is a separate check, against Base.
108
+ */
109
+ export function checkTreeFloor(proof: unknown, block: TreeMemberBlock | null = treeMemberOf(proof)): TreeFloorBlock | null {
110
+ const f = block?.floor;
111
+ if (!block || !f || typeof f.file !== "string" || typeof f.path !== "string" || !Number.isSafeInteger(f.index) || f.file.length > 2048) return null;
112
+ const parsed = parseDigestTreeRootText(block.rootText);
113
+ const bound = (proof as { artifact?: { digestB64?: string } } | null)?.artifact?.digestB64;
114
+ if (!parsed || parsed.files !== block.files || typeof bound !== "string" || unb64(bound) === null || b64(sha256(enc.encode(block.rootText))) !== b64(unb64(bound)!)) return null;
115
+ const path = unb64(f.path);
116
+ if (!path || treeRootFromPath(sha256(cat(new Uint8Array([0]), sha256(enc.encode(f.file)))), f.index, block.files, path) !== parsed.root) return null;
117
+ try {
118
+ const o = JSON.parse(f.file) as Partial<TreeFloorBlock> & { format?: string };
119
+ if (o.format !== BASE_BLOCK_FORMAT || typeof o.chain !== "string" || !Number.isSafeInteger(o.chainId) || !Number.isSafeInteger(o.number) || typeof o.hash !== "string" || !/^0x[0-9a-f]{64}$/i.test(o.hash) || !Number.isSafeInteger(o.timestamp)) return null;
120
+ return { chain: o.chain, chainId: o.chainId!, number: o.number!, hash: o.hash, timestamp: o.timestamp! };
121
+ } catch { return null; }
122
+ }
123
+
99
124
  /** The bytes a member's proof signs: its root text. */
100
125
  export const treeRootTextBytes = (block: TreeMemberBlock): Uint8Array => enc.encode(block.rootText);