@mikeargento/bitgraph-verify 1.16.0 → 1.18.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/README.md +24 -3
- package/dist/__tests__/carrier2.test.js +1 -1
- package/dist/__tests__/carrier2.test.js.map +1 -1
- package/dist/carrier-assemble.d.ts +30 -2
- package/dist/carrier-assemble.d.ts.map +1 -1
- package/dist/carrier-assemble.js +27 -3
- package/dist/carrier-assemble.js.map +1 -1
- package/dist/carrier-verify.d.ts +12 -2
- package/dist/carrier-verify.d.ts.map +1 -1
- package/dist/carrier-verify.js +222 -58
- package/dist/carrier-verify.js.map +1 -1
- package/dist/carrier.d.ts +77 -12
- package/dist/carrier.d.ts.map +1 -1
- package/dist/carrier.js +146 -17
- package/dist/carrier.js.map +1 -1
- package/dist/ceiling.d.ts +82 -3
- package/dist/ceiling.d.ts.map +1 -1
- package/dist/ceiling.js +137 -20
- package/dist/ceiling.js.map +1 -1
- package/dist/export.d.ts +10 -0
- package/dist/export.d.ts.map +1 -1
- package/dist/export.js +89 -30
- package/dist/export.js.map +1 -1
- package/dist/fuse.d.ts +43 -11
- package/dist/fuse.d.ts.map +1 -1
- package/dist/fuse.js +85 -18
- package/dist/fuse.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/measurements.d.ts.map +1 -1
- package/dist/measurements.js +1 -0
- package/dist/measurements.js.map +1 -1
- package/dist/tree.d.ts +15 -3
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +41 -12
- package/dist/tree.js.map +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/carrier2.test.ts +1 -1
- package/src/carrier-assemble.ts +47 -3
- package/src/carrier-verify.ts +227 -55
- package/src/carrier.ts +171 -26
- package/src/ceiling.ts +150 -24
- package/src/export.ts +94 -31
- package/src/fuse.ts +114 -23
- package/src/index.ts +24 -2
- package/src/measurements.ts +1 -0
- package/src/tree.ts +42 -10
- package/src/types.ts +22 -0
package/src/export.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* "member": TreeMemberEvidence one file's export
|
|
13
13
|
* or "leaves": base64(count x 65 bytes), the owner's export
|
|
14
14
|
* "names"?: [file name per leaf] }, unsigned, informational
|
|
15
|
-
* "floor": { "blockNumber", "blockHash", "header" } | null,
|
|
15
|
+
* "floor": { "chain"?, "blockNumber", "blockHash", "header" } | null, chain: "ethereum" (absent) or "base"
|
|
16
16
|
* "ceiling": a bitgraph-ceiling/1 sidecar | { "status": "pending" } | null,
|
|
17
17
|
* "settlement": a bitgraph-output-root/1 settlement | { "status": "pending", "baseBlock"? } | null
|
|
18
18
|
* }
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
* lookups say those blocks are the chains' own). This module never fetches.
|
|
24
24
|
*
|
|
25
25
|
* Three time claims, never merged:
|
|
26
|
-
* floor the committed bytes were finished after
|
|
26
|
+
* floor the committed bytes were finished after the floor block N, on the chain the
|
|
27
|
+
* proof signs: an Ethereum anchor (commit.slotAnchor, enclave v7 to v9) or a Base
|
|
28
|
+
* block (commit.slotFloor, enclave v10) (needs N canonical on that chain)
|
|
27
29
|
* ceiling.base the record existed by Base block B, at B's time (needs B canonical on Base; provisional until then)
|
|
28
30
|
* ceiling.ethereum the record existed by Ethereum block H (needs H canonical; Base's honesty not needed)
|
|
29
31
|
*/
|
|
@@ -32,9 +34,9 @@ import { sha256 } from "@noble/hashes/sha256";
|
|
|
32
34
|
import { verifyProofIntegrity, createVerificationContext } from "./verifier.js";
|
|
33
35
|
import { computeSignedBodyHash } from "./proof-hash.js";
|
|
34
36
|
import { verifyNitroAttestation } from "./nitro.js";
|
|
35
|
-
import { CEILING_VERSION, baseTimeIsBound, verifyCeiling, type CeilingSidecar } from "./ceiling.js";
|
|
36
|
-
import {
|
|
37
|
-
import { base64ToBytes, bytesEqual, hexToBytes } from "./fuse.js";
|
|
37
|
+
import { CEILING_VERSION, baseTimeIsBound, checkFloorHeader, floorTimeIsBound, verifyCeiling, type CeilingSidecar } from "./ceiling.js";
|
|
38
|
+
import { hexToBytes as evmHex } from "./ceiling-evm.js";
|
|
39
|
+
import { base64ToBytes, bytesEqual, hexToBytes, signedFloorOf, type SignedFloor } from "./fuse.js";
|
|
38
40
|
import { OUTPUT_ROOT_VERSION, verifyOutputRootSettlement, type OutputRootSettlement } from "./output-root.js";
|
|
39
41
|
import { MerkleTree } from "./fuse-merkle.js";
|
|
40
42
|
import { streamDigest, type ByteSource } from "./stream.js";
|
|
@@ -63,7 +65,8 @@ export interface BitGraphExport {
|
|
|
63
65
|
leaves?: string;
|
|
64
66
|
names?: string[];
|
|
65
67
|
};
|
|
66
|
-
floor
|
|
68
|
+
/** The floor block's header. `chain` absent is Ethereum (every export before enclave v10); "base" a Base floor. */
|
|
69
|
+
floor: { chain?: "ethereum" | "base"; blockNumber: number; blockHash: string; header: string } | null;
|
|
67
70
|
ceiling: CeilingSidecar | { status: "pending" } | null;
|
|
68
71
|
settlement: OutputRootSettlement | { status: "pending"; baseBlock?: number } | null;
|
|
69
72
|
}
|
|
@@ -121,7 +124,8 @@ export interface ExportVerifyResult {
|
|
|
121
124
|
floorCovers: TreeVerifyResult["floorCovers"];
|
|
122
125
|
/** The three time claims, as established. Null fields were not established. */
|
|
123
126
|
times: {
|
|
124
|
-
floor
|
|
127
|
+
/** `chain` is present only for a Base floor, so an Ethereum floor's result is exactly what it was before enclave v10. */
|
|
128
|
+
floor: { chain?: "base"; blockNumber: number; blockHash: string; blockTimestamp: number } | null;
|
|
125
129
|
ceilingBase: { chainId: number; blockNumber: number; blockHash: string; blockTimestamp: number; provisional: boolean } | null;
|
|
126
130
|
ceilingEthereum: { chainId: number; blockNumber: number; blockHash: string; blockTimestamp: number } | null;
|
|
127
131
|
};
|
|
@@ -131,6 +135,12 @@ export interface ExportVerifyResult {
|
|
|
131
135
|
* document (see baseTimeIsBound). The inclusion itself still holds.
|
|
132
136
|
*/
|
|
133
137
|
baseTimeWithheld: string | null;
|
|
138
|
+
/**
|
|
139
|
+
* Why the floor block's time is not stated as a bound, when it is not: the
|
|
140
|
+
* block is stamped after the attestation document (see floorTimeIsBound).
|
|
141
|
+
* The floor itself still holds: the record was made after that block.
|
|
142
|
+
*/
|
|
143
|
+
floorTimeWithheld: string | null;
|
|
134
144
|
/** Plain language, written from the claims. */
|
|
135
145
|
reading: string;
|
|
136
146
|
}
|
|
@@ -163,6 +173,7 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
163
173
|
let member: TreeVerifyResult["member"] = null;
|
|
164
174
|
|
|
165
175
|
let baseTimeWithheld: string | null = null;
|
|
176
|
+
let floorTimeWithheld: string | null = null;
|
|
166
177
|
|
|
167
178
|
const exp = parseExport(input);
|
|
168
179
|
if (exp === null) {
|
|
@@ -177,10 +188,19 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
177
188
|
if (declared === EXPORT_FORMAT) add("format", "This is a bitgraph-export/1 file", "FALSE", "its structure", "it says bitgraph-export/1 but lacks the parts that format requires (proof, tree.rootDocument)");
|
|
178
189
|
else if (typeof declared === "string" && declared.startsWith("bitgraph-export/")) add("format", "This is a bitgraph-export/1 file", "UNDETERMINED", "", `not judged: a format this verifier does not know (${declared})`);
|
|
179
190
|
else add("format", "This is a bitgraph-export/1 file", "UNDETERMINED", "", "not a bitgraph-export/1 document");
|
|
180
|
-
return finish(claims, null, times, member, null, null);
|
|
191
|
+
return finish(claims, null, times, member, null, null, null);
|
|
181
192
|
}
|
|
182
193
|
add("format", "This is a bitgraph-export/1 file", "TRUE", "its structure", "format, proof and tree present");
|
|
183
194
|
const proof = exp.proof;
|
|
195
|
+
// The floor the proof signs, whichever chain it is on. A proof that signs two is ambiguous: no floor is read from it.
|
|
196
|
+
let signedFloor: SignedFloor | null = null;
|
|
197
|
+
let floorAmbiguous: string | null = null;
|
|
198
|
+
try {
|
|
199
|
+
signedFloor = signedFloorOf(proof);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
floorAmbiguous = (e as Error).message;
|
|
202
|
+
}
|
|
203
|
+
const chainName = (c: "ethereum" | "base") => (c === "base" ? "Base" : "Ethereum");
|
|
184
204
|
|
|
185
205
|
// An optional part is absent (null or missing) or an object of its format;
|
|
186
206
|
// anything else is a malformed part, never read as "not carried".
|
|
@@ -325,8 +345,7 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
325
345
|
// Two floors, stated apart (SPEC 8.6). The record floor is every member's:
|
|
326
346
|
// the root document was signed after the floor block. The content floor
|
|
327
347
|
// is a placed member's: its committed bytes carry the commitment.
|
|
328
|
-
const
|
|
329
|
-
const block = typeof n === "number" ? `Ethereum block ${n}` : "the signed floor block";
|
|
348
|
+
const block = signedFloor ? `${chainName(signedFloor.chain)} block ${signedFloor.blockNumber}` : "the signed floor block";
|
|
330
349
|
add("floor.record", "The record was made after the floor block", "TRUE", "the signed root document, which carries the commitment to the floor block",
|
|
331
350
|
`recorded after ${block}: the tree this file is a leaf of was signed after it`);
|
|
332
351
|
if (tr.floorCovers === "content") {
|
|
@@ -339,23 +358,47 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
339
358
|
}
|
|
340
359
|
}
|
|
341
360
|
|
|
342
|
-
// 3. The floor: the header hashes to the SIGNED
|
|
343
|
-
|
|
361
|
+
// 3. The floor: the header hashes to the SIGNED floor block hash, on the chain the proof signs.
|
|
362
|
+
let floorBlock: { chain: "ethereum" | "base"; blockNumber: number; blockHash: string } | null = null;
|
|
363
|
+
let floorHeaderTs: number | null = null;
|
|
364
|
+
const fname = "The floor block's header is the one the proof signs";
|
|
344
365
|
if (isAbsent(exp.floor)) {
|
|
345
|
-
add("floor.header",
|
|
366
|
+
add("floor.header", fname, "NOT_CARRIED", "", "no floor header in the export");
|
|
346
367
|
} else if (!isObject(exp.floor)) {
|
|
347
|
-
add("floor.header",
|
|
348
|
-
} else if (
|
|
349
|
-
add("floor.header",
|
|
368
|
+
add("floor.header", fname, "FALSE", "", "the export's floor is neither absent nor a { blockNumber, blockHash, header } object");
|
|
369
|
+
} else if (floorAmbiguous !== null) {
|
|
370
|
+
add("floor.header", fname, "FALSE", "", floorAmbiguous);
|
|
371
|
+
} else if (!signedFloor) {
|
|
372
|
+
add("floor.header", fname, "FALSE", "", "the proof signs no floor block (commit.slotAnchor or commit.slotFloor)");
|
|
350
373
|
} else {
|
|
374
|
+
const f = exp.floor as Record<string, unknown>;
|
|
375
|
+
const chain = chainName(signedFloor.chain);
|
|
376
|
+
let raw: Uint8Array | null = null;
|
|
351
377
|
try {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
add("floor.header",
|
|
378
|
+
raw = evmHex(String(f["header"]));
|
|
379
|
+
} catch {
|
|
380
|
+
raw = null;
|
|
381
|
+
}
|
|
382
|
+
const fh = raw === null ? { ok: false as const, reason: "the header is not hex" } : checkFloorHeader(signedFloor, raw, f["chain"]);
|
|
383
|
+
if (!fh.ok) {
|
|
384
|
+
add("floor.header", fname, "FALSE", "", `floor header: ${fh.reason}`);
|
|
385
|
+
} else if (String(f["blockHash"]).toLowerCase() !== fh.header.hash || f["blockNumber"] !== fh.header.number) {
|
|
386
|
+
add("floor.header", fname, "FALSE", "", "the export's floor names a different block than its header");
|
|
387
|
+
} else {
|
|
388
|
+
const h = fh.header;
|
|
389
|
+
floorBlock = { chain: signedFloor.chain, blockNumber: h.number, blockHash: h.hash };
|
|
390
|
+
floorHeaderTs = h.timestamp;
|
|
391
|
+
// The floor's time is a bound only when it is no later than the attestation document.
|
|
392
|
+
const bound = floorTimeIsBound(h.timestamp, attestedAtMs);
|
|
393
|
+
if (bound.ok) {
|
|
394
|
+
times.floor = { ...(signedFloor.chain === "base" ? { chain: "base" as const } : {}), blockNumber: h.number, blockHash: h.hash, blockTimestamp: h.timestamp };
|
|
395
|
+
add("floor.header", fname, "TRUE", `${chain} block ${h.number}, header as given`,
|
|
396
|
+
`keccak-256 of the header equals the signed block hash${signedFloor.chain === "base" ? ", and its time is the signed one, on Base mainnet's schedule" : ""}; its time is ${iso(h.timestamp)}`);
|
|
397
|
+
} else {
|
|
398
|
+
floorTimeWithheld = bound.reason;
|
|
399
|
+
add("floor.header", fname, "TRUE", `${chain} block ${h.number}, header as given`,
|
|
400
|
+
`keccak-256 of the header equals the signed block hash; ${bound.reason}, so its time is not used as a bound`);
|
|
401
|
+
}
|
|
359
402
|
}
|
|
360
403
|
}
|
|
361
404
|
|
|
@@ -387,7 +430,7 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
387
430
|
ceilingB = { blockNumber: r.window.ceiling.blockNumber, blockHash: r.window.ceiling.blockHash };
|
|
388
431
|
const where = `under the root in transaction ${(c as CeilingSidecar).anchor!.txIndex} of Base block ${r.window.ceiling.blockNumber}`;
|
|
389
432
|
// The floor's time: the export's own header, else the verified header the sidecar carries.
|
|
390
|
-
const stamp = baseTimeIsBound(r.window.ceiling.blockTimestamp, { floorTimestampSec:
|
|
433
|
+
const stamp = baseTimeIsBound(r.window.ceiling.blockTimestamp, { floorTimestampSec: floorHeaderTs ?? r.window.floor.blockTimestamp ?? null, attestedAtMs });
|
|
391
434
|
if (stamp.ok) {
|
|
392
435
|
times.ceilingBase = { ...r.window.ceiling, provisional: true };
|
|
393
436
|
add("ceiling.base", "The record is in a Base block", "TRUE", `SHA-256 path, the BGC1 payload, secp256k1, Merkle-Patricia; Base block ${r.window.ceiling.blockNumber}, header as given`,
|
|
@@ -452,19 +495,20 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
452
495
|
add(id, name, "UNDETERMINED", "", `lookup failed: ${(e as Error).message}`, "confirmed");
|
|
453
496
|
}
|
|
454
497
|
};
|
|
455
|
-
|
|
498
|
+
// The floor is asked of its own chain, by height: the chain's block at N must be the signed one.
|
|
499
|
+
if (floorBlock !== null) await confirm("confirmed.floor", `The floor block is ${chainName(floorBlock.chain)}'s own`, floorBlock.chain, floorBlock);
|
|
456
500
|
await confirm("confirmed.ceiling.base", "The ceiling block is Base's own (makes its time final)", "base", ceilingB);
|
|
457
501
|
await confirm("confirmed.ceiling.ethereum", "The settlement block is Ethereum's own", "ethereum", times.ceilingEthereum);
|
|
458
502
|
const baseConfirmed = claims.find((x) => x.id === "confirmed.ceiling.base")?.result === "TRUE";
|
|
459
503
|
if (times.ceilingBase) times.ceilingBase.provisional = !baseConfirmed;
|
|
460
504
|
|
|
461
|
-
return finish(claims, exp, times, member, tr.floorCovers, baseTimeWithheld);
|
|
505
|
+
return finish(claims, exp, times, member, tr.floorCovers, baseTimeWithheld, floorTimeWithheld, floorBlock);
|
|
462
506
|
};
|
|
463
507
|
try {
|
|
464
508
|
return await run();
|
|
465
509
|
} catch (e) {
|
|
466
510
|
add("wellformed", "Every part of the export is well formed", "FALSE", "", `a part of this export is malformed: ${(e as Error).message}`);
|
|
467
|
-
return finish(claims, exp, times, member, null, baseTimeWithheld);
|
|
511
|
+
return finish(claims, exp, times, member, null, baseTimeWithheld, floorTimeWithheld);
|
|
468
512
|
}
|
|
469
513
|
}
|
|
470
514
|
|
|
@@ -485,6 +529,8 @@ function finish(
|
|
|
485
529
|
member: TreeVerifyResult["member"],
|
|
486
530
|
floorCovers: TreeVerifyResult["floorCovers"] = null,
|
|
487
531
|
baseTimeWithheld: string | null = null,
|
|
532
|
+
floorTimeWithheld: string | null = null,
|
|
533
|
+
floorBlock: { chain: "ethereum" | "base"; blockNumber: number } | null = null,
|
|
488
534
|
): ExportVerifyResult {
|
|
489
535
|
const offline = claims.filter((c) => c.level === "offline");
|
|
490
536
|
const failed = claims.filter((c) => c.result === "FALSE");
|
|
@@ -505,25 +551,42 @@ function finish(
|
|
|
505
551
|
const lc1 = (t: string) => t.charAt(0).toLowerCase() + t.slice(1);
|
|
506
552
|
if (unjudged.length > 0) parts.push(`Not judged in full: ${unjudged.map((c) => lc1(c.name)).join("; ")}.`);
|
|
507
553
|
const givenEth = "; that block's header is taken as given until it is checked against Ethereum";
|
|
508
|
-
|
|
509
|
-
|
|
554
|
+
const floorRead = floorBlock ?? (times.floor ? { chain: times.floor.chain ?? "ethereum", blockNumber: times.floor.blockNumber } : null);
|
|
555
|
+
if (floorRead) {
|
|
556
|
+
const chain = floorRead.chain === "base" ? "Base" : "Ethereum";
|
|
557
|
+
const time = times.floor ? ` (${iso(times.floor.blockTimestamp)})` : "";
|
|
558
|
+
const given = confirmedTrue("confirmed.floor") ? "" : `; that block's header is taken as given until it is checked against ${chain}`;
|
|
559
|
+
const at = `${chain} block ${floorRead.blockNumber}${time}${given}`;
|
|
510
560
|
parts.push(floorCovers === "record"
|
|
511
561
|
? `Recorded after ${at}; this file was kept as is, so the bytes themselves are not dated.`
|
|
512
562
|
: floorCovers === "content"
|
|
513
563
|
? `Recorded after ${at}, and these committed bytes were finished after that block; an original inside them is not dated by it.`
|
|
514
564
|
: `Recorded after ${at}.`);
|
|
565
|
+
if (!times.floor && floorTimeWithheld) parts.push(`The floor block's time is not used as a bound: ${floorTimeWithheld}.`);
|
|
515
566
|
}
|
|
516
567
|
if (times.ceilingBase) parts.push(`The record existed by Base block ${times.ceilingBase.blockNumber} (${iso(times.ceilingBase.blockTimestamp)}${times.ceilingBase.provisional ? ", provisional until checked against Base" : ""}).`);
|
|
517
568
|
else if (baseTimeWithheld) parts.push(`The record is in a Base block, but its time is not used as a bound: ${baseTimeWithheld}.`);
|
|
518
569
|
if (times.ceilingEthereum) parts.push(`It existed by Ethereum block ${times.ceilingEthereum.blockNumber} (${iso(times.ceilingEthereum.blockTimestamp)})${confirmedTrue("confirmed.ceiling.ethereum") ? "" : givenEth}.`);
|
|
519
570
|
if (member) parts.push(`The file is leaf ${member.index} of ${member.count} in the committed tree.`);
|
|
520
571
|
}
|
|
521
|
-
return { verdict, reasons, claims, member, floorCovers, times, baseTimeWithheld, reading: parts.join(" ") };
|
|
572
|
+
return { verdict, reasons, claims, member, floorCovers, times, baseTimeWithheld, floorTimeWithheld, reading: parts.join(" ") };
|
|
522
573
|
}
|
|
523
574
|
|
|
575
|
+
|
|
524
576
|
/** Build an export object from its parts (producers). Fields are written in the order the spec lists them. */
|
|
525
577
|
export function buildExport(parts: Omit<BitGraphExport, "format" | "spec">): BitGraphExport {
|
|
526
578
|
const spec = parts.proof.attribution?.message;
|
|
527
579
|
if (typeof spec !== "string") throw new TypeError("a tree/1 proof pins its spec in attribution.message");
|
|
528
|
-
|
|
580
|
+
// A Base floor names its chain; an Ethereum floor leaves it out, so exports made before enclave v10 stay byte for byte what they were.
|
|
581
|
+
let floor = parts.floor;
|
|
582
|
+
if (floor && floor.chain === undefined) {
|
|
583
|
+
let chain: "ethereum" | "base" | undefined;
|
|
584
|
+
try {
|
|
585
|
+
chain = signedFloorOf(parts.proof)?.chain;
|
|
586
|
+
} catch {
|
|
587
|
+
chain = undefined;
|
|
588
|
+
}
|
|
589
|
+
if (chain === "base") floor = { chain: "base", blockNumber: floor.blockNumber, blockHash: floor.blockHash, header: floor.header };
|
|
590
|
+
}
|
|
591
|
+
return { format: EXPORT_FORMAT, spec, proof: parts.proof, tree: parts.tree, floor, ceiling: parts.ceiling, settlement: parts.settlement };
|
|
529
592
|
}
|
package/src/fuse.ts
CHANGED
|
@@ -204,9 +204,76 @@ export const FUSE2_DOMAIN: Uint8Array = (() => {
|
|
|
204
204
|
return out;
|
|
205
205
|
})();
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// bitgraph-fuse/3 (2026-10-06, enclave v10): the floor is a Base block.
|
|
209
|
+
//
|
|
210
|
+
// commitment/3 = SHA256(UTF8("bitgraph-fuse/3") || 0x00 || slotRecordHash || nonce || floorBlockHash)
|
|
211
|
+
//
|
|
212
|
+
// floorBlockHash is the 32 raw bytes of commit.slotFloor.blockHash: the Base
|
|
213
|
+
// block the enclave fixed at allocation from a header it hashed itself, and
|
|
214
|
+
// signed into the proof with its chain named. fuse/2 is unchanged and still
|
|
215
|
+
// binds commit.slotAnchor (an Ethereum anchor). A proof carries one floor or
|
|
216
|
+
// the other, never both: a proof with both is ambiguous and binds nothing.
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
|
|
219
|
+
export const FUSE3_PROFILE = "bitgraph-fuse/3" as const;
|
|
220
|
+
export const FUSE3_ATTRIBUTION_NAME = FUSE3_PROFILE;
|
|
221
|
+
|
|
222
|
+
/** "bitgraph-fuse/3" followed by one zero byte. */
|
|
223
|
+
export const FUSE3_DOMAIN: Uint8Array = (() => {
|
|
224
|
+
const label = new TextEncoder().encode(FUSE3_PROFILE);
|
|
225
|
+
const out = new Uint8Array(label.length + 1);
|
|
226
|
+
out.set(label, 0);
|
|
227
|
+
out[label.length] = 0x00;
|
|
228
|
+
return out;
|
|
229
|
+
})();
|
|
230
|
+
|
|
231
|
+
/** The fused commitment versions: 1 binds no floor, 2 an Ethereum anchor, 3 a Base block. */
|
|
232
|
+
export type FuseVersion = 1 | 2 | 3;
|
|
233
|
+
|
|
234
|
+
/** Which commitment a fused proof's signed marker declares, or null when the proof is not fused. */
|
|
235
|
+
export function fuseVersionOfName(name: unknown): FuseVersion | null {
|
|
236
|
+
return name === FUSE_ATTRIBUTION_NAME ? 1 : name === FUSE2_ATTRIBUTION_NAME ? 2 : name === FUSE3_ATTRIBUTION_NAME ? 3 : null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The signed marker name for a version. */
|
|
240
|
+
export function fuseNameOfVersion(version: FuseVersion): string {
|
|
241
|
+
return version === 3 ? FUSE3_ATTRIBUTION_NAME : version === 2 ? FUSE2_ATTRIBUTION_NAME : FUSE_ATTRIBUTION_NAME;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The floor a proof signs, whichever kind it is: an Ethereum anchor fixed at
|
|
246
|
+
* allocation (commit.slotAnchor, enclave v7 to v9) or a Base block
|
|
247
|
+
* (commit.slotFloor, enclave v10). Null when the proof signs no floor. Throws
|
|
248
|
+
* when it signs both, or a slotFloor that does not name Base: such a proof is
|
|
249
|
+
* ambiguous and nothing should be read from it as a floor.
|
|
250
|
+
*/
|
|
251
|
+
export interface SignedFloor {
|
|
252
|
+
chain: "ethereum" | "base";
|
|
253
|
+
blockNumber: number;
|
|
254
|
+
/** 0x-prefixed lowercase hex. */
|
|
255
|
+
blockHash: string;
|
|
256
|
+
/** Unix seconds; signed only for a Base floor (an Ethereum floor's time is read from its header). */
|
|
257
|
+
blockTimestamp?: number;
|
|
258
|
+
/** The anchor proof's counter, for an Ethereum floor. */
|
|
259
|
+
anchorCounter?: string;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function signedFloorOf(proof: BitGraphProof): SignedFloor | null {
|
|
263
|
+
const a = proof.commit?.slotAnchor;
|
|
264
|
+
const f = proof.commit?.slotFloor;
|
|
265
|
+
if (a && f) throw new TypeError("the proof signs two floors (commit.slotAnchor and commit.slotFloor); it is ambiguous and binds neither");
|
|
266
|
+
if (f) {
|
|
267
|
+
if (f.chain !== "base" || f.evmChainId !== 8453) throw new TypeError("commit.slotFloor does not name Base mainnet");
|
|
268
|
+
if (typeof f.blockHash !== "string" || !/^0x[0-9a-f]{64}$/.test(f.blockHash)) throw new TypeError("commit.slotFloor.blockHash is not a 32-byte hash");
|
|
269
|
+
if (!Number.isSafeInteger(f.blockNumber) || !Number.isSafeInteger(f.blockTimestamp)) throw new TypeError("commit.slotFloor carries no block number or time");
|
|
270
|
+
return { chain: "base", blockNumber: f.blockNumber, blockHash: f.blockHash, blockTimestamp: f.blockTimestamp };
|
|
271
|
+
}
|
|
272
|
+
if (a) {
|
|
273
|
+
if (typeof a.blockHash !== "string") throw new TypeError("commit.slotAnchor.blockHash is missing");
|
|
274
|
+
return { chain: "ethereum", blockNumber: a.blockNumber, blockHash: a.blockHash.toLowerCase(), anchorCounter: a.counter };
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
210
277
|
}
|
|
211
278
|
|
|
212
279
|
/** True for either fused marker name. Use this, never a string compare against one version. */
|
|
@@ -234,30 +301,54 @@ export function computeSlotCommitment2(slot: SlotAllocation, floorBlockHash: str
|
|
|
234
301
|
return sha256(slotCommitment2Preimage(slot, floorBlockHash));
|
|
235
302
|
}
|
|
236
303
|
|
|
304
|
+
/** The exact preimage of commitment/3: domain/3 || slotRecordHash || nonce || floorBlockHash (a Base block). */
|
|
305
|
+
export function slotCommitment3Preimage(slot: SlotAllocation, floorBlockHash: string | Uint8Array): Uint8Array {
|
|
306
|
+
const nonce = base64ToBytes(slot.nonceB64);
|
|
307
|
+
if (nonce === null || nonce.length !== 32) {
|
|
308
|
+
throw new TypeError("slot.nonceB64 must decode to exactly 32 bytes");
|
|
309
|
+
}
|
|
310
|
+
return concat(FUSE3_DOMAIN, computeSlotRecordHash(slot), nonce, floorHashBytes(floorBlockHash));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** commitment/3 = SHA256(domain/3 || slotRecordHash || nonce || floorBlockHash). */
|
|
314
|
+
export function computeSlotCommitment3(slot: SlotAllocation, floorBlockHash: string | Uint8Array): Uint8Array {
|
|
315
|
+
return sha256(slotCommitment3Preimage(slot, floorBlockHash));
|
|
316
|
+
}
|
|
317
|
+
|
|
237
318
|
/**
|
|
238
319
|
* The commitment a fused proof's bytes must carry, chosen by its signed marker:
|
|
239
|
-
* fuse/
|
|
240
|
-
*
|
|
320
|
+
* fuse/3 binds the proof's signed Base floor (commit.slotFloor), fuse/2 its
|
|
321
|
+
* signed Ethereum anchor (commit.slotAnchor), fuse/1 no floor. Throws when the
|
|
322
|
+
* marker's floor is missing, or the proof signs both floors.
|
|
241
323
|
*/
|
|
242
324
|
export function commitmentForProof(proof: BitGraphProof, slot: SlotAllocation): Uint8Array {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
325
|
+
const version = fuseVersionOfName(proof.attribution?.name);
|
|
326
|
+
if (version === 1 || version === null) return computeSlotCommitment(slot);
|
|
327
|
+
const floor = signedFloorOf(proof);
|
|
328
|
+
if (version === 2) {
|
|
329
|
+
if (floor?.chain !== "ethereum") throw new TypeError("a bitgraph-fuse/2 proof must carry a signed commit.slotAnchor to bind");
|
|
330
|
+
return computeSlotCommitment2(slot, floor.blockHash);
|
|
247
331
|
}
|
|
248
|
-
|
|
332
|
+
if (floor?.chain !== "base") throw new TypeError("a bitgraph-fuse/3 proof must carry a signed commit.slotFloor (a Base block) to bind");
|
|
333
|
+
return computeSlotCommitment3(slot, floor.blockHash);
|
|
249
334
|
}
|
|
250
335
|
|
|
251
336
|
/**
|
|
252
337
|
* The commitment a PRODUCER writes into new bytes, from what the allocation
|
|
253
|
-
* returned: fuse/
|
|
254
|
-
*
|
|
255
|
-
* fuseAttribution's version argument.
|
|
338
|
+
* returned: fuse/3 when the enclave handed back a Base floor (v10), fuse/2 for
|
|
339
|
+
* an Ethereum floor anchor (v9), else fuse/1. The attribution name must match;
|
|
340
|
+
* see fuseAttribution's version argument.
|
|
256
341
|
*/
|
|
257
|
-
export function producerCommitment(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
342
|
+
export function producerCommitment(
|
|
343
|
+
slot: SlotAllocation,
|
|
344
|
+
floor?: { blockHash: string; chain?: string } | null,
|
|
345
|
+
): { commitment: Uint8Array; version: FuseVersion } {
|
|
346
|
+
if (floor && typeof floor.blockHash === "string") {
|
|
347
|
+
return floor.chain === "base"
|
|
348
|
+
? { commitment: computeSlotCommitment3(slot, floor.blockHash), version: 3 }
|
|
349
|
+
: { commitment: computeSlotCommitment2(slot, floor.blockHash), version: 2 };
|
|
350
|
+
}
|
|
351
|
+
return { commitment: computeSlotCommitment(slot), version: 1 };
|
|
261
352
|
}
|
|
262
353
|
|
|
263
354
|
// ---------------------------------------------------------------------------
|
|
@@ -998,11 +1089,11 @@ export function getPlacement(id: string): Placement | undefined {
|
|
|
998
1089
|
* set/1 refuses an origin digest: a set/1 marker carrying one is out of
|
|
999
1090
|
* profile and verifyFuseMember refuses it.
|
|
1000
1091
|
*/
|
|
1001
|
-
export function fuseAttribution(placement: PlacementId, originDigest?: Uint8Array, version:
|
|
1092
|
+
export function fuseAttribution(placement: PlacementId, originDigest?: Uint8Array, version: FuseVersion = 1): Attribution {
|
|
1002
1093
|
if (originDigest !== undefined && originDigest.length !== 32) throw new TypeError("originDigest must be 32 bytes");
|
|
1003
1094
|
if ((placement === SET_PLACEMENT_ID || placement === SET2_PLACEMENT_ID) && originDigest !== undefined) throw new TypeError(`${placement} has no single origin; a set marker carries no origin digest`);
|
|
1004
1095
|
return {
|
|
1005
|
-
name: version
|
|
1096
|
+
name: fuseNameOfVersion(version),
|
|
1006
1097
|
title: placement,
|
|
1007
1098
|
...(originDigest !== undefined ? { message: bytesToBase64(originDigest) } : {}),
|
|
1008
1099
|
};
|
|
@@ -1025,7 +1116,7 @@ export interface FuseMarker {
|
|
|
1025
1116
|
/** "attribution" when the proof's signed attribution marks it fused, else "manifest". */
|
|
1026
1117
|
source: MarkerSource;
|
|
1027
1118
|
/** Which commitment the signed marker declares; absent on a manifest-only marker, which means 1. */
|
|
1028
|
-
version?:
|
|
1119
|
+
version?: FuseVersion;
|
|
1029
1120
|
}
|
|
1030
1121
|
|
|
1031
1122
|
/** Read the fused marker from a proof's signed attribution, or null when the proof is not marked fused. */
|
|
@@ -1076,15 +1167,15 @@ export function findCommitment(bytes: Uint8Array, commitment: Uint8Array, encodi
|
|
|
1076
1167
|
}
|
|
1077
1168
|
|
|
1078
1169
|
/** The attribution a producer sends for an artifact made with the commitment inside it. */
|
|
1079
|
-
export function inlineAttribution(version:
|
|
1080
|
-
return { name: version
|
|
1170
|
+
export function inlineAttribution(version: FuseVersion = 1): { name: string; title: string } {
|
|
1171
|
+
return { name: fuseNameOfVersion(version), title: ENCODING_BASE64URL };
|
|
1081
1172
|
}
|
|
1082
1173
|
|
|
1083
1174
|
export function readFuseAttribution(proof: BitGraphProof): FuseMarker | null {
|
|
1084
1175
|
const a = proof.attribution;
|
|
1085
1176
|
const version = fuseVersionOfName(a?.name);
|
|
1086
1177
|
if (a === undefined || version === null) return null;
|
|
1087
|
-
// A tree/1 proof carries the fuse/2 name, but it is not a single fused file:
|
|
1178
|
+
// A tree/1 proof carries the fuse/2 or fuse/3 name, but it is not a single fused file:
|
|
1088
1179
|
// its committed artifact is the tree's root document and its message is the
|
|
1089
1180
|
// SPEC hash, not an origin. Read it with verifyTreeMember (tree.ts), never
|
|
1090
1181
|
// here, or the spec hash would be taken for an origin digest.
|
package/src/index.ts
CHANGED
|
@@ -62,6 +62,13 @@ export {
|
|
|
62
62
|
FUSE2_PROFILE,
|
|
63
63
|
FUSE2_DOMAIN,
|
|
64
64
|
FUSE2_ATTRIBUTION_NAME,
|
|
65
|
+
FUSE3_PROFILE,
|
|
66
|
+
FUSE3_DOMAIN,
|
|
67
|
+
FUSE3_ATTRIBUTION_NAME,
|
|
68
|
+
fuseNameOfVersion,
|
|
69
|
+
signedFloorOf,
|
|
70
|
+
slotCommitment3Preimage,
|
|
71
|
+
computeSlotCommitment3,
|
|
65
72
|
fuseVersionOfName,
|
|
66
73
|
isFuseMarkerName,
|
|
67
74
|
slotCommitment2Preimage,
|
|
@@ -82,7 +89,7 @@ export {
|
|
|
82
89
|
hexToBytes,
|
|
83
90
|
bytesEqual,
|
|
84
91
|
} from "./fuse.js";
|
|
85
|
-
export type { PlacementId, Placement, Located, FusePayload, FuseFrame, FuseMarker, MarkerSource, SetMember, SetManifest, FusedFrame } from "./fuse.js";
|
|
92
|
+
export type { PlacementId, Placement, Located, FusePayload, FuseFrame, FuseMarker, MarkerSource, SetMember, SetManifest, FusedFrame, FuseVersion, SignedFloor } from "./fuse.js";
|
|
86
93
|
export { MAX_CONTAINER_ENTRY_BYTES } from "./fuse.js";
|
|
87
94
|
/* Streaming checks: a file of any size against its leaf, in constant memory. */
|
|
88
95
|
export { bytesSource, blobSource, streamDigest, streamLeafCheck } from "./stream.js";
|
|
@@ -125,6 +132,18 @@ export type { CarrierVersion, CarrierCeilingInTime, CarrierSettlement, CarrierPi
|
|
|
125
132
|
export { assembleCarrierV2Payload, carrierBlockSize, CARRIER_BLOCK_ZIP_LIMIT } from "./carrier-assemble.js";
|
|
126
133
|
export type { CarrierV2Parts } from "./carrier-assemble.js";
|
|
127
134
|
|
|
135
|
+
/* bitgraph-carrier/3 (2026-10-06, enclave v10): the floor is the Base header the proof signs; no ceiling in position exists. */
|
|
136
|
+
export { CARRIER_VERSION_3, baseHeaderFields } from "./carrier.js";
|
|
137
|
+
export type { CarrierBaseFloor } from "./carrier.js";
|
|
138
|
+
export { assembleCarrierV3Payload } from "./carrier-assemble.js";
|
|
139
|
+
export type { CarrierV3Parts } from "./carrier-assemble.js";
|
|
140
|
+
|
|
141
|
+
/* 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. */
|
|
142
|
+
export { CARRIER_VERSION_4, memberArtifactDigest } from "./carrier.js";
|
|
143
|
+
export type { CarrierTree } from "./carrier.js";
|
|
144
|
+
export { assembleCarrierV4Payload } from "./carrier-assemble.js";
|
|
145
|
+
export type { CarrierV4Parts } from "./carrier-assemble.js";
|
|
146
|
+
|
|
128
147
|
/* AWS Nitro attestation: decode, verify (chain to the AWS root, validity at the document's instant), and the openssl-checkable witness. */
|
|
129
148
|
export {
|
|
130
149
|
AWS_NITRO_ROOT_CA_PEM, awsNitroRootDer, awsNitroRootSha256, decodeNitroAttestation, verifyNitroAttestation,
|
|
@@ -150,7 +169,7 @@ export type { RlpItem, DecodedHeader, DecodedTx } from "./ceiling-evm.js";
|
|
|
150
169
|
/* tree/1 (2026-10-03): every BitGraph is a Merkle tree under one position; a single file is a tree of one. */
|
|
151
170
|
export {
|
|
152
171
|
TREE_PLACEMENT_ID, TREE_PROFILE, TREE_DOMAIN, TREE_LEAF_BYTES, TREE_ROOT_DOCUMENT_BYTES, MAX_TREE_LEAVES, TREE_METADATA_KEY,
|
|
153
|
-
KNOWN_TREE_SPEC_HASHES, LEAF_AS_IS, LEAF_PLACEMENTS, TREE_MEMBER_CATEGORIES,
|
|
172
|
+
KNOWN_TREE_SPEC_HASHES, TREE_SPEC_V1_HASH, TREE_SPEC_V2_HASH, LEAF_AS_IS, LEAF_PLACEMENTS, TREE_MEMBER_CATEGORIES,
|
|
154
173
|
leafCodeOf, encodeTreeLeaf, decodeTreeLeaf, treeLeafHash, sortTreeLeaves, buildTree,
|
|
155
174
|
buildTreeRootDocument, parseTreeRootDocument, readTreeMetadata, treeAttribution, currentTreeSpecHash, isTreeProof,
|
|
156
175
|
buildTreeMemberEvidence, parseTreeMemberEvidence, treeRootFromMember, encodeTreeLeaves, decodeTreeLeaves, verifyTreeLeaves,
|
|
@@ -168,6 +187,9 @@ export type { OutputRootSettlement, OutputRootCheck, OutputRootVerifyResult, Out
|
|
|
168
187
|
/* bitgraph-export/1: one JSON file that, with the file, checks a tree/1 BitGraph with nothing of BitGraph's required. */
|
|
169
188
|
export { EXPORT_FORMAT, parseExport, verifyExport, buildExport } from "./export.js";
|
|
170
189
|
export { baseTimeIsBound, BASE_STAMP_TOLERANCE_SECONDS } from "./ceiling.js";
|
|
190
|
+
/* The floor block's header, on either chain (enclave v10 floors are Base blocks). */
|
|
191
|
+
export { checkFloorHeader, floorTimeIsBound, onBaseSchedule, headerRlpFromRpc, BASE_MAINNET_GENESIS_TIME, BASE_BLOCK_TIME_SECONDS } from "./ceiling.js";
|
|
192
|
+
export type { RpcBlockHeader } from "./ceiling.js";
|
|
171
193
|
/* The enclave images BitGraph has published: the default measurement policy (SPEC section 16). */
|
|
172
194
|
export { PUBLISHED_ENCLAVE_MEASUREMENTS, PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
|
|
173
195
|
export type { PublishedMeasurement } from "./measurements.js";
|
package/src/measurements.ts
CHANGED
|
@@ -35,6 +35,7 @@ export const PUBLISHED_ENCLAVE_MEASUREMENTS: readonly PublishedMeasurement[] = O
|
|
|
35
35
|
{ version: "v7", since: "2026-09-06", pcr0: "394c3cf515651dc27187d85e4716c12dfeb99c1227f1fe0eacfaa427d80018e1a28ebba9469e99c7936601f901d74e1d" },
|
|
36
36
|
{ version: "v8", since: "2026-09-07", pcr0: "eccfc1c78006f4b74f929c992785575c908a0f60eca08ff638cd6c0842f993f182ebb002457b8ef3e732a6a10805c72b" },
|
|
37
37
|
{ version: "v9", since: "2026-09-30", pcr0: "934feb8bb6f4f7e2d2f85d902a7d5edd0981f706d9d2385638988ac096a05ea0583c3d00eef2a7947865ec66efc1fcf8" },
|
|
38
|
+
{ version: "v10", since: "2026-10-08", pcr0: "5a947cc66095adcceefa9e5ece5d1416dfe08c3470df1bcaa5b2bc5267b0480e6cdc172fe077cd06b0afb07614307973" },
|
|
38
39
|
].map((m) => Object.freeze(m)));
|
|
39
40
|
|
|
40
41
|
/** PUBLISHED_ENCLAVE_MEASUREMENTS as the bare PCR0 list a verifier's pins take. */
|
package/src/tree.ts
CHANGED
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
bytesToHex,
|
|
44
44
|
commitmentForProof,
|
|
45
45
|
FUSE2_ATTRIBUTION_NAME,
|
|
46
|
+
FUSE3_ATTRIBUTION_NAME,
|
|
46
47
|
fuseVersionOfName,
|
|
47
48
|
getPlacement,
|
|
48
49
|
hexToBytes,
|
|
@@ -81,9 +82,25 @@ export const TREE_METADATA_KEY = TREE_PROFILE;
|
|
|
81
82
|
* Appending a revised spec here is how a verifier learns it; nothing is ever
|
|
82
83
|
* removed, so every proof made under an earlier spec keeps verifying.
|
|
83
84
|
*/
|
|
85
|
+
/** SPEC.md v1 (spec/SPEC.md). Frozen 2026-10-04 (spec/FROZEN.json): tree/1 under bitgraph-fuse/2, an Ethereum floor. */
|
|
86
|
+
export const TREE_SPEC_V1_HASH = "QazdIR0JYtHQwQuIISo7bvH1gxUvTS2cY+tW6BjUIRs=";
|
|
87
|
+
/** SPEC v2 (spec/SPEC-v2.md): tree/1 under bitgraph-fuse/3, a Base floor (enclave v10). */
|
|
88
|
+
export const TREE_SPEC_V2_HASH = "9O3sqlxqi6IQPVJd50NfjJtwWWoslZ9gpIIzbrRzAiU=";
|
|
89
|
+
|
|
84
90
|
export const KNOWN_TREE_SPEC_HASHES: readonly string[] = Object.freeze([
|
|
85
|
-
//
|
|
86
|
-
|
|
91
|
+
// Each spec never changes; a later spec is added beside it, never in its place.
|
|
92
|
+
TREE_SPEC_V1_HASH,
|
|
93
|
+
TREE_SPEC_V2_HASH,
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The marker each spec requires: v1 defines tree/1 under fuse/2 (the floor an
|
|
98
|
+
* Ethereum anchor), v2 under fuse/3 (the floor a Base block). A tree proof
|
|
99
|
+
* whose marker and spec disagree is refused, so neither spec's meaning moves.
|
|
100
|
+
*/
|
|
101
|
+
const TREE_SPEC_FUSE_VERSION: ReadonlyMap<string, 2 | 3> = new Map([
|
|
102
|
+
[TREE_SPEC_V1_HASH, 2],
|
|
103
|
+
[TREE_SPEC_V2_HASH, 3],
|
|
87
104
|
]);
|
|
88
105
|
|
|
89
106
|
/** Placement codes: the first byte of a leaf. */
|
|
@@ -210,16 +227,26 @@ export function readTreeMetadata(proof: BitGraphProof): Uint8Array | null {
|
|
|
210
227
|
// The signed marker
|
|
211
228
|
// ---------------------------------------------------------------------------
|
|
212
229
|
|
|
213
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* The attribution a producer sends for a tree/1 commit. specHash is the 32-byte
|
|
232
|
+
* SHA-256 of the spec the producer follows; the marker is the one that spec
|
|
233
|
+
* requires (fuse/2 for v1, fuse/3 for v2).
|
|
234
|
+
*/
|
|
214
235
|
export function treeAttribution(specHash: Uint8Array): Attribution {
|
|
215
236
|
if (specHash.length !== 32) throw new TypeError("the spec hash is 32 bytes");
|
|
216
|
-
|
|
237
|
+
const b64 = bytesToBase64(specHash);
|
|
238
|
+
const version = TREE_SPEC_FUSE_VERSION.get(b64) ?? 2;
|
|
239
|
+
return { name: version === 3 ? FUSE3_ATTRIBUTION_NAME : FUSE2_ATTRIBUTION_NAME, title: TREE_PLACEMENT_ID, message: b64 };
|
|
217
240
|
}
|
|
218
241
|
|
|
219
|
-
/**
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
242
|
+
/**
|
|
243
|
+
* The spec hash a producer pins, as raw bytes, for the floor its allocation
|
|
244
|
+
* returned: a Base floor (fuse/3) follows SPEC v2, an Ethereum floor anchor
|
|
245
|
+
* (fuse/2) follows SPEC v1. Throws while the requested spec hash is a placeholder.
|
|
246
|
+
*/
|
|
247
|
+
export function currentTreeSpecHash(fuseVersion: 2 | 3 = 2): Uint8Array {
|
|
248
|
+
const hash = fuseVersion === 3 ? TREE_SPEC_V2_HASH : TREE_SPEC_V1_HASH;
|
|
249
|
+
const b = base64ToBytes(hash);
|
|
223
250
|
if (b === null || b.length !== 32) throw new Error("the tree/1 spec hash has not been set");
|
|
224
251
|
return b;
|
|
225
252
|
}
|
|
@@ -429,14 +456,19 @@ export async function verifyTreeMember(opts: TreeVerifyOptions): Promise<TreeVer
|
|
|
429
456
|
if (!v.valid) return base("INVALID_UNDERLYING_PROOF", `the proof does not verify (${v.reason ?? "invalid"})`, { proof: proofResult });
|
|
430
457
|
}
|
|
431
458
|
|
|
432
|
-
// 2. The signed marker: fuse/2 (the floor is bound) and a known spec.
|
|
459
|
+
// 2. The signed marker: fuse/2 or fuse/3 (the floor is bound) and a known spec that requires it.
|
|
433
460
|
const a = proof.attribution!;
|
|
434
|
-
|
|
461
|
+
const markerVersion = fuseVersionOfName(a.name);
|
|
462
|
+
if (markerVersion !== 2 && markerVersion !== 3) return base("INVALID_TREE_MARKER", "a tree/1 proof must be marked bitgraph-fuse/2 or bitgraph-fuse/3, which bind the floor block into the commitment", { proof: proofResult });
|
|
435
463
|
const specBytes = typeof a.message === "string" ? base64ToBytes(a.message) : null;
|
|
436
464
|
if (specBytes === null || specBytes.length !== 32) return base("INVALID_TREE_MARKER", "a tree/1 proof must pin its spec: the signed message is the base64 SHA-256 of SPEC.md", { proof: proofResult });
|
|
437
465
|
const specHashB64 = a.message as string;
|
|
438
466
|
const known = new Set([...KNOWN_TREE_SPEC_HASHES, ...(opts.extraSpecHashes ?? [])]);
|
|
439
467
|
if (!known.has(specHashB64)) return base("UNKNOWN_SPEC", `the proof follows a spec this verifier does not know (${specHashB64})`, { proof: proofResult, specHashB64 });
|
|
468
|
+
const required = TREE_SPEC_FUSE_VERSION.get(specHashB64);
|
|
469
|
+
if (required !== undefined && required !== markerVersion) {
|
|
470
|
+
return base("INVALID_TREE_MARKER", `the proof pins a spec that defines tree/1 under bitgraph-fuse/${required}, but is marked bitgraph-fuse/${markerVersion}`, { proof: proofResult, specHashB64 });
|
|
471
|
+
}
|
|
440
472
|
|
|
441
473
|
// 3. The commitment, from the proof's own slot record and signed floor block.
|
|
442
474
|
if (!proof.slotAllocation) return base("INVALID_SLOT_COMMITMENT", "the proof carries no slot record, so no commitment can be recomputed", { proof: proofResult, specHashB64 });
|