@mikeargento/bitgraph-verify 1.28.0 → 1.29.1
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 +33 -25
- package/dist/__tests__/carrier6.test.d.ts +10 -0
- package/dist/__tests__/carrier6.test.d.ts.map +1 -0
- package/dist/__tests__/carrier6.test.js +82 -0
- package/dist/__tests__/carrier6.test.js.map +1 -0
- package/dist/__tests__/timeline-bundle.test.js +30 -2
- package/dist/__tests__/timeline-bundle.test.js.map +1 -1
- package/dist/carrier-verify.d.ts +1 -1
- package/dist/carrier-verify.d.ts.map +1 -1
- package/dist/carrier-verify.js +3 -3
- package/dist/carrier-verify.js.map +1 -1
- package/dist/carrier.d.ts +10 -2
- package/dist/carrier.d.ts.map +1 -1
- package/dist/carrier.js +19 -5
- package/dist/carrier.js.map +1 -1
- package/dist/carrier5.d.ts +22 -2
- package/dist/carrier5.d.ts.map +1 -1
- package/dist/carrier5.js +36 -2
- package/dist/carrier5.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/timeline-export.d.ts +5 -0
- package/dist/timeline-export.d.ts.map +1 -1
- package/dist/timeline-export.js +4 -1
- package/dist/timeline-export.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/carrier6.test.ts +86 -0
- package/src/__tests__/fixtures/carrier6/ceiling.json +73 -0
- package/src/__tests__/fixtures/carrier6/floor-block.json +9 -0
- package/src/__tests__/fixtures/carrier6/floor-proof.json +39 -0
- package/src/__tests__/fixtures/carrier6/proof.json +39 -0
- package/src/__tests__/timeline-bundle.test.ts +34 -2
- package/src/carrier-verify.ts +5 -5
- package/src/carrier.ts +19 -6
- package/src/carrier5.ts +43 -3
- package/src/index.ts +2 -2
- package/src/timeline-export.ts +9 -2
package/src/carrier5.ts
CHANGED
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
import { sha256 } from "@noble/hashes/sha256";
|
|
24
|
-
import { CARRIER_VERSION_5, buildCarrier, type CarrierPayload, type CarrierBounds } from "./carrier.js";
|
|
24
|
+
import { CARRIER_VERSION_5, CARRIER_VERSION_6, buildCarrier, type CarrierPayload, type CarrierBounds } from "./carrier.js";
|
|
25
|
+
import { parseBlockReadFile } from "./block-read.js";
|
|
26
|
+
import { computeChainHash } from "./proof-hash.js";
|
|
25
27
|
import { verifyAttested } from "./attested.js";
|
|
26
28
|
import { verifyCeiling, type CeilingSidecar } from "./ceiling.js";
|
|
27
29
|
import { checkTreeFloor, treeMemberOf } from "./tree-member.js";
|
|
@@ -32,16 +34,31 @@ export const BITGRAPH_CEILING_WRITER_V5 = "0xf3972408D853c975F86351C311f4310220b
|
|
|
32
34
|
const BASE_CHAIN_ID = 8453;
|
|
33
35
|
|
|
34
36
|
export interface CarrierV5Payload {
|
|
35
|
-
carrier: typeof CARRIER_VERSION_5;
|
|
37
|
+
carrier: typeof CARRIER_VERSION_5 | typeof CARRIER_VERSION_6;
|
|
36
38
|
proof: Record<string, unknown>;
|
|
37
39
|
ceilingInTime: { status: "unfetched" } | { status: "present"; sidecar: Record<string, unknown> };
|
|
40
|
+
/** v6 only: the file's own Base floor, the block read bound on the counts right before it. */
|
|
41
|
+
floorInTime?: CarrierV6Floor;
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
/** A drop's floor as v6 carries it: the block read's proof and the bitgraph-block-read/1 file it binds. */
|
|
45
|
+
export type CarrierV6Floor = { status: "none" } | { status: "present"; proof: Record<string, unknown>; blockFile: string };
|
|
46
|
+
|
|
40
47
|
/** The v5 payload for a proof (as the ledger serves it for these bytes) and its ceiling sidecar, if written yet. */
|
|
41
48
|
export function assembleCarrierV5Payload(proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null): CarrierV5Payload {
|
|
42
49
|
return { carrier: CARRIER_VERSION_5, proof, ceilingInTime: ceilingSidecar ? { status: "present", sidecar: ceilingSidecar } : { status: "unfetched" } };
|
|
43
50
|
}
|
|
44
51
|
|
|
52
|
+
/** The v6 payload: v5's, and the file's own floor (the block read before it), or none. */
|
|
53
|
+
export function assembleCarrierV6Payload(proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null, floor: { proof: Record<string, unknown>; blockFile: string } | null): CarrierV5Payload {
|
|
54
|
+
return { ...assembleCarrierV5Payload(proof, ceilingSidecar), carrier: CARRIER_VERSION_6, floorInTime: floor ? { status: "present", proof: floor.proof, blockFile: floor.blockFile } : { status: "none" } };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The BitGraphed file, v6: the bound bytes, unchanged, followed by the v6 block. */
|
|
58
|
+
export function buildBitGraphedFileV6(bytes: Uint8Array, proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null, floor: { proof: Record<string, unknown>; blockFile: string } | null): Uint8Array {
|
|
59
|
+
return buildCarrier(bytes, assembleCarrierV6Payload(proof, ceilingSidecar, floor) as unknown as CarrierPayload);
|
|
60
|
+
}
|
|
61
|
+
|
|
45
62
|
/** The BitGraphed file: the bound bytes, unchanged, followed by the v5 block. */
|
|
46
63
|
export function buildBitGraphedFileV5(bytes: Uint8Array, proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null): Uint8Array {
|
|
47
64
|
return buildCarrier(bytes, assembleCarrierV5Payload(proof, ceilingSidecar) as unknown as CarrierPayload);
|
|
@@ -79,6 +96,29 @@ export async function verifyCarrierV5(payloadIn: CarrierPayload, inner: Uint8Arr
|
|
|
79
96
|
}
|
|
80
97
|
}
|
|
81
98
|
|
|
99
|
+
// 3b. v6: the file's own floor. The block read bound on the counts right before the file: its proof is BitGraph's,
|
|
100
|
+
// it binds its block file, and the file's signed prevB64 is its hash, so nothing was bound between them. The block's
|
|
101
|
+
// hash could not be known before the block, so the file was bound after it. Whether the block is on Base's canonical
|
|
102
|
+
// chain is a check against Base.
|
|
103
|
+
const fl = payload.floorInTime;
|
|
104
|
+
if (fl?.status === "present") {
|
|
105
|
+
const fp = fl.proof as unknown as BitGraphProof;
|
|
106
|
+
const text = new TextEncoder().encode(fl.blockFile);
|
|
107
|
+
const fr = await verifyAttested({ proof: fp, bytes: text, ...(opts.pcr0 ? { pcr0: opts.pcr0 } : {}), ...(opts.rootDer ? { rootDer: opts.rootDer } : {}) });
|
|
108
|
+
const f = parseBlockReadFile(fl.blockFile);
|
|
109
|
+
const sameEpoch = fp.commit?.epochId === proof.commit?.epochId && f?.epochId === proof.commit?.epochId;
|
|
110
|
+
const next = !!fp.commit?.counter && !!proof.commit?.slotCounter && BigInt(fp.commit.counter) + 1n === BigInt(proof.commit.slotCounter);
|
|
111
|
+
const chained = proof.commit?.prevB64 === computeChainHash(fp);
|
|
112
|
+
const ok = fr.valid && f !== null && f.chain === "base" && f.chainId === "eip155:8453" && sameEpoch && next && chained;
|
|
113
|
+
const why = !fr.valid ? `the floor's proof does not verify: ${fr.reason ?? "invalid"}` : f === null ? "the floor's block file is not a bitgraph-block-read/1 file" : f.chain !== "base" || f.chainId !== "eip155:8453" ? "the floor is not a Base mainnet block" : !sameEpoch ? "the floor is not of this file's epoch" : !next ? "the floor is not the record right before this file" : "this file's prevB64 is not the floor's hash";
|
|
114
|
+
add("floor.read", "The floor is the Base block read bound right before this file", ok ? "TRUE" : "FALSE", "BitGraph's previous record, chained by prevB64", ok ? `BitGraph #${fp.commit.counter} bound Base block ${f!.number} (${f!.hash.slice(0, 12)}…), and this file's signed prevB64 is that record's hash: the bind came after the block existed` : why);
|
|
115
|
+
if (ok) {
|
|
116
|
+
const after = r.attestedAtMs !== null && r.attestedAtMs >= f!.timestamp * 1000;
|
|
117
|
+
add("floor.time", "The bind came after the floor block's time", after ? "TRUE" : "FALSE", "the AWS Nitro attestation's time", after ? `bound ${iso(Math.floor(r.attestedAtMs! / 1000))}, block ${iso(f!.timestamp)}` : "the attested bind time is not after the block's time");
|
|
118
|
+
notBefore = { chain: "base", blockNumber: f!.number, blockHash: f!.hash, timestamp: f!.timestamp };
|
|
119
|
+
}
|
|
120
|
+
} else if (fl?.status === "none") add("floor.read", "A Base floor", "NOT_CARRIED", "", "this record was bound without a Base block read before it");
|
|
121
|
+
|
|
82
122
|
// 4. The ceiling: this proof's hash is in the batch the Base transaction carries, and that transaction is in its block.
|
|
83
123
|
let existedBy: CarrierBounds["existedBy"] = null;
|
|
84
124
|
if (payload.ceilingInTime.status === "present") {
|
|
@@ -95,7 +135,7 @@ export async function verifyCarrierV5(payloadIn: CarrierPayload, inner: Uint8Arr
|
|
|
95
135
|
? `BitGraph #${proof.commit?.counter}: ${where}, bound by BitGraph's published enclave image ${r.image?.version ?? ""}${notBefore ? ` after Base block ${notBefore.blockNumber}` : ""}${existedBy ? ` and written to Base by block ${existedBy.blockNumber}` : ""}. Check those blocks on Base to place it in real time.`
|
|
96
136
|
: `This BitGraphed file does not check: ${failed.map((c) => c.detail).join("; ") || "the proof did not verify"}.`;
|
|
97
137
|
return {
|
|
98
|
-
verdict, carrier: "ok", version: 5, reasons: claims.filter((c) => c.result !== "TRUE" && c.result !== "NOT_CARRIED").map((c) => c.detail),
|
|
138
|
+
verdict, carrier: "ok", version: payload.carrier === CARRIER_VERSION_6 ? 6 : 5, reasons: claims.filter((c) => c.result !== "TRUE" && c.result !== "NOT_CARRIED").map((c) => c.detail),
|
|
99
139
|
bounds: notBefore ? { notBefore, notAfter: null, existedBy, settledBy: null } : null,
|
|
100
140
|
ceiling: null, claims, reading, payload: payloadIn, inner,
|
|
101
141
|
};
|
package/src/index.ts
CHANGED
|
@@ -150,8 +150,8 @@ export type { CarrierV3Parts } from "./carrier-assemble.js";
|
|
|
150
150
|
/* 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. */
|
|
151
151
|
export { CARRIER_VERSION_4, memberArtifactDigest } from "./carrier.js";
|
|
152
152
|
// The BitGraphed file for atomic proofs: the proof (with its tree path and floor leaf) and its Base ceiling (2026-10-20).
|
|
153
|
-
export { CARRIER_VERSION_5 } from "./carrier.js";
|
|
154
|
-
export { assembleCarrierV5Payload, buildBitGraphedFileV5, verifyCarrierV5, type CarrierV5Payload } from "./carrier5.js";
|
|
153
|
+
export { CARRIER_VERSION_5, CARRIER_VERSION_6 } from "./carrier.js";
|
|
154
|
+
export { assembleCarrierV5Payload, buildBitGraphedFileV5, assembleCarrierV6Payload, buildBitGraphedFileV6, verifyCarrierV5, type CarrierV5Payload, type CarrierV6Floor } from "./carrier5.js";
|
|
155
155
|
export { checkTreeFloor, BASE_BLOCK_FORMAT, type TreeFloor, type TreeFloorBlock } from "./tree-member.js";
|
|
156
156
|
export type { CarrierTree } from "./carrier.js";
|
|
157
157
|
export { assembleCarrierV4Payload } from "./carrier-assemble.js";
|
package/src/timeline-export.ts
CHANGED
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
* Not ready yet (retryable) when the file has no qualifying ceiling read after it in the records given: a ceiling
|
|
13
13
|
* needs a block stamped after the file, read within the lag limits, so a bundle can be made a few seconds after the
|
|
14
14
|
* file is bound. A gap in the records (a lost record) cannot be bridged and is not retryable.
|
|
15
|
+
*
|
|
16
|
+
* A drop's own floor (2026-11-02): when the record right before the file is a Base block read, it is the floor the
|
|
17
|
+
* host bound for that drop, and the file's prevB64 is that read's hash. Such a file needs no ceiling read (its
|
|
18
|
+
* ceiling is its own Base write, ceiling.ts): the bundle is the read and the file, and verifyTimelineBundle reports it
|
|
19
|
+
* unconfirmed only for the missing ceiling read, with the floor checked.
|
|
15
20
|
*/
|
|
16
21
|
|
|
17
22
|
import type { BitGraphProof } from "./types.js";
|
|
@@ -92,17 +97,19 @@ export function buildTimelineBundle(args: {
|
|
|
92
97
|
};
|
|
93
98
|
|
|
94
99
|
const notes: string[] = [];
|
|
95
|
-
let chosen: { chain: BlockReadChain; floor: number; ceiling: number } | null = null;
|
|
100
|
+
let chosen: { chain: BlockReadChain; floor: number; ceiling: number | null } | null = null;
|
|
96
101
|
for (const chain of ["base", "ethereum"] as const) {
|
|
97
102
|
const p = pick(chain);
|
|
98
103
|
if (p.ceiling !== null) { chosen = { chain, floor: p.floor!, ceiling: p.ceiling }; break; }
|
|
99
104
|
notes.push(p.floor === null ? `no ${chain} read before the file in these records` : `no qualifying ${chain} ceiling after the file yet`);
|
|
100
105
|
}
|
|
106
|
+
const own = reads.get(t - 1);
|
|
107
|
+
if (!chosen && own && own.chain === "base" && own.timestamp * 1000 <= fileMs) chosen = { chain: "base", floor: t - 1, ceiling: null };
|
|
101
108
|
if (!chosen) return { ok: false, retryable: true, reason: `not ready: ${notes.join("; ")}` };
|
|
102
109
|
if (chosen.chain !== "base") notes.unshift("bracketed on Ethereum: Base had no qualifying ceiling");
|
|
103
110
|
else notes.length = 0;
|
|
104
111
|
|
|
105
|
-
const run = lines.slice(chosen.floor, chosen.ceiling + 1);
|
|
112
|
+
const run = lines.slice(chosen.floor, (chosen.ceiling ?? t) + 1);
|
|
106
113
|
const s = verifyStretch(run.map((l) => l.proof));
|
|
107
114
|
if (!s.ok) return { ok: false, retryable: false, reason: `the records are not one unbroken run: ${s.reasons[0]}` };
|
|
108
115
|
|