@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
package/dist/tot.js ADDED
@@ -0,0 +1,242 @@
1
+ // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
+ /**
3
+ * The reference check for the TOT receipt formats: bitgraph-tot-v1 (spec/BITGRAPH-TOT-1.md) and bitgraph-tot-v2
4
+ * (spec/BITGRAPH-TOT-2.md), which is v1 with one addition: the TOT may carry a public floor, a block of a public
5
+ * chain signed into the TOT body (record version bitgraph/slot/2). Every offline check is v1's. Looking the floor's
6
+ * block up is a separate, optional step (checkTotFloor) that needs the network and never changes a verdict.
7
+ *
8
+ * Two checks, as the spec defines them:
9
+ *
10
+ * verifyTotReceipt one receipt: its form (section 7, R1), then the full attested check that every BitGraph tool
11
+ * runs (verifyAttested in @mikeargento/bitgraph-verify: the TOT and its binding, the count order,
12
+ * both signatures, the Nitro document, its binding to this receipt, the measurement, and the
13
+ * file when given), limited to the measurements this format accepts.
14
+ * checkSpentOnce a set of receipts: refused when two different receipts spend one TOT (section 8). One receipt
15
+ * on its own cannot show this, so it is a check over the set. It counts every receipt whose two
16
+ * signatures and TOT binding hold (R2 to R6), attested or not: a key that signed one TOT into two
17
+ * receipts has spent it twice whoever holds the key, and a receipt whose signatures fail is
18
+ * nobody's and cannot refuse another.
19
+ */
20
+ import { verifyAttested, verifyProofIntegrity, createVerificationContext, computeSignedBodyHash, computeSlotRecordHash, buildSignedBody, slotFloorProblem, totFloorOf, checkFloorOnline, checkFloorAgainstBlock, } from "@mikeargento/bitgraph-verify";
21
+ /** The first format's name. */
22
+ export const TOT_FORMAT = "bitgraph-tot-v1";
23
+ /** The second format's name: v1, and a TOT may carry a public floor. */
24
+ export const TOT_FORMAT_V2 = "bitgraph-tot-v2";
25
+ /** The enclave measurements (PCR0, lowercase hex) bitgraph-tot-v1 accepts by default: the v13 image. */
26
+ export const TOT_V1_MEASUREMENTS = Object.freeze([
27
+ "adaad0bef62292d35197ae8db19e40685229f1a1e6070a7c77a148c4ada88ee66a1ca50819eebc2017c6716a49f2692f",
28
+ ]);
29
+ /** The enclave measurements bitgraph-tot-v2 accepts by default: the v14 image, the first that signs a floor. */
30
+ export const TOT_V2_MEASUREMENTS = Object.freeze([
31
+ "10273c68951dd81156364b4b86d240208f37a1999dac27d54ebf3fc7a2fc723a1e2e852b91528d0a24aaf0544af6c52f",
32
+ ]);
33
+ /** Every measurement the reference check accepts by default: both formats'. */
34
+ export const TOT_MEASUREMENTS = Object.freeze([...TOT_V1_MEASUREMENTS, ...TOT_V2_MEASUREMENTS]);
35
+ /** The two TOT record versions. */
36
+ const SLOT_1 = "bitgraph/slot/1";
37
+ const SLOT_2 = "bitgraph/slot/2";
38
+ /** Exactly what a bitgraph/slot/2 TOT holds, its signature included. Nothing else may sit in the record. */
39
+ const SLOT_2_FIELDS = "chainId,counter,epochId,floor,nonceB64,publicKeyB64,signatureB64,version";
40
+ const B64_32 = (s) => {
41
+ if (typeof s !== "string")
42
+ return false;
43
+ {
44
+ const b = Buffer.from(s, "base64");
45
+ return b.length === 32 && b.toString("base64") === s;
46
+ }
47
+ };
48
+ const DEC = /^(0|[1-9][0-9]*)$/;
49
+ const HEX96 = /^[0-9a-f]{96}$/;
50
+ const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
51
+ /** R1, the receipt's form: every field this format requires, in the shape it requires. Null when it is in form. */
52
+ export function totFormProblem(receipt) {
53
+ if (!isObject(receipt))
54
+ return "the receipt is not a JSON object";
55
+ const r = receipt;
56
+ if (r["version"] !== "bitgraph/1")
57
+ return 'version must be "bitgraph/1"';
58
+ const a = r["artifact"];
59
+ if (!isObject(a) || a["hashAlg"] !== "sha256" || !B64_32(a["digestB64"]))
60
+ return "artifact must be {hashAlg: \"sha256\", digestB64: 32 bytes in canonical base64}";
61
+ const c = r["commit"];
62
+ if (!isObject(c))
63
+ return "commit is missing";
64
+ if (c["atomic"] !== true)
65
+ return "commit.atomic must be true";
66
+ if (!B64_32(c["nonceB64"]))
67
+ return "commit.nonceB64 must be 32 bytes in canonical base64";
68
+ if (typeof c["counter"] !== "string" || !DEC.test(c["counter"]))
69
+ return "commit.counter must be a decimal string";
70
+ if (typeof c["slotCounter"] !== "string" || !DEC.test(c["slotCounter"]))
71
+ return "commit.slotCounter must be a decimal string";
72
+ if (!B64_32(c["slotHashB64"]))
73
+ return "commit.slotHashB64 must be 32 bytes in canonical base64";
74
+ if (!B64_32(c["epochId"]))
75
+ return "commit.epochId must be 32 bytes in canonical base64";
76
+ if (c["prevB64"] !== undefined && !B64_32(c["prevB64"]))
77
+ return "commit.prevB64, when present, must be 32 bytes in canonical base64";
78
+ if (c["chainId"] !== "bitgraph:main")
79
+ return 'commit.chainId must be "bitgraph:main"';
80
+ const s = r["signer"];
81
+ if (!isObject(s) || !B64_32(s["publicKeyB64"]) || typeof s["signatureB64"] !== "string")
82
+ return "signer must carry publicKeyB64 (32 bytes) and signatureB64";
83
+ const e = r["environment"];
84
+ if (!isObject(e))
85
+ return "environment is missing";
86
+ if (e["enforcement"] !== "measured-tee")
87
+ return 'environment.enforcement must be "measured-tee"';
88
+ if (typeof e["measurement"] !== "string" || !HEX96.test(e["measurement"]))
89
+ return "environment.measurement must be 96 lowercase hex characters";
90
+ const at = e["attestation"];
91
+ if (!isObject(at) || at["format"] !== "aws-nitro" || typeof at["reportB64"] !== "string" || at["reportB64"].length === 0)
92
+ return 'environment.attestation must be {format: "aws-nitro", reportB64}';
93
+ const t = r["slotAllocation"];
94
+ if (!isObject(t))
95
+ return "slotAllocation (the TOT) is missing";
96
+ if (t["version"] !== SLOT_1 && t["version"] !== SLOT_2)
97
+ return 'slotAllocation.version must be "bitgraph/slot/1" or "bitgraph/slot/2"';
98
+ // A floor is signed in a slot/2 TOT and absent from a slot/1 TOT. A slot/2 TOT holds its listed fields and no others.
99
+ const floor = slotFloorProblem(t);
100
+ if (floor)
101
+ return floor;
102
+ if (t["version"] === SLOT_2 && Object.keys(t).sort().join(",") !== SLOT_2_FIELDS)
103
+ return "a bitgraph/slot/2 slotAllocation must hold exactly its listed fields";
104
+ if (typeof t["counter"] !== "string" || !DEC.test(t["counter"]))
105
+ return "slotAllocation.counter must be a decimal string";
106
+ if (t["time"] !== undefined)
107
+ return "slotAllocation.time must be absent";
108
+ if (!B64_32(t["nonceB64"]) || !B64_32(t["epochId"]) || !B64_32(t["publicKeyB64"]))
109
+ return "slotAllocation.nonceB64, epochId and publicKeyB64 must each be 32 bytes in canonical base64";
110
+ if (t["chainId"] !== "bitgraph:main")
111
+ return 'slotAllocation.chainId must be "bitgraph:main"';
112
+ if (typeof t["signatureB64"] !== "string")
113
+ return "slotAllocation.signatureB64 is missing";
114
+ return null;
115
+ }
116
+ const PRINTABLE_ASCII = /^[\x20-\x7e]*$/;
117
+ /** R2: a signed record holds only strings, booleans and objects, with printable ASCII in every key and string. */
118
+ function recordProblem(value, path) {
119
+ if (typeof value === "boolean")
120
+ return null;
121
+ if (typeof value === "string")
122
+ return PRINTABLE_ASCII.test(value) ? null : `${path} holds a character outside printable ASCII`;
123
+ if (!isObject(value))
124
+ return `${path} is not a string, boolean or object`;
125
+ for (const [k, v] of Object.entries(value)) {
126
+ if (!PRINTABLE_ASCII.test(k))
127
+ return `${path} has a key outside printable ASCII`;
128
+ const p = recordProblem(v, `${path}.${k}`);
129
+ if (p)
130
+ return p;
131
+ }
132
+ return null;
133
+ }
134
+ /** The check of one receipt, with the file when it is given. */
135
+ export async function verifyTotReceipt(opts) {
136
+ const file = opts.file !== undefined ? "compared" : "not-compared";
137
+ const form = totFormProblem(opts.receipt);
138
+ if (form)
139
+ return { verdict: "REJECT", reason: `R1 form: ${form}`, file, checks: [] };
140
+ const p = opts.receipt;
141
+ const { signatureB64: _sig, ...totBody } = p.slotAllocation;
142
+ const records = recordProblem(buildSignedBody(p), "the signed body") ?? recordProblem(totBody, "the TOT body");
143
+ if (records)
144
+ return { verdict: "REJECT", reason: `R2 canonical records: ${records}`, file, checks: [] };
145
+ const r = await verifyAttested({
146
+ proof: opts.receipt,
147
+ ...(opts.file !== undefined ? { bytes: opts.file } : {}),
148
+ pcr0: opts.measurements ?? TOT_MEASUREMENTS,
149
+ ...(opts.rootDer ? { rootDer: opts.rootDer } : {}),
150
+ });
151
+ if (!r.valid)
152
+ return { verdict: "REJECT", reason: r.reason ?? "the receipt does not verify", file, checks: r.checks };
153
+ return {
154
+ verdict: "ACCEPT",
155
+ file,
156
+ ...(r.attestedAtMs !== null ? { attestedAt: new Date(r.attestedAtMs).toISOString() } : {}),
157
+ checks: r.checks,
158
+ ...(totFloorOf(p) ? { floor: totFloorOf(p) } : {}),
159
+ };
160
+ }
161
+ /**
162
+ * The optional online step for a receipt whose TOT carries a floor (bitgraph-tot-v2, section 4): look the block up
163
+ * on its chain. It is run only on a receipt the offline check already accepted, and whatever it answers, that
164
+ * verdict stands.
165
+ *
166
+ * confirmed the chain holds that block: the TOT was made after it. The block's time and the gap from it to
167
+ * the attestation's time are reported; `stale` is set when maxFloorGapMs is given and exceeded.
168
+ * not-confirmed the chain has no such block, or another one at that number: the floor shows nothing.
169
+ * not-checked the lookup could not be made.
170
+ * none the TOT carries no floor.
171
+ *
172
+ * Pass `block` (what the chain says, or null for "no such block") to apply the rule with no network.
173
+ */
174
+ export async function checkTotFloor(opts) {
175
+ if (totFormProblem(opts.receipt) !== null)
176
+ return { status: "none" };
177
+ const proof = opts.receipt;
178
+ const at = opts.attestedAt !== undefined ? Date.parse(opts.attestedAt) : NaN;
179
+ const common = {
180
+ proof,
181
+ ...(Number.isFinite(at) ? { attestedAtMs: at } : {}),
182
+ ...(opts.maxFloorGapMs !== undefined ? { maxGapMs: opts.maxFloorGapMs } : {}),
183
+ };
184
+ if (opts.block !== undefined)
185
+ return checkFloorAgainstBlock({ ...common, block: opts.block });
186
+ return checkFloorOnline({ ...common, ...(opts.rpcUrl ? { rpcUrl: opts.rpcUrl } : {}), ...(opts.fetcher ? { fetcher: opts.fetcher } : {}) });
187
+ }
188
+ /**
189
+ * The set check (section 8): every TOT is spent once. Two receipts that differ in their signed bodies and carry the same
190
+ * TOT, or two different TOTs at one position (the same key, epoch, chain and count), are refused together. The same
191
+ * receipt given twice is one receipt, not two. Only receipts whose signatures and TOT binding hold are counted.
192
+ */
193
+ export async function checkSpentOnce(receipts) {
194
+ const byTot = new Map();
195
+ const byPosition = new Map();
196
+ const add = (m, key, body, i) => {
197
+ const bodies = m.get(key) ?? new Map();
198
+ const list = bodies.get(body) ?? [];
199
+ list.push(i);
200
+ bodies.set(body, list);
201
+ m.set(key, bodies);
202
+ };
203
+ const counted = [];
204
+ for (const [i, r] of receipts.entries()) {
205
+ if (!isObject(r) || !isObject(r["slotAllocation"]) || !isObject(r["commit"]) || r["commit"]["atomic"] !== true)
206
+ continue;
207
+ const p = r;
208
+ // R2: both signed records hold only what the format allows.
209
+ const { signatureB64: _sig, ...totBody } = r["slotAllocation"];
210
+ let inForm = false;
211
+ try {
212
+ inForm = recordProblem(buildSignedBody(p), "the signed body") === null && recordProblem(totBody, "the TOT body") === null;
213
+ }
214
+ catch {
215
+ inForm = false;
216
+ }
217
+ if (!inForm)
218
+ continue;
219
+ const ok = await verifyProofIntegrity({ proof: p, trustAnchors: { requireAtomic: true }, context: createVerificationContext() });
220
+ if (!ok.valid)
221
+ continue;
222
+ counted.push(i);
223
+ const t = p.slotAllocation;
224
+ const body = computeSignedBodyHash(p);
225
+ const totHash = Buffer.from(computeSlotRecordHash(t)).toString("base64");
226
+ add(byTot, totHash, body, i);
227
+ add(byPosition, `${t.publicKeyB64}|${t.epochId}|${t.chainId ?? ""}|${t.counter}`, `${totHash}|${body}`, i);
228
+ }
229
+ const spentTwice = [];
230
+ for (const bodies of byTot.values()) {
231
+ if (bodies.size > 1)
232
+ spentTwice.push({ code: "DUPLICATE_TOT", receipts: [...bodies.values()].map((l) => l[0]).sort((a, b) => a - b) });
233
+ }
234
+ for (const bodies of byPosition.values()) {
235
+ const tots = new Set([...bodies.keys()].map((k) => k.split("|")[0]));
236
+ if (tots.size > 1)
237
+ spentTwice.push({ code: "DUPLICATE_TOT_POSITION", receipts: [...bodies.values()].map((l) => l[0]).sort((a, b) => a - b) });
238
+ }
239
+ const first = spentTwice[0];
240
+ return first ? { verdict: "REJECT", reason: first.code, spentTwice, counted } : { verdict: "ACCEPT", spentTwice, counted };
241
+ }
242
+ //# sourceMappingURL=tot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tot.js","sourceRoot":"","sources":["../src/tot.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,cAAc,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,eAAe,EAC9H,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,sBAAsB,GAEvE,MAAM,8BAA8B,CAAC;AAEtC,+BAA+B;AAC/B,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAC5C,wEAAwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAE/C,wGAAwG;AACxG,MAAM,CAAC,MAAM,mBAAmB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAClE,kGAAkG;CACnG,CAAC,CAAC;AAEH,gHAAgH;AAChH,MAAM,CAAC,MAAM,mBAAmB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAClE,kGAAkG;CACnG,CAAC,CAAC;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,mBAAmB,EAAE,GAAG,mBAAmB,CAAC,CAAC,CAAC;AAEnH,mCAAmC;AACnC,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACjC,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACjC,4GAA4G;AAC5G,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,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAC7H,CAAC"}
package/dist/types.js CHANGED
@@ -1,3 +1,3 @@
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
  export {};
3
3
  //# sourceMappingURL=types.js.map
package/dist/validity.js 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
  * bitgraph-audit intrinsic validity (internal)
4
4
  *
@@ -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
  * bitgraph-audit verification tiers
4
4
  *
package/dist/witness.js 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
  * bitgraph-audit anchor witness verification
4
4
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikeargento/bitgraph-audit",
3
- "version": "0.11.0",
4
- "description": "Offline audit of BitGraph proof bundles: ingest, tiered verification, causal reconstruction, divergence reporting.",
3
+ "version": "0.12.0",
4
+ "description": "Offline audit of a folder of BitGraph proofs: each proof checked, the counter order rebuilt, gaps and conflicts reported.",
5
5
  "keywords": [
6
6
  "bitgraph",
7
7
  "audit",
@@ -35,13 +35,14 @@
35
35
  "prepack": "rm -rf dist && tsc",
36
36
  "typecheck": "tsc --noEmit",
37
37
  "test": "tsc && node --test src/__tests__/*.test.ts",
38
- "bench": "node scripts/bench-audit.mjs"
38
+ "bench": "node scripts/bench-audit.mjs",
39
+ "test:archive": "tsc && node --test src/__tests__/archive/*.test.ts"
39
40
  },
40
41
  "engines": {
41
42
  "node": ">=20"
42
43
  },
43
44
  "dependencies": {
44
- "@mikeargento/bitgraph-verify": "^1.18.0",
45
+ "@mikeargento/bitgraph-verify": "^1.30.0",
45
46
  "@noble/hashes": "^1.4.0",
46
47
  "@paulmillr/trusted-setups": "0.3.0",
47
48
  "micro-eth-signer": "0.20.1"
@@ -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
  * What counts as an anchor, and where its block is read from.
@@ -17,8 +17,8 @@
17
17
  */
18
18
  import { test } from "node:test";
19
19
  import assert from "node:assert/strict";
20
- import { identifyAnchors } from "../anchors.ts";
21
- import type { IngestResult, ObservedProof } from "../types.ts";
20
+ import { identifyAnchors } from "../../anchors.ts";
21
+ import type { IngestResult, ObservedProof } from "../../types.ts";
22
22
 
23
23
  const BLOCK = 25928913;
24
24
  const HASH = "0x0ce4f044093cdd272ce4d7f47903a2f77e9195c4a5267a3eb7200e3a7d9ba7fa";
@@ -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
  * Base floors (enclave v10) in the audit.
@@ -38,8 +38,8 @@ import { buildJsonReport, buildMarkdownReport, computeExitFlags, runAudit, FLOOR
38
38
  import type { AuditResult, TemporalSegment } from "@mikeargento/bitgraph-audit";
39
39
 
40
40
  const here = dirname(fileURLToPath(import.meta.url));
41
- const FIX = join(here, "../../../../src/__tests__/fuse3-fixtures");
42
- const CLI = join(here, "../../dist/cli.js");
41
+ const FIX = join(here, "../../../../../src/__tests__/fuse3-fixtures");
42
+ const CLI = join(here, "../../../dist/cli.js");
43
43
  const HEADER = readFileSync(join(FIX, "floor-base-52271417.rlp.hex"), "utf8").trim();
44
44
  const BLOCK = 52271417;
45
45
  const BLOCK_HASH = "0x71d926aeae9847fcc15fad2d4de8871923f56862d42db7a7463e95a838f8f9b0";
@@ -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
  * bitgraph-carrier/4 through the CLI: a tree member's BitGraphed file unpacks
@@ -29,8 +29,8 @@ import {
29
29
  } from "@mikeargento/bitgraph-verify";
30
30
 
31
31
  const here = dirname(fileURLToPath(import.meta.url));
32
- const FIX = join(here, "../../../../src/__tests__/fuse3-fixtures");
33
- const CLI = join(here, "../../dist/cli.js");
32
+ const FIX = join(here, "../../../../../src/__tests__/fuse3-fixtures");
33
+ const CLI = join(here, "../../../dist/cli.js");
34
34
  const HEADER = readFileSync(join(FIX, "floor-base-52271417.rlp.hex"), "utf8").trim();
35
35
  const b64 = (u: Uint8Array): string => Buffer.from(u).toString("base64");
36
36
  const utf8 = (s: string): Uint8Array => new TextEncoder().encode(s);
@@ -0,0 +1,256 @@
1
+ // Copyright (c) 2025-2026 Argento Computing Inc.
2
+
3
+ /**
4
+ * Epoch genesis: the note, the write (a receipt as JSON text), and the offline check of a BitGraph's
5
+ * bitgraph-publication/2 block against real signed transactions in real headers and transaction tries (built here,
6
+ * not mocked). The receipts are stand-ins, so these tests use the checks that do not verify signatures; one test runs
7
+ * the full check over a real v13 receipt.
8
+ */
9
+
10
+ import { test, describe } from "node:test";
11
+ import assert from "node:assert/strict";
12
+ import { readFileSync } from "node:fs";
13
+ import { Transaction, addr } from "micro-eth-signer";
14
+ import { rlpEncode, keccak256, txTrieProof, evmBytesToHex, evmHexToBytes, bytesToB64 } from "@mikeargento/bitgraph-verify";
15
+ import {
16
+ hourTree, publishedChainHash, type WriteEvidence,
17
+ genesisNoteText, parseGenesisNote, genesisNoteDigestB64, encodeGenesisCalldata, decodeGenesisCalldata, genesisLink,
18
+ checkGenesis, verifyGenesis, checkEpochPublication, checkGenesisChain, GENESIS_FORMAT, EPOCH_PUBLICATION_KEY,
19
+ type EpochPublicationBlock, type GenesisRecord, type GenesisNote,
20
+ } from "@mikeargento/bitgraph-audit";
21
+
22
+ const epoch = (n: number): string => bytesToB64(new Uint8Array(32).fill(n));
23
+ const EA = epoch(1), EB = epoch(2), EC = epoch(3);
24
+ const keyOf = (e: string): string => bytesToB64(new Uint8Array(32).fill(e === EA ? 11 : e === EB ? 12 : 13));
25
+ const ZERO = "0".repeat(64);
26
+ const writer = addr.random();
27
+ const stranger = addr.random();
28
+ const after = (n: number): GenesisNote["after"] => ({ blockNumber: n, blockHash: "0x" + n.toString(16).padStart(64, "0"), blockTimestamp: 1_794_000_000 + n });
29
+
30
+ function fakeProof(counter: number, epochId: string, digestB64 = bytesToB64(new Uint8Array(32).fill(counter & 255))): Record<string, unknown> {
31
+ return {
32
+ version: "bitgraph/1",
33
+ artifact: { hashAlg: "sha256", digestB64 },
34
+ commit: { nonceB64: bytesToB64(new Uint8Array(32).fill((counter * 3) & 255)), counter: String(counter), slotCounter: String(counter - 1), epochId, atomic: true },
35
+ signer: { publicKeyB64: keyOf(epochId), signatureB64: "AA==" },
36
+ };
37
+ }
38
+
39
+ /** A signed self-addressed write, in a block with a neighbor, with header and trie evidence. */
40
+ function publish(calldata: Uint8Array, opts: { from?: { privateKey: string; address: string }; blockNumber?: number } = {}): WriteEvidence {
41
+ const from = opts.from ?? writer;
42
+ const tx = Transaction.prepare({ to: from.address, value: 0n, nonce: 0n, maxFeePerGas: 1_000_000n, maxPriorityFeePerGas: 1n, gasLimit: 600_000n, chainId: 8453n, data: evmBytesToHex(calldata) } as never);
43
+ const raw = evmHexToBytes(tx.signBy(from.privateKey).toHex(true));
44
+ 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));
45
+ const { root, proof } = txTrieProof([neighbor, raw], 1);
46
+ const number = opts.blockNumber ?? 64_000_000;
47
+ const timestamp = 1_794_000_000 + number;
48
+ const n = (v: number): Uint8Array => { const h = v.toString(16); return evmHexToBytes((h.length % 2 ? "0" : "") + h); };
49
+ const header = rlpEncode([
50
+ new Uint8Array(32).fill(1), new Uint8Array(32).fill(2), new Uint8Array(20).fill(4), new Uint8Array(32).fill(5), root,
51
+ new Uint8Array(32).fill(6), new Uint8Array(256), new Uint8Array(0), n(number), n(30_000_000), n(100_000), n(timestamp),
52
+ new Uint8Array(0), new Uint8Array(32).fill(8), new Uint8Array(8), n(1000),
53
+ ]);
54
+ return {
55
+ chain: "base", chainId: 8453, writer: from.address.toLowerCase(),
56
+ txHash: evmBytesToHex(keccak256(raw)), blockNumber: number, blockHash: evmBytesToHex(keccak256(header)), blockTimestamp: timestamp,
57
+ headerRlp: evmBytesToHex(header), txIndex: 1, txInclusionProof: proof.map(evmBytesToHex), rawTx: evmBytesToHex(raw),
58
+ };
59
+ }
60
+
61
+ /** One genesis: a note closing `closed`, bound as the first BitGraph of `opens`, written to Base. */
62
+ function genesis(opens: string, closes: string | null, closed: Array<Record<string, unknown>>, prevLinkHex: string, blockNumber: number, counter = 2) {
63
+ const tree = hourTree(closed.map(publishedChainHash));
64
+ const counts = closed.map((p) => Number((p["commit"] as { counter: string }).counter));
65
+ const note = genesisNoteText({
66
+ chainId: 8453, prevLinkHex,
67
+ closes: closes === null ? null : { epochId: closes, first: counts[0] ?? 0, last: counts.at(-1) ?? 0, leaves: closed.length, rootHex: tree.rootHex },
68
+ after: after(blockNumber - 10),
69
+ });
70
+ const receipt = fakeProof(counter, opens, genesisNoteDigestB64(note));
71
+ const calldata = encodeGenesisCalldata(receipt, note);
72
+ return { note, receipt, calldata, link: genesisLink(calldata), write: publish(calldata, { blockNumber }), tree, members: closed };
73
+ }
74
+
75
+ /** Epoch A (three BitGraphs) is closed by the genesis that opens B; B (its genesis and two more) by the one that opens C. */
76
+ function scenario() {
77
+ const a = [2, 4, 6].map((c) => fakeProof(c, EA));
78
+ const gB = genesis(EB, EA, a, ZERO, 64_000_000);
79
+ const b = [gB.receipt, fakeProof(4, EB), fakeProof(6, EB)];
80
+ const gC = genesis(EC, EB, b, gB.link, 64_400_000);
81
+ return { a, gB, b, gC };
82
+ }
83
+
84
+ function blockFor(proof: Record<string, unknown>, index: number, closing: ReturnType<typeof genesis>, opening: ReturnType<typeof genesis> | null, withRaw = true): EpochPublicationBlock {
85
+ const c = proof["commit"] as { epochId: string; counter: string };
86
+ const { rawTx, ...rest } = closing.write;
87
+ return {
88
+ format: EPOCH_PUBLICATION_KEY, epochId: c.epochId, counter: c.counter, chainHashB64: publishedChainHash(proof), leafIndex: index, path: closing.tree.paths[index]!,
89
+ closedBy: withRaw ? { ...rest, rawTx } : rest,
90
+ openedBy: opening ? { calldata: evmBytesToHex(opening.calldata) } : null,
91
+ };
92
+ }
93
+ const attach = (proof: Record<string, unknown>, block: EpochPublicationBlock): Record<string, unknown> => ({ ...proof, metadata: { ...((proof["metadata"] as object | undefined) ?? {}), [EPOCH_PUBLICATION_KEY]: block } });
94
+ const check = (proof: Record<string, unknown>, block: EpochPublicationBlock) => checkEpochPublication(attach(proof, block), { writer: writer.address.toLowerCase() });
95
+
96
+ describe("the genesis note and write", () => {
97
+ test("the note round-trips, with and without an epoch to close", () => {
98
+ const n: GenesisNote = { chainId: 8453, prevLinkHex: "ab".repeat(32), closes: { epochId: EA, first: 2, last: 6, leaves: 3, rootHex: "cd".repeat(32) }, after: after(64_000_000) };
99
+ assert.deepEqual(parseGenesisNote(genesisNoteText(n)), n);
100
+ const first: GenesisNote = { chainId: 8453, prevLinkHex: ZERO, closes: null, after: after(5) };
101
+ assert.deepEqual(parseGenesisNote(genesisNoteText(first)), first);
102
+ const empty: GenesisNote = { ...n, closes: { epochId: EA, first: 0, last: 0, leaves: 0, rootHex: ZERO } };
103
+ assert.deepEqual(parseGenesisNote(genesisNoteText(empty)), empty);
104
+ });
105
+
106
+ test("a note that disagrees with itself, or has anything added, does not parse", () => {
107
+ const n: GenesisNote = { chainId: 8453, prevLinkHex: ZERO, closes: { epochId: EA, first: 2, last: 6, leaves: 3, rootHex: "cd".repeat(32) }, after: after(9) };
108
+ const text = genesisNoteText(n);
109
+ assert.equal(parseGenesisNote(text + "extra\n"), null);
110
+ assert.equal(parseGenesisNote(text.replace("bitgraphs: 3", "bitgraphs: 0")), null, "no BitGraphs with a nonzero root");
111
+ assert.equal(parseGenesisNote(text.replace("last count: 6", "last count: 0")), null, "a range that runs backward");
112
+ assert.equal(parseGenesisNote(text.replace(`closes epoch: ${EA}`, "closes epoch: none")), null, "nothing closed, yet a root");
113
+ });
114
+
115
+ test("the write is the receipt's JSON as text, and it carries the note it binds", () => {
116
+ const { gB } = scenario();
117
+ const text = new TextDecoder().decode(gB.calldata);
118
+ assert.ok(text.startsWith('{"version":"bitgraph/1"'), "the transaction's data reads as a receipt");
119
+ const w = decodeGenesisCalldata(gB.calldata)!;
120
+ assert.equal(w.note, gB.note);
121
+ assert.equal((w.receipt["artifact"] as { digestB64: string }).digestB64, genesisNoteDigestB64(gB.note));
122
+ assert.equal((w.receipt["metadata"] as Record<string, { format: string }>)[GENESIS_FORMAT]!.format, GENESIS_FORMAT);
123
+ const g = checkGenesis(gB.calldata);
124
+ assert.deepEqual(g.problems, []);
125
+ assert.equal(g.epochId, EB);
126
+ assert.equal(g.publicKeyB64, keyOf(EB));
127
+ assert.equal(g.note!.closes!.epochId, EA);
128
+ });
129
+
130
+ test("unsigned metadata the receipt already had is kept beside the note", () => {
131
+ const { gB } = scenario();
132
+ const cd = encodeGenesisCalldata({ ...gB.receipt, metadata: { other: { a: 1 } } }, gB.note);
133
+ const w = decodeGenesisCalldata(cd)!;
134
+ assert.deepEqual((w.receipt["metadata"] as Record<string, unknown>)["other"], { a: 1 });
135
+ assert.deepEqual(checkGenesis(cd).problems, []);
136
+ });
137
+
138
+ test("anything else does not decode, and a changed note is caught", () => {
139
+ assert.equal(decodeGenesisCalldata(new Uint8Array([0xff, 0xfe])), null);
140
+ assert.equal(decodeGenesisCalldata(new TextEncoder().encode("[1,2]")), null);
141
+ assert.equal(decodeGenesisCalldata(new TextEncoder().encode(JSON.stringify(fakeProof(2, EB)))), null, "a receipt with no note");
142
+ const { gB } = scenario();
143
+ const changed = encodeGenesisCalldata(gB.receipt, gB.note.replace("bitgraphs: 3", "bitgraphs: 2"));
144
+ assert.ok(checkGenesis(changed).problems.includes("the genesis BitGraph does not bind its note"));
145
+ const self = genesis(EA, EA, [], ZERO, 64_000_000);
146
+ assert.ok(checkGenesis(self.calldata).problems.includes("the genesis BitGraph is in the epoch it closes"));
147
+ });
148
+
149
+ test("the full check runs the verifier over the receipt: a real v13 receipt verifies, though it binds no note", async () => {
150
+ const real = JSON.parse(readFileSync(new URL("../../../../verify/src/__tests__/fixtures/v13/proof-4.json", import.meta.url), "utf8")) as Record<string, unknown>;
151
+ delete real["proofHash"];
152
+ const note = genesisNoteText({ chainId: 8453, prevLinkHex: ZERO, closes: null, after: after(7) });
153
+ const g = await verifyGenesis(encodeGenesisCalldata(real, note));
154
+ assert.deepEqual(g.problems, ["the genesis BitGraph does not bind its note"], "its signatures and attestation pass; only the binding fails");
155
+ const forged = await verifyGenesis(encodeGenesisCalldata({ ...real, signer: { ...(real["signer"] as object), signatureB64: "AA==" } }, note));
156
+ assert.ok(forged.problems.some((p) => p.startsWith("the genesis BitGraph does not verify")));
157
+ });
158
+ });
159
+
160
+ describe("a BitGraph's epoch publication block", () => {
161
+ test("a BitGraph of an epoch with no genesis of its own checks, with a ceiling and no floor", () => {
162
+ const { a, gB } = scenario();
163
+ a.forEach((p, i) => {
164
+ const r = check(p, blockFor(p, i, gB, null));
165
+ assert.deepEqual(r.problems, []);
166
+ assert.equal(r.ceiling!.blockNumber, gB.write.blockNumber);
167
+ assert.equal(r.floor, null);
168
+ assert.equal(r.nextEpochId, EB);
169
+ });
170
+ });
171
+
172
+ test("a BitGraph after its epoch's genesis checks, with the Base block the genesis names as its floor", () => {
173
+ const { b, gB, gC } = scenario();
174
+ for (const i of [1, 2]) {
175
+ const r = check(b[i]!, blockFor(b[i]!, i, gC, gB));
176
+ assert.deepEqual(r.problems, []);
177
+ assert.equal(r.ceiling!.blockNumber, 64_400_000);
178
+ assert.equal(r.floor!.blockNumber, 64_000_000 - 10);
179
+ assert.equal(r.floor!.genesisCounter, "2");
180
+ assert.equal(r.nextEpochId, EC);
181
+ }
182
+ });
183
+
184
+ test("the genesis BitGraph itself is under the next genesis's root, and has no floor", () => {
185
+ const { b, gC, gB } = scenario();
186
+ assert.deepEqual(check(b[0]!, blockFor(b[0]!, 0, gC, null)).problems, []);
187
+ assert.ok(check(b[0]!, blockFor(b[0]!, 0, gC, gB)).problems.includes("the opening genesis does not come before the proof"));
188
+ });
189
+
190
+ test("the raw transaction may be left out: it is read from the block's transaction trie", () => {
191
+ const { b, gB, gC } = scenario();
192
+ assert.deepEqual(check(b[1]!, blockFor(b[1]!, 1, gC, gB, false)).problems, []);
193
+ const wrongRaw = blockFor(b[1]!, 1, gC, gB);
194
+ wrongRaw.closedBy.rawTx = gB.write.rawTx;
195
+ assert.ok(check(b[1]!, wrongRaw).problems.includes("the raw transaction is not the one in the block"));
196
+ });
197
+
198
+ test("tampering anywhere is caught", () => {
199
+ const { a, b, gB, gC } = scenario();
200
+ const good = (): EpochPublicationBlock => blockFor(b[1]!, 1, gC, gB);
201
+ const has = (block: EpochPublicationBlock, problem: string, proof = b[1]!) => assert.ok(check(proof, block).problems.includes(problem), `${problem}: ${JSON.stringify(check(proof, block).problems)}`);
202
+
203
+ has({ ...good(), path: gC.tree.paths[2]! }, "the path does not reach the closing genesis's root");
204
+ has({ ...good(), leafIndex: 9 }, "the leaf index is outside the tree");
205
+ has({ ...good(), chainHashB64: publishedChainHash(b[2]!) }, "the block's chain hash is not this proof's");
206
+ has({ ...good(), counter: "6" }, "the block names a different epoch or count");
207
+ has({ ...good(), closedBy: { ...gC.write, blockHash: "0x" + "00".repeat(32) } }, "the header does not hash to the block hash");
208
+ has({ ...good(), closedBy: { ...gC.write, txIndex: 0 } }, "the transaction is not in the block's transaction trie at that index");
209
+ // A genesis that closes another epoch cannot stand in.
210
+ has(blockFor(b[1]!, 1, gB, null), "the closing genesis closes a different epoch");
211
+ // A BitGraph outside the closed range.
212
+ const late = fakeProof(8, EB);
213
+ has({ ...blockFor(late, 1, gC, gB) }, "the proof's count is outside the closed range", late);
214
+ // The opening genesis must be this epoch's, signed by its key, and the write the closing one links back to.
215
+ const elsewhere = genesis(EC, EB, b, gB.link, 64_400_000);
216
+ has({ ...good(), openedBy: { calldata: evmBytesToHex(elsewhere.calldata) } }, "the opening genesis is in a different epoch");
217
+ const lookalike = genesis(EB, EA, a, "ee".repeat(32), 64_000_000);
218
+ has({ ...good(), openedBy: { calldata: evmBytesToHex(lookalike.calldata) } }, "the opening genesis is not the write the closing genesis links back to");
219
+ has({ ...good(), openedBy: { calldata: "0x00" } }, "the opening genesis does not decode");
220
+ });
221
+
222
+ test("a write from anyone but the expected writer is refused", () => {
223
+ const { b, gB } = scenario();
224
+ const other = addr.random();
225
+ const tree = hourTree(b.map(publishedChainHash));
226
+ const note = genesisNoteText({ chainId: 8453, prevLinkHex: gB.link, closes: { epochId: EB, first: 2, last: 6, leaves: 3, rootHex: tree.rootHex }, after: after(64_399_990) });
227
+ const calldata = encodeGenesisCalldata(fakeProof(2, EC, genesisNoteDigestB64(note)), note);
228
+ const theirs = { note, receipt: {}, calldata, link: genesisLink(calldata), write: publish(calldata, { from: other, blockNumber: 64_400_000 }), tree, members: b };
229
+ const block = blockFor(b[1]!, 1, theirs as ReturnType<typeof genesis>, gB);
230
+ assert.ok(check(b[1]!, block).problems.includes("the transaction is not from the expected writer"));
231
+ assert.deepEqual(checkEpochPublication(attach(b[1]!, block)).problems, [], "with no writer named, the evidence itself holds together");
232
+ });
233
+
234
+ test("no block, no check", () => {
235
+ assert.deepEqual(checkEpochPublication(fakeProof(4, EB)).problems, ["the proof carries no bitgraph-publication/2 block"]);
236
+ });
237
+ });
238
+
239
+ describe("the chain of genesis writes", () => {
240
+ const record = (g: ReturnType<typeof genesis>, opens: string): GenesisRecord => ({
241
+ format: GENESIS_FORMAT, epochId: opens, counter: "2", calldata: evmBytesToHex(g.calldata), link: g.link, note: g.note, write: g.write,
242
+ members: g.members.map((p) => ({ counter: (p["commit"] as { counter: string }).counter, chainHashB64: publishedChainHash(p) })), missing: [], writtenAt: "2026-12-01T00:02:00.000Z",
243
+ });
244
+
245
+ test("each genesis links to the one before and closes the epoch it opened; a break or wrong members show", () => {
246
+ const { gB, gC } = scenario();
247
+ const recs = [record(gB, EB), record(gC, EC)];
248
+ assert.deepEqual(checkGenesisChain(recs, ZERO), { ok: true, problems: [], writes: 2 });
249
+ assert.ok(checkGenesisChain(recs, "aa".repeat(32)).problems.includes("genesis 0: does not link to the write before it"));
250
+ assert.ok(checkGenesisChain([recs[1]!, recs[0]!]).problems.includes("genesis 1: does not close the epoch the one before it opened"));
251
+ const short = { ...recs[1]!, members: recs[1]!.members.slice(0, 2) };
252
+ assert.ok(checkGenesisChain([recs[0]!, short]).problems.includes("genesis 1: leaf count differs from its members"));
253
+ const swapped = { ...recs[1]!, members: [...recs[1]!.members].reverse() };
254
+ assert.ok(checkGenesisChain([recs[0]!, swapped]).problems.includes("genesis 1: members do not make its root"));
255
+ });
256
+ });