@mikeargento/bitgraph-verify 1.23.0 → 1.25.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 +1 -1
- package/dist/__tests__/carrier2.test.js +1 -1
- package/dist/__tests__/carrier2.test.js.map +1 -1
- package/dist/__tests__/carrier5.test.d.ts +9 -0
- package/dist/__tests__/carrier5.test.d.ts.map +1 -0
- package/dist/__tests__/carrier5.test.js +62 -0
- package/dist/__tests__/carrier5.test.js.map +1 -0
- package/dist/__tests__/tree-member.test.d.ts +12 -0
- package/dist/__tests__/tree-member.test.d.ts.map +1 -0
- package/dist/__tests__/tree-member.test.js +91 -0
- package/dist/__tests__/tree-member.test.js.map +1 -0
- package/dist/attested.d.ts +6 -0
- package/dist/attested.d.ts.map +1 -1
- package/dist/attested.js +15 -2
- package/dist/attested.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 +5 -1
- 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 +20 -1
- package/dist/carrier.js.map +1 -1
- package/dist/carrier5.d.ts +24 -0
- package/dist/carrier5.d.ts.map +1 -0
- package/dist/carrier5.js +93 -0
- package/dist/carrier5.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/tree-member.d.ts +48 -0
- package/dist/tree-member.d.ts.map +1 -0
- package/dist/tree-member.js +140 -0
- package/dist/tree-member.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/carrier2.test.ts +1 -1
- package/src/__tests__/carrier5.test.ts +65 -0
- package/src/__tests__/fixtures/carrier5/ceiling.json +95 -0
- package/src/__tests__/fixtures/carrier5/proof.json +53 -0
- package/src/__tests__/fixtures/carrier5/single.txt +1 -0
- package/src/__tests__/fixtures/tree-member/member-1.txt +1 -0
- package/src/__tests__/fixtures/tree-member/member-2.proof.json +48 -0
- package/src/__tests__/fixtures/tree-member/member-2.txt +1 -0
- package/src/__tests__/fixtures/tree-member/member-3.txt +1 -0
- package/src/__tests__/tree-member.test.ts +91 -0
- package/src/attested.ts +18 -2
- package/src/carrier-verify.ts +6 -3
- package/src/carrier.ts +19 -3
- package/src/carrier5.ts +105 -0
- package/src/index.ts +6 -0
- package/src/tree-member.ts +125 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file of a tree, checked by its own hash (bitgraph-tree-member/1).
|
|
3
|
+
*
|
|
4
|
+
* The fixture is real: BitGraph #18 of epoch pa9R…, made by enclave v13 on 2026-10-20 from bitgraph.ing's Make page,
|
|
5
|
+
* binding the root text of a three-file tree; member-2.proof.json is the proof the site's index serves under
|
|
6
|
+
* member-2.txt's own hash (the tree's proof with member-2's block in its unsigned metadata). Its attestation is
|
|
7
|
+
* AWS-signed, so verifyAttested checks the real chain.
|
|
8
|
+
*
|
|
9
|
+
* cd packages/verify && npx tsc -p . && node --test dist/__tests__/tree-member.test.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { test } from "node:test";
|
|
13
|
+
import { strict as assert } from "node:assert";
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
16
|
+
import { verifyAttested } from "../attested.js";
|
|
17
|
+
import { TREE_MEMBER_METADATA_KEY, checkTreeMember, digestTreeRootText, parseDigestTreeRootText, treeMemberOf, treeRootFromPath, type TreeMemberBlock } from "../tree-member.js";
|
|
18
|
+
import type { BitGraphProof } from "../types.js";
|
|
19
|
+
|
|
20
|
+
const dir = new URL("../../src/__tests__/fixtures/tree-member/", import.meta.url);
|
|
21
|
+
const file = (n: number) => new Uint8Array(readFileSync(new URL(`member-${n}.txt`, dir)));
|
|
22
|
+
const proof = JSON.parse(readFileSync(new URL("member-2.proof.json", dir), "utf8")) as BitGraphProof;
|
|
23
|
+
const b64 = (u: Uint8Array) => Buffer.from(u).toString("base64");
|
|
24
|
+
const clone = <T>(x: T): T => JSON.parse(JSON.stringify(x)) as T;
|
|
25
|
+
|
|
26
|
+
test("the real member checks: its file is file 2 of 3, and the proof is BitGraph's", async () => {
|
|
27
|
+
const block = treeMemberOf(proof);
|
|
28
|
+
assert.ok(block);
|
|
29
|
+
assert.equal(block!.index, 1); assert.equal(block!.files, 3);
|
|
30
|
+
assert.ok(checkTreeMember(proof, sha256(file(2))));
|
|
31
|
+
const r = await verifyAttested({ proof, bytes: file(2) });
|
|
32
|
+
assert.equal(r.valid, true, r.reason);
|
|
33
|
+
assert.deepEqual(r.treeMember, { index: 1, files: 3 });
|
|
34
|
+
assert.equal(r.image?.version, "v13");
|
|
35
|
+
assert.equal(r.artifactBinding, "checked");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("the tree's other files and outside bytes are refused under member 2's block", async () => {
|
|
39
|
+
for (const bytes of [file(1), file(3), new TextEncoder().encode("not in the tree\n")]) {
|
|
40
|
+
const r = await verifyAttested({ proof, bytes });
|
|
41
|
+
assert.equal(r.valid, false);
|
|
42
|
+
assert.equal(r.reason, "the file is not in the tree this proof binds");
|
|
43
|
+
assert.equal(r.treeMember, undefined);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("a block that was edited does not check, wherever the edit is", async () => {
|
|
48
|
+
const block = treeMemberOf(proof)!;
|
|
49
|
+
const d = sha256(file(2));
|
|
50
|
+
const edit = (e: Partial<TreeMemberBlock>) => { const p = clone(proof) as unknown as { metadata: Record<string, unknown> }; p.metadata[TREE_MEMBER_METADATA_KEY] = { ...block, ...e }; return p; };
|
|
51
|
+
assert.equal(checkTreeMember(edit({ index: 0 }), d), false, "another index");
|
|
52
|
+
assert.equal(checkTreeMember(edit({ files: 4 }), d), false, "a count the text does not name");
|
|
53
|
+
assert.equal(checkTreeMember(edit({ rootText: digestTreeRootText(3, "0".repeat(64)) }), d), false, "a root text the proof does not sign");
|
|
54
|
+
assert.equal(checkTreeMember(edit({ path: b64(new Uint8Array(64)) }), d), false, "another path");
|
|
55
|
+
// The proof's signed digest is untouched by any of these: metadata is unsigned, so the check is what binds it.
|
|
56
|
+
const r = await verifyAttested({ proof: edit({ index: 0 }) as unknown as BitGraphProof, bytes: file(2) });
|
|
57
|
+
assert.equal(r.valid, false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("without the file, the proof still verifies as the tree's: against its root text", async () => {
|
|
61
|
+
const r = await verifyAttested({ proof });
|
|
62
|
+
assert.equal(r.valid, true, r.reason);
|
|
63
|
+
assert.equal(r.treeMember, undefined, "membership needs the file (or its hash, through checkTreeMember)");
|
|
64
|
+
assert.equal(r.artifactBinding, "not-checked");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("every leaf walks to its root, for odd and even trees", () => {
|
|
68
|
+
const h = (...p: Uint8Array[]) => sha256(new Uint8Array(p.reduce<number[]>((a, x) => a.concat(Array.from(x)), [])));
|
|
69
|
+
for (const n of [1, 2, 3, 5, 7, 8, 13, 100]) {
|
|
70
|
+
const digests = Array.from({ length: n }, (_, i) => sha256(new TextEncoder().encode(`file ${i} of ${n}`)));
|
|
71
|
+
const rows: Uint8Array[][] = [digests.map((d) => h(new Uint8Array([0]), d))];
|
|
72
|
+
while (rows[rows.length - 1]!.length > 1) {
|
|
73
|
+
const row = rows[rows.length - 1]!, next: Uint8Array[] = [];
|
|
74
|
+
for (let i = 0; i < row.length; i += 2) next.push(i + 1 < row.length ? h(new Uint8Array([1]), row[i]!, row[i + 1]!) : row[i]!);
|
|
75
|
+
rows.push(next);
|
|
76
|
+
}
|
|
77
|
+
const rootHex = Buffer.from(rows[rows.length - 1]![0]!).toString("hex");
|
|
78
|
+
const rootText = digestTreeRootText(n, rootHex);
|
|
79
|
+
assert.deepEqual(parseDigestTreeRootText(rootText), { files: n, root: rootHex });
|
|
80
|
+
const fake = { artifact: { digestB64: b64(sha256(new TextEncoder().encode(rootText))) } };
|
|
81
|
+
for (let i = 0; i < n; i++) {
|
|
82
|
+
const sibs: number[] = [];
|
|
83
|
+
for (let k = 0, idx = i; rows[k]!.length > 1; k++, idx >>= 1) { const s = idx ^ 1; if (s < rows[k]!.length) sibs.push(...rows[k]![s]!); }
|
|
84
|
+
const path = new Uint8Array(sibs);
|
|
85
|
+
assert.equal(treeRootFromPath(rows[0]![i]!, i, n, path), rootHex, `n=${n} i=${i}`);
|
|
86
|
+
const block: TreeMemberBlock = { format: TREE_MEMBER_METADATA_KEY, files: n, index: i, path: b64(path), rootText };
|
|
87
|
+
assert.ok(checkTreeMember(fake, digests[i]!, block), `n=${n} i=${i} checks`);
|
|
88
|
+
if (n > 1) assert.equal(checkTreeMember(fake, digests[(i + 1) % n]!, block), false, `n=${n} i=${i} refuses a neighbour`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
package/src/attested.ts
CHANGED
|
@@ -25,6 +25,8 @@ import { verify, verifyProofIntegrity, createVerificationContext, type Verificat
|
|
|
25
25
|
import { verifyNitroAttestation, type NitroCheck } from "./nitro.js";
|
|
26
26
|
import { computeSignedBodyHash } from "./proof-hash.js";
|
|
27
27
|
import { PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
|
|
28
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
29
|
+
import { checkTreeMember, treeMemberOf, treeRootTextBytes } from "./tree-member.js";
|
|
28
30
|
|
|
29
31
|
export interface AttestedOptions {
|
|
30
32
|
/** The proof to check. */
|
|
@@ -54,17 +56,25 @@ export interface AttestedResult {
|
|
|
54
56
|
attestedAtMs: number | null;
|
|
55
57
|
/** Whether the bytes were compared with the proof's digest. */
|
|
56
58
|
artifactBinding: "checked" | "not-checked";
|
|
59
|
+
/** When the proof is a tree member's (bitgraph-tree-member/1) and the file was given: which file of how many it is,
|
|
60
|
+
* its hash checked up the tree to the root the proof binds. */
|
|
61
|
+
treeMember?: { index: number; files: number };
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
/** Images from v11 on make every proof atomic; a proof from one must be in the atomic form. */
|
|
60
65
|
const ATOMIC_FROM = new Set(["v11", "v12", "v13"]);
|
|
61
66
|
|
|
62
67
|
export async function verifyAttested(opts: AttestedOptions): Promise<AttestedResult> {
|
|
63
|
-
const { proof
|
|
68
|
+
const { proof } = opts;
|
|
69
|
+
let bytes = opts.bytes;
|
|
64
70
|
const artifactBinding = bytes !== undefined ? "checked" : "not-checked";
|
|
71
|
+
// A tree member's proof (tree-member.ts): the file's hash must walk up to the root the proof binds, and the proof is
|
|
72
|
+
// then checked against the root's text, the bytes it signs, as any proof is against its file.
|
|
73
|
+
const member = bytes !== undefined ? treeMemberOf(proof) : null;
|
|
74
|
+
let treeMember: AttestedResult["treeMember"];
|
|
65
75
|
const out = (valid: boolean, reason: string | undefined, checks: NitroCheck[], pcr0: string | null, attestedAtMs: number | null): AttestedResult => {
|
|
66
76
|
const pub = pcr0 ? publishedMeasurement(pcr0) : null;
|
|
67
|
-
return { valid, ...(reason !== undefined ? { reason } : {}), checks, pcr0, image: pub ? { version: pub.version, since: pub.since } : null, attestedAtMs, artifactBinding };
|
|
77
|
+
return { valid, ...(reason !== undefined ? { reason } : {}), checks, pcr0, image: pub ? { version: pub.version, since: pub.since } : null, attestedAtMs, artifactBinding, ...(treeMember ? { treeMember } : {}) };
|
|
68
78
|
};
|
|
69
79
|
|
|
70
80
|
// 2 first, because it decides 1's atomic rule: the hardware's word about which image made this proof.
|
|
@@ -93,6 +103,12 @@ export async function verifyAttested(opts: AttestedOptions): Promise<AttestedRes
|
|
|
93
103
|
return out(false, opts.pcr0 ? `PCR0 ${pcr0.slice(0, 16)}… is not an image this verifier accepts` : `PCR0 ${pcr0.slice(0, 16)}… is not an enclave image BitGraph published`, n.checks, pcr0, attestedAtMs);
|
|
94
104
|
}
|
|
95
105
|
|
|
106
|
+
if (member && bytes !== undefined) {
|
|
107
|
+
if (!checkTreeMember(proof, sha256(bytes), member)) return out(false, "the file is not in the tree this proof binds", n.checks, pcr0, attestedAtMs);
|
|
108
|
+
treeMember = { index: member.index, files: member.files };
|
|
109
|
+
bytes = treeRootTextBytes(member);
|
|
110
|
+
}
|
|
111
|
+
|
|
96
112
|
// 1. The proof's own consistency, with the atomic rule where it applies.
|
|
97
113
|
const image = publishedMeasurement(pcr0);
|
|
98
114
|
const atomic = proof.commit?.atomic === true || (image !== null && ATOMIC_FROM.has(image.version));
|
package/src/carrier-verify.ts
CHANGED
|
@@ -55,9 +55,10 @@ import { PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
|
|
|
55
55
|
import { verifySettlementPointer, checkSettlementOnline, BASE_MAINNET_SETTLEMENT_PINS, type SettlementPointer, type SettlementPins } from "./settlement.js";
|
|
56
56
|
import type { BitGraphProof } from "./types.js";
|
|
57
57
|
import { sha256 } from "@noble/hashes/sha256";
|
|
58
|
+
import { verifyCarrierV5 } from "./carrier5.js";
|
|
58
59
|
import {
|
|
59
60
|
parseCarrier, checkFloorBinding, checkCeilingBinding, anchorMessageBytes,
|
|
60
|
-
verifyWitnessHeader, carrierBounds, innerDigestMatches, carrierVersionOf, CARRIER_VERSION_4,
|
|
61
|
+
verifyWitnessHeader, carrierBounds, innerDigestMatches, carrierVersionOf, CARRIER_VERSION_4, CARRIER_VERSION_5,
|
|
61
62
|
type CarrierBounds, type CarrierPayload,
|
|
62
63
|
} from "./carrier.js";
|
|
63
64
|
|
|
@@ -115,7 +116,7 @@ export interface CarrierVerifyResult {
|
|
|
115
116
|
floorTimeWithheld?: string | null;
|
|
116
117
|
/** "ok" | "none" | "corrupt" — whether the bytes carried a readable block at all. */
|
|
117
118
|
carrier: "ok" | "none" | "corrupt";
|
|
118
|
-
version: 1 | 2 | 3 | 4 | null;
|
|
119
|
+
version: 1 | 2 | 3 | 4 | 5 | null;
|
|
119
120
|
/** v4: the leaf the committed bytes are, once its path reached the signed root; null otherwise (and on v1 to v3). */
|
|
120
121
|
member?: TreeVerifyResult["member"];
|
|
121
122
|
/** v4: "content" when the bytes carry the commitment (a placed leaf), "record" when kept as is; null when the bytes were not matched or not in hand. */
|
|
@@ -169,6 +170,8 @@ function envelopeSentence(outer: Uint8Array, inner: Uint8Array, member = false):
|
|
|
169
170
|
* as not carried, and everything else is judged exactly as for a file.
|
|
170
171
|
*/
|
|
171
172
|
export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8Array | null, opts: CarrierVerifyOptions = {}): Promise<CarrierVerifyResult> {
|
|
173
|
+
// v5: its own path (carrier5.ts), with no floor anchor to look for.
|
|
174
|
+
if (payload.carrier === CARRIER_VERSION_5) return verifyCarrierV5(payload, inner, { ...(opts.pins?.pcr0 ? { pcr0: opts.pins.pcr0 } : {}), ...(opts.pins?.rootDer ? { rootDer: opts.pins.rootDer } : {}) });
|
|
172
175
|
const claims: CarrierClaim[] = [];
|
|
173
176
|
const add = (id: string, name: string, result: ClaimResult, restsOn: string, detail: string, level: "offline" | "confirmed" = "offline") =>
|
|
174
177
|
claims.push({ id, name, result, restsOn, detail, level });
|
|
@@ -179,7 +182,7 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
|
|
|
179
182
|
} catch (e) {
|
|
180
183
|
const detail = `a part of this proof block is malformed: ${e instanceof Error ? e.message : String(e)}`;
|
|
181
184
|
add("wellformed", "Every part of the proof block is well formed", "FALSE", "", detail);
|
|
182
|
-
let version: 1 | 2 | 3 | 4 | null = null;
|
|
185
|
+
let version: 1 | 2 | 3 | 4 | 5 | null = null;
|
|
183
186
|
try { version = carrierVersionOf(payload); } catch { /* unreadable */ }
|
|
184
187
|
const ceilingStatus = (payload as { ceiling?: { status?: unknown } } | null)?.ceiling?.status;
|
|
185
188
|
return {
|
package/src/carrier.ts
CHANGED
|
@@ -96,7 +96,15 @@ export const CARRIER_VERSION = "bitgraph-carrier/1";
|
|
|
96
96
|
export const CARRIER_VERSION_2 = "bitgraph-carrier/2";
|
|
97
97
|
export const CARRIER_VERSION_3 = "bitgraph-carrier/3";
|
|
98
98
|
export const CARRIER_VERSION_4 = "bitgraph-carrier/4";
|
|
99
|
-
|
|
99
|
+
/**
|
|
100
|
+
* v5 (2026-10-20): the BitGraphed file for proofs made in one atomic action (enclave v11 on), which sign no floor of
|
|
101
|
+
* their own. The block carries the proof exactly as the ledger serves it for these bytes (for a file of a tree, with
|
|
102
|
+
* its bitgraph-tree-member/1 block in the proof's unsigned metadata: the path to the root, and the tree's floor leaf,
|
|
103
|
+
* base-block.json) and its Base ceiling (bitgraph-ceiling/1). No anchor, no header: the floor is a leaf of the tree.
|
|
104
|
+
* Checked by carrier5.ts.
|
|
105
|
+
*/
|
|
106
|
+
export const CARRIER_VERSION_5 = "bitgraph-carrier/5";
|
|
107
|
+
export type CarrierVersion = typeof CARRIER_VERSION | typeof CARRIER_VERSION_2 | typeof CARRIER_VERSION_3 | typeof CARRIER_VERSION_4 | typeof CARRIER_VERSION_5;
|
|
100
108
|
/** The sidecar and pointer formats a v2 block carries; their shapes are checked by their own modules. */
|
|
101
109
|
export const CEILING_SIDECAR_VERSION = "bitgraph-ceiling/1";
|
|
102
110
|
export const SETTLEMENT_POINTER_VERSION = "bitgraph-settlement/1";
|
|
@@ -308,6 +316,14 @@ function treeShapeError(t: unknown): string | null {
|
|
|
308
316
|
function payloadShapeError(p: unknown): string | null {
|
|
309
317
|
const o = record(p);
|
|
310
318
|
if (o === null) return "payload is not an object";
|
|
319
|
+
if (o["carrier"] === CARRIER_VERSION_5) {
|
|
320
|
+
// v5: exactly the proof and its ceiling in time; whether either holds is verifyCarrier's question.
|
|
321
|
+
if (Object.keys(o).sort().join(",") !== "carrier,ceilingInTime,proof") return `a ${CARRIER_VERSION_5} block holds exactly carrier, proof and ceilingInTime`;
|
|
322
|
+
if (record(o["proof"]) === null) return "payload carries no proof object";
|
|
323
|
+
const c = record(o["ceilingInTime"]);
|
|
324
|
+
if (c === null || !(c["status"] === "unfetched" || (c["status"] === "present" && record(c["sidecar"]) !== null))) return "ceilingInTime must be present (with its sidecar) or unfetched";
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
311
327
|
const v4 = o["carrier"] === CARRIER_VERSION_4;
|
|
312
328
|
const v3 = o["carrier"] === CARRIER_VERSION_3;
|
|
313
329
|
const v2 = o["carrier"] === CARRIER_VERSION_2 || v3 || v4;
|
|
@@ -370,8 +386,8 @@ function payloadShapeError(p: unknown): string | null {
|
|
|
370
386
|
}
|
|
371
387
|
|
|
372
388
|
/** 1, 2, 3 or 4, from a parsed payload. */
|
|
373
|
-
export function carrierVersionOf(payload: CarrierPayload): 1 | 2 | 3 | 4 {
|
|
374
|
-
return payload.carrier === CARRIER_VERSION_4 ? 4 : payload.carrier === CARRIER_VERSION_3 ? 3 : payload.carrier === CARRIER_VERSION_2 ? 2 : 1;
|
|
389
|
+
export function carrierVersionOf(payload: CarrierPayload): 1 | 2 | 3 | 4 | 5 {
|
|
390
|
+
return payload.carrier === CARRIER_VERSION_5 ? 5 : payload.carrier === CARRIER_VERSION_4 ? 4 : payload.carrier === CARRIER_VERSION_3 ? 3 : payload.carrier === CARRIER_VERSION_2 ? 2 : 1;
|
|
375
391
|
}
|
|
376
392
|
|
|
377
393
|
export function parseCarrier(bytes: Uint8Array): CarrierParse {
|
package/src/carrier5.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (c) Argento Computing Inc. All rights reserved. See LICENSE.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The BitGraphed file, version 5 (2026-10-20): a file that carries its own proof, for proofs made in one atomic action
|
|
5
|
+
* (enclave v11 on). The bytes are the file exactly as it was bound, then the block (carrier.ts framing) holding:
|
|
6
|
+
*
|
|
7
|
+
* { carrier: "bitgraph-carrier/5", proof, ceilingInTime }
|
|
8
|
+
*
|
|
9
|
+
* proof the bitgraph/1 proof as the ledger serves it for these bytes. For a file of a tree (every drop on
|
|
10
|
+
* bitgraph.ing from 2026-10-20) it carries, in its unsigned metadata, the file's bitgraph-tree-member/1
|
|
11
|
+
* block: its path to the bound root, and the tree's floor leaf, base-block.json (the latest Base block
|
|
12
|
+
* read just before the bind).
|
|
13
|
+
* ceilingInTime the proof's Base ceiling (bitgraph-ceiling/1: the batch transaction, its block header, the trie and
|
|
14
|
+
* Merkle paths), or "unfetched".
|
|
15
|
+
*
|
|
16
|
+
* Checked offline, in this order: the bytes before the block are the bound bytes (directly, or as the member the tree
|
|
17
|
+
* names); the proof is BitGraph's (verifyAttested: signature, atomic counts, AWS Nitro attestation, published image);
|
|
18
|
+
* the floor block is a leaf of the very tree the proof binds, and the attested bind time is after its timestamp; the
|
|
19
|
+
* ceiling's batch holds this proof and its transaction is in the Base block it names. Whether those two Base blocks are
|
|
20
|
+
* on Base's canonical chain is a check against Base (Basescan), not one a file can carry.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
24
|
+
import { CARRIER_VERSION_5, buildCarrier, type CarrierPayload, type CarrierBounds } from "./carrier.js";
|
|
25
|
+
import { verifyAttested } from "./attested.js";
|
|
26
|
+
import { verifyCeiling, type CeilingSidecar } from "./ceiling.js";
|
|
27
|
+
import { checkTreeFloor, treeMemberOf } from "./tree-member.js";
|
|
28
|
+
import type { BitGraphProof } from "./types.js";
|
|
29
|
+
import type { CarrierClaim, CarrierVerifyResult, ClaimResult } from "./carrier-verify.js";
|
|
30
|
+
|
|
31
|
+
export const BITGRAPH_CEILING_WRITER_V5 = "0xf3972408D853c975F86351C311f4310220bbF2a3";
|
|
32
|
+
const BASE_CHAIN_ID = 8453;
|
|
33
|
+
|
|
34
|
+
export interface CarrierV5Payload {
|
|
35
|
+
carrier: typeof CARRIER_VERSION_5;
|
|
36
|
+
proof: Record<string, unknown>;
|
|
37
|
+
ceilingInTime: { status: "unfetched" } | { status: "present"; sidecar: Record<string, unknown> };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The v5 payload for a proof (as the ledger serves it for these bytes) and its ceiling sidecar, if written yet. */
|
|
41
|
+
export function assembleCarrierV5Payload(proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null): CarrierV5Payload {
|
|
42
|
+
return { carrier: CARRIER_VERSION_5, proof, ceilingInTime: ceilingSidecar ? { status: "present", sidecar: ceilingSidecar } : { status: "unfetched" } };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The BitGraphed file: the bound bytes, unchanged, followed by the v5 block. */
|
|
46
|
+
export function buildBitGraphedFileV5(bytes: Uint8Array, proof: Record<string, unknown>, ceilingSidecar: Record<string, unknown> | null): Uint8Array {
|
|
47
|
+
return buildCarrier(bytes, assembleCarrierV5Payload(proof, ceilingSidecar) as unknown as CarrierPayload);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const hex = (b: Uint8Array) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
51
|
+
const iso = (s: number) => new Date(s * 1000).toISOString().replace(".000Z", "Z");
|
|
52
|
+
|
|
53
|
+
export async function verifyCarrierV5(payloadIn: CarrierPayload, inner: Uint8Array | null, opts: { pcr0?: readonly string[]; rootDer?: Uint8Array } = {}): Promise<CarrierVerifyResult> {
|
|
54
|
+
const payload = payloadIn as unknown as CarrierV5Payload;
|
|
55
|
+
const proof = payload.proof as unknown as BitGraphProof;
|
|
56
|
+
const claims: CarrierClaim[] = [];
|
|
57
|
+
const add = (id: string, name: string, result: ClaimResult, restsOn: string, detail: string) => claims.push({ id, name, result, restsOn, detail, level: "offline" });
|
|
58
|
+
const member = treeMemberOf(proof);
|
|
59
|
+
|
|
60
|
+
// 1 + 2. The bytes, and the proof: verifyAttested walks a member's hash up its path first, then checks the proof
|
|
61
|
+
// against the root text it signs; plain bytes are checked against the proof's digest.
|
|
62
|
+
const r = await verifyAttested({ proof, ...(inner ? { bytes: inner } : {}), ...(opts.pcr0 ? { pcr0: opts.pcr0 } : {}), ...(opts.rootDer ? { rootDer: opts.rootDer } : {}) });
|
|
63
|
+
if (!inner) add("bytes.digest", "The file is the bound bytes", "NOT_CARRIED", "SHA-256", "no file in hand");
|
|
64
|
+
else if (member) add("tree.member", "The file is in the tree the proof binds", r.treeMember ? "TRUE" : "FALSE", "SHA-256", r.treeMember ? `file ${r.treeMember.index + 1} of ${r.treeMember.files}: its hash walks up the tree to the root the proof binds` : (r.reason ?? "its hash does not reach the root"));
|
|
65
|
+
else add("bytes.digest", "The file is the bound bytes", r.valid || !/digest/.test(r.reason ?? "") ? "TRUE" : "FALSE", "SHA-256", "the bytes before the block hash to the proof's digest");
|
|
66
|
+
for (const c of r.checks) add(`attestation.${c.name.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`, c.name, c.pass ? "TRUE" : "FALSE", "the AWS Nitro attestation", c.detail);
|
|
67
|
+
add("attestation.pins", "The image is one BitGraph published", r.image ? "TRUE" : "FALSE", "BitGraph's published enclave images", r.image ? `PCR0 ${String(r.pcr0).slice(0, 16)}… is the ${r.image.version} image` : `PCR0 ${String(r.pcr0 ?? "").slice(0, 16)}… is not one of BitGraph's`);
|
|
68
|
+
add("proof.signature", "The signature, the nonce's record and the two consecutive counts", r.valid ? "TRUE" : "FALSE", "Ed25519", r.valid ? "the enclave's key signed this body" : (r.reason ?? "did not verify"));
|
|
69
|
+
|
|
70
|
+
// 3. The floor: a leaf of the very tree the proof binds, and before the attested bind time.
|
|
71
|
+
let notBefore: CarrierBounds["notBefore"] | null = null;
|
|
72
|
+
if (member?.floor) {
|
|
73
|
+
const f = checkTreeFloor(proof, member);
|
|
74
|
+
const after = f !== null && r.attestedAtMs !== null && r.attestedAtMs >= f.timestamp * 1000;
|
|
75
|
+
add("floor.leaf", "The floor block is a leaf of the tree the proof binds", f ? "TRUE" : "FALSE", "SHA-256", f ? `Base block ${f.number} (${f.hash.slice(0, 12)}…): base-block.json walks up the tree to the bound root, so the bind came after this block existed` : "base-block.json does not reach the bound root");
|
|
76
|
+
if (f) {
|
|
77
|
+
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");
|
|
78
|
+
notBefore = { chain: "base", blockNumber: f.number, blockHash: f.hash, timestamp: f.timestamp };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 4. The ceiling: this proof's hash is in the batch the Base transaction carries, and that transaction is in its block.
|
|
83
|
+
let existedBy: CarrierBounds["existedBy"] = null;
|
|
84
|
+
if (payload.ceilingInTime.status === "present") {
|
|
85
|
+
const c = await verifyCeiling(proof, payload.ceilingInTime.sidecar as unknown as CeilingSidecar, { writerAddress: BITGRAPH_CEILING_WRITER_V5, chainId: BASE_CHAIN_ID, proofAlreadyVerified: r.valid });
|
|
86
|
+
const w = c.window?.ceiling;
|
|
87
|
+
add("ceiling.time", "Written to Base, in a batch from BitGraph's writer", c.ok ? "TRUE" : "FALSE", "Base: the batch root, the transaction and the block header", c.ok && w ? `Base block ${w.blockNumber} (${iso(w.blockTimestamp)}): the proof existed by then` : (c.reason ?? "the ceiling does not verify"));
|
|
88
|
+
if (c.ok && w) existedBy = { chain: "base", blockNumber: w.blockNumber, blockHash: w.blockHash, timestamp: w.blockTimestamp };
|
|
89
|
+
} else add("ceiling.time", "Written to Base", "NOT_CARRIED", "", "this file was made before the Base write landed; the ceiling can be looked up by the proof's hash");
|
|
90
|
+
|
|
91
|
+
const failed = claims.filter((c) => c.result === "FALSE");
|
|
92
|
+
const verdict: CarrierVerifyResult["verdict"] = failed.length > 0 ? "FALSE" : r.valid ? "TRUE" : "UNDETERMINED";
|
|
93
|
+
const where = member ? `file ${member.index + 1} of a tree of ${member.files}` : "these exact bytes";
|
|
94
|
+
const reading = verdict === "TRUE"
|
|
95
|
+
? `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
|
+
: `This BitGraphed file does not check: ${failed.map((c) => c.detail).join("; ") || "the proof did not verify"}.`;
|
|
97
|
+
return {
|
|
98
|
+
verdict, carrier: "ok", version: 5, reasons: claims.filter((c) => c.result !== "TRUE" && c.result !== "NOT_CARRIED").map((c) => c.detail),
|
|
99
|
+
bounds: notBefore ? { notBefore, notAfter: null, existedBy, settledBy: null } : null,
|
|
100
|
+
ceiling: null, claims, reading, payload: payloadIn, inner,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The bound bytes' SHA-256 as hex (for callers printing the envelope rule). */
|
|
105
|
+
export const innerHex = (inner: Uint8Array) => hex(sha256(inner));
|
package/src/index.ts
CHANGED
|
@@ -43,6 +43,8 @@ export { canonicalize, canonicalizeToString, constantTimeEqual } from "./canonic
|
|
|
43
43
|
export { verifyStretch, verifyBetween } from "./stretch.js";
|
|
44
44
|
// The full check of a plain proof: verify() plus the AWS Nitro attestation and the published image (2026-10-18).
|
|
45
45
|
export { verifyAttested } from "./attested.js";
|
|
46
|
+
// A file of a tree, checked by its own hash (bitgraph-tree-member/1, 2026-10-20). verifyAttested applies it.
|
|
47
|
+
export { TREE_MEMBER_METADATA_KEY, treeMemberOf, checkTreeMember, treeRootFromPath, digestTreeRootText, parseDigestTreeRootText, treeRootTextBytes, type TreeMemberBlock } from "./tree-member.js";
|
|
46
48
|
export type { AttestedOptions, AttestedResult } from "./attested.js";
|
|
47
49
|
export type { StretchResult } from "./stretch.js";
|
|
48
50
|
|
|
@@ -147,6 +149,10 @@ export type { CarrierV3Parts } from "./carrier-assemble.js";
|
|
|
147
149
|
|
|
148
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. */
|
|
149
151
|
export { CARRIER_VERSION_4, memberArtifactDigest } from "./carrier.js";
|
|
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";
|
|
155
|
+
export { checkTreeFloor, BASE_BLOCK_FORMAT, type TreeFloor, type TreeFloorBlock } from "./tree-member.js";
|
|
150
156
|
export type { CarrierTree } from "./carrier.js";
|
|
151
157
|
export { assembleCarrierV4Payload } from "./carrier-assemble.js";
|
|
152
158
|
export type { CarrierV4Parts } from "./carrier-assemble.js";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Copyright (c) Argento Computing Inc. All rights reserved. See LICENSE.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A file of a tree, checked by its own hash (bitgraph-tree-member/1, the format bitgraph.ing's Make page writes from
|
|
5
|
+
* 2026-10-20: a drop of many files is one tree, one BitGraph, and each file is found and checked like a file bound
|
|
6
|
+
* alone).
|
|
7
|
+
*
|
|
8
|
+
* leaf = SHA-256( 0x00 || SHA-256(file) ) node = SHA-256( 0x01 || left || right ); an odd last node rises
|
|
9
|
+
* bound = the root's text, exactly: "Merkle root (RFC 6962, SHA-256; each leaf is a file's SHA-256) of N files:\n<root hex>\n"
|
|
10
|
+
*
|
|
11
|
+
* A member's proof is the tree's proof with, in its UNSIGNED metadata:
|
|
12
|
+
*
|
|
13
|
+
* metadata["bitgraph-tree-member/1"] = { format, files, index, path, rootText }
|
|
14
|
+
* path: base64 of the 32-byte siblings from the leaf up, concatenated (a level where the node rose has none)
|
|
15
|
+
*
|
|
16
|
+
* The block is advisory until checked: the file's hash is walked up the path to a root, rootText must name that root
|
|
17
|
+
* and that count, and SHA-256(rootText) must be the digest the proof signs. The proof is then verified against
|
|
18
|
+
* rootText's bytes like any proof against its file (verifyAttested does both).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
22
|
+
|
|
23
|
+
export const TREE_MEMBER_METADATA_KEY = "bitgraph-tree-member/1" as const;
|
|
24
|
+
/** The tree's floor (bitgraph.ing, 2026-10-20): base-block.json, the latest Base block read just before the bind, as the
|
|
25
|
+
* tree's first leaf; `file` is its exact text, `index` and `path` place it in the same tree. */
|
|
26
|
+
export interface TreeFloor { file: string; index: number; path: string }
|
|
27
|
+
export interface TreeMemberBlock { format: typeof TREE_MEMBER_METADATA_KEY; files: number; index: number; path: string; rootText: string; floor?: TreeFloor }
|
|
28
|
+
export const BASE_BLOCK_FORMAT = "bitgraph-base-block/1" as const;
|
|
29
|
+
export interface TreeFloorBlock { chain: string; chainId: number; number: number; hash: string; timestamp: number }
|
|
30
|
+
|
|
31
|
+
const enc = new TextEncoder();
|
|
32
|
+
const HEX = "0123456789abcdef";
|
|
33
|
+
const hex = (b: Uint8Array): string => { let s = ""; for (const x of b) s += HEX[x >> 4]! + HEX[x & 15]!; return s; };
|
|
34
|
+
const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
35
|
+
function b64(u: Uint8Array): string {
|
|
36
|
+
let s = "";
|
|
37
|
+
for (let i = 0; i < u.length; i += 3) {
|
|
38
|
+
const n = (u[i]! << 16) | ((u[i + 1] ?? 0) << 8) | (u[i + 2] ?? 0);
|
|
39
|
+
s += B64[(n >> 18) & 63]! + B64[(n >> 12) & 63]! + (i + 1 < u.length ? B64[(n >> 6) & 63]! : "=") + (i + 2 < u.length ? B64[n & 63]! : "=");
|
|
40
|
+
}
|
|
41
|
+
return s;
|
|
42
|
+
}
|
|
43
|
+
function unb64(s: string): Uint8Array | null {
|
|
44
|
+
const t = s.replace(/-/g, "+").replace(/_/g, "/").replace(/=+$/, "");
|
|
45
|
+
if (!/^[A-Za-z0-9+/]*$/.test(t) || t.length % 4 === 1) return null;
|
|
46
|
+
const out: number[] = [];
|
|
47
|
+
let buf = 0, bits = 0;
|
|
48
|
+
for (const c of t) { buf = (buf << 6) | B64.indexOf(c); bits += 6; if (bits >= 8) { bits -= 8; out.push((buf >> bits) & 255); } }
|
|
49
|
+
return new Uint8Array(out);
|
|
50
|
+
}
|
|
51
|
+
const cat = (...p: Uint8Array[]): Uint8Array => { const o = new Uint8Array(p.reduce((a, x) => a + x.length, 0)); let i = 0; for (const x of p) { o.set(x, i); i += x.length; } return o; };
|
|
52
|
+
|
|
53
|
+
/** The text a digest-leaf tree binds. */
|
|
54
|
+
export const digestTreeRootText = (files: number, rootHex: string): string =>
|
|
55
|
+
`Merkle root (RFC 6962, SHA-256; each leaf is a file's SHA-256) of ${files} files:\n${rootHex}\n`;
|
|
56
|
+
|
|
57
|
+
export function parseDigestTreeRootText(text: string): { files: number; root: string } | null {
|
|
58
|
+
const m = /^Merkle root \(RFC 6962, SHA-256; each leaf is a file's SHA-256\) of (\d+) files:\n([0-9a-f]{64})\n$/.exec(text);
|
|
59
|
+
if (!m) return null;
|
|
60
|
+
const files = Number(m[1]);
|
|
61
|
+
return Number.isSafeInteger(files) && files >= 1 ? { files, root: m[2]! } : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Walk a leaf up its siblings (RFC 6962, an odd last node rising unchanged): the root as hex, or null if they cannot be this leaf's. */
|
|
65
|
+
export function treeRootFromPath(leaf32: Uint8Array, index: number, files: number, siblings: Uint8Array): string | null {
|
|
66
|
+
if (!Number.isSafeInteger(index) || !Number.isSafeInteger(files) || index < 0 || index >= files || siblings.length % 32 !== 0) return null;
|
|
67
|
+
let h = leaf32, idx = index, n = files, at = 0;
|
|
68
|
+
while (n > 1) {
|
|
69
|
+
if (!(idx === n - 1 && idx % 2 === 0)) {
|
|
70
|
+
if (at + 32 > siblings.length) return null;
|
|
71
|
+
const s = siblings.subarray(at, at + 32); at += 32;
|
|
72
|
+
h = sha256(cat(new Uint8Array([1]), idx % 2 === 1 ? s : h, idx % 2 === 1 ? h : s));
|
|
73
|
+
}
|
|
74
|
+
idx >>= 1; n = Math.ceil(n / 2);
|
|
75
|
+
}
|
|
76
|
+
return at === siblings.length ? hex(h) : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The member block a proof carries, strictly parsed; null when absent or malformed. Unchecked: see checkTreeMember. */
|
|
80
|
+
export function treeMemberOf(proof: unknown): TreeMemberBlock | null {
|
|
81
|
+
const m = (proof as { metadata?: Record<string, unknown> } | null)?.metadata?.[TREE_MEMBER_METADATA_KEY] as Partial<TreeMemberBlock> | undefined;
|
|
82
|
+
if (!m || typeof m !== "object") return null;
|
|
83
|
+
if (m.format !== TREE_MEMBER_METADATA_KEY || !Number.isSafeInteger(m.files) || !Number.isSafeInteger(m.index) || typeof m.path !== "string" || typeof m.rootText !== "string") return null;
|
|
84
|
+
if (m.rootText.length > 512 || m.path.length > 4096) return null;
|
|
85
|
+
return m as TreeMemberBlock;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Whether a file with this SHA-256 (32 bytes, or base64 of them) is the block's member of the tree whose root text the
|
|
90
|
+
* proof signs. The membership only: the proof itself is verified against rootText's bytes (treeRootTextBytes).
|
|
91
|
+
*/
|
|
92
|
+
export function checkTreeMember(proof: unknown, fileDigest: Uint8Array | string, block: TreeMemberBlock | null = treeMemberOf(proof)): boolean {
|
|
93
|
+
if (!block) return false;
|
|
94
|
+
const parsed = parseDigestTreeRootText(block.rootText);
|
|
95
|
+
if (!parsed || parsed.files !== block.files || block.index < 0 || block.index >= block.files) return false;
|
|
96
|
+
const bound = (proof as { artifact?: { digestB64?: string } } | null)?.artifact?.digestB64;
|
|
97
|
+
if (typeof bound !== "string" || unb64(bound) === null || b64(sha256(enc.encode(block.rootText))) !== b64(unb64(bound)!)) return false;
|
|
98
|
+
const d = typeof fileDigest === "string" ? unb64(fileDigest) : fileDigest;
|
|
99
|
+
const path = unb64(block.path);
|
|
100
|
+
if (!d || d.length !== 32 || !path) return false;
|
|
101
|
+
return treeRootFromPath(sha256(cat(new Uint8Array([0]), d)), block.index, block.files, path) === parsed.root;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The tree's floor block, when the member carries one and base-block.json is in the very tree the proof binds (its hash
|
|
106
|
+
* walks up its path to the root rootText names, and SHA-256(rootText) is what the proof signs). Null otherwise. That the
|
|
107
|
+
* block exists on Base with that hash and time is a separate check, against Base.
|
|
108
|
+
*/
|
|
109
|
+
export function checkTreeFloor(proof: unknown, block: TreeMemberBlock | null = treeMemberOf(proof)): TreeFloorBlock | null {
|
|
110
|
+
const f = block?.floor;
|
|
111
|
+
if (!block || !f || typeof f.file !== "string" || typeof f.path !== "string" || !Number.isSafeInteger(f.index) || f.file.length > 2048) return null;
|
|
112
|
+
const parsed = parseDigestTreeRootText(block.rootText);
|
|
113
|
+
const bound = (proof as { artifact?: { digestB64?: string } } | null)?.artifact?.digestB64;
|
|
114
|
+
if (!parsed || parsed.files !== block.files || typeof bound !== "string" || unb64(bound) === null || b64(sha256(enc.encode(block.rootText))) !== b64(unb64(bound)!)) return null;
|
|
115
|
+
const path = unb64(f.path);
|
|
116
|
+
if (!path || treeRootFromPath(sha256(cat(new Uint8Array([0]), sha256(enc.encode(f.file)))), f.index, block.files, path) !== parsed.root) return null;
|
|
117
|
+
try {
|
|
118
|
+
const o = JSON.parse(f.file) as Partial<TreeFloorBlock> & { format?: string };
|
|
119
|
+
if (o.format !== BASE_BLOCK_FORMAT || typeof o.chain !== "string" || !Number.isSafeInteger(o.chainId) || !Number.isSafeInteger(o.number) || typeof o.hash !== "string" || !/^0x[0-9a-f]{64}$/i.test(o.hash) || !Number.isSafeInteger(o.timestamp)) return null;
|
|
120
|
+
return { chain: o.chain, chainId: o.chainId!, number: o.number!, hash: o.hash, timestamp: o.timestamp! };
|
|
121
|
+
} catch { return null; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The bytes a member's proof signs: its root text. */
|
|
125
|
+
export const treeRootTextBytes = (block: TreeMemberBlock): Uint8Array => enc.encode(block.rootText);
|