@mikeargento/bitgraph-audit 0.11.0 → 0.12.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 (91) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +7 -5
  3. package/dist/anchors.js +1 -1
  4. package/dist/anomalies.js +1 -1
  5. package/dist/attestation.js +1 -1
  6. package/dist/audit.d.ts +1 -1
  7. package/dist/audit.js +2 -2
  8. package/dist/authority.js +1 -1
  9. package/dist/aws-nitro-root-ca.js +1 -1
  10. package/dist/ceilings.js +1 -1
  11. package/dist/cli.js +1 -1
  12. package/dist/contents-hash.js +1 -1
  13. package/dist/export.js +1 -1
  14. package/dist/exports.js +1 -1
  15. package/dist/floors.js +1 -1
  16. package/dist/genesis.d.ts +141 -0
  17. package/dist/genesis.d.ts.map +1 -0
  18. package/dist/genesis.js +359 -0
  19. package/dist/genesis.js.map +1 -0
  20. package/dist/index.d.ts +6 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +6 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/ingest.js +1 -1
  25. package/dist/publication.d.ts +148 -0
  26. package/dist/publication.d.ts.map +1 -0
  27. package/dist/publication.js +392 -0
  28. package/dist/publication.js.map +1 -0
  29. package/dist/reconstruct.js +1 -1
  30. package/dist/report-json.js +1 -1
  31. package/dist/report-md.js +1 -1
  32. package/dist/rlp.js +1 -1
  33. package/dist/rollup-schedule.d.ts +58 -0
  34. package/dist/rollup-schedule.d.ts.map +1 -0
  35. package/dist/rollup-schedule.js +105 -0
  36. package/dist/rollup-schedule.js.map +1 -0
  37. package/dist/settlement-blobs.d.ts +16 -19
  38. package/dist/settlement-blobs.d.ts.map +1 -1
  39. package/dist/settlement-blobs.js +37 -17
  40. package/dist/settlement-blobs.js.map +1 -1
  41. package/dist/tar.js +1 -1
  42. package/dist/temporal.js +1 -1
  43. package/dist/tot.d.ts +99 -0
  44. package/dist/tot.d.ts.map +1 -0
  45. package/dist/tot.js +242 -0
  46. package/dist/tot.js.map +1 -0
  47. package/dist/types.js +1 -1
  48. package/dist/validity.js +1 -1
  49. package/dist/verify-tiers.js +1 -1
  50. package/dist/witness.js +1 -1
  51. package/package.json +5 -4
  52. package/src/__tests__/{anchors.test.ts → archive/anchors.test.ts} +3 -3
  53. package/src/__tests__/{base-floor.test.ts → archive/base-floor.test.ts} +3 -3
  54. package/src/__tests__/{carrier-tree.test.ts → archive/carrier-tree.test.ts} +3 -3
  55. package/src/__tests__/archive/genesis.test.ts +256 -0
  56. package/src/__tests__/archive/publication.test.ts +210 -0
  57. package/src/__tests__/{settlement.test.ts → archive/settlement.test.ts} +1 -1
  58. package/src/__tests__/tot-v2-vectors.test.ts +87 -0
  59. package/src/__tests__/tot-vectors.test.ts +120 -0
  60. package/src/anchors.ts +1 -1
  61. package/src/anomalies.ts +1 -1
  62. package/src/attestation.ts +1 -1
  63. package/src/audit.ts +2 -2
  64. package/src/authority.ts +1 -1
  65. package/src/aws-nitro-root-ca.ts +1 -1
  66. package/src/ceilings.ts +1 -1
  67. package/src/cli.ts +1 -1
  68. package/src/contents-hash.ts +1 -1
  69. package/src/export.ts +1 -1
  70. package/src/exports.ts +1 -1
  71. package/src/floors.ts +1 -1
  72. package/src/genesis.ts +382 -0
  73. package/src/index.ts +27 -1
  74. package/src/ingest.ts +1 -1
  75. package/src/publication.ts +461 -0
  76. package/src/reconstruct.ts +1 -1
  77. package/src/report-json.ts +1 -1
  78. package/src/report-md.ts +1 -1
  79. package/src/rlp.ts +1 -1
  80. package/src/rollup-schedule.ts +105 -0
  81. package/src/settlement-blobs.ts +41 -21
  82. package/src/tar.ts +1 -1
  83. package/src/temporal.ts +1 -1
  84. package/src/tot.ts +253 -0
  85. package/src/types.ts +1 -1
  86. package/src/validity.ts +1 -1
  87. package/src/verify-tiers.ts +1 -1
  88. package/src/witness.ts +1 -1
  89. /package/src/__tests__/{fixtures → archive/fixtures}/settlement/0x018efc046e94610e2530344caf1574e507a3182e1a975fb25b032ec1434a3f5c.bin +0 -0
  90. /package/src/__tests__/{fixtures → archive/fixtures}/settlement/ceiling-51979918.json +0 -0
  91. /package/src/__tests__/{fixtures → archive/fixtures}/settlement/pointer-51979918.json +0 -0
@@ -0,0 +1,210 @@
1
+ // Copyright (c) 2025-2026 Argento Computing Inc.
2
+
3
+ /**
4
+ * Hourly publication: the write's calldata, the hour's tree, the floor note, and the offline check of a proof's
5
+ * publication block against a real signed transaction in a real header and transaction trie (built here, not mocked).
6
+ */
7
+
8
+ import { test, describe } from "node:test";
9
+ import assert from "node:assert/strict";
10
+ import { Transaction, addr } from "micro-eth-signer";
11
+ import { rlpEncode, keccak256, txTrieProof, evmBytesToHex, evmHexToBytes, bytesToB64 } from "@mikeargento/bitgraph-verify";
12
+ import {
13
+ encodeHourCalldata, decodeHourCalldata, hourLink, hourTree, floorNoteText, parseFloorNote, floorNoteDigestB64,
14
+ publishedChainHash, checkPublication, checkHourChain, PUBLICATION_METADATA_KEY, HOUR_RECORD_FORMAT,
15
+ type HourWrite, type PublicationBlock, type WriteEvidence, type HourRecord,
16
+ } from "../../publication.ts";
17
+
18
+ const EPOCH = bytesToB64(new Uint8Array(32).fill(7));
19
+ const OTHER_EPOCH = bytesToB64(new Uint8Array(32).fill(9));
20
+ const KEY = bytesToB64(new Uint8Array(32).fill(3));
21
+ const ZERO = "0".repeat(64);
22
+ const writer = addr.random();
23
+ const stranger = addr.random();
24
+
25
+ function fakeProof(counter: number, epochId = EPOCH, digestB64 = bytesToB64(new Uint8Array(32).fill(counter & 255))): Record<string, unknown> {
26
+ return {
27
+ version: "bitgraph/1",
28
+ artifact: { hashAlg: "sha256", digestB64 },
29
+ commit: { nonceB64: bytesToB64(new Uint8Array(32).fill((counter * 3) & 255)), counter: String(counter), slotCounter: String(counter - 1), epochId, atomic: true },
30
+ signer: { publicKeyB64: KEY, signatureB64: "AA==" },
31
+ };
32
+ }
33
+
34
+ /** A signed self-addressed write, in a block of its own plus a neighbor, with header and trie evidence. */
35
+ function publish(calldata: Uint8Array, opts: { from?: { privateKey: string; address: string }; chainId?: bigint; blockNumber?: number } = {}): WriteEvidence {
36
+ const from = opts.from ?? writer;
37
+ const tx = Transaction.prepare({ to: from.address, value: 0n, nonce: 0n, maxFeePerGas: 1_000_000n, maxPriorityFeePerGas: 1n, gasLimit: 60_000n, chainId: opts.chainId ?? 8453n, data: evmBytesToHex(calldata) } as never);
38
+ const raw = evmHexToBytes(tx.signBy(from.privateKey).toHex(true));
39
+ const neighbor = evmHexToBytes(Transaction.prepare({ to: stranger.address, value: 1n, nonce: 4n, maxFeePerGas: 1_000_000n, maxPriorityFeePerGas: 1n, gasLimit: 21_000n, chainId: 8453n } as never).signBy(stranger.privateKey).toHex(true));
40
+ const txs = [neighbor, raw];
41
+ const { root, proof } = txTrieProof(txs, 1);
42
+ const number = opts.blockNumber ?? 38_000_000;
43
+ const timestamp = 1_794_000_000 + number;
44
+ const n = (v: number): Uint8Array => { const h = v.toString(16); return evmHexToBytes((h.length % 2 ? "0" : "") + h); };
45
+ const header = rlpEncode([
46
+ new Uint8Array(32).fill(1), new Uint8Array(32).fill(2), new Uint8Array(20).fill(4), new Uint8Array(32).fill(5), root,
47
+ new Uint8Array(32).fill(6), new Uint8Array(256), new Uint8Array(0), n(number), n(30_000_000), n(100_000), n(timestamp),
48
+ new Uint8Array(0), new Uint8Array(32).fill(8), new Uint8Array(8), n(1000),
49
+ ]);
50
+ return {
51
+ chain: "base", chainId: 8453, writer: from.address.toLowerCase(),
52
+ txHash: evmBytesToHex(keccak256(raw)), blockNumber: number, blockHash: evmBytesToHex(keccak256(header)), blockTimestamp: timestamp,
53
+ headerRlp: evmBytesToHex(header), txIndex: 1, txInclusionProof: proof.map(evmBytesToHex), rawTx: evmBytesToHex(raw),
54
+ };
55
+ }
56
+
57
+ function attach(proof: Record<string, unknown>, block: PublicationBlock): Record<string, unknown> {
58
+ return { ...proof, metadata: { ...((proof["metadata"] as object | undefined) ?? {}), [PUBLICATION_METADATA_KEY]: block } };
59
+ }
60
+
61
+ /** Two published hours of one epoch: hour A covers 2..6, its floor is #8, hour B covers 8..12. */
62
+ function scenario() {
63
+ const a = [2, 4, 6].map((c) => fakeProof(c));
64
+ const treeA = hourTree(a.map(publishedChainHash));
65
+ const wA: HourWrite = { epochId: EPOCH, first: 2, last: 6, leaves: 3, rootHex: treeA.rootHex, prevLinkHex: ZERO, epochPublicKeyB64: KEY };
66
+ const cdA = encodeHourCalldata(wA);
67
+ const evA = publish(cdA, { blockNumber: 38_000_000 });
68
+ const note = floorNoteText({ chainId: 8453, blockNumber: evA.blockNumber, blockHash: evA.blockHash, blockTimestamp: evA.blockTimestamp, txHash: evA.txHash, writeLinkHex: hourLink(cdA) });
69
+ const floor = fakeProof(8, EPOCH, floorNoteDigestB64(note));
70
+ const b = [floor, fakeProof(10), fakeProof(12)];
71
+ const treeB = hourTree(b.map(publishedChainHash));
72
+ const wB: HourWrite = { epochId: EPOCH, first: 8, last: 12, leaves: 3, rootHex: treeB.rootHex, prevLinkHex: hourLink(cdA) };
73
+ const cdB = encodeHourCalldata(wB);
74
+ const evB = publish(cdB, { blockNumber: 38_001_800 });
75
+ return { a, treeA, cdA, evA, note, floor, b, treeB, cdB, evB };
76
+ }
77
+
78
+ function blockFor(proof: Record<string, unknown>, index: number, tree: { paths: string[] }, calldata: Uint8Array, write: WriteEvidence, floor: PublicationBlock["floor"]): PublicationBlock {
79
+ const c = proof["commit"] as { epochId: string; counter: string };
80
+ return { format: PUBLICATION_METADATA_KEY, epochId: c.epochId, counter: c.counter, chainHashB64: publishedChainHash(proof), leafIndex: index, path: tree.paths[index]!, calldata: evmBytesToHex(calldata), write, floor };
81
+ }
82
+
83
+ describe("the hourly write", () => {
84
+ test("calldata round-trips, with and without the epoch key", () => {
85
+ const w: HourWrite = { epochId: EPOCH, first: 2, last: 40, leaves: 20, rootHex: "ab".repeat(32), prevLinkHex: "cd".repeat(32) };
86
+ const cd = encodeHourCalldata(w);
87
+ assert.equal(cd.length, 121);
88
+ assert.deepEqual(decodeHourCalldata(cd), w);
89
+ const wk = { ...w, epochPublicKeyB64: KEY };
90
+ const cdk = encodeHourCalldata(wk);
91
+ assert.equal(cdk.length, 153);
92
+ assert.deepEqual(decodeHourCalldata(cdk), wk);
93
+ });
94
+
95
+ test("a quiet hour has no leaves and a zero root; a nonzero root with no leaves is refused", () => {
96
+ const q: HourWrite = { epochId: EPOCH, first: 40, last: 40, leaves: 0, rootHex: ZERO, prevLinkHex: "cd".repeat(32) };
97
+ assert.deepEqual(decodeHourCalldata(encodeHourCalldata(q)), q);
98
+ assert.throws(() => encodeHourCalldata({ ...q, rootHex: "ab".repeat(32) }));
99
+ });
100
+
101
+ test("anything else does not decode", () => {
102
+ const cd = encodeHourCalldata({ epochId: EPOCH, first: 2, last: 4, leaves: 2, rootHex: "ab".repeat(32), prevLinkHex: ZERO });
103
+ const bad = cd.slice(); bad[0] = 0x41;
104
+ assert.equal(decodeHourCalldata(bad), null);
105
+ const flag = cd.slice(); flag[4] = 1; // says it carries a key but is 121 bytes
106
+ assert.equal(decodeHourCalldata(flag), null);
107
+ assert.equal(decodeHourCalldata(cd.subarray(0, 120)), null);
108
+ });
109
+
110
+ test("the floor note round-trips and its digest is SHA-256 of its text", () => {
111
+ const n = { chainId: 8453, blockNumber: 38_000_000, blockHash: "0x" + "ab".repeat(32), blockTimestamp: 1_794_000_000, txHash: "0x" + "cd".repeat(32), writeLinkHex: "ef".repeat(32) };
112
+ const t = floorNoteText(n);
113
+ assert.deepEqual(parseFloorNote(t), n);
114
+ assert.equal(parseFloorNote(t.replace("block: ", "block: ")), null);
115
+ assert.equal(floorNoteDigestB64(t).length, 44);
116
+ });
117
+
118
+ test("a proof publishes under the same leaf with or without unsigned metadata", () => {
119
+ const p = fakeProof(10);
120
+ const withMember = { ...p, metadata: { "bitgraph-tree-member/1": { format: "bitgraph-tree-member/1", files: 2, index: 0, path: "", rootText: "x" } } };
121
+ assert.equal(publishedChainHash(withMember), publishedChainHash(p));
122
+ });
123
+ });
124
+
125
+ describe("a proof's publication block", () => {
126
+ test("a proof in the first hour of an epoch checks, with no floor", () => {
127
+ const s = scenario();
128
+ const p = attach(s.a[1]!, blockFor(s.a[1]!, 1, s.treeA, s.cdA, s.evA, null));
129
+ const r = checkPublication(p, { writer: writer.address.toLowerCase() });
130
+ assert.deepEqual(r.problems, []);
131
+ assert.equal(r.ok, true);
132
+ assert.equal(r.ceiling?.blockNumber, 38_000_000);
133
+ assert.equal(r.floor, null);
134
+ });
135
+
136
+ test("a proof after the floor checks, with the floor in the same tree", () => {
137
+ const s = scenario();
138
+ const floor = { proof: s.floor, note: s.note, hourCalldata: evmBytesToHex(s.cdB), leafIndex: 0, path: s.treeB.paths[0]! };
139
+ const p = attach(s.b[2]!, blockFor(s.b[2]!, 2, s.treeB, s.cdB, s.evB, floor));
140
+ const r = checkPublication(p, { writer: writer.address.toLowerCase() });
141
+ assert.deepEqual(r.problems, []);
142
+ assert.equal(r.floor?.blockNumber, 38_000_000, "after the first hour's block");
143
+ assert.equal(r.ceiling?.blockNumber, 38_001_800, "by the second hour's block");
144
+ });
145
+
146
+ test("a floor in the tree the write links back to also checks", () => {
147
+ // A third hour whose proof's floor is #8, published in hour B's tree.
148
+ const s = scenario();
149
+ const c = [fakeProof(14)];
150
+ const treeC = hourTree(c.map(publishedChainHash));
151
+ const cdC = encodeHourCalldata({ epochId: EPOCH, first: 14, last: 14, leaves: 1, rootHex: treeC.rootHex, prevLinkHex: hourLink(s.cdB) });
152
+ const evC = publish(cdC, { blockNumber: 38_003_600 });
153
+ const floor = { proof: s.floor, note: s.note, hourCalldata: evmBytesToHex(s.cdB), leafIndex: 0, path: s.treeB.paths[0]! };
154
+ const r = checkPublication(attach(c[0]!, blockFor(c[0]!, 0, treeC, cdC, evC, floor)), { writer: writer.address.toLowerCase() });
155
+ assert.deepEqual(r.problems, []);
156
+ });
157
+
158
+ test("tampering anywhere is caught", () => {
159
+ const s = scenario();
160
+ const floor = { proof: s.floor, note: s.note, hourCalldata: evmBytesToHex(s.cdB), leafIndex: 0, path: s.treeB.paths[0]! };
161
+ const good = blockFor(s.b[2]!, 2, s.treeB, s.cdB, s.evB, floor);
162
+ const w = writer.address.toLowerCase();
163
+ const bad = (blk: PublicationBlock, proof = s.b[2]!, o: { writer?: string } = { writer: w }) => checkPublication(attach(proof, blk), o);
164
+
165
+ assert.equal(bad({ ...good, path: s.treeB.paths[1]! }).ok, false, "a wrong path");
166
+ assert.equal(bad(good, s.b[1]!).ok, false, "another proof under this block");
167
+ assert.equal(bad({ ...good, calldata: evmBytesToHex(s.cdA) }).ok, false, "another write's calldata");
168
+ assert.equal(bad({ ...good, write: { ...good.write, txIndex: 0 } }).ok, false, "the wrong trie position");
169
+ assert.equal(bad({ ...good, write: { ...good.write, blockTimestamp: good.write.blockTimestamp + 1 } }).ok, false, "a time the header does not say");
170
+ assert.equal(bad({ ...good, write: { ...good.write, headerRlp: s.evA.headerRlp } }).ok, false, "another block's header");
171
+ assert.equal(bad(good, s.b[2]!, { writer: stranger.address.toLowerCase() }).ok, false, "a different expected writer");
172
+ const forged = publish(s.cdB, { from: stranger });
173
+ assert.equal(bad({ ...good, write: forged }, s.b[2]!).ok, false, "the same calldata sent by someone else");
174
+ assert.equal(bad({ ...good, floor: { ...floor, note: s.note.replace("block: 38000000", "block: 37999999") } }).ok, false, "a floor note that is not what the floor binds");
175
+ assert.equal(bad({ ...good, floor: { ...floor, proof: fakeProof(14, EPOCH, floorNoteDigestB64(s.note)) } }).ok, false, "a floor after the proof");
176
+ assert.equal(bad({ ...good, floor: { ...floor, proof: fakeProof(8, OTHER_EPOCH, floorNoteDigestB64(s.note)) } }).ok, false, "a floor from another epoch");
177
+ assert.equal(bad({ ...good, floor: { ...floor, hourCalldata: evmBytesToHex(s.cdA) } }).ok, false, "a floor in a tree that is not this write's nor the one before");
178
+ const otherKey = { ...s.floor, signer: { publicKeyB64: bytesToB64(new Uint8Array(32).fill(5)), signatureB64: "AA==" } };
179
+ assert.equal(bad({ ...good, floor: { ...floor, proof: otherKey } }).ok, false, "a floor signed by another key (anyone can make one)");
180
+ assert.deepEqual(bad({ ...good, floor: { ...floor, proof: null as never } }).problems, ["the floor is malformed"], "a malformed floor is a problem, not a throw");
181
+ assert.deepEqual(bad(good).problems, [], "and the untouched block still checks");
182
+ });
183
+
184
+ test("a proof outside the write's range is refused", () => {
185
+ const s = scenario();
186
+ const outside = attach(s.b[2]!, { ...blockFor(s.b[2]!, 2, s.treeB, s.cdB, s.evB, null), calldata: evmBytesToHex(encodeHourCalldata({ epochId: EPOCH, first: 8, last: 10, leaves: 3, rootHex: s.treeB.rootHex, prevLinkHex: hourLink(s.cdA) })) });
187
+ assert.equal(checkPublication(outside).ok, false);
188
+ });
189
+
190
+ test("no block, no check", () => {
191
+ assert.equal(checkPublication(fakeProof(2)).ok, false);
192
+ });
193
+ });
194
+
195
+ describe("the chain of hourly writes", () => {
196
+ test("writes link in order, quiet hours count, and a broken link or wrong members show", () => {
197
+ const s = scenario();
198
+ const quiet = encodeHourCalldata({ epochId: EPOCH, first: 12, last: 12, leaves: 0, rootHex: ZERO, prevLinkHex: hourLink(s.cdB) });
199
+ const rec = (cd: Uint8Array, ev: WriteEvidence, members: Record<string, unknown>[]): HourRecord => ({
200
+ format: HOUR_RECORD_FORMAT, calldata: evmBytesToHex(cd), link: hourLink(cd), write: ev,
201
+ members: members.map((m) => ({ counter: (m["commit"] as { counter: string }).counter, chainHashB64: publishedChainHash(m) })), missing: [], writtenAt: "2026-11-13T00:00:00.000Z",
202
+ });
203
+ const run = [rec(s.cdA, s.evA, s.a), rec(s.cdB, s.evB, s.b), rec(quiet, publish(quiet), [])];
204
+ const ok = checkHourChain(run);
205
+ assert.deepEqual(ok.problems, []);
206
+ assert.equal(ok.quietHours, 1);
207
+ assert.equal(checkHourChain([run[0]!, run[2]!]).ok, false, "a missing hour breaks the links");
208
+ assert.equal(checkHourChain([run[0]!, { ...run[1]!, members: run[1]!.members.slice(1) }]).ok, false, "members that do not make the root");
209
+ });
210
+ });
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc.
2
2
 
3
3
  /**
4
4
  * The blob layer of a ceiling's settlement on Ethereum, on REAL data.
@@ -0,0 +1,87 @@
1
+ // Copyright (c) 2024-2026 Argento Computing Inc.
2
+
3
+ /**
4
+ * The bitgraph-tot-v2 vectors (spec/vectors/bitgraph-tot-v2.json), checked against the reference check: each
5
+ * receipt's verdict with the test trust inputs passed in, its refusal with the real ones, and the optional floor
6
+ * step run against the chain answers the file records, with no network.
7
+ */
8
+
9
+ import { test } from "node:test";
10
+ import assert from "node:assert/strict";
11
+ import { readFileSync } from "node:fs";
12
+ import { verifyTotReceipt, checkTotFloor, checkSpentOnce, TOT_FORMAT_V2, TOT_V2_MEASUREMENTS, TOT_V1_MEASUREMENTS, TOT_MEASUREMENTS } from "@mikeargento/bitgraph-audit";
13
+
14
+ const V = JSON.parse(readFileSync(new URL("../../../../spec/vectors/bitgraph-tot-v2.json", import.meta.url), "utf8"));
15
+ const V1 = JSON.parse(readFileSync(new URL("../../../../spec/vectors/bitgraph-tot-v1.json", import.meta.url), "utf8"));
16
+ const inputs = { rootDer: new Uint8Array(Buffer.from(V.testTrustInputs.rootDerB64, "base64")), measurements: V.testTrustInputs.acceptedMeasurements as string[] };
17
+ const byName = (n: string) => V.receipts.find((r: { name: string }) => r.name === n);
18
+ const fileOf = (v: { fileB64: string }) => new Uint8Array(Buffer.from(v.fileB64, "base64"));
19
+ /** What the recorded chain says about a floor's block: a header, null for "no such block". */
20
+ const recorded = (floor: { network: string; number: string }) => V.chain[floor.network][floor.number];
21
+
22
+ test("the file names this format and its inputs, and the default accepts both formats' images", () => {
23
+ assert.equal(V.format, TOT_FORMAT_V2);
24
+ assert.deepEqual(V.inputs.acceptedMeasurements, [...TOT_V2_MEASUREMENTS]);
25
+ assert.deepEqual([...TOT_MEASUREMENTS], [...TOT_V1_MEASUREMENTS, ...TOT_V2_MEASUREMENTS]);
26
+ });
27
+
28
+ test("every vector gets its expected verdict with the test inputs, and is refused with the real ones", async () => {
29
+ for (const v of V.receipts) {
30
+ const r = await verifyTotReceipt({ receipt: v.receipt, file: fileOf(v), ...inputs });
31
+ assert.equal(r.verdict, v.expected.verdict, v.name);
32
+ if (v.expected.reason) assert.equal(r.reason, v.expected.reason, v.name);
33
+ if (v.expected.attestedAt) assert.equal(r.attestedAt, v.expected.attestedAt, v.name);
34
+ assert.deepEqual(r.floor, v.expected.floor, `${v.name}: the signed floor, when accepted`);
35
+ assert.equal((await verifyTotReceipt({ receipt: v.receipt, file: fileOf(v) })).verdict, "REJECT", `${v.name} with the real inputs`);
36
+ }
37
+ });
38
+
39
+ test("the floor step gives each accepted vector its expected answer, from the recorded chain alone", async () => {
40
+ for (const v of V.receipts) {
41
+ if (v.expected.verdict !== "ACCEPT") { assert.equal(v.expectedFloor, undefined, `${v.name}: a refused receipt has no floor step`); continue; }
42
+ const f = v.receipt.slotAllocation.floor;
43
+ const c = await checkTotFloor({ receipt: v.receipt, attestedAt: v.expected.attestedAt, maxFloorGapMs: V.maxFloorGapMs, block: f ? recorded(f) : null });
44
+ for (const [k, want] of Object.entries(v.expectedFloor)) assert.deepEqual((c as unknown as Record<string, unknown>)[k], want, `${v.name}: ${k}`);
45
+ }
46
+ });
47
+
48
+ test("with-floor: confirmed, the block's time bound by its hash, a gap of 412 ms", async () => {
49
+ const v = byName("with-floor");
50
+ const c = await checkTotFloor({ receipt: v.receipt, attestedAt: v.expected.attestedAt, block: recorded(v.receipt.slotAllocation.floor) });
51
+ assert.equal(c.status, "confirmed");
52
+ assert.equal(c.timeBoundByHash, true);
53
+ assert.equal(c.gapMs, 412);
54
+ assert.equal(c.stale, undefined, "no limit given, nothing flagged");
55
+ assert.equal(c.networkName, "Base");
56
+ assert.equal(c.blockUrl, "https://basescan.org/block/66088566");
57
+ });
58
+
59
+ test("the floor step never changes a verdict: stale, ahead of the clock and unconfirmed floors all sit on accepted receipts", () => {
60
+ for (const n of ["stale-floor", "clock-ahead", "unknown-hash", "unknown-block"]) assert.equal(byName(n).expected.verdict, "ACCEPT", n);
61
+ assert.equal(byName("stale-floor").expectedFloor.stale, true);
62
+ assert.equal(byName("clock-ahead").expectedFloor.gapMs, -300);
63
+ assert.equal(byName("clock-ahead").expectedFloor.stale, false);
64
+ assert.equal(byName("unknown-hash").expectedFloor.status, "not-confirmed");
65
+ assert.equal(byName("unknown-block").expectedFloor.status, "not-confirmed");
66
+ });
67
+
68
+ test("the refused vectors fail where the spec says", async () => {
69
+ assert.match(byName("tampered-floor").expected.reason, /signature verification failed/);
70
+ for (const n of ["malformed-floor", "floor-on-slot-1", "extra-field"]) assert.match(byName(n).expected.reason, /^R1 form: /, n);
71
+ // A refused receipt's floor is never read.
72
+ for (const n of ["tampered-floor", "malformed-floor", "floor-on-slot-1", "extra-field"]) {
73
+ const v = byName(n);
74
+ assert.equal((await verifyTotReceipt({ receipt: v.receipt, ...inputs })).floor, undefined, n);
75
+ }
76
+ });
77
+
78
+ test("the set rule covers both TOT versions, and version 1's vectors are judged as before", async () => {
79
+ const set = await checkSpentOnce(V.receipts.map((r: { receipt: unknown }) => r.receipt));
80
+ assert.equal(set.verdict, V.setExpected.verdict);
81
+ assert.deepEqual(set.counted.map((i) => V.receipts[i].name), V.setExpected.counted);
82
+ for (const v of V1.receipts) {
83
+ const r = await verifyTotReceipt({ receipt: v.receipt, ...(v.fileB64 ? { file: new Uint8Array(Buffer.from(v.fileB64, "base64")) } : {}) });
84
+ assert.equal(r.verdict, v.expected.verdict, `v1 ${v.name}`);
85
+ assert.equal(r.floor, undefined);
86
+ }
87
+ });
@@ -0,0 +1,120 @@
1
+ // Copyright (c) 2024-2026 Argento Computing Inc.
2
+
3
+ /**
4
+ * The bitgraph-tot-v1 vectors (spec/vectors/bitgraph-tot-v1.json), checked against the reference check, and each
5
+ * refused vector checked to fail for the reason the spec gives.
6
+ */
7
+
8
+ import { test } from "node:test";
9
+ import assert from "node:assert/strict";
10
+ import { readFileSync } from "node:fs";
11
+ import { createHash } from "node:crypto";
12
+ import { verifyProofIntegrity, createVerificationContext, computeSignedBodyHash, type BitGraphProof } from "@mikeargento/bitgraph-verify";
13
+ import { verifyTotReceipt, checkSpentOnce, totFormProblem, TOT_FORMAT, TOT_V1_MEASUREMENTS } from "@mikeargento/bitgraph-audit";
14
+
15
+ const V = JSON.parse(readFileSync(new URL("../../../../spec/vectors/bitgraph-tot-v1.json", import.meta.url), "utf8"));
16
+ const byName = (n: string) => V.receipts.find((r: { name: string }) => r.name === n);
17
+
18
+ test("the file names this format and its inputs", () => {
19
+ assert.equal(V.format, TOT_FORMAT);
20
+ assert.deepEqual(V.inputs.acceptedMeasurements, [...TOT_V1_MEASUREMENTS]);
21
+ });
22
+
23
+ test("every single-receipt vector gets its expected verdict", async () => {
24
+ for (const v of V.receipts) {
25
+ const file = v.fileB64 ? new Uint8Array(Buffer.from(v.fileB64, "base64")) : undefined;
26
+ const r = await verifyTotReceipt({ receipt: v.receipt, ...(file ? { file } : {}) });
27
+ assert.equal(r.verdict, v.expected.verdict, v.name);
28
+ if (v.expected.reason) assert.equal(r.reason, v.expected.reason, v.name);
29
+ }
30
+ });
31
+
32
+ test("valid: the file is the one bound, and the receipt also passes without it", async () => {
33
+ const v = byName("valid");
34
+ const file = Buffer.from(v.fileB64, "base64");
35
+ assert.equal(createHash("sha256").update(file).digest("base64"), v.receipt.artifact.digestB64);
36
+ const withFile = await verifyTotReceipt({ receipt: v.receipt, file: new Uint8Array(file) });
37
+ assert.equal(withFile.file, "compared");
38
+ assert.equal(withFile.attestedAt, v.expected.attestedAt);
39
+ const without = await verifyTotReceipt({ receipt: v.receipt });
40
+ assert.equal(without.verdict, "ACCEPT");
41
+ assert.equal(without.file, "not-compared");
42
+ // The wrong file is refused (R10).
43
+ const wrong = await verifyTotReceipt({ receipt: v.receipt, file: new Uint8Array(Buffer.from("not the file")) });
44
+ assert.equal(wrong.verdict, "REJECT");
45
+ });
46
+
47
+ test("altered-digest fails the receipt signature (R6) as well as the attestation binding (R8)", async () => {
48
+ const v = byName("altered-digest");
49
+ const sig = await verifyProofIntegrity({ proof: v.receipt as BitGraphProof, context: createVerificationContext() });
50
+ assert.equal(sig.valid, false);
51
+ assert.match(sig.reason ?? "", /signature/);
52
+ });
53
+
54
+ test("wrong-attestation keeps a valid signature: only the binding (R8) refuses it", async () => {
55
+ const v = byName("wrong-attestation");
56
+ const sig = await verifyProofIntegrity({ proof: v.receipt as BitGraphProof, context: createVerificationContext() });
57
+ assert.equal(sig.valid, true);
58
+ assert.equal(computeSignedBodyHash(v.receipt), computeSignedBodyHash(byName("valid").receipt));
59
+ });
60
+
61
+ const spentTwice = () => V.sets.find((x: { name: string }) => x.name === "spent-twice");
62
+ const testInputs = () => {
63
+ const t = spentTwice().testTrustInputs;
64
+ return { rootDer: new Uint8Array(Buffer.from(t.rootDerB64, "base64")), measurements: t.acceptedMeasurements as string[] };
65
+ };
66
+
67
+ test("spent-twice: under the test inputs, each receipt is accepted on its own (R1 to R10, file compared)", async () => {
68
+ const s = spentTwice();
69
+ for (const [i, r] of s.receipts.entries()) {
70
+ const file = new Uint8Array(Buffer.from(s.filesB64[i], "base64"));
71
+ const one = await verifyTotReceipt({ receipt: r, file, ...testInputs() });
72
+ assert.equal(one.verdict, "ACCEPT", one.reason);
73
+ assert.equal(one.file, "compared");
74
+ assert.deepEqual({ verdict: one.verdict, attestedAt: one.attestedAt }, s.expectedEachWithTestInputs[i]);
75
+ }
76
+ });
77
+
78
+ test("spent-twice: only the set rule refuses the pair, with DUPLICATE_TOT", async () => {
79
+ const s = spentTwice();
80
+ const set = await checkSpentOnce(s.receipts);
81
+ assert.equal(set.verdict, "REJECT");
82
+ assert.equal(set.reason, "DUPLICATE_TOT");
83
+ assert.equal(s.expected.reason, "DUPLICATE_TOT");
84
+ assert.deepEqual(set.spentTwice, s.expected.spentTwice);
85
+ assert.deepEqual(set.counted, [0, 1]);
86
+ // Each one alone passes the set rule: the refusal comes from the pair.
87
+ assert.equal((await checkSpentOnce([s.receipts[0]])).verdict, "ACCEPT");
88
+ assert.equal((await checkSpentOnce([s.receipts[1]])).verdict, "ACCEPT");
89
+ });
90
+
91
+ test("guardrail: the test trust inputs are never accepted by default", async () => {
92
+ const s = spentTwice();
93
+ const t = s.testTrustInputs;
94
+ assert.ok(!TOT_V1_MEASUREMENTS.includes(t.acceptedMeasurements[0]), "the test measurement is not a default");
95
+ assert.notEqual(t.rootSha256, V.inputs.awsNitroRootSha256, "the test root is not the AWS root");
96
+ for (const [i, r] of s.receipts.entries()) {
97
+ const file = new Uint8Array(Buffer.from(s.filesB64[i], "base64"));
98
+ const real = await verifyTotReceipt({ receipt: r, file });
99
+ assert.equal(real.verdict, "REJECT");
100
+ assert.match(real.reason ?? "", /Trust root/);
101
+ assert.equal(s.expectedEachWithRealInputs[i], "REJECT");
102
+ // The test root alone is not enough: the measurement must also be passed in.
103
+ const rootOnly = await verifyTotReceipt({ receipt: r, file, rootDer: testInputs().rootDer });
104
+ assert.equal(rootOnly.verdict, "REJECT");
105
+ assert.match(rootOnly.reason ?? "", /not an image this verifier accepts/);
106
+ }
107
+ });
108
+
109
+ test("the set check: one receipt twice is one receipt; a real epoch's receipts pass", async () => {
110
+ const valid = byName("valid").receipt;
111
+ assert.equal((await checkSpentOnce([valid, valid])).verdict, "ACCEPT");
112
+ const r12 = JSON.parse(readFileSync(new URL("../../../../spec/vectors/bitgraph-tot-v1-sources/receipt-12.json", import.meta.url), "utf8"));
113
+ assert.equal((await checkSpentOnce([valid, r12])).verdict, "ACCEPT");
114
+ // A receipt whose signature fails is not counted, so it cannot refuse a real one.
115
+ const forged = JSON.parse(JSON.stringify(valid));
116
+ forged.artifact.digestB64 = Buffer.alloc(32, 7).toString("base64");
117
+ const r = await checkSpentOnce([valid, forged]);
118
+ assert.equal(r.verdict, "ACCEPT");
119
+ assert.deepEqual(r.counted, [0]);
120
+ });
package/src/anchors.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * bitgraph-audit anchor identification (G5)
package/src/anomalies.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * bitgraph-audit anomaly classification
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * bitgraph-audit offline attestation validation
package/src/audit.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * Audit orchestrator: the full offline pipeline in canonical order.
@@ -40,7 +40,7 @@ import type { AuditOptions, AuditResult, ExitFlags, IngestResult } from "./types
40
40
  * this equals package.json's version, so the constant cannot drift silently
41
41
  * across releases.
42
42
  */
43
- export const AUDIT_VERSION = "0.11.0";
43
+ export const AUDIT_VERSION = "0.12.0";
44
44
 
45
45
  /** The audit package's own version. */
46
46
  export function auditToolVersion(): string {
package/src/authority.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * bitgraph-audit authority analysis
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * AWS Nitro Enclaves Root CA G1
package/src/ceilings.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * Ceilings in time (bitgraph-ceiling/1): each ceiling file in the bundle is
package/src/cli.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
3
3
 
4
4
  /**
5
5
  * bitgraph-audit CLI: run the full offline audit pipeline over a bundle
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * Deterministic bundle contents hash, per docs/BUNDLE-FORMAT.md section 8.
package/src/export.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * Bundle archive builder: the producer counterpart of ingest.
package/src/exports.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * Exports (bitgraph-export/1) through the audit.
package/src/floors.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
1
+ // Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
4
  * bitgraph-audit signed floors (enclave v10)