@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.
- package/README.md +24 -3
- package/dist/__tests__/carrier2.test.js +62 -3
- package/dist/__tests__/carrier2.test.js.map +1 -1
- package/dist/__tests__/ceiling.test.js +11 -4
- package/dist/__tests__/ceiling.test.js.map +1 -1
- package/dist/carrier-assemble.d.ts +12 -2
- package/dist/carrier-assemble.d.ts.map +1 -1
- package/dist/carrier-assemble.js +14 -3
- package/dist/carrier-assemble.js.map +1 -1
- package/dist/carrier-verify.d.ts +15 -4
- package/dist/carrier-verify.d.ts.map +1 -1
- package/dist/carrier-verify.js +201 -59
- package/dist/carrier-verify.js.map +1 -1
- package/dist/carrier.d.ts +48 -13
- package/dist/carrier.d.ts.map +1 -1
- package/dist/carrier.js +74 -16
- package/dist/carrier.js.map +1 -1
- package/dist/ceiling.d.ts +115 -6
- package/dist/ceiling.d.ts.map +1 -1
- package/dist/ceiling.js +189 -23
- package/dist/ceiling.js.map +1 -1
- package/dist/export.d.ts +122 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.js +510 -0
- package/dist/export.js.map +1 -0
- package/dist/fuse.d.ts +45 -11
- package/dist/fuse.d.ts.map +1 -1
- package/dist/fuse.js +100 -18
- package/dist/fuse.js.map +1 -1
- package/dist/index.d.ts +20 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/measurements.d.ts +30 -0
- package/dist/measurements.d.ts.map +1 -0
- package/dist/measurements.js +22 -0
- package/dist/measurements.js.map +1 -0
- package/dist/output-root.d.ts +88 -0
- package/dist/output-root.d.ts.map +1 -0
- package/dist/output-root.js +260 -0
- package/dist/output-root.js.map +1 -0
- package/dist/stream.d.ts +46 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +290 -0
- package/dist/stream.js.map +1 -0
- package/dist/tree.d.ts +167 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +485 -0
- package/dist/tree.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/carrier2.test.ts +65 -3
- package/src/__tests__/ceiling.test.ts +12 -4
- package/src/carrier-assemble.ts +21 -3
- package/src/carrier-verify.ts +204 -61
- package/src/carrier.ts +95 -27
- package/src/ceiling.ts +217 -28
- package/src/export.ts +592 -0
- package/src/fuse.ts +126 -23
- package/src/index.ts +47 -1
- package/src/measurements.ts +49 -0
- package/src/output-root.ts +301 -0
- package/src/stream.ts +291 -0
- package/src/tree.ts +580 -0
- package/src/types.ts +22 -0
package/dist/stream.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
|
|
2
|
+
/**
|
|
3
|
+
* Streaming checks of a file against a tree leaf (2026-10-03): constant
|
|
4
|
+
* memory, one pass over the bytes, any size. The tree/1 format needs nothing
|
|
5
|
+
* for this; it is how a verifier judges a 40 GB file on a laptop or in a
|
|
6
|
+
* browser tab, where reading it whole is impossible. The in-memory path
|
|
7
|
+
* (verifyTreeMember with `bytes`) and this one give the same category for the
|
|
8
|
+
* same bytes; a test holds them equal over every placement.
|
|
9
|
+
*
|
|
10
|
+
* Three hypotheses run in the same pass, each with its own hasher:
|
|
11
|
+
* - the bytes are the file as handed in, the ORIGIN of a placed leaf:
|
|
12
|
+
* SHA-256(prefix || bytes || suffix) for the leaf's placement, the frame
|
|
13
|
+
* built exactly as a producer builds it (the origin a container's
|
|
14
|
+
* manifest names is the leaf's);
|
|
15
|
+
* - the bytes are the COMMITTED bytes of a placed leaf: the stream must be
|
|
16
|
+
* exactly prefix || original || suffix for that placement. The original's
|
|
17
|
+
* length comes from the layout (the ustar header for a container, the
|
|
18
|
+
* last 48 bytes for the trailer), the manifest is parsed where it lies
|
|
19
|
+
* and the frame rebuilt from it, and the original inside is hashed as it
|
|
20
|
+
* passes;
|
|
21
|
+
* - the plain SHA-256 of every byte, which decides which hypothesis applies.
|
|
22
|
+
* A fourth pass-along asks whether the bytes carry this commitment under
|
|
23
|
+
* ANY placement (the in-memory check tries every placement's locate), for
|
|
24
|
+
* the "carries the commitment but is not this leaf" verdict: the last 48
|
|
25
|
+
* bytes as a trailer, or the container layout the first block announces,
|
|
26
|
+
* whose original inside is hashed by a second small machine when it is not
|
|
27
|
+
* the placement already being checked.
|
|
28
|
+
*/
|
|
29
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
30
|
+
import { bytesEqual, getPlacement, parseFusePayload, CONTAINER_MANIFEST_PATH, CONTAINER_ORIGINAL_PATH, TRAILER_LENGTH, TRAILER_MAGIC } from "./fuse.js";
|
|
31
|
+
export function bytesSource(bytes) {
|
|
32
|
+
return {
|
|
33
|
+
size: bytes.length,
|
|
34
|
+
async *stream() {
|
|
35
|
+
yield bytes;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** A Blob or File (browser or Node) as a source. */
|
|
40
|
+
export function blobSource(blob) {
|
|
41
|
+
return {
|
|
42
|
+
size: blob.size,
|
|
43
|
+
async *stream() {
|
|
44
|
+
const reader = blob.stream().getReader();
|
|
45
|
+
try {
|
|
46
|
+
for (;;) {
|
|
47
|
+
const { done, value } = await reader.read();
|
|
48
|
+
if (done)
|
|
49
|
+
return;
|
|
50
|
+
if (value !== undefined && value.length > 0)
|
|
51
|
+
yield value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
reader.releaseLock();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const HEAD = 64;
|
|
61
|
+
const BLOCK = 512;
|
|
62
|
+
const MANIFEST_BYTES = 250;
|
|
63
|
+
const padTo = (n) => (BLOCK - (n % BLOCK)) % BLOCK;
|
|
64
|
+
/** The original's length from a ustar header's size field: 11 octal digits at offset 124. */
|
|
65
|
+
function ustarSize(header) {
|
|
66
|
+
if (header.length < BLOCK)
|
|
67
|
+
return null;
|
|
68
|
+
let n = 0;
|
|
69
|
+
for (let i = 124; i < 135; i++) {
|
|
70
|
+
const c = header[i];
|
|
71
|
+
if (c < 0x30 || c > 0x37)
|
|
72
|
+
return null;
|
|
73
|
+
n = n * 8 + (c - 0x30);
|
|
74
|
+
}
|
|
75
|
+
return header[135] === 0 ? n : null;
|
|
76
|
+
}
|
|
77
|
+
/** Where the manifest and the original's header sit, and how long the prefix is, for each container layout. */
|
|
78
|
+
const LAYOUT = {
|
|
79
|
+
"container/1": { prefixLength: BLOCK + MANIFEST_BYTES + padTo(MANIFEST_BYTES) + BLOCK, manifestAt: BLOCK, originalHeaderAt: BLOCK + MANIFEST_BYTES + padTo(MANIFEST_BYTES) },
|
|
80
|
+
"container/2": { prefixLength: BLOCK, manifestAt: null, originalHeaderAt: 0 },
|
|
81
|
+
};
|
|
82
|
+
function concat(a, b) {
|
|
83
|
+
const out = new Uint8Array(a.length + b.length);
|
|
84
|
+
out.set(a, 0);
|
|
85
|
+
out.set(b, a.length);
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** SHA-256 of a source, streamed. */
|
|
89
|
+
export async function streamDigest(source) {
|
|
90
|
+
const h = sha256.create();
|
|
91
|
+
for await (const chunk of source.stream())
|
|
92
|
+
h.update(chunk);
|
|
93
|
+
return h.digest();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* One pass over a source for the hypotheses above. `origin` is the leaf's
|
|
97
|
+
* origin when a leaf is in hand (the origin a producer wrote into a
|
|
98
|
+
* container's manifest); null when only the bytes' own digest will do.
|
|
99
|
+
*/
|
|
100
|
+
export async function streamLeafCheck(source, opts) {
|
|
101
|
+
const { placement, commitment } = opts;
|
|
102
|
+
if (commitment.length !== 32)
|
|
103
|
+
throw new TypeError("commitment must be 32 bytes");
|
|
104
|
+
const size = source.size;
|
|
105
|
+
if (!Number.isSafeInteger(size) || size < 0)
|
|
106
|
+
throw new TypeError("the source's size must be a non-negative integer");
|
|
107
|
+
const p = placement === null ? null : getPlacement(placement) ?? null;
|
|
108
|
+
if (placement !== null && (p === null || p.frame === undefined))
|
|
109
|
+
throw new TypeError(`${placement} is not a streamable placement`);
|
|
110
|
+
const whole = sha256.create();
|
|
111
|
+
let head = new Uint8Array(0);
|
|
112
|
+
// The origin hypothesis: the frame around a file of exactly `size` bytes.
|
|
113
|
+
let fused = null;
|
|
114
|
+
let fusedSuffix = null;
|
|
115
|
+
if (p !== null) {
|
|
116
|
+
const originForFrame = opts.origin ?? (placement === "container/1" ? null : new Uint8Array(32));
|
|
117
|
+
if (originForFrame !== null) {
|
|
118
|
+
const frame = p.frame({ originalSize: size, originDigest: originForFrame, commitment });
|
|
119
|
+
fused = sha256.create();
|
|
120
|
+
fused.update(frame.prefix);
|
|
121
|
+
fusedSuffix = frame.suffix;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// The committed-bytes hypothesis: prefix || original || suffix, read in
|
|
125
|
+
// place. One machine for the placement asked; a second for the layout the
|
|
126
|
+
// first block announces, when that differs, so "carries the commitment"
|
|
127
|
+
// is judged the way the in-memory locate judges it.
|
|
128
|
+
class Machine {
|
|
129
|
+
id;
|
|
130
|
+
p;
|
|
131
|
+
prefixLength;
|
|
132
|
+
originalSize = null;
|
|
133
|
+
prefix = new Uint8Array(0);
|
|
134
|
+
suffix = new Uint8Array(0);
|
|
135
|
+
embedded = sha256.create();
|
|
136
|
+
failed = null;
|
|
137
|
+
constructor(id) {
|
|
138
|
+
this.id = id;
|
|
139
|
+
this.p = getPlacement(id);
|
|
140
|
+
this.prefixLength = id === "trailer/1" ? 0 : LAYOUT[id].prefixLength;
|
|
141
|
+
if (id === "trailer/1") {
|
|
142
|
+
if (size < TRAILER_LENGTH)
|
|
143
|
+
this.failed = "shorter than a trailer";
|
|
144
|
+
else
|
|
145
|
+
this.originalSize = size - TRAILER_LENGTH;
|
|
146
|
+
}
|
|
147
|
+
else if (size < this.prefixLength) {
|
|
148
|
+
this.failed = "shorter than the container's headers";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** The prefix is in hand: the original's length from its header, and the size must fit the layout. */
|
|
152
|
+
settle() {
|
|
153
|
+
const headerAt = LAYOUT[this.id].originalHeaderAt;
|
|
154
|
+
const n = ustarSize(this.prefix.subarray(headerAt, headerAt + BLOCK));
|
|
155
|
+
if (n === null) {
|
|
156
|
+
this.failed = "the original's ustar header does not carry a size";
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const frame = this.p.frame({ originalSize: n, originDigest: new Uint8Array(32), commitment });
|
|
160
|
+
if (size !== frame.prefix.length + n + frame.suffix.length) {
|
|
161
|
+
this.failed = "the file's length does not fit the container layout its header states";
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.originalSize = n;
|
|
165
|
+
}
|
|
166
|
+
feed(chunk, at) {
|
|
167
|
+
if (this.failed !== null)
|
|
168
|
+
return;
|
|
169
|
+
let off = 0;
|
|
170
|
+
if (at < this.prefixLength) {
|
|
171
|
+
const take = Math.min(chunk.length, this.prefixLength - at);
|
|
172
|
+
this.prefix = concat(this.prefix, chunk.subarray(0, take));
|
|
173
|
+
off = take;
|
|
174
|
+
if (this.prefix.length === this.prefixLength && this.originalSize === null)
|
|
175
|
+
this.settle();
|
|
176
|
+
}
|
|
177
|
+
if (this.failed === null && this.originalSize !== null && off < chunk.length) {
|
|
178
|
+
const originalEnd = this.prefixLength + this.originalSize;
|
|
179
|
+
const here = at + off;
|
|
180
|
+
if (here < originalEnd) {
|
|
181
|
+
const take = Math.min(chunk.length - off, originalEnd - here);
|
|
182
|
+
this.embedded.update(chunk.subarray(off, off + take));
|
|
183
|
+
off += take;
|
|
184
|
+
}
|
|
185
|
+
if (off < chunk.length)
|
|
186
|
+
this.suffix = concat(this.suffix, chunk.subarray(off));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
finish() {
|
|
190
|
+
if (this.failed !== null)
|
|
191
|
+
return { ok: false, reason: this.failed };
|
|
192
|
+
if (this.originalSize === null)
|
|
193
|
+
return { ok: false, reason: "the stream ended inside the container's headers" };
|
|
194
|
+
const embeddedOrigin = this.embedded.digest();
|
|
195
|
+
let manifestOrigin = null;
|
|
196
|
+
let frameOk = false;
|
|
197
|
+
if (this.id === "trailer/1") {
|
|
198
|
+
frameOk = bytesEqual(this.suffix, this.p.frame({ originalSize: this.originalSize, originDigest: embeddedOrigin, commitment }).suffix);
|
|
199
|
+
manifestOrigin = embeddedOrigin;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const manifestBytes = this.id === "container/1"
|
|
203
|
+
? this.prefix.subarray(LAYOUT["container/1"].manifestAt, LAYOUT["container/1"].manifestAt + MANIFEST_BYTES)
|
|
204
|
+
: this.suffix.subarray(padTo(this.originalSize) + BLOCK, padTo(this.originalSize) + BLOCK + MANIFEST_BYTES);
|
|
205
|
+
const manifest = parseFusePayload(manifestBytes);
|
|
206
|
+
if (manifest !== null && manifest.originDigest !== undefined && bytesEqual(manifest.commitment, commitment)) {
|
|
207
|
+
manifestOrigin = manifest.originDigest;
|
|
208
|
+
const expected = this.p.frame({ originalSize: this.originalSize, originDigest: manifestOrigin, commitment });
|
|
209
|
+
frameOk = bytesEqual(this.prefix, expected.prefix) && bytesEqual(this.suffix, expected.suffix);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (!frameOk)
|
|
213
|
+
return { ok: false, reason: `the bytes are not a ${this.id} carrying this position's commitment` };
|
|
214
|
+
if (manifestOrigin === null || !bytesEqual(manifestOrigin, embeddedOrigin))
|
|
215
|
+
return { ok: false, reason: `the original inside the ${this.id} does not hash to the origin its manifest names` };
|
|
216
|
+
return { ok: true, embeddedOrigin, originalSize: this.originalSize };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const asked = placement === null ? null : new Machine(placement);
|
|
220
|
+
let guessed = null;
|
|
221
|
+
// Bytes seen before the first block is whole, replayed into a machine made late.
|
|
222
|
+
let early = new Uint8Array(0);
|
|
223
|
+
let decided = false;
|
|
224
|
+
const trailerMagic = new TextEncoder().encode(TRAILER_MAGIC);
|
|
225
|
+
let tail = new Uint8Array(0);
|
|
226
|
+
let pos = 0;
|
|
227
|
+
for await (const chunk of source.stream()) {
|
|
228
|
+
if (chunk.length === 0)
|
|
229
|
+
continue;
|
|
230
|
+
if (pos + chunk.length > size)
|
|
231
|
+
throw new RangeError("the source yielded more bytes than its size");
|
|
232
|
+
whole.update(chunk);
|
|
233
|
+
if (fused !== null)
|
|
234
|
+
fused.update(chunk);
|
|
235
|
+
if (head.length < HEAD)
|
|
236
|
+
head = concat(head, chunk.subarray(0, HEAD - head.length));
|
|
237
|
+
tail = concat(tail, chunk).subarray(-TRAILER_LENGTH);
|
|
238
|
+
if (asked !== null)
|
|
239
|
+
asked.feed(chunk, pos);
|
|
240
|
+
if (!decided) {
|
|
241
|
+
early = concat(early, chunk);
|
|
242
|
+
if (early.length >= BLOCK || pos + chunk.length === size) {
|
|
243
|
+
decided = true;
|
|
244
|
+
const layout = containerLayoutOf(early.subarray(0, BLOCK));
|
|
245
|
+
if (layout !== null && layout !== placement) {
|
|
246
|
+
guessed = new Machine(layout);
|
|
247
|
+
guessed.feed(early, 0);
|
|
248
|
+
}
|
|
249
|
+
early = new Uint8Array(0);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else if (guessed !== null) {
|
|
253
|
+
guessed.feed(chunk, pos);
|
|
254
|
+
}
|
|
255
|
+
pos += chunk.length;
|
|
256
|
+
}
|
|
257
|
+
if (pos !== size)
|
|
258
|
+
throw new RangeError(`the source yielded ${pos} bytes; its size says ${size}`);
|
|
259
|
+
const digest = whole.digest();
|
|
260
|
+
let fusedFromOrigin = null;
|
|
261
|
+
if (fused !== null && fusedSuffix !== null) {
|
|
262
|
+
fused.update(fusedSuffix);
|
|
263
|
+
fusedFromOrigin = fused.digest();
|
|
264
|
+
}
|
|
265
|
+
const directResult = asked === null ? null : asked.finish();
|
|
266
|
+
// Carries this commitment under some placement: a trailer at the end (as the
|
|
267
|
+
// in-memory locate, no origin check), or the announced container layout.
|
|
268
|
+
const trailerCarries = size >= TRAILER_LENGTH
|
|
269
|
+
&& bytesEqual(tail.subarray(0, 8), trailerMagic)
|
|
270
|
+
&& tail.subarray(8, 16).every((b) => b === 0)
|
|
271
|
+
&& bytesEqual(tail.subarray(16, 48), commitment);
|
|
272
|
+
const containerCarries = (placement !== "trailer/1" && directResult?.ok === true) || (guessed !== null && guessed.finish()?.ok === true);
|
|
273
|
+
const carries = trailerCarries || containerCarries;
|
|
274
|
+
return { size, digest, head, fusedFromOrigin, direct: directResult, carriesCommitment: carries };
|
|
275
|
+
}
|
|
276
|
+
/** The container layout a first block announces, by its ustar magic and entry name; null for anything else (a trailer file, or no placement). */
|
|
277
|
+
function containerLayoutOf(block) {
|
|
278
|
+
if (block.length < BLOCK)
|
|
279
|
+
return null;
|
|
280
|
+
if (new TextDecoder().decode(block.subarray(257, 263)) !== "ustar\0")
|
|
281
|
+
return null;
|
|
282
|
+
const end = block.subarray(0, 100).indexOf(0);
|
|
283
|
+
const name = new TextDecoder().decode(block.subarray(0, end < 0 ? 100 : end));
|
|
284
|
+
if (name === CONTAINER_MANIFEST_PATH)
|
|
285
|
+
return "container/1";
|
|
286
|
+
if (name === CONTAINER_ORIGINAL_PATH)
|
|
287
|
+
return "container/2";
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,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AAC;AAED,iJAAiJ;AACjJ,SAAS,iBAAiB,CAAC,KAAiB;IAC1C,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK;QAAE,OAAO,IAAI,CAAC;IACtC,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAClF,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9E,IAAI,IAAI,KAAK,uBAAuB;QAAE,OAAO,aAAa,CAAC;IAC3D,IAAI,IAAI,KAAK,uBAAuB;QAAE,OAAO,aAAa,CAAC;IAC3D,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/tree.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { type ByteSource } from "./stream.js";
|
|
2
|
+
import { MerkleTree } from "./fuse-merkle.js";
|
|
3
|
+
import { type FuseSpan } from "./fuse-verify.js";
|
|
4
|
+
import type { Attribution, BitGraphProof, VerificationPolicy } from "./types.js";
|
|
5
|
+
export declare const TREE_PLACEMENT_ID: "tree/1";
|
|
6
|
+
export declare const TREE_PROFILE: "bitgraph-tree/1";
|
|
7
|
+
/** "bitgraph-tree/1" followed by one zero byte: 16 bytes. */
|
|
8
|
+
export declare const TREE_DOMAIN: Uint8Array;
|
|
9
|
+
export declare const TREE_LEAF_BYTES = 65;
|
|
10
|
+
export declare const TREE_ROOT_DOCUMENT_BYTES = 84;
|
|
11
|
+
/** The most leaves one tree lists. A stated limit; the layout allows up to 2^32 - 1. */
|
|
12
|
+
export declare const MAX_TREE_LEAVES = 1000000;
|
|
13
|
+
/** proof.metadata key carrying the root document as lowercase hex. Unsigned; bound only by hashing to the signed digest. */
|
|
14
|
+
export declare const TREE_METADATA_KEY: "bitgraph-tree/1";
|
|
15
|
+
/**
|
|
16
|
+
* The spec hashes this verifier knows: base64 SHA-256 of each SPEC.md
|
|
17
|
+
* version. A tree/1 proof's signed attribution.message must be one of them.
|
|
18
|
+
* Appending a revised spec here is how a verifier learns it; nothing is ever
|
|
19
|
+
* removed, so every proof made under an earlier spec keeps verifying.
|
|
20
|
+
*/
|
|
21
|
+
/** SPEC.md v1 (spec/SPEC.md). Frozen 2026-10-04 (spec/FROZEN.json): tree/1 under bitgraph-fuse/2, an Ethereum floor. */
|
|
22
|
+
export declare const TREE_SPEC_V1_HASH = "QazdIR0JYtHQwQuIISo7bvH1gxUvTS2cY+tW6BjUIRs=";
|
|
23
|
+
/** SPEC v2 (spec/SPEC-v2.md): tree/1 under bitgraph-fuse/3, a Base floor (enclave v10). */
|
|
24
|
+
export declare const TREE_SPEC_V2_HASH = "9O3sqlxqi6IQPVJd50NfjJtwWWoslZ9gpIIzbrRzAiU=";
|
|
25
|
+
export declare const KNOWN_TREE_SPEC_HASHES: readonly string[];
|
|
26
|
+
/** Placement codes: the first byte of a leaf. */
|
|
27
|
+
export declare const LEAF_AS_IS = 0;
|
|
28
|
+
export declare const LEAF_PLACEMENTS: Readonly<Record<number, "as-is" | "trailer/1" | "container/1" | "container/2">>;
|
|
29
|
+
export declare function leafCodeOf(placement: string): number | null;
|
|
30
|
+
export interface TreeLeaf {
|
|
31
|
+
/** 0x00 as is, 0x01 trailer/1, 0x02 container/1, 0x03 container/2. */
|
|
32
|
+
placement: number;
|
|
33
|
+
/** SHA-256 of the committed bytes (for 0x00, the file itself). */
|
|
34
|
+
artifact: Uint8Array;
|
|
35
|
+
/** SHA-256 of the file as dropped (for 0x00, equal to artifact). */
|
|
36
|
+
origin: Uint8Array;
|
|
37
|
+
}
|
|
38
|
+
export declare function encodeTreeLeaf(l: TreeLeaf): Uint8Array;
|
|
39
|
+
/** Strict: 65 bytes, a registered code, and for 0x00 artifact = origin. Null otherwise. */
|
|
40
|
+
export declare function decodeTreeLeaf(bytes: Uint8Array): TreeLeaf | null;
|
|
41
|
+
export declare function treeLeafHash(l: TreeLeaf): Uint8Array;
|
|
42
|
+
/** Tree order: strictly ascending by artifact digest. Throws on an empty list, too many leaves, a bad leaf or a duplicate artifact. */
|
|
43
|
+
export declare function sortTreeLeaves(leaves: readonly TreeLeaf[]): TreeLeaf[];
|
|
44
|
+
export interface BuiltTree {
|
|
45
|
+
sorted: TreeLeaf[];
|
|
46
|
+
leafHashes: Uint8Array[];
|
|
47
|
+
root: Uint8Array;
|
|
48
|
+
tree: MerkleTree;
|
|
49
|
+
}
|
|
50
|
+
export declare function buildTree(leaves: readonly TreeLeaf[]): BuiltTree;
|
|
51
|
+
export declare function buildTreeRootDocument(commitment: Uint8Array, count: number, root: Uint8Array): Uint8Array;
|
|
52
|
+
/** Strict: 84 bytes, the domain, a count from 1 to MAX_TREE_LEAVES. Null otherwise. */
|
|
53
|
+
export declare function parseTreeRootDocument(bytes: Uint8Array): {
|
|
54
|
+
count: number;
|
|
55
|
+
root: Uint8Array;
|
|
56
|
+
commitment: Uint8Array;
|
|
57
|
+
} | null;
|
|
58
|
+
/** The root document a proof carries in its unsigned metadata, as bytes; null when absent or malformed hex. */
|
|
59
|
+
export declare function readTreeMetadata(proof: BitGraphProof): Uint8Array | null;
|
|
60
|
+
/**
|
|
61
|
+
* The attribution a producer sends for a tree/1 commit. specHash is the 32-byte
|
|
62
|
+
* SHA-256 of the spec the producer follows; the marker is the one that spec
|
|
63
|
+
* requires (fuse/2 for v1, fuse/3 for v2).
|
|
64
|
+
*/
|
|
65
|
+
export declare function treeAttribution(specHash: Uint8Array): Attribution;
|
|
66
|
+
/**
|
|
67
|
+
* The spec hash a producer pins, as raw bytes, for the floor its allocation
|
|
68
|
+
* returned: a Base floor (fuse/3) follows SPEC v2, an Ethereum floor anchor
|
|
69
|
+
* (fuse/2) follows SPEC v1. Throws while the requested spec hash is a placeholder.
|
|
70
|
+
*/
|
|
71
|
+
export declare function currentTreeSpecHash(fuseVersion?: 2 | 3): Uint8Array;
|
|
72
|
+
export declare function isTreeProof(proof: {
|
|
73
|
+
attribution?: unknown;
|
|
74
|
+
} | null | undefined): boolean;
|
|
75
|
+
/** One member's evidence as JSON: its leaf (lowercase hex, 130 chars), its index, the tree size, and its sibling path from the leaf up. */
|
|
76
|
+
export interface TreeMemberEvidence {
|
|
77
|
+
index: number;
|
|
78
|
+
count: number;
|
|
79
|
+
leaf: string;
|
|
80
|
+
path: string[];
|
|
81
|
+
}
|
|
82
|
+
export declare function buildTreeMemberEvidence(leaf: TreeLeaf, index: number, count: number, path: readonly Uint8Array[]): TreeMemberEvidence;
|
|
83
|
+
/** Strict read: exactly the four keys, integers in range, a valid leaf, 32-byte lowercase-hex path nodes. Null on any deviation. Unbound. */
|
|
84
|
+
export declare function parseTreeMemberEvidence(value: unknown): {
|
|
85
|
+
leaf: TreeLeaf;
|
|
86
|
+
index: number;
|
|
87
|
+
count: number;
|
|
88
|
+
path: Uint8Array[];
|
|
89
|
+
} | null;
|
|
90
|
+
/** The root a member's leaf and path reach, or null when the path does not fit the index and count. */
|
|
91
|
+
export declare function treeRootFromMember(leaf: TreeLeaf, index: number, count: number, path: readonly Uint8Array[]): Uint8Array | null;
|
|
92
|
+
/** The owner's list: every leaf in tree order, concatenated (count x 65 bytes). */
|
|
93
|
+
export declare function encodeTreeLeaves(sorted: readonly TreeLeaf[]): Uint8Array;
|
|
94
|
+
export declare function decodeTreeLeaves(bytes: Uint8Array): TreeLeaf[] | null;
|
|
95
|
+
export interface TreeLeavesCheck {
|
|
96
|
+
ok: boolean;
|
|
97
|
+
reason?: string;
|
|
98
|
+
count?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The whole list against a root document: the count matches, the leaves are
|
|
102
|
+
* strictly ascending by artifact digest with no duplicate, every leaf is
|
|
103
|
+
* valid, and the rebuilt root equals the document's. This is the only check
|
|
104
|
+
* that establishes ordering and uniqueness; a single member's path cannot.
|
|
105
|
+
*/
|
|
106
|
+
export declare function verifyTreeLeaves(rootDocument: Uint8Array, leavesBytes: Uint8Array): TreeLeavesCheck;
|
|
107
|
+
/** The committed bytes a placement makes from an original. For 0x00 the original is the committed bytes. */
|
|
108
|
+
export declare function committedBytesFor(code: number, original: Uint8Array, commitment: Uint8Array): Uint8Array;
|
|
109
|
+
/** A leaf for an original under a placement and a commitment. */
|
|
110
|
+
export declare function leafFor(code: number, original: Uint8Array, commitment: Uint8Array): {
|
|
111
|
+
leaf: TreeLeaf;
|
|
112
|
+
committed: Uint8Array;
|
|
113
|
+
};
|
|
114
|
+
export type TreeCategory = "TREE_MEMBER_DIRECT" | "TREE_MEMBER_FROM_ORIGIN" | "TREE_MEMBER_AS_IS" | "TREE_PATH_VALID" | "TREE_ROOT_VALID" | "TREE_MEMBERSHIP_UNPROVEN" | "NO_MATCH" | "RECONSTRUCTION_MISMATCH" | "INVALID_ORIGIN" | "INVALID_TREE_PATH" | "INVALID_TREE_ROOT" | "INVALID_SLOT_COMMITMENT" | "INVALID_TREE_MARKER" | "UNKNOWN_SPEC" | "INVALID_UNDERLYING_PROOF" | "NOT_TREE";
|
|
115
|
+
/** The categories that mean the supplied file is a member of the committed tree. */
|
|
116
|
+
export declare const TREE_MEMBER_CATEGORIES: readonly TreeCategory[];
|
|
117
|
+
export interface TreeVerifyOptions {
|
|
118
|
+
proof: BitGraphProof;
|
|
119
|
+
/** The file in hand: the original or the committed bytes. Omit to check the proof, the root and the path alone. */
|
|
120
|
+
bytes?: Uint8Array;
|
|
121
|
+
/** The file in hand as a stream (stream.ts), for a file of any size: the same judgment as `bytes`, in constant memory. One of the two. */
|
|
122
|
+
source?: ByteSource;
|
|
123
|
+
/** The member's evidence (TreeMemberEvidence JSON). Omit to check the proof and the root alone. */
|
|
124
|
+
member?: unknown;
|
|
125
|
+
/** The 84-byte root document; when omitted it is read from proof.metadata. */
|
|
126
|
+
rootDocument?: Uint8Array | null;
|
|
127
|
+
trustAnchors?: VerificationPolicy;
|
|
128
|
+
/** Spec hashes (base64) to accept in addition to KNOWN_TREE_SPEC_HASHES. */
|
|
129
|
+
extraSpecHashes?: readonly string[];
|
|
130
|
+
/** Skip the proof's own checks (only when the caller already ran them on this exact proof). */
|
|
131
|
+
proofAlreadyVerified?: boolean;
|
|
132
|
+
}
|
|
133
|
+
export interface TreeVerifyResult {
|
|
134
|
+
category: TreeCategory;
|
|
135
|
+
/** One sentence: what was established, or why not. */
|
|
136
|
+
reason: string;
|
|
137
|
+
proof: {
|
|
138
|
+
valid: boolean;
|
|
139
|
+
reason?: string;
|
|
140
|
+
};
|
|
141
|
+
/** The spec hash the proof pins (base64), when it has one. */
|
|
142
|
+
specHashB64: string | null;
|
|
143
|
+
/** Present once the root document is bound to the signed digest and to the slot. */
|
|
144
|
+
tree: {
|
|
145
|
+
count: number;
|
|
146
|
+
rootHex: string;
|
|
147
|
+
commitmentHex: string;
|
|
148
|
+
} | null;
|
|
149
|
+
/** Present once the member's path reaches the bound root. */
|
|
150
|
+
member: {
|
|
151
|
+
index: number;
|
|
152
|
+
count: number;
|
|
153
|
+
placement: string;
|
|
154
|
+
artifactHex: string;
|
|
155
|
+
originHex: string;
|
|
156
|
+
} | null;
|
|
157
|
+
/**
|
|
158
|
+
* What the floor covers for THIS file. "content": the committed bytes carry
|
|
159
|
+
* the commitment, so they were finished after the floor block (the original
|
|
160
|
+
* inside them is not dated by it). "record": an as-is leaf; the record was
|
|
161
|
+
* made after the floor block, and the bytes themselves are not dated.
|
|
162
|
+
*/
|
|
163
|
+
floorCovers: "content" | "record" | null;
|
|
164
|
+
span: FuseSpan | null;
|
|
165
|
+
}
|
|
166
|
+
export declare function verifyTreeMember(opts: TreeVerifyOptions): Promise<TreeVerifyResult>;
|
|
167
|
+
//# sourceM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