@pacspace-io/check 0.5.4 → 0.5.5
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/cli.js +211 -34
- package/dist/index.js +211 -34
- package/dist/release.d.ts +4 -0
- package/dist/report.d.ts +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.5 - 2026-11-17
|
|
4
|
+
|
|
5
|
+
### Security
|
|
6
|
+
|
|
7
|
+
- Reads from a mirror (the default source or `--source <url>`) hold the source to its own address: a redirect is not followed, and a next page is read only from the same source and the same contract's log. A page with more logs than were asked for is not read. A page larger than 1 MiB is asked for again in smaller pages, and a single answer larger than 1 MiB is not read. With a source that does any of these the report says the proof layer was not read, and why, and the exit code is the one for a proof layer that could not be reached. A source given as `http://` that redirects to `https://` must now be given as `https://`. The list of where each entry was committed reads its pages under the same limits.
|
|
8
|
+
|
|
3
9
|
## 0.5.4 - 2026-11-16
|
|
4
10
|
|
|
5
11
|
### Added
|
package/README.md
CHANGED
|
@@ -137,7 +137,7 @@ fingerprint comparison; and the sentences printed above.
|
|
|
137
137
|
|
|
138
138
|
Node.js 20.19 or later, and the network, for the proof layer. open reads the record from the link's host, and release reads the key pages from the host it checks. Checking a file sends nothing to PacSpace. Where a record was committed is named inside the history
|
|
139
139
|
file; `--source` and `--rpc` point the checker at a mirror or endpoint of
|
|
140
|
-
your own.
|
|
140
|
+
your own. A redirect from a source is not followed. Pass the address it leads to; a source given as `http://` usually needs `https://`. When a report says the proof layer was not read because of its source, name another source, or read without a mirror with `--rpc <url>`.
|
|
141
141
|
|
|
142
142
|
## License
|
|
143
143
|
|
package/dist/cli.js
CHANGED
|
@@ -2110,20 +2110,121 @@ var MIRROR_NODE_BY_CHAIN = Object.freeze({
|
|
|
2110
2110
|
|
|
2111
2111
|
// ../shared/src/records/ledger-write-search-v1.ts
|
|
2112
2112
|
var LEDGER_WRITE_SEARCH_WINDOW_LIMIT_SECONDS = 7 * 24 * 60 * 60;
|
|
2113
|
+
var LEDGER_WRITE_SEARCH_PAGE_LIMIT = 100;
|
|
2114
|
+
var MIRROR_ANSWER_MAX_BYTES = 1048576;
|
|
2115
|
+
var HEX40 = /^0x[0-9a-f]{40}$/;
|
|
2113
2116
|
var HEX642 = /^0x[0-9a-f]{64}$/;
|
|
2114
2117
|
var HEX_DATA = /^0x[0-9a-f]*$/;
|
|
2115
2118
|
var TIMESTAMP = /^\d+(\.\d+)?$/;
|
|
2116
|
-
var
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2119
|
+
var REFUSAL_CODES = ["redirect", "too-large", "too-many-logs", "next-page"];
|
|
2120
|
+
var MirrorAnswerRefused = class extends Error {
|
|
2121
|
+
constructor(code, message) {
|
|
2122
|
+
super(message);
|
|
2123
|
+
this.name = "MirrorAnswerRefused";
|
|
2124
|
+
this.code = code;
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
function mirrorRefusalOf(error) {
|
|
2128
|
+
if (!error || typeof error !== "object") return null;
|
|
2129
|
+
const { name, code } = error;
|
|
2130
|
+
return name === "MirrorAnswerRefused" && typeof code === "string" && REFUSAL_CODES.includes(code) ? code : null;
|
|
2131
|
+
}
|
|
2132
|
+
function pathLabel(path) {
|
|
2133
|
+
return path ? ` (${path.split("?")[0]})` : "";
|
|
2134
|
+
}
|
|
2135
|
+
var mirrorRefusal = {
|
|
2136
|
+
redirect: (path) => new MirrorAnswerRefused("redirect", `mirror node answered with a redirect, which is not followed${pathLabel(path)}`),
|
|
2137
|
+
tooLarge: (maxBytes, path) => new MirrorAnswerRefused("too-large", `mirror node answer is larger than ${maxBytes} bytes${pathLabel(path)}`),
|
|
2138
|
+
tooManyLogs: (asked, path) => new MirrorAnswerRefused("too-many-logs", `mirror node returned more logs than the ${asked} asked for${pathLabel(path)}`),
|
|
2139
|
+
nextPage: () => new MirrorAnswerRefused("next-page", "mirror node gave a next page that is not this contract's log")
|
|
2140
|
+
};
|
|
2141
|
+
function isMirrorRedirect(response) {
|
|
2142
|
+
return response.redirected === true || response.type === "opaqueredirect" || response.status >= 300 && response.status < 400;
|
|
2143
|
+
}
|
|
2144
|
+
async function readMirrorText(response, maxBytes = MIRROR_ANSWER_MAX_BYTES, path) {
|
|
2145
|
+
const declared = Number(response.headers?.get?.("content-length") ?? Number.NaN);
|
|
2146
|
+
const body = response.body;
|
|
2147
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
2148
|
+
await body?.cancel?.().catch(() => void 0);
|
|
2149
|
+
throw mirrorRefusal.tooLarge(maxBytes, path);
|
|
2150
|
+
}
|
|
2151
|
+
if (body && typeof body.getReader === "function") {
|
|
2152
|
+
const reader = body.getReader();
|
|
2153
|
+
const decoder = new TextDecoder();
|
|
2154
|
+
let text2 = "";
|
|
2155
|
+
let read = 0;
|
|
2156
|
+
for (; ; ) {
|
|
2157
|
+
const { done, value } = await reader.read();
|
|
2158
|
+
if (done) break;
|
|
2159
|
+
read += value.byteLength;
|
|
2160
|
+
if (read > maxBytes) {
|
|
2161
|
+
await reader.cancel().catch(() => void 0);
|
|
2162
|
+
throw mirrorRefusal.tooLarge(maxBytes, path);
|
|
2163
|
+
}
|
|
2164
|
+
text2 += decoder.decode(value, { stream: true });
|
|
2165
|
+
}
|
|
2166
|
+
return text2 + decoder.decode();
|
|
2167
|
+
}
|
|
2168
|
+
const text = await response.text();
|
|
2169
|
+
if (new TextEncoder().encode(text).byteLength > maxBytes) throw mirrorRefusal.tooLarge(maxBytes, path);
|
|
2170
|
+
return text;
|
|
2120
2171
|
}
|
|
2121
|
-
function
|
|
2122
|
-
return
|
|
2172
|
+
async function readMirrorJson(response, maxBytes = MIRROR_ANSWER_MAX_BYTES, path) {
|
|
2173
|
+
return JSON.parse(await readMirrorText(response, maxBytes, path));
|
|
2174
|
+
}
|
|
2175
|
+
function contractLogPath(contractAddress) {
|
|
2176
|
+
return `/api/v1/contracts/${contractAddress}/results/logs`;
|
|
2177
|
+
}
|
|
2178
|
+
function ledgerWriteSearchPath(input) {
|
|
2179
|
+
const query = `topic0=${input.topic0}&topic1=${input.recordKey}×tamp=gte:${input.lower}×tamp=lt:${input.upper}&order=desc&limit=${LEDGER_WRITE_SEARCH_PAGE_LIMIT}`;
|
|
2180
|
+
return `${contractLogPath(input.contractAddress)}?${query}`;
|
|
2181
|
+
}
|
|
2182
|
+
function nextLogPath(next, source) {
|
|
2183
|
+
if (typeof next !== "string" || next === "") return null;
|
|
2184
|
+
const contract = source.contract.toLowerCase();
|
|
2185
|
+
if (!HEX40.test(contract)) return null;
|
|
2186
|
+
if (!/^[\x21-\x5b\x5d-\x7e]+$/.test(next)) return null;
|
|
2187
|
+
if (next.startsWith("//")) return null;
|
|
2188
|
+
let base;
|
|
2189
|
+
let url;
|
|
2190
|
+
try {
|
|
2191
|
+
base = new URL(source.base);
|
|
2192
|
+
url = new URL(next, `${base.origin}/`);
|
|
2193
|
+
} catch {
|
|
2194
|
+
return null;
|
|
2195
|
+
}
|
|
2196
|
+
if (base.protocol !== "https:" && base.protocol !== "http:") return null;
|
|
2197
|
+
if (url.origin !== base.origin || url.username !== "" || url.password !== "" || url.hash !== "" || next.includes("#")) return null;
|
|
2198
|
+
const written = (next.startsWith("/") ? next : next.slice(next.indexOf("/", next.indexOf("//") + 2))).split("?")[0];
|
|
2199
|
+
if (/(^|\/)\.{1,2}(\/|$)/.test(written) || /%2e/i.test(written) || written !== url.pathname) return null;
|
|
2200
|
+
if (url.search.length < 2) return null;
|
|
2201
|
+
const logs = contractLogPath(contract);
|
|
2202
|
+
const prefix = base.pathname.replace(/\/+$/, "");
|
|
2203
|
+
const path = url.pathname.toLowerCase();
|
|
2204
|
+
if (path !== logs && !(prefix !== "" && url.pathname.startsWith(`${prefix}/`) && url.pathname.slice(prefix.length).toLowerCase() === logs)) return null;
|
|
2205
|
+
return `${logs}${url.search}`;
|
|
2206
|
+
}
|
|
2207
|
+
function withLogPageLimit(path, limit) {
|
|
2208
|
+
const at = path.indexOf("?");
|
|
2209
|
+
const before = at === -1 ? path : path.slice(0, at);
|
|
2210
|
+
const parts = at === -1 ? [] : path.slice(at + 1).split("&").filter((part) => part !== "");
|
|
2211
|
+
let placed = false;
|
|
2212
|
+
const out = [];
|
|
2213
|
+
for (const part of parts) {
|
|
2214
|
+
if (!part.startsWith("limit=")) out.push(part);
|
|
2215
|
+
else if (!placed) {
|
|
2216
|
+
out.push(`limit=${limit}`);
|
|
2217
|
+
placed = true;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
if (!placed) out.push(`limit=${limit}`);
|
|
2221
|
+
return `${before}?${out.join("&")}`;
|
|
2123
2222
|
}
|
|
2124
2223
|
function parseLedgerWriteLog(log, expected) {
|
|
2125
2224
|
if (!log || typeof log !== "object") return null;
|
|
2126
2225
|
const raw = log;
|
|
2226
|
+
const address = typeof raw.address === "string" ? raw.address.toLowerCase() : "";
|
|
2227
|
+
if (!HEX40.test(address) || address !== String(expected.contractAddress).toLowerCase()) return null;
|
|
2127
2228
|
const topics = Array.isArray(raw.topics) ? raw.topics.map((topic) => String(topic).toLowerCase()) : [];
|
|
2128
2229
|
if (topics[0] !== expected.topic0 || topics[1] !== expected.recordKey) return null;
|
|
2129
2230
|
const data = typeof raw.data === "string" ? raw.data.toLowerCase() : "";
|
|
@@ -2137,7 +2238,6 @@ function parseLedgerWriteLog(log, expected) {
|
|
|
2137
2238
|
const [seconds, fraction = ""] = timestamp.split(".");
|
|
2138
2239
|
const ms = Number(seconds) * 1e3 + Number(fraction.slice(0, 3).padEnd(3, "0"));
|
|
2139
2240
|
if (!Number.isFinite(ms) || Math.abs(ms) > 864e13) return null;
|
|
2140
|
-
const address = typeof raw.address === "string" ? raw.address.toLowerCase() : null;
|
|
2141
2241
|
return {
|
|
2142
2242
|
transactionHash,
|
|
2143
2243
|
timestamp,
|
|
@@ -2558,6 +2658,23 @@ function committedAtOf(timestamp) {
|
|
|
2558
2658
|
const [seconds, fraction] = timestamp.split(".");
|
|
2559
2659
|
return new Date(Number(seconds) * 1e3 + Number(fraction.slice(0, 3))).toISOString();
|
|
2560
2660
|
}
|
|
2661
|
+
var KEPT_TOPICS = [RECORD_WRITTEN_TOPIC.toLowerCase(), LEDGER_HEAD_ADVANCED_TOPIC.toLowerCase()];
|
|
2662
|
+
function keptMirrorLog(raw) {
|
|
2663
|
+
if (!raw || typeof raw !== "object") return null;
|
|
2664
|
+
const log = raw;
|
|
2665
|
+
if (!Array.isArray(log.topics) || typeof log.data !== "string") return null;
|
|
2666
|
+
const topics = log.topics.map((topic) => String(topic));
|
|
2667
|
+
if (!KEPT_TOPICS.includes((topics[0] ?? "").toLowerCase())) return null;
|
|
2668
|
+
return {
|
|
2669
|
+
address: log.address,
|
|
2670
|
+
data: log.data,
|
|
2671
|
+
index: log.index,
|
|
2672
|
+
topics,
|
|
2673
|
+
block_number: log.block_number,
|
|
2674
|
+
transaction_hash: log.transaction_hash,
|
|
2675
|
+
timestamp: log.timestamp
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2561
2678
|
function createMirrorNodeRecordChainReader(options) {
|
|
2562
2679
|
const chainId = options.chainId ?? 296;
|
|
2563
2680
|
const base = (options.mirrorBaseUrl ?? MIRROR_NODE_BY_CHAIN[chainId] ?? "").replace(/\/+$/, "");
|
|
@@ -2569,22 +2686,28 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2569
2686
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
2570
2687
|
const iface = new import_ethers12.ethers.Interface(RECORD_LANE_ABI_V38);
|
|
2571
2688
|
async function request(path, init) {
|
|
2572
|
-
const url =
|
|
2689
|
+
const url = `${base}${path}`;
|
|
2573
2690
|
let lastError = null;
|
|
2574
2691
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
2575
2692
|
const controller = new AbortController();
|
|
2576
2693
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
2577
2694
|
try {
|
|
2578
|
-
const response = await fetchImpl(url, { ...init, signal: controller.signal });
|
|
2695
|
+
const response = await fetchImpl(url, { ...init, redirect: "manual", signal: controller.signal });
|
|
2696
|
+
if (isMirrorRedirect(response)) {
|
|
2697
|
+
await response.body?.cancel?.().catch(() => void 0);
|
|
2698
|
+
throw mirrorRefusal.redirect(path);
|
|
2699
|
+
}
|
|
2579
2700
|
if (response.status === 429 || response.status >= 500) {
|
|
2701
|
+
await response.body?.cancel?.().catch(() => void 0);
|
|
2580
2702
|
lastError = new Error(`mirror node ${response.status} for ${path}`);
|
|
2581
2703
|
} else if (!response.ok) {
|
|
2582
|
-
const body = await response
|
|
2704
|
+
const body = await readMirrorText(response, MIRROR_ANSWER_MAX_BYTES, path).catch(() => "");
|
|
2583
2705
|
throw new Error(`mirror node ${response.status} for ${path}${body ? `: ${body.slice(0, 200)}` : ""}`);
|
|
2584
2706
|
} else {
|
|
2585
|
-
return await response
|
|
2707
|
+
return await readMirrorJson(response, MIRROR_ANSWER_MAX_BYTES, path);
|
|
2586
2708
|
}
|
|
2587
2709
|
} catch (error) {
|
|
2710
|
+
if (mirrorRefusalOf(error)) throw error;
|
|
2588
2711
|
if (error.name === "AbortError") lastError = new Error(`mirror node request timed out after ${timeoutMs}ms (${path})`);
|
|
2589
2712
|
else if (/^mirror node \d{3} for/.test(error.message) && !/^mirror node (429|5\d\d)/.test(error.message)) throw error;
|
|
2590
2713
|
else lastError = error;
|
|
@@ -2626,18 +2749,43 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2626
2749
|
const params = new URLSearchParams();
|
|
2627
2750
|
params.set("order", "asc");
|
|
2628
2751
|
params.set("limit", String(pageSize));
|
|
2629
|
-
let next =
|
|
2752
|
+
let next = `${contractLogPath(contractAddress)}?${params.toString()}`;
|
|
2630
2753
|
const out = [];
|
|
2631
2754
|
let pages = 0;
|
|
2755
|
+
let size = pageSize;
|
|
2632
2756
|
while (next) {
|
|
2633
|
-
const page = await
|
|
2634
|
-
|
|
2635
|
-
|
|
2757
|
+
const { page, asked } = await readLogPage(next, size);
|
|
2758
|
+
size = Math.min(pageSize, asked * 2);
|
|
2759
|
+
const logs = Array.isArray(page.logs) ? page.logs : [...page.logs ?? []];
|
|
2760
|
+
if (logs.length > asked) throw mirrorRefusal.tooManyLogs(asked, next);
|
|
2761
|
+
for (const raw of logs) {
|
|
2762
|
+
const log = keptMirrorLog(raw);
|
|
2763
|
+
if (log) out.push(log);
|
|
2764
|
+
}
|
|
2765
|
+
const link = page.links?.next;
|
|
2766
|
+
if (link === null || link === void 0 || link === "") {
|
|
2767
|
+
next = null;
|
|
2768
|
+
} else {
|
|
2769
|
+
const path = nextLogPath(link, { base, contract: contractAddress });
|
|
2770
|
+
if (!path) throw mirrorRefusal.nextPage();
|
|
2771
|
+
next = withLogPageLimit(path, size);
|
|
2772
|
+
}
|
|
2636
2773
|
pages += 1;
|
|
2637
2774
|
if (pages > 1e4) throw new Error("mirror node log scan exceeded 10,000 pages");
|
|
2638
2775
|
}
|
|
2639
2776
|
return out;
|
|
2640
2777
|
}
|
|
2778
|
+
async function readLogPage(path, start) {
|
|
2779
|
+
let asked = start;
|
|
2780
|
+
for (; ; ) {
|
|
2781
|
+
try {
|
|
2782
|
+
return { page: await request(withLogPageLimit(path, asked)), asked };
|
|
2783
|
+
} catch (error) {
|
|
2784
|
+
if (mirrorRefusalOf(error) !== "too-large" || asked <= 1) throw error;
|
|
2785
|
+
asked = Math.max(1, Math.floor(asked / 2));
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2641
2789
|
async function scanLogs(topics, fromBlock, toBlock) {
|
|
2642
2790
|
const out = [];
|
|
2643
2791
|
for (const log of await readAllLogs()) {
|
|
@@ -2654,8 +2802,11 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2654
2802
|
const timer = setTimeout(() => controller.abort(), ms);
|
|
2655
2803
|
try {
|
|
2656
2804
|
const response = await fetchImpl(`${base}${path}`, { headers: { accept: "application/json" }, redirect: "error", signal: controller.signal });
|
|
2805
|
+
if (isMirrorRedirect(response)) throw mirrorRefusal.redirect(path);
|
|
2657
2806
|
if (!response.ok) throw new Error(`mirror node ${response.status} for a record's writes`);
|
|
2658
|
-
|
|
2807
|
+
const page = await readMirrorJson(response, MIRROR_ANSWER_MAX_BYTES, path);
|
|
2808
|
+
if (Array.isArray(page.logs) && page.logs.length > LEDGER_WRITE_SEARCH_PAGE_LIMIT) throw mirrorRefusal.tooManyLogs(LEDGER_WRITE_SEARCH_PAGE_LIMIT, path);
|
|
2809
|
+
return page;
|
|
2659
2810
|
} catch (error) {
|
|
2660
2811
|
if (controller.signal.aborted) return "timeout";
|
|
2661
2812
|
throw error;
|
|
@@ -2749,9 +2900,9 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2749
2900
|
requests += 1;
|
|
2750
2901
|
const page = await searchPage(path, left);
|
|
2751
2902
|
if (page === "timeout") return end("timeout");
|
|
2752
|
-
for (const log of Array.isArray(page
|
|
2753
|
-
const write = parseLedgerWriteLog(log, { topic0, recordKey: key });
|
|
2754
|
-
if (!write ||
|
|
2903
|
+
for (const log of Array.isArray(page?.logs) ? page.logs : []) {
|
|
2904
|
+
const write = parseLedgerWriteLog(log, { topic0, recordKey: key, contractAddress });
|
|
2905
|
+
if (!write || !CONSENSUS_TIMESTAMP.test(write.timestamp)) continue;
|
|
2755
2906
|
writes.push({
|
|
2756
2907
|
previousWord: write.previousWord,
|
|
2757
2908
|
newWord: write.newWord,
|
|
@@ -2765,7 +2916,9 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2765
2916
|
});
|
|
2766
2917
|
}
|
|
2767
2918
|
if (search.done(writes)) return end("done");
|
|
2768
|
-
|
|
2919
|
+
const link = page?.links?.next;
|
|
2920
|
+
path = nextLogPath(link, { base, contract: contractAddress });
|
|
2921
|
+
if (!path && link !== null && link !== void 0 && link !== "") throw mirrorRefusal.nextPage();
|
|
2769
2922
|
}
|
|
2770
2923
|
upper = lower;
|
|
2771
2924
|
}
|
|
@@ -3486,6 +3639,12 @@ var SEP5 = new Uint8Array([0]);
|
|
|
3486
3639
|
|
|
3487
3640
|
// src/report.ts
|
|
3488
3641
|
var REPORT_SCHEMA = "pacspace-check-report/v1";
|
|
3642
|
+
var SOURCE_REFUSAL_REASONS = {
|
|
3643
|
+
redirect: "its source answered with a redirect, which is not followed",
|
|
3644
|
+
"too-large": "its source gave an answer larger than this checker reads",
|
|
3645
|
+
"too-many-logs": "its source returned a longer page than was asked for",
|
|
3646
|
+
"next-page": "its source pointed somewhere else for the next page"
|
|
3647
|
+
};
|
|
3489
3648
|
var ENCRYPTED_OPENED_SENTENCE = "Each entry was opened on this machine and matches its sealed record hash.";
|
|
3490
3649
|
function refusedUnopenedSentence(k) {
|
|
3491
3650
|
return `${k} refused ${entryWord(k)} could not be opened with this record key. Their seals are checked.`;
|
|
@@ -3605,9 +3764,13 @@ function sealsVerdict(entries, v, queued = []) {
|
|
|
3605
3764
|
}
|
|
3606
3765
|
return { sentence: sealsPassedSentence(entries), passed: true };
|
|
3607
3766
|
}
|
|
3767
|
+
function refusedOf(source) {
|
|
3768
|
+
return !source.compared && source.reason === "unreachable" ? source.refused : void 0;
|
|
3769
|
+
}
|
|
3608
3770
|
function sourceSentence(source) {
|
|
3609
3771
|
if (!source.compared) {
|
|
3610
|
-
|
|
3772
|
+
if (source.reason === "offline") return "Not compared with the proof layer. The check ran on this file alone.";
|
|
3773
|
+
return source.refused ? `The proof layer was not read: ${SOURCE_REFUSAL_REASONS[source.refused]}. The check ran on this file alone.` : "The proof layer could not be reached. The check ran on this file alone.";
|
|
3611
3774
|
}
|
|
3612
3775
|
return source.matches ? "Compared with the proof layer for this record: it matches." : `Compared with the proof layer for this record: it does not match.${source.detail ? ` ${source.detail}` : ""}`;
|
|
3613
3776
|
}
|
|
@@ -3816,7 +3979,7 @@ function renderReport(report, options = {}) {
|
|
|
3816
3979
|
var WRITES_LOOKUP_MAX_REQUESTS = 40;
|
|
3817
3980
|
var WRITES_LOOKUP_DEFAULT_BUDGET_MS = 1e4;
|
|
3818
3981
|
var HEX643 = /^0x[0-9a-f]{64}$/;
|
|
3819
|
-
var
|
|
3982
|
+
var HEX402 = /^0x[0-9a-f]{40}$/;
|
|
3820
3983
|
var ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
3821
3984
|
var WRITE_EXPLORERS = Object.freeze({
|
|
3822
3985
|
295: "https://hashscan.io/mainnet/transaction/",
|
|
@@ -3866,7 +4029,7 @@ async function within(p, ms) {
|
|
|
3866
4029
|
async function lookUpWrites(input) {
|
|
3867
4030
|
try {
|
|
3868
4031
|
const contractAddress = String(input.contractAddress ?? "").toLowerCase();
|
|
3869
|
-
if (!
|
|
4032
|
+
if (!HEX402.test(contractAddress)) return { read: false, reason: "unreachable" };
|
|
3870
4033
|
if (input.wanted.length === 0) return { read: true, entries: [], notFound: [] };
|
|
3871
4034
|
const done = (writes2) => input.wanted.every((entry) => hitsFor(entry, writes2, contractAddress).length > 0);
|
|
3872
4035
|
let writes;
|
|
@@ -3925,7 +4088,7 @@ async function lookUpWrites(input) {
|
|
|
3925
4088
|
|
|
3926
4089
|
// src/check.ts
|
|
3927
4090
|
var CHECKER_NAME = "@pacspace-io/check";
|
|
3928
|
-
var CHECKER_VERSION = true ? "0.5.
|
|
4091
|
+
var CHECKER_VERSION = true ? "0.5.5" : "0.0.0-dev";
|
|
3929
4092
|
var HISTORY_SCHEMAS = [
|
|
3930
4093
|
RECORD_HISTORY_BUNDLE_SCHEMA_V1,
|
|
3931
4094
|
RECORD_HISTORY_BUNDLE_SCHEMA_V2,
|
|
@@ -4247,7 +4410,7 @@ async function checkBundle(file, options) {
|
|
|
4247
4410
|
};
|
|
4248
4411
|
} catch (error) {
|
|
4249
4412
|
if (error instanceof HistoryFileError) throw error;
|
|
4250
|
-
source =
|
|
4413
|
+
source = notReached(error);
|
|
4251
4414
|
}
|
|
4252
4415
|
const report = buildReport({
|
|
4253
4416
|
...base,
|
|
@@ -4370,7 +4533,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
|
|
|
4370
4533
|
};
|
|
4371
4534
|
} catch (error) {
|
|
4372
4535
|
if (error instanceof HistoryFileError) throw error;
|
|
4373
|
-
source =
|
|
4536
|
+
source = notReached(error);
|
|
4374
4537
|
}
|
|
4375
4538
|
const report = buildReport({
|
|
4376
4539
|
...base,
|
|
@@ -4403,18 +4566,30 @@ function ledgerAgrees(form, material) {
|
|
|
4403
4566
|
}
|
|
4404
4567
|
function answeringReader(reader) {
|
|
4405
4568
|
const answered = /* @__PURE__ */ new Set();
|
|
4569
|
+
let refused;
|
|
4406
4570
|
return {
|
|
4407
4571
|
answered,
|
|
4572
|
+
// The first refusal of the source's answer, when a root was not read for that and not for want of an answer.
|
|
4573
|
+
refused: () => refused,
|
|
4408
4574
|
reader: {
|
|
4409
4575
|
...reader,
|
|
4410
4576
|
getBatchRoot: async (batchId) => {
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4577
|
+
try {
|
|
4578
|
+
const root = await reader.getBatchRoot(batchId);
|
|
4579
|
+
answered.add(String(batchId));
|
|
4580
|
+
return root;
|
|
4581
|
+
} catch (error) {
|
|
4582
|
+
refused ??= mirrorRefusalOf(error) ?? void 0;
|
|
4583
|
+
throw error;
|
|
4584
|
+
}
|
|
4414
4585
|
}
|
|
4415
4586
|
}
|
|
4416
4587
|
};
|
|
4417
4588
|
}
|
|
4589
|
+
function notReached(error) {
|
|
4590
|
+
const refused = mirrorRefusalOf(error);
|
|
4591
|
+
return { compared: false, reason: "unreachable", detail: error.message, ...refused ? { refused } : {} };
|
|
4592
|
+
}
|
|
4418
4593
|
var pointerToken = (name) => name.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
4419
4594
|
async function checkDisclosure(form, disclosure, reader, onRevealed) {
|
|
4420
4595
|
const sub = disclosureFormOfV1(form, disclosure);
|
|
@@ -4495,7 +4670,7 @@ async function checkSeals(formName, form, disclosure, options) {
|
|
|
4495
4670
|
};
|
|
4496
4671
|
} catch (error) {
|
|
4497
4672
|
if (error instanceof HistoryFileError) throw error;
|
|
4498
|
-
source =
|
|
4673
|
+
source = notReached(error);
|
|
4499
4674
|
reader = null;
|
|
4500
4675
|
}
|
|
4501
4676
|
let disclosureOutcome = null;
|
|
@@ -4862,6 +5037,7 @@ var releaseWords = {
|
|
|
4862
5037
|
notProductionRecord: "The ledger record here is not the production release record.",
|
|
4863
5038
|
inProgress: (served, latest) => `The host serves ${served}; the release record's latest entry is ${latest}. A release may be in progress; run it again in a few minutes.`,
|
|
4864
5039
|
unreachable: (origin) => `Couldn't reach ${origin} or the ledger. Nothing was checked.`,
|
|
5040
|
+
refused: (code) => `The ledger was not read: ${SOURCE_REFUSAL_REASONS[code]}. Nothing was checked.`,
|
|
4865
5041
|
total: (n) => n === 1 ? "1 difference from the release record." : `${n} differences from the release record.`
|
|
4866
5042
|
};
|
|
4867
5043
|
var ReleaseUsageError = class extends Error {
|
|
@@ -4995,11 +5171,12 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
|
|
|
4995
5171
|
files: 0,
|
|
4996
5172
|
differences: []
|
|
4997
5173
|
};
|
|
4998
|
-
const unreachable = () => ({
|
|
5174
|
+
const unreachable = (refused) => ({
|
|
4999
5175
|
...base,
|
|
5000
5176
|
outcome: "unreachable",
|
|
5001
|
-
sentences: [releaseWords.unreachable(origin)],
|
|
5002
|
-
exitCode: 2
|
|
5177
|
+
sentences: [refused ? releaseWords.refused(refused) : releaseWords.unreachable(origin)],
|
|
5178
|
+
exitCode: 2,
|
|
5179
|
+
...refused ? { refused } : {}
|
|
5003
5180
|
});
|
|
5004
5181
|
const differs = (differences, extra = {}) => ({
|
|
5005
5182
|
...base,
|
|
@@ -5052,7 +5229,7 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
|
|
|
5052
5229
|
throw error;
|
|
5053
5230
|
}
|
|
5054
5231
|
if (report.exitCode === 3 || report.source.compared === false && report.source.reason === "unreachable") {
|
|
5055
|
-
return unreachable();
|
|
5232
|
+
return unreachable(refusedOf(report.source));
|
|
5056
5233
|
}
|
|
5057
5234
|
if (!report.passed) return differs([{ kind: "differs", path: historyPath }]);
|
|
5058
5235
|
const latest = report.record.entries;
|
package/dist/index.js
CHANGED
|
@@ -2110,20 +2110,121 @@ var MIRROR_NODE_BY_CHAIN = Object.freeze({
|
|
|
2110
2110
|
|
|
2111
2111
|
// ../shared/src/records/ledger-write-search-v1.ts
|
|
2112
2112
|
var LEDGER_WRITE_SEARCH_WINDOW_LIMIT_SECONDS = 7 * 24 * 60 * 60;
|
|
2113
|
+
var LEDGER_WRITE_SEARCH_PAGE_LIMIT = 100;
|
|
2114
|
+
var MIRROR_ANSWER_MAX_BYTES = 1048576;
|
|
2115
|
+
var HEX40 = /^0x[0-9a-f]{40}$/;
|
|
2113
2116
|
var HEX642 = /^0x[0-9a-f]{64}$/;
|
|
2114
2117
|
var HEX_DATA = /^0x[0-9a-f]*$/;
|
|
2115
2118
|
var TIMESTAMP = /^\d+(\.\d+)?$/;
|
|
2116
|
-
var
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2119
|
+
var REFUSAL_CODES = ["redirect", "too-large", "too-many-logs", "next-page"];
|
|
2120
|
+
var MirrorAnswerRefused = class extends Error {
|
|
2121
|
+
constructor(code, message) {
|
|
2122
|
+
super(message);
|
|
2123
|
+
this.name = "MirrorAnswerRefused";
|
|
2124
|
+
this.code = code;
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
function mirrorRefusalOf(error) {
|
|
2128
|
+
if (!error || typeof error !== "object") return null;
|
|
2129
|
+
const { name, code } = error;
|
|
2130
|
+
return name === "MirrorAnswerRefused" && typeof code === "string" && REFUSAL_CODES.includes(code) ? code : null;
|
|
2131
|
+
}
|
|
2132
|
+
function pathLabel(path) {
|
|
2133
|
+
return path ? ` (${path.split("?")[0]})` : "";
|
|
2134
|
+
}
|
|
2135
|
+
var mirrorRefusal = {
|
|
2136
|
+
redirect: (path) => new MirrorAnswerRefused("redirect", `mirror node answered with a redirect, which is not followed${pathLabel(path)}`),
|
|
2137
|
+
tooLarge: (maxBytes, path) => new MirrorAnswerRefused("too-large", `mirror node answer is larger than ${maxBytes} bytes${pathLabel(path)}`),
|
|
2138
|
+
tooManyLogs: (asked, path) => new MirrorAnswerRefused("too-many-logs", `mirror node returned more logs than the ${asked} asked for${pathLabel(path)}`),
|
|
2139
|
+
nextPage: () => new MirrorAnswerRefused("next-page", "mirror node gave a next page that is not this contract's log")
|
|
2140
|
+
};
|
|
2141
|
+
function isMirrorRedirect(response) {
|
|
2142
|
+
return response.redirected === true || response.type === "opaqueredirect" || response.status >= 300 && response.status < 400;
|
|
2143
|
+
}
|
|
2144
|
+
async function readMirrorText(response, maxBytes = MIRROR_ANSWER_MAX_BYTES, path) {
|
|
2145
|
+
const declared = Number(response.headers?.get?.("content-length") ?? Number.NaN);
|
|
2146
|
+
const body = response.body;
|
|
2147
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
2148
|
+
await body?.cancel?.().catch(() => void 0);
|
|
2149
|
+
throw mirrorRefusal.tooLarge(maxBytes, path);
|
|
2150
|
+
}
|
|
2151
|
+
if (body && typeof body.getReader === "function") {
|
|
2152
|
+
const reader = body.getReader();
|
|
2153
|
+
const decoder = new TextDecoder();
|
|
2154
|
+
let text2 = "";
|
|
2155
|
+
let read = 0;
|
|
2156
|
+
for (; ; ) {
|
|
2157
|
+
const { done, value } = await reader.read();
|
|
2158
|
+
if (done) break;
|
|
2159
|
+
read += value.byteLength;
|
|
2160
|
+
if (read > maxBytes) {
|
|
2161
|
+
await reader.cancel().catch(() => void 0);
|
|
2162
|
+
throw mirrorRefusal.tooLarge(maxBytes, path);
|
|
2163
|
+
}
|
|
2164
|
+
text2 += decoder.decode(value, { stream: true });
|
|
2165
|
+
}
|
|
2166
|
+
return text2 + decoder.decode();
|
|
2167
|
+
}
|
|
2168
|
+
const text = await response.text();
|
|
2169
|
+
if (new TextEncoder().encode(text).byteLength > maxBytes) throw mirrorRefusal.tooLarge(maxBytes, path);
|
|
2170
|
+
return text;
|
|
2120
2171
|
}
|
|
2121
|
-
function
|
|
2122
|
-
return
|
|
2172
|
+
async function readMirrorJson(response, maxBytes = MIRROR_ANSWER_MAX_BYTES, path) {
|
|
2173
|
+
return JSON.parse(await readMirrorText(response, maxBytes, path));
|
|
2174
|
+
}
|
|
2175
|
+
function contractLogPath(contractAddress) {
|
|
2176
|
+
return `/api/v1/contracts/${contractAddress}/results/logs`;
|
|
2177
|
+
}
|
|
2178
|
+
function ledgerWriteSearchPath(input) {
|
|
2179
|
+
const query = `topic0=${input.topic0}&topic1=${input.recordKey}×tamp=gte:${input.lower}×tamp=lt:${input.upper}&order=desc&limit=${LEDGER_WRITE_SEARCH_PAGE_LIMIT}`;
|
|
2180
|
+
return `${contractLogPath(input.contractAddress)}?${query}`;
|
|
2181
|
+
}
|
|
2182
|
+
function nextLogPath(next, source) {
|
|
2183
|
+
if (typeof next !== "string" || next === "") return null;
|
|
2184
|
+
const contract = source.contract.toLowerCase();
|
|
2185
|
+
if (!HEX40.test(contract)) return null;
|
|
2186
|
+
if (!/^[\x21-\x5b\x5d-\x7e]+$/.test(next)) return null;
|
|
2187
|
+
if (next.startsWith("//")) return null;
|
|
2188
|
+
let base;
|
|
2189
|
+
let url;
|
|
2190
|
+
try {
|
|
2191
|
+
base = new URL(source.base);
|
|
2192
|
+
url = new URL(next, `${base.origin}/`);
|
|
2193
|
+
} catch {
|
|
2194
|
+
return null;
|
|
2195
|
+
}
|
|
2196
|
+
if (base.protocol !== "https:" && base.protocol !== "http:") return null;
|
|
2197
|
+
if (url.origin !== base.origin || url.username !== "" || url.password !== "" || url.hash !== "" || next.includes("#")) return null;
|
|
2198
|
+
const written = (next.startsWith("/") ? next : next.slice(next.indexOf("/", next.indexOf("//") + 2))).split("?")[0];
|
|
2199
|
+
if (/(^|\/)\.{1,2}(\/|$)/.test(written) || /%2e/i.test(written) || written !== url.pathname) return null;
|
|
2200
|
+
if (url.search.length < 2) return null;
|
|
2201
|
+
const logs = contractLogPath(contract);
|
|
2202
|
+
const prefix = base.pathname.replace(/\/+$/, "");
|
|
2203
|
+
const path = url.pathname.toLowerCase();
|
|
2204
|
+
if (path !== logs && !(prefix !== "" && url.pathname.startsWith(`${prefix}/`) && url.pathname.slice(prefix.length).toLowerCase() === logs)) return null;
|
|
2205
|
+
return `${logs}${url.search}`;
|
|
2206
|
+
}
|
|
2207
|
+
function withLogPageLimit(path, limit) {
|
|
2208
|
+
const at = path.indexOf("?");
|
|
2209
|
+
const before = at === -1 ? path : path.slice(0, at);
|
|
2210
|
+
const parts = at === -1 ? [] : path.slice(at + 1).split("&").filter((part) => part !== "");
|
|
2211
|
+
let placed = false;
|
|
2212
|
+
const out = [];
|
|
2213
|
+
for (const part of parts) {
|
|
2214
|
+
if (!part.startsWith("limit=")) out.push(part);
|
|
2215
|
+
else if (!placed) {
|
|
2216
|
+
out.push(`limit=${limit}`);
|
|
2217
|
+
placed = true;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
if (!placed) out.push(`limit=${limit}`);
|
|
2221
|
+
return `${before}?${out.join("&")}`;
|
|
2123
2222
|
}
|
|
2124
2223
|
function parseLedgerWriteLog(log, expected) {
|
|
2125
2224
|
if (!log || typeof log !== "object") return null;
|
|
2126
2225
|
const raw = log;
|
|
2226
|
+
const address = typeof raw.address === "string" ? raw.address.toLowerCase() : "";
|
|
2227
|
+
if (!HEX40.test(address) || address !== String(expected.contractAddress).toLowerCase()) return null;
|
|
2127
2228
|
const topics = Array.isArray(raw.topics) ? raw.topics.map((topic) => String(topic).toLowerCase()) : [];
|
|
2128
2229
|
if (topics[0] !== expected.topic0 || topics[1] !== expected.recordKey) return null;
|
|
2129
2230
|
const data = typeof raw.data === "string" ? raw.data.toLowerCase() : "";
|
|
@@ -2137,7 +2238,6 @@ function parseLedgerWriteLog(log, expected) {
|
|
|
2137
2238
|
const [seconds, fraction = ""] = timestamp.split(".");
|
|
2138
2239
|
const ms = Number(seconds) * 1e3 + Number(fraction.slice(0, 3).padEnd(3, "0"));
|
|
2139
2240
|
if (!Number.isFinite(ms) || Math.abs(ms) > 864e13) return null;
|
|
2140
|
-
const address = typeof raw.address === "string" ? raw.address.toLowerCase() : null;
|
|
2141
2241
|
return {
|
|
2142
2242
|
transactionHash,
|
|
2143
2243
|
timestamp,
|
|
@@ -2558,6 +2658,23 @@ function committedAtOf(timestamp) {
|
|
|
2558
2658
|
const [seconds, fraction] = timestamp.split(".");
|
|
2559
2659
|
return new Date(Number(seconds) * 1e3 + Number(fraction.slice(0, 3))).toISOString();
|
|
2560
2660
|
}
|
|
2661
|
+
var KEPT_TOPICS = [RECORD_WRITTEN_TOPIC.toLowerCase(), LEDGER_HEAD_ADVANCED_TOPIC.toLowerCase()];
|
|
2662
|
+
function keptMirrorLog(raw) {
|
|
2663
|
+
if (!raw || typeof raw !== "object") return null;
|
|
2664
|
+
const log = raw;
|
|
2665
|
+
if (!Array.isArray(log.topics) || typeof log.data !== "string") return null;
|
|
2666
|
+
const topics = log.topics.map((topic) => String(topic));
|
|
2667
|
+
if (!KEPT_TOPICS.includes((topics[0] ?? "").toLowerCase())) return null;
|
|
2668
|
+
return {
|
|
2669
|
+
address: log.address,
|
|
2670
|
+
data: log.data,
|
|
2671
|
+
index: log.index,
|
|
2672
|
+
topics,
|
|
2673
|
+
block_number: log.block_number,
|
|
2674
|
+
transaction_hash: log.transaction_hash,
|
|
2675
|
+
timestamp: log.timestamp
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2561
2678
|
function createMirrorNodeRecordChainReader(options) {
|
|
2562
2679
|
const chainId = options.chainId ?? 296;
|
|
2563
2680
|
const base = (options.mirrorBaseUrl ?? MIRROR_NODE_BY_CHAIN[chainId] ?? "").replace(/\/+$/, "");
|
|
@@ -2569,22 +2686,28 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2569
2686
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
2570
2687
|
const iface = new import_ethers12.ethers.Interface(RECORD_LANE_ABI_V38);
|
|
2571
2688
|
async function request(path, init) {
|
|
2572
|
-
const url =
|
|
2689
|
+
const url = `${base}${path}`;
|
|
2573
2690
|
let lastError = null;
|
|
2574
2691
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
2575
2692
|
const controller = new AbortController();
|
|
2576
2693
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
2577
2694
|
try {
|
|
2578
|
-
const response = await fetchImpl(url, { ...init, signal: controller.signal });
|
|
2695
|
+
const response = await fetchImpl(url, { ...init, redirect: "manual", signal: controller.signal });
|
|
2696
|
+
if (isMirrorRedirect(response)) {
|
|
2697
|
+
await response.body?.cancel?.().catch(() => void 0);
|
|
2698
|
+
throw mirrorRefusal.redirect(path);
|
|
2699
|
+
}
|
|
2579
2700
|
if (response.status === 429 || response.status >= 500) {
|
|
2701
|
+
await response.body?.cancel?.().catch(() => void 0);
|
|
2580
2702
|
lastError = new Error(`mirror node ${response.status} for ${path}`);
|
|
2581
2703
|
} else if (!response.ok) {
|
|
2582
|
-
const body = await response
|
|
2704
|
+
const body = await readMirrorText(response, MIRROR_ANSWER_MAX_BYTES, path).catch(() => "");
|
|
2583
2705
|
throw new Error(`mirror node ${response.status} for ${path}${body ? `: ${body.slice(0, 200)}` : ""}`);
|
|
2584
2706
|
} else {
|
|
2585
|
-
return await response
|
|
2707
|
+
return await readMirrorJson(response, MIRROR_ANSWER_MAX_BYTES, path);
|
|
2586
2708
|
}
|
|
2587
2709
|
} catch (error) {
|
|
2710
|
+
if (mirrorRefusalOf(error)) throw error;
|
|
2588
2711
|
if (error.name === "AbortError") lastError = new Error(`mirror node request timed out after ${timeoutMs}ms (${path})`);
|
|
2589
2712
|
else if (/^mirror node \d{3} for/.test(error.message) && !/^mirror node (429|5\d\d)/.test(error.message)) throw error;
|
|
2590
2713
|
else lastError = error;
|
|
@@ -2626,18 +2749,43 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2626
2749
|
const params = new URLSearchParams();
|
|
2627
2750
|
params.set("order", "asc");
|
|
2628
2751
|
params.set("limit", String(pageSize));
|
|
2629
|
-
let next =
|
|
2752
|
+
let next = `${contractLogPath(contractAddress)}?${params.toString()}`;
|
|
2630
2753
|
const out = [];
|
|
2631
2754
|
let pages = 0;
|
|
2755
|
+
let size = pageSize;
|
|
2632
2756
|
while (next) {
|
|
2633
|
-
const page = await
|
|
2634
|
-
|
|
2635
|
-
|
|
2757
|
+
const { page, asked } = await readLogPage(next, size);
|
|
2758
|
+
size = Math.min(pageSize, asked * 2);
|
|
2759
|
+
const logs = Array.isArray(page.logs) ? page.logs : [...page.logs ?? []];
|
|
2760
|
+
if (logs.length > asked) throw mirrorRefusal.tooManyLogs(asked, next);
|
|
2761
|
+
for (const raw of logs) {
|
|
2762
|
+
const log = keptMirrorLog(raw);
|
|
2763
|
+
if (log) out.push(log);
|
|
2764
|
+
}
|
|
2765
|
+
const link = page.links?.next;
|
|
2766
|
+
if (link === null || link === void 0 || link === "") {
|
|
2767
|
+
next = null;
|
|
2768
|
+
} else {
|
|
2769
|
+
const path = nextLogPath(link, { base, contract: contractAddress });
|
|
2770
|
+
if (!path) throw mirrorRefusal.nextPage();
|
|
2771
|
+
next = withLogPageLimit(path, size);
|
|
2772
|
+
}
|
|
2636
2773
|
pages += 1;
|
|
2637
2774
|
if (pages > 1e4) throw new Error("mirror node log scan exceeded 10,000 pages");
|
|
2638
2775
|
}
|
|
2639
2776
|
return out;
|
|
2640
2777
|
}
|
|
2778
|
+
async function readLogPage(path, start) {
|
|
2779
|
+
let asked = start;
|
|
2780
|
+
for (; ; ) {
|
|
2781
|
+
try {
|
|
2782
|
+
return { page: await request(withLogPageLimit(path, asked)), asked };
|
|
2783
|
+
} catch (error) {
|
|
2784
|
+
if (mirrorRefusalOf(error) !== "too-large" || asked <= 1) throw error;
|
|
2785
|
+
asked = Math.max(1, Math.floor(asked / 2));
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2641
2789
|
async function scanLogs(topics, fromBlock, toBlock) {
|
|
2642
2790
|
const out = [];
|
|
2643
2791
|
for (const log of await readAllLogs()) {
|
|
@@ -2654,8 +2802,11 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2654
2802
|
const timer = setTimeout(() => controller.abort(), ms);
|
|
2655
2803
|
try {
|
|
2656
2804
|
const response = await fetchImpl(`${base}${path}`, { headers: { accept: "application/json" }, redirect: "error", signal: controller.signal });
|
|
2805
|
+
if (isMirrorRedirect(response)) throw mirrorRefusal.redirect(path);
|
|
2657
2806
|
if (!response.ok) throw new Error(`mirror node ${response.status} for a record's writes`);
|
|
2658
|
-
|
|
2807
|
+
const page = await readMirrorJson(response, MIRROR_ANSWER_MAX_BYTES, path);
|
|
2808
|
+
if (Array.isArray(page.logs) && page.logs.length > LEDGER_WRITE_SEARCH_PAGE_LIMIT) throw mirrorRefusal.tooManyLogs(LEDGER_WRITE_SEARCH_PAGE_LIMIT, path);
|
|
2809
|
+
return page;
|
|
2659
2810
|
} catch (error) {
|
|
2660
2811
|
if (controller.signal.aborted) return "timeout";
|
|
2661
2812
|
throw error;
|
|
@@ -2749,9 +2900,9 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2749
2900
|
requests += 1;
|
|
2750
2901
|
const page = await searchPage(path, left);
|
|
2751
2902
|
if (page === "timeout") return end("timeout");
|
|
2752
|
-
for (const log of Array.isArray(page
|
|
2753
|
-
const write = parseLedgerWriteLog(log, { topic0, recordKey: key });
|
|
2754
|
-
if (!write ||
|
|
2903
|
+
for (const log of Array.isArray(page?.logs) ? page.logs : []) {
|
|
2904
|
+
const write = parseLedgerWriteLog(log, { topic0, recordKey: key, contractAddress });
|
|
2905
|
+
if (!write || !CONSENSUS_TIMESTAMP.test(write.timestamp)) continue;
|
|
2755
2906
|
writes.push({
|
|
2756
2907
|
previousWord: write.previousWord,
|
|
2757
2908
|
newWord: write.newWord,
|
|
@@ -2765,7 +2916,9 @@ function createMirrorNodeRecordChainReader(options) {
|
|
|
2765
2916
|
});
|
|
2766
2917
|
}
|
|
2767
2918
|
if (search.done(writes)) return end("done");
|
|
2768
|
-
|
|
2919
|
+
const link = page?.links?.next;
|
|
2920
|
+
path = nextLogPath(link, { base, contract: contractAddress });
|
|
2921
|
+
if (!path && link !== null && link !== void 0 && link !== "") throw mirrorRefusal.nextPage();
|
|
2769
2922
|
}
|
|
2770
2923
|
upper = lower;
|
|
2771
2924
|
}
|
|
@@ -3339,6 +3492,12 @@ var SEP5 = new Uint8Array([0]);
|
|
|
3339
3492
|
|
|
3340
3493
|
// src/report.ts
|
|
3341
3494
|
var REPORT_SCHEMA = "pacspace-check-report/v1";
|
|
3495
|
+
var SOURCE_REFUSAL_REASONS = {
|
|
3496
|
+
redirect: "its source answered with a redirect, which is not followed",
|
|
3497
|
+
"too-large": "its source gave an answer larger than this checker reads",
|
|
3498
|
+
"too-many-logs": "its source returned a longer page than was asked for",
|
|
3499
|
+
"next-page": "its source pointed somewhere else for the next page"
|
|
3500
|
+
};
|
|
3342
3501
|
var ENCRYPTED_OPENED_SENTENCE = "Each entry was opened on this machine and matches its sealed record hash.";
|
|
3343
3502
|
function refusedUnopenedSentence(k) {
|
|
3344
3503
|
return `${k} refused ${entryWord(k)} could not be opened with this record key. Their seals are checked.`;
|
|
@@ -3457,9 +3616,13 @@ function sealsVerdict(entries, v, queued = []) {
|
|
|
3457
3616
|
}
|
|
3458
3617
|
return { sentence: sealsPassedSentence(entries), passed: true };
|
|
3459
3618
|
}
|
|
3619
|
+
function refusedOf(source) {
|
|
3620
|
+
return !source.compared && source.reason === "unreachable" ? source.refused : void 0;
|
|
3621
|
+
}
|
|
3460
3622
|
function sourceSentence(source) {
|
|
3461
3623
|
if (!source.compared) {
|
|
3462
|
-
|
|
3624
|
+
if (source.reason === "offline") return "Not compared with the proof layer. The check ran on this file alone.";
|
|
3625
|
+
return source.refused ? `The proof layer was not read: ${SOURCE_REFUSAL_REASONS[source.refused]}. The check ran on this file alone.` : "The proof layer could not be reached. The check ran on this file alone.";
|
|
3463
3626
|
}
|
|
3464
3627
|
return source.matches ? "Compared with the proof layer for this record: it matches." : `Compared with the proof layer for this record: it does not match.${source.detail ? ` ${source.detail}` : ""}`;
|
|
3465
3628
|
}
|
|
@@ -3668,7 +3831,7 @@ function renderReport(report, options = {}) {
|
|
|
3668
3831
|
var WRITES_LOOKUP_MAX_REQUESTS = 40;
|
|
3669
3832
|
var WRITES_LOOKUP_DEFAULT_BUDGET_MS = 1e4;
|
|
3670
3833
|
var HEX643 = /^0x[0-9a-f]{64}$/;
|
|
3671
|
-
var
|
|
3834
|
+
var HEX402 = /^0x[0-9a-f]{40}$/;
|
|
3672
3835
|
var ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
3673
3836
|
var WRITE_EXPLORERS = Object.freeze({
|
|
3674
3837
|
295: "https://hashscan.io/mainnet/transaction/",
|
|
@@ -3718,7 +3881,7 @@ async function within(p, ms) {
|
|
|
3718
3881
|
async function lookUpWrites(input) {
|
|
3719
3882
|
try {
|
|
3720
3883
|
const contractAddress = String(input.contractAddress ?? "").toLowerCase();
|
|
3721
|
-
if (!
|
|
3884
|
+
if (!HEX402.test(contractAddress)) return { read: false, reason: "unreachable" };
|
|
3722
3885
|
if (input.wanted.length === 0) return { read: true, entries: [], notFound: [] };
|
|
3723
3886
|
const done = (writes2) => input.wanted.every((entry) => hitsFor(entry, writes2, contractAddress).length > 0);
|
|
3724
3887
|
let writes;
|
|
@@ -3777,7 +3940,7 @@ async function lookUpWrites(input) {
|
|
|
3777
3940
|
|
|
3778
3941
|
// src/check.ts
|
|
3779
3942
|
var CHECKER_NAME = "@pacspace-io/check";
|
|
3780
|
-
var CHECKER_VERSION = true ? "0.5.
|
|
3943
|
+
var CHECKER_VERSION = true ? "0.5.5" : "0.0.0-dev";
|
|
3781
3944
|
var HISTORY_SCHEMAS = [
|
|
3782
3945
|
RECORD_HISTORY_BUNDLE_SCHEMA_V1,
|
|
3783
3946
|
RECORD_HISTORY_BUNDLE_SCHEMA_V2,
|
|
@@ -4099,7 +4262,7 @@ async function checkBundle(file, options) {
|
|
|
4099
4262
|
};
|
|
4100
4263
|
} catch (error) {
|
|
4101
4264
|
if (error instanceof HistoryFileError) throw error;
|
|
4102
|
-
source =
|
|
4265
|
+
source = notReached(error);
|
|
4103
4266
|
}
|
|
4104
4267
|
const report = buildReport({
|
|
4105
4268
|
...base,
|
|
@@ -4222,7 +4385,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
|
|
|
4222
4385
|
};
|
|
4223
4386
|
} catch (error) {
|
|
4224
4387
|
if (error instanceof HistoryFileError) throw error;
|
|
4225
|
-
source =
|
|
4388
|
+
source = notReached(error);
|
|
4226
4389
|
}
|
|
4227
4390
|
const report = buildReport({
|
|
4228
4391
|
...base,
|
|
@@ -4255,18 +4418,30 @@ function ledgerAgrees(form, material) {
|
|
|
4255
4418
|
}
|
|
4256
4419
|
function answeringReader(reader) {
|
|
4257
4420
|
const answered = /* @__PURE__ */ new Set();
|
|
4421
|
+
let refused;
|
|
4258
4422
|
return {
|
|
4259
4423
|
answered,
|
|
4424
|
+
// The first refusal of the source's answer, when a root was not read for that and not for want of an answer.
|
|
4425
|
+
refused: () => refused,
|
|
4260
4426
|
reader: {
|
|
4261
4427
|
...reader,
|
|
4262
4428
|
getBatchRoot: async (batchId) => {
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4429
|
+
try {
|
|
4430
|
+
const root = await reader.getBatchRoot(batchId);
|
|
4431
|
+
answered.add(String(batchId));
|
|
4432
|
+
return root;
|
|
4433
|
+
} catch (error) {
|
|
4434
|
+
refused ??= mirrorRefusalOf(error) ?? void 0;
|
|
4435
|
+
throw error;
|
|
4436
|
+
}
|
|
4266
4437
|
}
|
|
4267
4438
|
}
|
|
4268
4439
|
};
|
|
4269
4440
|
}
|
|
4441
|
+
function notReached(error) {
|
|
4442
|
+
const refused = mirrorRefusalOf(error);
|
|
4443
|
+
return { compared: false, reason: "unreachable", detail: error.message, ...refused ? { refused } : {} };
|
|
4444
|
+
}
|
|
4270
4445
|
var pointerToken = (name) => name.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
4271
4446
|
async function checkDisclosure(form, disclosure, reader, onRevealed) {
|
|
4272
4447
|
const sub = disclosureFormOfV1(form, disclosure);
|
|
@@ -4347,7 +4522,7 @@ async function checkSeals(formName, form, disclosure, options) {
|
|
|
4347
4522
|
};
|
|
4348
4523
|
} catch (error) {
|
|
4349
4524
|
if (error instanceof HistoryFileError) throw error;
|
|
4350
|
-
source =
|
|
4525
|
+
source = notReached(error);
|
|
4351
4526
|
reader = null;
|
|
4352
4527
|
}
|
|
4353
4528
|
let disclosureOutcome = null;
|
|
@@ -4393,6 +4568,7 @@ var releaseWords = {
|
|
|
4393
4568
|
notProductionRecord: "The ledger record here is not the production release record.",
|
|
4394
4569
|
inProgress: (served, latest) => `The host serves ${served}; the release record's latest entry is ${latest}. A release may be in progress; run it again in a few minutes.`,
|
|
4395
4570
|
unreachable: (origin) => `Couldn't reach ${origin} or the ledger. Nothing was checked.`,
|
|
4571
|
+
refused: (code) => `The ledger was not read: ${SOURCE_REFUSAL_REASONS[code]}. Nothing was checked.`,
|
|
4396
4572
|
total: (n) => n === 1 ? "1 difference from the release record." : `${n} differences from the release record.`
|
|
4397
4573
|
};
|
|
4398
4574
|
var ReleaseUsageError = class extends Error {
|
|
@@ -4526,11 +4702,12 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
|
|
|
4526
4702
|
files: 0,
|
|
4527
4703
|
differences: []
|
|
4528
4704
|
};
|
|
4529
|
-
const unreachable = () => ({
|
|
4705
|
+
const unreachable = (refused) => ({
|
|
4530
4706
|
...base,
|
|
4531
4707
|
outcome: "unreachable",
|
|
4532
|
-
sentences: [releaseWords.unreachable(origin)],
|
|
4533
|
-
exitCode: 2
|
|
4708
|
+
sentences: [refused ? releaseWords.refused(refused) : releaseWords.unreachable(origin)],
|
|
4709
|
+
exitCode: 2,
|
|
4710
|
+
...refused ? { refused } : {}
|
|
4534
4711
|
});
|
|
4535
4712
|
const differs = (differences, extra = {}) => ({
|
|
4536
4713
|
...base,
|
|
@@ -4583,7 +4760,7 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
|
|
|
4583
4760
|
throw error;
|
|
4584
4761
|
}
|
|
4585
4762
|
if (report.exitCode === 3 || report.source.compared === false && report.source.reason === "unreachable") {
|
|
4586
|
-
return unreachable();
|
|
4763
|
+
return unreachable(refusedOf(report.source));
|
|
4587
4764
|
}
|
|
4588
4765
|
if (!report.passed) return differs([{ kind: "differs", path: historyPath }]);
|
|
4589
4766
|
const latest = report.record.entries;
|
package/dist/release.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MirrorRefusalCode } from '@pacspace/shared';
|
|
1
2
|
import { type CheckOptions } from './check';
|
|
2
3
|
export declare const RELEASES_SCHEMA = "pacspace-releases/v1";
|
|
3
4
|
export declare const RELEASE_MANIFEST_FORMAT = "pacspace-release-manifest/v2";
|
|
@@ -30,6 +31,7 @@ export declare const releaseWords: {
|
|
|
30
31
|
readonly notProductionRecord: "The ledger record here is not the production release record.";
|
|
31
32
|
readonly inProgress: (served: string, latest: string) => string;
|
|
32
33
|
readonly unreachable: (origin: string) => string;
|
|
34
|
+
readonly refused: (code: MirrorRefusalCode) => string;
|
|
33
35
|
readonly total: (n: number) => string;
|
|
34
36
|
};
|
|
35
37
|
export interface ReleaseManifestFile {
|
|
@@ -113,6 +115,8 @@ export interface ReleaseReport {
|
|
|
113
115
|
stagingRecord?: string;
|
|
114
116
|
/** 0 everything matches; 1 any difference, or any staging run; 2 the host or the ledger could not be reached. */
|
|
115
117
|
exitCode: 0 | 1 | 2;
|
|
118
|
+
/** Present only with `unreachable` when the ledger's source answered and its answer was refused: which rule it broke. */
|
|
119
|
+
refused?: MirrorRefusalCode;
|
|
116
120
|
}
|
|
117
121
|
/** One answer as the host sent it: no decoding, every header. */
|
|
118
122
|
export interface RawAnswer {
|
package/dist/report.d.ts
CHANGED
|
@@ -8,7 +8,13 @@
|
|
|
8
8
|
* from the forbidden lists. A seal history's sentences are the Shared
|
|
9
9
|
* Record page's, verbatim.
|
|
10
10
|
*/
|
|
11
|
+
import type { MirrorRefusalCode } from '@pacspace/shared';
|
|
11
12
|
export declare const REPORT_SCHEMA: "pacspace-check-report/v1";
|
|
13
|
+
/**
|
|
14
|
+
* Why a source's answer was not read, by the reader's refusal code. Each command puts the reason in its own
|
|
15
|
+
* sentence; nothing the source sent is printed.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SOURCE_REFUSAL_REASONS: Record<MirrorRefusalCode, string>;
|
|
12
18
|
export type SourceOutcome = {
|
|
13
19
|
compared: false;
|
|
14
20
|
reason: 'offline';
|
|
@@ -16,6 +22,8 @@ export type SourceOutcome = {
|
|
|
16
22
|
compared: false;
|
|
17
23
|
reason: 'unreachable';
|
|
18
24
|
detail: string;
|
|
25
|
+
/** Present only when the source answered and its answer was refused: which rule it broke. */
|
|
26
|
+
refused?: MirrorRefusalCode;
|
|
19
27
|
} | {
|
|
20
28
|
compared: true;
|
|
21
29
|
matches: boolean;
|
|
@@ -231,6 +239,8 @@ export declare function sealsVerdict(entries: number | null, v: SealsFacts, queu
|
|
|
231
239
|
sentence: string;
|
|
232
240
|
passed: boolean;
|
|
233
241
|
};
|
|
242
|
+
/** The refusal code of a source that answered and was refused; undefined for any other outcome. */
|
|
243
|
+
export declare function refusedOf(source: SourceOutcome): MirrorRefusalCode | undefined;
|
|
234
244
|
export declare function sourceSentence(source: SourceOutcome): string;
|
|
235
245
|
/**
|
|
236
246
|
* The report's line on the daily statement. `changed` is true when the file no longer produces the
|
package/package.json
CHANGED