@mikeargento/bitgraph-verify 1.26.0 → 1.28.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.
- package/dist/__tests__/block-read.test.d.ts +8 -0
- package/dist/__tests__/block-read.test.d.ts.map +1 -0
- package/dist/__tests__/block-read.test.js +104 -0
- package/dist/__tests__/block-read.test.js.map +1 -0
- package/dist/__tests__/epoch-genesis.test.js +8 -1
- package/dist/__tests__/epoch-genesis.test.js.map +1 -1
- package/dist/__tests__/measurements-windows.test.d.ts +7 -0
- package/dist/__tests__/measurements-windows.test.d.ts.map +1 -0
- package/dist/__tests__/measurements-windows.test.js +27 -0
- package/dist/__tests__/measurements-windows.test.js.map +1 -0
- package/dist/__tests__/timeline-bundle.test.d.ts +14 -0
- package/dist/__tests__/timeline-bundle.test.d.ts.map +1 -0
- package/dist/__tests__/timeline-bundle.test.js +448 -0
- package/dist/__tests__/timeline-bundle.test.js.map +1 -0
- package/dist/attested.d.ts +4 -2
- package/dist/attested.d.ts.map +1 -1
- package/dist/attested.js +40 -6
- package/dist/attested.js.map +1 -1
- package/dist/block-read.d.ts +66 -0
- package/dist/block-read.d.ts.map +1 -0
- package/dist/block-read.js +151 -0
- package/dist/block-read.js.map +1 -0
- package/dist/ceiling.d.ts +2 -2
- package/dist/ceiling.d.ts.map +1 -1
- package/dist/ceiling.js +8 -4
- package/dist/ceiling.js.map +1 -1
- package/dist/epoch-genesis.d.ts +8 -0
- package/dist/epoch-genesis.d.ts.map +1 -1
- package/dist/epoch-genesis.js +11 -1
- package/dist/epoch-genesis.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/measurements.d.ts +25 -0
- package/dist/measurements.d.ts.map +1 -1
- package/dist/measurements.js +34 -0
- package/dist/measurements.js.map +1 -1
- package/dist/timeline-bundle.d.ts +129 -0
- package/dist/timeline-bundle.d.ts.map +1 -0
- package/dist/timeline-bundle.js +271 -0
- package/dist/timeline-bundle.js.map +1 -0
- package/dist/timeline-export.d.ts +47 -0
- package/dist/timeline-export.d.ts.map +1 -0
- package/dist/timeline-export.js +102 -0
- package/dist/timeline-export.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/block-read.test.ts +119 -0
- package/src/__tests__/epoch-genesis.test.ts +9 -1
- package/src/__tests__/fixtures/v13/genesis-file.json +12 -0
- package/src/__tests__/fixtures/v13/proof-2.json +37 -0
- package/src/__tests__/fixtures/v13/proof-4.json +38 -0
- package/src/__tests__/fixtures/v13/proof-6.json +38 -0
- package/src/__tests__/measurements-windows.test.ts +31 -0
- package/src/__tests__/timeline-bundle.test.ts +495 -0
- package/src/attested.ts +39 -9
- package/src/block-read.ts +177 -0
- package/src/ceiling.ts +9 -6
- package/src/epoch-genesis.ts +12 -2
- package/src/index.ts +12 -2
- package/src/measurements.ts +51 -0
- package/src/timeline-bundle.ts +351 -0
- package/src/timeline-export.ts +121 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* bitgraph-block-read/1: a read of a public chain's block, bound as a plain BitGraph.
|
|
5
|
+
*
|
|
6
|
+
* The host reads the newest block of Base or Ethereum and binds the SHA-256 of a small JSON file naming
|
|
7
|
+
* it, the same bind as any file: a fresh nonce at count N, the file's digest at N+1. Block reads and files share
|
|
8
|
+
* one counter sequence, so a file's floor is the nearest block read before it and its ceiling the nearest block
|
|
9
|
+
* read after it. The block read cannot predate its block, because a block hash cannot be known before its block.
|
|
10
|
+
*
|
|
11
|
+
* The file names the chain (CAIP-2), the block's number, hash and timestamp, and the epoch, so no two epochs bind
|
|
12
|
+
* the same file. Only the hash is evidence. A verifier never takes the number or the timestamp from the file: it
|
|
13
|
+
* looks the hash up on the chain itself and takes both from there, and a hash that is not on the canonical chain
|
|
14
|
+
* fails (checkBlockRead). The file's number and timestamp are labels, and a file whose labels disagree with the
|
|
15
|
+
* chain fails too, because the host that wrote it misreported the block.
|
|
16
|
+
*
|
|
17
|
+
* Nothing here fetches anything; the caller supplies what the chain says.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
21
|
+
import type { BitGraphProof } from "./types.js";
|
|
22
|
+
|
|
23
|
+
export const BLOCK_READ_FORMAT = "bitgraph-block-read/1" as const;
|
|
24
|
+
|
|
25
|
+
/** Base and Ethereum only: their block timestamps follow real time closely enough for a time check. */
|
|
26
|
+
export type BlockReadChain = "base" | "ethereum";
|
|
27
|
+
|
|
28
|
+
/** Each chain's CAIP-2 ids, mainnet first. The test networks are for local runs. */
|
|
29
|
+
export const BLOCK_READ_CHAIN_IDS: Readonly<Record<BlockReadChain, readonly string[]>> = {
|
|
30
|
+
base: ["eip155:8453", "eip155:84532"],
|
|
31
|
+
ethereum: ["eip155:1", "eip155:11155111"],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface BlockReadFile {
|
|
35
|
+
format: typeof BLOCK_READ_FORMAT;
|
|
36
|
+
epochId: string;
|
|
37
|
+
chain: BlockReadChain;
|
|
38
|
+
chainId: string;
|
|
39
|
+
number: number;
|
|
40
|
+
/** 0x and 64 lowercase hex. */
|
|
41
|
+
hash: string;
|
|
42
|
+
/** The block's own timestamp, Unix seconds. */
|
|
43
|
+
timestamp: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const enc = new TextEncoder();
|
|
47
|
+
|
|
48
|
+
/** A block hash as Base and Ethereum show it: 0x and 64 lowercase hex. */
|
|
49
|
+
export function isBlockReadHash(chain: BlockReadChain, hash: string): boolean {
|
|
50
|
+
return (chain === "base" || chain === "ethereum") && /^0x[0-9a-f]{64}$/.test(hash);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The file's text, byte for byte, as the host makes it and the BitGraph binds it. Throws on a malformed block. */
|
|
54
|
+
export function blockReadFileText(f: Omit<BlockReadFile, "format">): string {
|
|
55
|
+
const body: BlockReadFile = {
|
|
56
|
+
format: BLOCK_READ_FORMAT,
|
|
57
|
+
epochId: f.epochId,
|
|
58
|
+
chain: f.chain,
|
|
59
|
+
chainId: f.chainId,
|
|
60
|
+
number: f.number,
|
|
61
|
+
hash: f.hash.toLowerCase(),
|
|
62
|
+
timestamp: f.timestamp,
|
|
63
|
+
};
|
|
64
|
+
const reasons = shapeReasons(body as unknown as Record<string, unknown>);
|
|
65
|
+
if (reasons.length > 0) throw new TypeError(`not a block read: ${reasons.join("; ")}`);
|
|
66
|
+
return JSON.stringify(body, null, 2) + "\n";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The digest a BitGraph of this file binds: SHA-256 of its text, standard base64. */
|
|
70
|
+
export function blockReadDigestB64(text: string): string {
|
|
71
|
+
return bytesToB64(sha256(enc.encode(text)));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Strict: the format, exactly its fields, a 32-byte epoch id, a known chain and CAIP-2 id, safe integers. Null otherwise. */
|
|
75
|
+
export function parseBlockReadFile(text: string): BlockReadFile | null {
|
|
76
|
+
let o: unknown;
|
|
77
|
+
try { o = JSON.parse(text); } catch { return null; }
|
|
78
|
+
if (!o || typeof o !== "object" || Array.isArray(o)) return null;
|
|
79
|
+
return shapeReasons(o as Record<string, unknown>).length === 0 ? (o as BlockReadFile) : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const FIELDS = new Set(["format", "epochId", "chain", "chainId", "number", "hash", "timestamp"]);
|
|
83
|
+
|
|
84
|
+
function shapeReasons(o: Record<string, unknown>): string[] {
|
|
85
|
+
const reasons: string[] = [];
|
|
86
|
+
if (o["format"] !== BLOCK_READ_FORMAT) return [`not ${BLOCK_READ_FORMAT}`];
|
|
87
|
+
for (const k of Object.keys(o)) if (!FIELDS.has(k)) reasons.push(`unexpected field ${k}`);
|
|
88
|
+
const epochId = o["epochId"];
|
|
89
|
+
if (typeof epochId !== "string" || !isB64Of32(epochId)) reasons.push("epochId is not 32 bytes of standard base64");
|
|
90
|
+
const chain = o["chain"];
|
|
91
|
+
if (chain !== "base" && chain !== "ethereum") {
|
|
92
|
+
reasons.push(`unknown chain ${JSON.stringify(chain)}`);
|
|
93
|
+
} else {
|
|
94
|
+
if (typeof o["chainId"] !== "string" || !BLOCK_READ_CHAIN_IDS[chain].includes(o["chainId"])) reasons.push(`chainId is not one of ${chain}'s`);
|
|
95
|
+
if (typeof o["hash"] !== "string" || !isBlockReadHash(chain, o["hash"])) reasons.push(`hash is not a ${chain} block hash`);
|
|
96
|
+
}
|
|
97
|
+
if (!isCount(o["number"])) reasons.push("number is not a safe non-negative integer");
|
|
98
|
+
if (!isCount(o["timestamp"])) reasons.push("timestamp is not a safe non-negative integer (Unix seconds)");
|
|
99
|
+
return reasons;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** What the chain says about a block hash, from the caller's lookup (eth_getBlockByHash). */
|
|
103
|
+
export interface ChainBlock {
|
|
104
|
+
/** The CAIP-2 id of the chain that answered. */
|
|
105
|
+
chainId: string;
|
|
106
|
+
hash: string;
|
|
107
|
+
number: number;
|
|
108
|
+
timestamp: number;
|
|
109
|
+
/** True only when the block is on the chain's canonical (best) chain. */
|
|
110
|
+
canonical: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface BlockReadCheck {
|
|
114
|
+
/** True only when confirmed: the chain itself vouched for the block. */
|
|
115
|
+
ok: boolean;
|
|
116
|
+
/** confirmed: the chain vouched; unconfirmed: nothing failed but the chain was not asked; failed: see reasons. */
|
|
117
|
+
status: "confirmed" | "unconfirmed" | "failed";
|
|
118
|
+
/** What failed; empty unless failed. */
|
|
119
|
+
reasons: string[];
|
|
120
|
+
file: BlockReadFile | null;
|
|
121
|
+
/** The block's number and timestamp as the CHAIN reports them; set only when the chain confirmed the block. */
|
|
122
|
+
block: { chain: BlockReadChain; chainId: string; hash: string; number: number; timestamp: number } | null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Check a block read against its BitGraph and against the chain.
|
|
127
|
+
*
|
|
128
|
+
* The file must hash to the proof's digest and name the proof's epoch. `chain` is the lookup of the file's hash on
|
|
129
|
+
* the file's chain: null means the chain does not know the hash. Every field must match: the block must be that
|
|
130
|
+
* hash, on the canonical chain, with the CAIP-2 chain id, number and timestamp the file names. Without `chain` (undefined) the read is unconfirmed and
|
|
131
|
+
* not ok: the file alone says nothing about time. The number and timestamp returned are the chain's.
|
|
132
|
+
*/
|
|
133
|
+
export function checkBlockRead(args: { file: string; proof: BitGraphProof; chain?: ChainBlock | null }): BlockReadCheck {
|
|
134
|
+
const file = parseBlockReadFile(args.file);
|
|
135
|
+
if (!file) return { ok: false, status: "failed", reasons: [`the file is not a ${BLOCK_READ_FORMAT} record`], file: null, block: null };
|
|
136
|
+
const reasons: string[] = [];
|
|
137
|
+
if (blockReadDigestB64(args.file) !== args.proof.artifact?.digestB64) reasons.push("the file does not hash to the proof's digest");
|
|
138
|
+
if (args.proof.commit?.epochId !== file.epochId) reasons.push("the proof is not of the epoch the file names");
|
|
139
|
+
|
|
140
|
+
const c = args.chain;
|
|
141
|
+
if (c === undefined) {
|
|
142
|
+
// Not looked up: nothing more to check, and nothing about time is known.
|
|
143
|
+
} else if (c === null) {
|
|
144
|
+
reasons.push(`${file.chain} does not know block ${file.hash}`);
|
|
145
|
+
} else {
|
|
146
|
+
if (c.chainId !== file.chainId) reasons.push(`the file names chain ${file.chainId}; the answer came from ${c.chainId}`);
|
|
147
|
+
if (c.hash.toLowerCase() !== file.hash) reasons.push(`${file.chain} answered for another block`);
|
|
148
|
+
if (!c.canonical) reasons.push(`block ${file.hash} is not on ${file.chain}'s canonical chain`);
|
|
149
|
+
if (c.number !== file.number) reasons.push(`the file says block ${file.number}; ${file.chain} says ${c.number}`);
|
|
150
|
+
if (c.timestamp !== file.timestamp) reasons.push(`the file says time ${file.timestamp}; ${file.chain} says ${c.timestamp}`);
|
|
151
|
+
}
|
|
152
|
+
const confirmed = reasons.length === 0 && c;
|
|
153
|
+
const status = reasons.length > 0 ? "failed" : c ? "confirmed" : "unconfirmed";
|
|
154
|
+
return {
|
|
155
|
+
ok: status === "confirmed",
|
|
156
|
+
status,
|
|
157
|
+
reasons,
|
|
158
|
+
file,
|
|
159
|
+
block: confirmed ? { chain: file.chain, chainId: file.chainId, hash: file.hash, number: c.number, timestamp: c.timestamp } : null,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isCount(v: unknown): v is number {
|
|
164
|
+
return typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isB64Of32(s: string): boolean {
|
|
168
|
+
if (!/^[A-Za-z0-9+/]{43}=$/.test(s)) return false;
|
|
169
|
+
const bin = typeof atob === "function" ? atob(s) : Buffer.from(s, "base64").toString("binary");
|
|
170
|
+
return bin.length === 32;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function bytesToB64(u: Uint8Array): string {
|
|
174
|
+
let bin = "";
|
|
175
|
+
for (const x of u) bin += String.fromCharCode(x);
|
|
176
|
+
return typeof btoa === "function" ? btoa(bin) : Buffer.from(bin, "binary").toString("base64");
|
|
177
|
+
}
|
package/src/ceiling.ts
CHANGED
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
* What stays OUTSIDE this function, and is reported, not assumed:
|
|
27
27
|
* - whether that header is really a Base block (check it against any Base
|
|
28
28
|
* RPC; see checkCeilingOnline), and
|
|
29
|
-
* - who the writer is
|
|
30
|
-
*
|
|
29
|
+
* - who the writer is: the caller may name the address it trusts; by default
|
|
30
|
+
* only BitGraph's published writers (measurements.ts) are accepted.
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
import { sha256 } from "@noble/hashes/sha256";
|
|
34
34
|
import { verifyProofIntegrity, createVerificationContext } from "./verifier.js";
|
|
35
35
|
import { computeProofHash } from "./proof-hash.js";
|
|
36
|
+
import { isPublishedWriter } from "./measurements.js";
|
|
36
37
|
import { merkleLeafHash, merkleRootFromPath } from "./fuse-merkle.js";
|
|
37
38
|
import { base64ToBytes, signedFloorOf, type SignedFloor } from "./fuse.js";
|
|
38
39
|
import {
|
|
@@ -159,8 +160,8 @@ export interface CeilingVerifyResult {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
export interface CeilingVerifyOptions {
|
|
162
|
-
/** The
|
|
163
|
-
writerAddress
|
|
163
|
+
/** The writer address trusted. Omitted: BitGraph's published writers (PUBLISHED_WRITERS). Any other sender is refused. */
|
|
164
|
+
writerAddress?: string;
|
|
164
165
|
/** 8453 Base mainnet, 84532 Base Sepolia. */
|
|
165
166
|
chainId: number;
|
|
166
167
|
/** Skip the proof's own signature check (only when the caller already ran verify()). */
|
|
@@ -280,8 +281,10 @@ async function verifyCeilingChecks(
|
|
|
280
281
|
try {
|
|
281
282
|
rawTx = hexToBytes(a.rawTx);
|
|
282
283
|
const tx = decodeEip1559(rawTx);
|
|
283
|
-
const writer = opts.writerAddress.toLowerCase();
|
|
284
|
-
if (tx.from !== writer) return fail("sender", `the transaction was signed by ${tx.from}, not the declared writer ${writer}`);
|
|
284
|
+
const writer = opts.writerAddress !== undefined ? opts.writerAddress.toLowerCase() : tx.from;
|
|
285
|
+
if (opts.writerAddress !== undefined && tx.from !== writer) return fail("sender", `the transaction was signed by ${tx.from}, not the declared writer ${writer}`);
|
|
286
|
+
// The block number is the sidecar's here; the header step below refuses a sidecar whose number is not the header's.
|
|
287
|
+
if (opts.writerAddress === undefined && !isPublishedWriter(tx.from, opts.chainId, a.blockNumber)) return fail("sender", `the transaction was signed by ${tx.from}, which is not a BitGraph writer`);
|
|
285
288
|
if (tx.to !== writer) return fail("sender", `the transaction is addressed to ${tx.to ?? "a contract creation"}, not to the writer`);
|
|
286
289
|
if (tx.chainId !== BigInt(opts.chainId)) return fail("chain", `the transaction is for chain ${tx.chainId}, expected ${opts.chainId}`);
|
|
287
290
|
if (a.chainId !== opts.chainId) return fail("chain", `the sidecar names chain ${a.chainId}, expected ${opts.chainId}`);
|
package/src/epoch-genesis.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { sha256 } from "@noble/hashes/sha256";
|
|
22
22
|
import type { BitGraphProof } from "./types.js";
|
|
23
|
+
import { isPublishedWriter } from "./measurements.js";
|
|
23
24
|
|
|
24
25
|
export const EPOCH_GENESIS_FORMAT = "bitgraph-epoch-genesis/1" as const;
|
|
25
26
|
export const EPOCH_GENESIS_REQUEST_FORMAT = "bitgraph-epoch-genesis-request/1" as const;
|
|
@@ -156,8 +157,14 @@ export interface EpochGenesisCheck {
|
|
|
156
157
|
* file's epoch; the transaction, when supplied, must be the writer's self-addressed transaction carrying this
|
|
157
158
|
* epoch's id, mined in the block the file names; the block, when supplied, must be that block with that time.
|
|
158
159
|
* Without `tx` and `block` only the file and the proof are checked (offline).
|
|
160
|
+
*
|
|
161
|
+
* The writer must be one of BitGraph's published writers on Base mainnet, unless the caller names the writers it trusts
|
|
162
|
+
* (`writers`): an epoch opened from any other address is not BitGraph's, though its enclave image may be.
|
|
163
|
+
*
|
|
164
|
+
* `position: "any"` drops the counts-1-and-2 rule, for a timeline epoch that read blocks and bound files while the
|
|
165
|
+
* Base write was still pending: its genesis record is the first record that ends pre-genesis, wherever it falls.
|
|
159
166
|
*/
|
|
160
|
-
export function checkEpochGenesis(args: { file: string; proof: BitGraphProof; tx?: EpochGenesisTx | null; block?: EpochGenesisBlock | null }): EpochGenesisCheck {
|
|
167
|
+
export function checkEpochGenesis(args: { file: string; proof: BitGraphProof; tx?: EpochGenesisTx | null; block?: EpochGenesisBlock | null; position?: "first" | "any"; writers?: readonly string[] }): EpochGenesisCheck {
|
|
161
168
|
const reasons: string[] = [];
|
|
162
169
|
const genesis = parseEpochGenesisFile(args.file);
|
|
163
170
|
if (!genesis) return { ok: false, reasons: ["the file is not a bitgraph-epoch-genesis/1 record"], genesis: null };
|
|
@@ -165,7 +172,10 @@ export function checkEpochGenesis(args: { file: string; proof: BitGraphProof; tx
|
|
|
165
172
|
if (digest !== args.proof.artifact?.digestB64) reasons.push("the file does not hash to the proof's digest");
|
|
166
173
|
const commit = args.proof.commit as { counter?: string; slotCounter?: string; epochId?: string };
|
|
167
174
|
if (commit.epochId !== genesis.epochId) reasons.push("the proof is not of the epoch the file names");
|
|
168
|
-
if (
|
|
175
|
+
if (args.writers ? !args.writers.map((w) => w.toLowerCase()).includes(genesis.writer) : genesis.chainId === 8453 && !isPublishedWriter(genesis.writer, 8453, genesis.blockNumber)) {
|
|
176
|
+
reasons.push(`the writer ${genesis.writer} is not ${args.writers ? "one this verifier trusts" : "a BitGraph writer"}`);
|
|
177
|
+
}
|
|
178
|
+
if (args.position !== "any" && (commit.slotCounter !== "1" || commit.counter !== "2")) reasons.push("the proof is not the epoch's first BitGraph (counts 1 and 2)");
|
|
169
179
|
if (args.tx) {
|
|
170
180
|
const t = args.tx;
|
|
171
181
|
if (t.from.toLowerCase() !== genesis.writer) reasons.push("the transaction was not sent by the writer the file names");
|
package/src/index.ts
CHANGED
|
@@ -204,9 +204,19 @@ export { baseTimeIsBound, BASE_STAMP_TOLERANCE_SECONDS } from "./ceiling.js";
|
|
|
204
204
|
export { checkFloorHeader, floorTimeIsBound, onBaseSchedule, headerRlpFromRpc, BASE_MAINNET_GENESIS_TIME, BASE_BLOCK_TIME_SECONDS } from "./ceiling.js";
|
|
205
205
|
export type { RpcBlockHeader } from "./ceiling.js";
|
|
206
206
|
/* The enclave images BitGraph has published: the default measurement policy (SPEC section 16). */
|
|
207
|
-
export { PUBLISHED_ENCLAVE_MEASUREMENTS, PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
|
|
208
|
-
export type { PublishedMeasurement } from "./measurements.js";
|
|
207
|
+
export { PUBLISHED_ENCLAVE_MEASUREMENTS, PUBLISHED_PCR0S, publishedMeasurement, imageIsAtomic, imageRetiredAfterMs, IMAGE_RETIREMENT_GRACE_DAYS, PUBLISHED_WRITERS, isPublishedWriter } from "./measurements.js";
|
|
208
|
+
export type { PublishedMeasurement, PublishedWriter } from "./measurements.js";
|
|
209
209
|
export type { BitGraphExport, ExportClaim, ExportClaimResult, ExportLookups, ExportVerifyOptions, ExportVerifyResult } from "./export.js";
|
|
210
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
211
|
export { EPOCH_GENESIS_FORMAT, EPOCH_GENESIS_REQUEST_FORMAT, EPOCH_GENESIS_MAGIC, epochGenesisCalldata, epochGenesisCalldataHex, epochIdOfCalldata, epochGenesisFileText, parseEpochGenesisFile, checkEpochGenesis } from "./epoch-genesis.js";
|
|
212
212
|
export type { EpochGenesisFile, EpochGenesisTx, EpochGenesisBlock, EpochGenesisCheck } from "./epoch-genesis.js";
|
|
213
|
+
|
|
214
|
+
/* bitgraph-block-read/1: a block of Base or Ethereum read and bound as a plain BitGraph; only the chain's own answer about the hash counts. */
|
|
215
|
+
export { BLOCK_READ_FORMAT, BLOCK_READ_CHAIN_IDS, isBlockReadHash, blockReadFileText, blockReadDigestB64, parseBlockReadFile, checkBlockRead } from "./block-read.js";
|
|
216
|
+
export type { BlockReadChain, BlockReadFile, ChainBlock, BlockReadCheck } from "./block-read.js";
|
|
217
|
+
/* bitgraph-timeline-bundle/1: a file's proof with the block reads either side of it and every proof between, verified offline; the chains give the time. */
|
|
218
|
+
export { TIMELINE_BUNDLE_FORMAT, DEFAULT_LAG_LIMITS, verifyTimelineBundle } from "./timeline-bundle.js";
|
|
219
|
+
export type { TimelineBundle, LagLimit, TimelineLookups, TimelineBundleOptions, TimelineBound, TimelineBundleResult } from "./timeline-bundle.js";
|
|
220
|
+
/* Building a timeline bundle for a file from the timeline's records; verifyTimelineBundle settles it. */
|
|
221
|
+
export { buildTimelineBundle, attestationTimeMs } from "./timeline-export.js";
|
|
222
|
+
export type { TimelineRecordLine, BuildTimelineBundleResult } from "./timeline-export.js";
|
package/src/measurements.ts
CHANGED
|
@@ -50,3 +50,54 @@ export function publishedMeasurement(pcr0: unknown): PublishedMeasurement | null
|
|
|
50
50
|
const want = pcr0.toLowerCase();
|
|
51
51
|
return PUBLISHED_ENCLAVE_MEASUREMENTS.find((m) => m.pcr0 === want) ?? null;
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
/** Images from v11 on bind atomically: the nonce at N and the digest at N+1 in one action. Earlier images could hand
|
|
55
|
+
* out a position before its content arrived. */
|
|
56
|
+
const ATOMIC_IMAGES: ReadonlySet<string> = new Set(["v11", "v12", "v13"]);
|
|
57
|
+
|
|
58
|
+
export function imageIsAtomic(version: string): boolean {
|
|
59
|
+
return ATOMIC_IMAGES.has(version);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Days an image stays accepted after the next image went live. A switch was never instant, so an image's last proofs
|
|
64
|
+
* can trail its successor's first by a little; past that, a proof attested by the older image is refused. Anyone can
|
|
65
|
+
* still boot a retired image on their own AWS account, and without this its new proofs would pass.
|
|
66
|
+
*/
|
|
67
|
+
export const IMAGE_RETIREMENT_GRACE_DAYS = 7;
|
|
68
|
+
|
|
69
|
+
/** The last instant (ms since the epoch) at which a proof attested by this image is accepted; null for the newest. */
|
|
70
|
+
export function imageRetiredAfterMs(pcr0: unknown): number | null {
|
|
71
|
+
const m = publishedMeasurement(pcr0);
|
|
72
|
+
if (!m) return null;
|
|
73
|
+
const i = PUBLISHED_ENCLAVE_MEASUREMENTS.indexOf(m);
|
|
74
|
+
const next = PUBLISHED_ENCLAVE_MEASUREMENTS[i + 1];
|
|
75
|
+
if (!next) return null;
|
|
76
|
+
return Date.parse(`${next.since}T00:00:00Z`) + (IMAGE_RETIREMENT_GRACE_DAYS + 1) * 86_400_000 - 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The Base addresses BitGraph writes from: every Base write of a proof (bitgraph-ceiling/1) and every epoch genesis
|
|
81
|
+
* transaction. A write from any other address is not BitGraph's, though the enclave image that made the proof may be
|
|
82
|
+
* the published one: the image says what code ran, the writer says who ran it. A leaked key gets `untilBlock`, the
|
|
83
|
+
* last block its writes are accepted in, and a new address is added; older writes stay valid.
|
|
84
|
+
*/
|
|
85
|
+
export interface PublishedWriter {
|
|
86
|
+
/** Lowercase 0x hex. */
|
|
87
|
+
address: string;
|
|
88
|
+
/** 8453, Base mainnet. */
|
|
89
|
+
chainId: number;
|
|
90
|
+
untilBlock?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const PUBLISHED_WRITERS: readonly PublishedWriter[] = Object.freeze([
|
|
94
|
+
{ address: "0xf3972408d853c975f86351c311f4310220bbf2a3", chainId: 8453 },
|
|
95
|
+
].map((w) => Object.freeze(w)));
|
|
96
|
+
|
|
97
|
+
/** Whether a write from `address` on `chainId` in block `blockNumber` (when known) is one of BitGraph's. */
|
|
98
|
+
export function isPublishedWriter(address: unknown, chainId: number, blockNumber?: number | null): boolean {
|
|
99
|
+
if (typeof address !== "string") return false;
|
|
100
|
+
const a = address.toLowerCase();
|
|
101
|
+
return PUBLISHED_WRITERS.some((w) => w.address === a && w.chainId === chainId
|
|
102
|
+
&& (w.untilBlock === undefined || blockNumber === undefined || blockNumber === null || blockNumber <= w.untilBlock));
|
|
103
|
+
}
|