@mikeargento/bitgraph-audit 0.11.1 → 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.
- package/dist/audit.d.ts +1 -1
- package/dist/audit.js +1 -1
- package/dist/genesis.d.ts +141 -0
- package/dist/genesis.d.ts.map +1 -0
- package/dist/genesis.js +359 -0
- package/dist/genesis.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/publication.d.ts +148 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/publication.js +392 -0
- package/dist/publication.js.map +1 -0
- package/dist/tot.d.ts +99 -0
- package/dist/tot.d.ts.map +1 -0
- package/dist/tot.js +242 -0
- package/dist/tot.js.map +1 -0
- package/package.json +4 -3
- package/src/__tests__/{anchors.test.ts → archive/anchors.test.ts} +2 -2
- package/src/__tests__/{base-floor.test.ts → archive/base-floor.test.ts} +2 -2
- package/src/__tests__/{carrier-tree.test.ts → archive/carrier-tree.test.ts} +2 -2
- package/src/__tests__/archive/genesis.test.ts +256 -0
- package/src/__tests__/archive/publication.test.ts +210 -0
- package/src/__tests__/tot-v2-vectors.test.ts +87 -0
- package/src/__tests__/tot-vectors.test.ts +120 -0
- package/src/audit.ts +1 -1
- package/src/genesis.ts +382 -0
- package/src/index.ts +26 -0
- package/src/publication.ts +461 -0
- package/src/tot.ts +253 -0
- /package/src/__tests__/{fixtures → archive/fixtures}/settlement/0x018efc046e94610e2530344caf1574e507a3182e1a975fb25b032ec1434a3f5c.bin +0 -0
- /package/src/__tests__/{fixtures → archive/fixtures}/settlement/ceiling-51979918.json +0 -0
- /package/src/__tests__/{fixtures → archive/fixtures}/settlement/pointer-51979918.json +0 -0
- /package/src/__tests__/{settlement.test.ts → archive/settlement.test.ts} +0 -0
package/dist/tot.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reference check for the TOT receipt formats: bitgraph-tot-v1 (spec/BITGRAPH-TOT-1.md) and bitgraph-tot-v2
|
|
3
|
+
* (spec/BITGRAPH-TOT-2.md), which is v1 with one addition: the TOT may carry a public floor, a block of a public
|
|
4
|
+
* chain signed into the TOT body (record version bitgraph/slot/2). Every offline check is v1's. Looking the floor's
|
|
5
|
+
* block up is a separate, optional step (checkTotFloor) that needs the network and never changes a verdict.
|
|
6
|
+
*
|
|
7
|
+
* Two checks, as the spec defines them:
|
|
8
|
+
*
|
|
9
|
+
* verifyTotReceipt one receipt: its form (section 7, R1), then the full attested check that every BitGraph tool
|
|
10
|
+
* runs (verifyAttested in @mikeargento/bitgraph-verify: the TOT and its binding, the count order,
|
|
11
|
+
* both signatures, the Nitro document, its binding to this receipt, the measurement, and the
|
|
12
|
+
* file when given), limited to the measurements this format accepts.
|
|
13
|
+
* checkSpentOnce a set of receipts: refused when two different receipts spend one TOT (section 8). One receipt
|
|
14
|
+
* on its own cannot show this, so it is a check over the set. It counts every receipt whose two
|
|
15
|
+
* signatures and TOT binding hold (R2 to R6), attested or not: a key that signed one TOT into two
|
|
16
|
+
* receipts has spent it twice whoever holds the key, and a receipt whose signatures fail is
|
|
17
|
+
* nobody's and cannot refuse another.
|
|
18
|
+
*/
|
|
19
|
+
import { type NitroCheck, type SlotFloor, type FloorCheck, type RpcBlockHeader } from "@mikeargento/bitgraph-verify";
|
|
20
|
+
/** The first format's name. */
|
|
21
|
+
export declare const TOT_FORMAT = "bitgraph-tot-v1";
|
|
22
|
+
/** The second format's name: v1, and a TOT may carry a public floor. */
|
|
23
|
+
export declare const TOT_FORMAT_V2 = "bitgraph-tot-v2";
|
|
24
|
+
/** The enclave measurements (PCR0, lowercase hex) bitgraph-tot-v1 accepts by default: the v13 image. */
|
|
25
|
+
export declare const TOT_V1_MEASUREMENTS: readonly string[];
|
|
26
|
+
/** The enclave measurements bitgraph-tot-v2 accepts by default: the v14 image, the first that signs a floor. */
|
|
27
|
+
export declare const TOT_V2_MEASUREMENTS: readonly string[];
|
|
28
|
+
/** Every measurement the reference check accepts by default: both formats'. */
|
|
29
|
+
export declare const TOT_MEASUREMENTS: readonly string[];
|
|
30
|
+
export interface TotVerdict {
|
|
31
|
+
verdict: "ACCEPT" | "REJECT";
|
|
32
|
+
/** Why it was refused; absent on ACCEPT. */
|
|
33
|
+
reason?: string;
|
|
34
|
+
/** Whether a file was compared with the receipt's digest. */
|
|
35
|
+
file: "compared" | "not-compared";
|
|
36
|
+
/** The attestation document's own time, when the receipt was accepted (ISO 8601). */
|
|
37
|
+
attestedAt?: string;
|
|
38
|
+
/** The attestation's checks, in order, when the document was read. */
|
|
39
|
+
checks: NitroCheck[];
|
|
40
|
+
/** The public floor signed into the TOT, when the receipt was accepted and its TOT carries one. Not yet looked up. */
|
|
41
|
+
floor?: SlotFloor;
|
|
42
|
+
}
|
|
43
|
+
/** R1, the receipt's form: every field this format requires, in the shape it requires. Null when it is in form. */
|
|
44
|
+
export declare function totFormProblem(receipt: unknown): string | null;
|
|
45
|
+
/** The check of one receipt, with the file when it is given. */
|
|
46
|
+
export declare function verifyTotReceipt(opts: {
|
|
47
|
+
receipt: unknown;
|
|
48
|
+
file?: Uint8Array;
|
|
49
|
+
/** The accepted measurements. Default: TOT_MEASUREMENTS, both formats'. */
|
|
50
|
+
measurements?: readonly string[];
|
|
51
|
+
/** A different root certificate (DER), for tests against a non-AWS chain. */
|
|
52
|
+
rootDer?: Uint8Array;
|
|
53
|
+
}): Promise<TotVerdict>;
|
|
54
|
+
/**
|
|
55
|
+
* The optional online step for a receipt whose TOT carries a floor (bitgraph-tot-v2, section 4): look the block up
|
|
56
|
+
* on its chain. It is run only on a receipt the offline check already accepted, and whatever it answers, that
|
|
57
|
+
* verdict stands.
|
|
58
|
+
*
|
|
59
|
+
* confirmed the chain holds that block: the TOT was made after it. The block's time and the gap from it to
|
|
60
|
+
* the attestation's time are reported; `stale` is set when maxFloorGapMs is given and exceeded.
|
|
61
|
+
* not-confirmed the chain has no such block, or another one at that number: the floor shows nothing.
|
|
62
|
+
* not-checked the lookup could not be made.
|
|
63
|
+
* none the TOT carries no floor.
|
|
64
|
+
*
|
|
65
|
+
* Pass `block` (what the chain says, or null for "no such block") to apply the rule with no network.
|
|
66
|
+
*/
|
|
67
|
+
export declare function checkTotFloor(opts: {
|
|
68
|
+
receipt: unknown;
|
|
69
|
+
/** The accepted receipt's attestation time, from its verdict's attestedAt. */
|
|
70
|
+
attestedAt?: string;
|
|
71
|
+
/** Flag the floor as stale when the attestation is more than this long after the block. */
|
|
72
|
+
maxFloorGapMs?: number;
|
|
73
|
+
rpcUrl?: string;
|
|
74
|
+
fetcher?: typeof fetch;
|
|
75
|
+
block?: (Partial<RpcBlockHeader> & {
|
|
76
|
+
timestampMs?: string;
|
|
77
|
+
}) | null;
|
|
78
|
+
}): Promise<FloorCheck>;
|
|
79
|
+
/** The set rule's reasons: two receipts spend one TOT, or two TOTs claim one position. */
|
|
80
|
+
export type SpentTwiceCode = "DUPLICATE_TOT" | "DUPLICATE_TOT_POSITION";
|
|
81
|
+
export interface SpentTwice {
|
|
82
|
+
/** DUPLICATE_TOT: the receipts carry the same TOT. DUPLICATE_TOT_POSITION: different TOTs at one position (the same
|
|
83
|
+
* key, epoch, chain and count). */
|
|
84
|
+
code: SpentTwiceCode;
|
|
85
|
+
/** The indexes, in the set given, of the receipts that spend it. */
|
|
86
|
+
receipts: number[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The set check (section 8): every TOT is spent once. Two receipts that differ in their signed bodies and carry the same
|
|
90
|
+
* TOT, or two different TOTs at one position (the same key, epoch, chain and count), are refused together. The same
|
|
91
|
+
* receipt given twice is one receipt, not two. Only receipts whose signatures and TOT binding hold are counted.
|
|
92
|
+
*/
|
|
93
|
+
export declare function checkSpentOnce(receipts: readonly unknown[]): Promise<{
|
|
94
|
+
verdict: "ACCEPT" | "REJECT";
|
|
95
|
+
reason?: SpentTwiceCode;
|
|
96
|
+
spentTwice: S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AAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAsBtB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CACrE,GAAG,OAAO,CAAC,UAAU,CAAC,CAWtB;AAED,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,wBAAwB,CAAC;AAExE,MAAM,WAAW,UAAU;IACzB;wCACoC;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,oEAAoE;IACpE,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IAAC,UAAU,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAsClL"}
|
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
|
package/dist/tot.js.map
ADDED
|
@@ -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,g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C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IACjJ,CAAC;IACD,MAAM,KAAK,GAAG,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikeargento/bitgraph-audit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
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",
|
|
@@ -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.
|
|
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"
|
|
@@ -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 "
|
|
21
|
-
import type { IngestResult, ObservedProof } from "
|
|
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";
|
|
@@ -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, "
|
|
42
|
-
const CLI = join(here, "
|
|
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";
|
|
@@ -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, "
|
|
33
|
-
const CLI = join(here, "
|
|
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);
|