@mikeargento/bitgraph-verify 1.15.2 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +24 -3
  2. package/dist/__tests__/carrier2.test.js +62 -3
  3. package/dist/__tests__/carrier2.test.js.map +1 -1
  4. package/dist/__tests__/ceiling.test.js +11 -4
  5. package/dist/__tests__/ceiling.test.js.map +1 -1
  6. package/dist/carrier-assemble.d.ts +12 -2
  7. package/dist/carrier-assemble.d.ts.map +1 -1
  8. package/dist/carrier-assemble.js +14 -3
  9. package/dist/carrier-assemble.js.map +1 -1
  10. package/dist/carrier-verify.d.ts +15 -4
  11. package/dist/carrier-verify.d.ts.map +1 -1
  12. package/dist/carrier-verify.js +201 -59
  13. package/dist/carrier-verify.js.map +1 -1
  14. package/dist/carrier.d.ts +48 -13
  15. package/dist/carrier.d.ts.map +1 -1
  16. package/dist/carrier.js +74 -16
  17. package/dist/carrier.js.map +1 -1
  18. package/dist/ceiling.d.ts +115 -6
  19. package/dist/ceiling.d.ts.map +1 -1
  20. package/dist/ceiling.js +189 -23
  21. package/dist/ceiling.js.map +1 -1
  22. package/dist/export.d.ts +122 -0
  23. package/dist/export.d.ts.map +1 -0
  24. package/dist/export.js +510 -0
  25. package/dist/export.js.map +1 -0
  26. package/dist/fuse.d.ts +45 -11
  27. package/dist/fuse.d.ts.map +1 -1
  28. package/dist/fuse.js +100 -18
  29. package/dist/fuse.js.map +1 -1
  30. package/dist/index.d.ts +20 -2
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +18 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/measurements.d.ts +30 -0
  35. package/dist/measurements.d.ts.map +1 -0
  36. package/dist/measurements.js +22 -0
  37. package/dist/measurements.js.map +1 -0
  38. package/dist/output-root.d.ts +88 -0
  39. package/dist/output-root.d.ts.map +1 -0
  40. package/dist/output-root.js +260 -0
  41. package/dist/output-root.js.map +1 -0
  42. package/dist/stream.d.ts +46 -0
  43. package/dist/stream.d.ts.map +1 -0
  44. package/dist/stream.js +290 -0
  45. package/dist/stream.js.map +1 -0
  46. package/dist/tree.d.ts +167 -0
  47. package/dist/tree.d.ts.map +1 -0
  48. package/dist/tree.js +485 -0
  49. package/dist/tree.js.map +1 -0
  50. package/dist/types.d.ts +21 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/__tests__/carrier2.test.ts +65 -3
  54. package/src/__tests__/ceiling.test.ts +12 -4
  55. package/src/carrier-assemble.ts +21 -3
  56. package/src/carrier-verify.ts +204 -61
  57. package/src/carrier.ts +95 -27
  58. package/src/ceiling.ts +217 -28
  59. package/src/export.ts +592 -0
  60. package/src/fuse.ts +126 -23
  61. package/src/index.ts +47 -1
  62. package/src/measurements.ts +49 -0
  63. package/src/output-root.ts +301 -0
  64. package/src/stream.ts +291 -0
  65. package/src/tree.ts +580 -0
  66. package/src/types.ts +22 -0
@@ -19,6 +19,7 @@ import {
19
19
  import { verifyCarrier } from "../carrier-verify.js";
20
20
  import { verifyNitroAttestation, attestationWitness, witnessMatchesAttestation, awsNitroRootSha256 } from "../nitro.js";
21
21
  import { computeSignedBodyHash } from "../proof-hash.js";
22
+ import { verifyCeiling } from "../ceiling.js";
22
23
 
23
24
  const fix = (name: string): Buffer => readFileSync(new URL(`../../src/__tests__/fixtures/carrier2/${name}`, import.meta.url));
24
25
  const jfix = <T = Record<string, unknown>>(name: string): T => JSON.parse(fix(name).toString("utf-8")) as T;
@@ -41,7 +42,7 @@ test("the golden carrier/2 verifies TRUE offline, every carried claim TRUE, the
41
42
  for (const id of ["block", "bytes.digest", "proof.signature", "proof.hash", "proof.fused", "attestation.signature", "attestation.chain", "attestation.root", "attestation.validity", "attestation.pcr0", "attestation.binding", "attestation.witness", "floor.anchor", "floor.binding", "floor.header", "ceiling.position.anchor", "ceiling.position.binding", "ceiling.position.header", "ceiling.time.record", "ceiling.time.payload", "ceiling.time.sender", "ceiling.time.inclusion", "ceiling.time.floor", "pins"]) {
42
43
  assert.equal(c[id], "TRUE", `${id}: ${r.claims.find((x) => x.id === id)?.detail}`);
43
44
  }
44
- assert.equal(c["attestation.pins"], "UNDETERMINED", "no allowlist given");
45
+ assert.equal(c["attestation.pins"], "TRUE", "BitGraph's published v9 image, the default policy");
45
46
  assert.equal(c["confirmed.floor"], "UNDETERMINED");
46
47
  assert.equal(c["confirmed.ceiling.time"], "UNDETERMINED");
47
48
  assert.equal(c["ceiling.time.status"], "UNDETERMINED", "status is reported, never proven");
@@ -51,10 +52,71 @@ test("the golden carrier/2 verifies TRUE offline, every carried claim TRUE, the
51
52
  assert.equal(r.bounds?.notAfter?.blockNumber, 26088459);
52
53
  assert.equal(r.bounds?.existedBy?.blockNumber, 51979918);
53
54
  assert.equal(r.bounds?.existedBy?.timestamp, 1790749183);
54
- assert.match(r.reading, /made after Ethereum block 26088457 \(2026-09-30T06:19:23Z\), and existed by Base block 51979918 \(2026-09-30T06:19:43Z\)/);
55
+ assert.match(r.reading, /Recorded after Ethereum block 26088457 \(2026-09-30T06:19:23Z\), and existed by Base block 51979918 \(2026-09-30T06:19:43Z\)/);
56
+ assert.match(r.reading, /^These exact bytes carry the commitment, so they were finished after (the floor block|their position was opened) \(the content floor\)\. Recorded after/);
55
57
  assert.match(r.reading, /Rests on: SHA-256, Ed25519, the AWS Nitro root \(641A0321…\), Ethereum block 26088457, Base block 51979918/);
56
58
  });
57
59
 
60
+ test("the enclave image decides: an image off the list is FALSE, no list or no attestation leaves the file undetermined", async () => {
61
+ const bytes = buildCarrier(inner, golden());
62
+ const off = await verifyCarrier(bytes, { pins: { pcr0: ["00".repeat(48)] } });
63
+ assert.equal(off.verdict, "FALSE");
64
+ assert.equal(claimsById(off)["attestation.pins"], "FALSE");
65
+ const none = await verifyCarrier(bytes, { pins: { pcr0: [] } });
66
+ assert.equal(none.verdict, "UNDETERMINED", "an attestation alone says only that some Nitro enclave signed");
67
+ assert.equal(claimsById(none)["attestation.pins"], "UNDETERMINED");
68
+ assert.match(none.reading, /^Not judged in full\./);
69
+ // Without its attestation the file is never TRUE (for this proof the signature covers it, so it is FALSE).
70
+ const bare = JSON.parse(JSON.stringify(golden())) as CarrierPayload;
71
+ delete (bare.proof as { environment: { attestation?: unknown } }).environment.attestation;
72
+ delete (bare as { attestation?: unknown }).attestation;
73
+ const unattested = await verifyCarrier(buildCarrier(inner, bare));
74
+ assert.notEqual(unattested.verdict, "TRUE");
75
+ assert.equal(claimsById(unattested)["attestation.signature"], "NOT_CARRIED");
76
+ });
77
+
78
+ test("an attestation that does not decode is FALSE; a declared measurement is never hardware evidence", async () => {
79
+ // A deep copy: the fixture's proof object is shared by every test here.
80
+ const p = JSON.parse(JSON.stringify(golden())) as CarrierPayload;
81
+ (p.proof as { environment: { attestation: { reportB64: string } } }).environment.attestation.reportB64 = "AA==";
82
+ delete (p as { attestation?: unknown }).attestation;
83
+ const r = await verifyCarrier(buildCarrier(inner, p));
84
+ const c = claimsById(r);
85
+ assert.equal(c["attestation.signature"], "FALSE");
86
+ assert.equal(c["attestation.pins"], "UNDETERMINED", "the proof names a published image, and that is a claim, not evidence");
87
+ assert.equal(r.verdict, "FALSE");
88
+ });
89
+
90
+ test("a sidecar whose floor is present but carries no header fails; one with a null floor passes", async () => {
91
+ const opts = { writerAddress: "0xf3972408D853c975F86351C311f4310220bbF2a3", chainId: 8453 };
92
+ const empty = { ...sidecar, floor: { ...(sidecar as { floor: object }).floor, blockHeader: "" } };
93
+ const r = await verifyCeiling(proof as never, empty as never, opts);
94
+ assert.equal(r.ok, false);
95
+ assert.match(r.reason ?? "", /^floor: the sidecar carries a floor without a header/);
96
+ const none = await verifyCeiling(proof as never, { ...sidecar, floor: null } as never, opts);
97
+ assert.equal(none.ok, true, none.reason);
98
+ });
99
+
100
+ test("malformed evidence never throws: a null root is FALSE in the sidecar check and in the file", async () => {
101
+ const opts = { writerAddress: "0xf3972408D853c975F86351C311f4310220bbF2a3", chainId: 8453 };
102
+ const broken = { ...sidecar, root: null };
103
+ const r = await verifyCeiling(proof as never, broken as never, opts);
104
+ assert.equal(r.ok, false);
105
+ const p = golden();
106
+ (p.ceilingInTime as { sidecar: Record<string, unknown> }).sidecar = broken;
107
+ const f = await verifyCarrier(buildCarrier(inner, p));
108
+ assert.equal(f.verdict, "FALSE");
109
+ assert.equal(f.bounds?.existedBy ?? null, null, "a ceiling that did not verify states no Base time");
110
+ for (const field of [["anchor", "rawTx"], ["anchor", "blockHeader"], ["anchor", "txIndex"], ["merklePath"], ["proofHash"]]) {
111
+ const s = JSON.parse(JSON.stringify(sidecar)) as Record<string, unknown>;
112
+ let at: Record<string, unknown> = s;
113
+ for (const k of field.slice(0, -1)) at = at[k] as Record<string, unknown>;
114
+ at[field[field.length - 1]!] = null;
115
+ const x = await verifyCeiling(proof as never, s as never, opts);
116
+ assert.equal(x.ok, false, field.join("."));
117
+ }
118
+ });
119
+
58
120
  test("the block stays under the ZIP limit, with the witness inside", () => {
59
121
  const size = carrierBlockSize(golden());
60
122
  assert.ok(size < CARRIER_BLOCK_ZIP_LIMIT, `block is ${size} bytes`);
@@ -149,7 +211,7 @@ test("a v1 reader's view of a v2 block: an unknown version is UNDETERMINED, neve
149
211
  // A reader from before /2 rejects the version string in payloadShapeError; the same
150
212
  // path is taken here for any version this reader does not know.
151
213
  const p = golden() as unknown as Record<string, unknown>;
152
- p["carrier"] = "bitgraph-carrier/3";
214
+ p["carrier"] = "bitgraph-carrier/4"; // /3 exists since 2026-10-06 (a Base floor); /4 does not
153
215
  const r = await verifyCarrier(buildCarrier(inner, p as unknown as CarrierPayload));
154
216
  assert.equal(r.verdict, "UNDETERMINED");
155
217
  assert.equal(r.carrier, "corrupt");
@@ -269,14 +269,22 @@ test("a rebuilt header with a moved timestamp passes offline and says it was not
269
269
  assert.equal(r.headerCheckedAgainstChain, false);
270
270
  });
271
271
 
272
- test("a floor header that is not the proof's signed floor is ignored, not trusted", async () => {
272
+ test("a floor header that is not the proof's signed floor fails the sidecar: every part it carries must hold", async () => {
273
273
  const w = build();
274
274
  const s = clone(w.sidecar);
275
275
  const f = rlpDecode(hexToBytes(s.floor!.blockHeader)) as Uint8Array[];
276
276
  f[11] = u(1);
277
277
  s.floor!.blockHeader = bytesToHex(rlpEncode(f));
278
278
  const r = await verifyCeiling(proof, s, { writerAddress: w.writer, chainId: CHAIN });
279
- assert.equal(r.ok, true);
280
- assert.equal(r.window!.floor.blockTimestamp, null);
281
- assert.equal(r.window!.widthSeconds, null);
279
+ assert.equal(r.ok, false);
280
+ assert.match(r.reason ?? "", /^floor: the carried floor header does not match the proof's signed slotAnchor/);
281
+ assert.equal(r.window, undefined, "no window from a sidecar that failed");
282
+ });
283
+
284
+ test("the status field never decides: a sidecar with its transaction verifies whatever its status says", async () => {
285
+ const w = build();
286
+ const s = clone(w.sidecar);
287
+ (s as { status: string }).status = "pending";
288
+ const r = await verifyCeiling(proof, s, { writerAddress: w.writer, chainId: CHAIN });
289
+ assert.equal(r.ok, true, r.reason);
282
290
  });
@@ -1,15 +1,20 @@
1
1
  // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
- * Assemble a bitgraph-carrier/2 payload from vetted parts. The caller has
4
+ * Assemble a bitgraph-carrier/2 or /3 payload from vetted parts. The caller has
5
5
  * already verified every part (the anchors over their messages, the headers
6
6
  * by hash, the Base sidecar with verifyCeiling); this lays them out, derives
7
7
  * the attestation witness from the proof's own document, and declares the
8
8
  * pins the file was made under. It computes nothing that a verifier would
9
9
  * later trust: the witness is recomputed on read, the pins compared.
10
+ *
11
+ * /3 is for a proof whose floor is a Base block (commit.slotFloor): the floor
12
+ * is its header (checked by the caller with checkFloorHeader), and the block
13
+ * states that no ceiling in position exists, since order is the chain of
14
+ * proof hashes. /2 stays the format for Ethereum-floor proofs.
10
15
  */
11
16
 
12
- import { CARRIER_VERSION_2, encodeCarrierBlock, type CarrierPayload, type CarrierFloor, type CarrierCeiling, type CarrierCeilingInTime, type CarrierSettlement, type CarrierPins, type CarrierProof } from "./carrier.js";
17
+ import { CARRIER_VERSION_2, CARRIER_VERSION_3, encodeCarrierBlock, type CarrierPayload, type CarrierFloor, type CarrierBaseFloor, type CarrierCeiling, type CarrierCeilingInTime, type CarrierSettlement, type CarrierPins, type CarrierProof } from "./carrier.js";
13
18
  import { attestationWitness } from "./nitro.js";
14
19
  import { computeProofHash, computeSignedBodyHash } from "./proof-hash.js";
15
20
  import { BITGRAPH_CEILING_WRITER, BASE_MAINNET_CHAIN_ID } from "./carrier-verify.js";
@@ -37,7 +42,20 @@ export interface CarrierV2Parts {
37
42
  */
38
43
  export const CARRIER_BLOCK_ZIP_LIMIT = 60_000;
39
44
 
45
+ /** The parts of a /3 block: a Base floor header, and no ceiling in position (there is none). */
46
+ export interface CarrierV3Parts extends Omit<CarrierV2Parts, "floor" | "ceiling"> {
47
+ floor: CarrierBaseFloor;
48
+ }
49
+
40
50
  export function assembleCarrierV2Payload(parts: CarrierV2Parts): CarrierPayload {
51
+ return assemble(CARRIER_VERSION_2, parts);
52
+ }
53
+
54
+ export function assembleCarrierV3Payload(parts: CarrierV3Parts): CarrierPayload {
55
+ return assemble(CARRIER_VERSION_3, { ...parts, ceiling: { status: "none", basis: "hash-chain" } });
56
+ }
57
+
58
+ function assemble(version: typeof CARRIER_VERSION_2 | typeof CARRIER_VERSION_3, parts: Omit<CarrierV2Parts, "floor"> & { floor: CarrierFloor | CarrierBaseFloor }): CarrierPayload {
41
59
  const proof = parts.proof as unknown as BitGraphProof;
42
60
  const att = proof.environment?.attestation;
43
61
  const wantWitness = parts.withAttestationWitness ?? (att?.format === "aws-nitro" && typeof att.reportB64 === "string");
@@ -48,7 +66,7 @@ export function assembleCarrierV2Payload(parts: CarrierV2Parts): CarrierPayload
48
66
  ...(parts.pins ?? {}),
49
67
  };
50
68
  const payload: CarrierPayload = {
51
- carrier: CARRIER_VERSION_2,
69
+ carrier: version,
52
70
  proof: parts.proof,
53
71
  floor: parts.floor,
54
72
  ceiling: parts.ceiling,