@pacspace-io/check 0.5.5 → 0.5.6

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/cli.js CHANGED
@@ -2097,10 +2097,10 @@ async function readRecordCopyV1(file) {
2097
2097
  }
2098
2098
 
2099
2099
  // ../shared/src/records/record-seal-history-v1.ts
2100
- var import_ethers13 = require("ethers");
2100
+ var import_ethers14 = require("ethers");
2101
2101
 
2102
2102
  // ../shared/src/demo/mirror-node-record-chain-reader.ts
2103
- var import_ethers12 = require("ethers");
2103
+ var import_ethers13 = require("ethers");
2104
2104
 
2105
2105
  // ../shared/src/records/inspect-record-calldata-v1.ts
2106
2106
  var MIRROR_NODE_BY_CHAIN = Object.freeze({
@@ -2116,7 +2116,15 @@ var HEX40 = /^0x[0-9a-f]{40}$/;
2116
2116
  var HEX642 = /^0x[0-9a-f]{64}$/;
2117
2117
  var HEX_DATA = /^0x[0-9a-f]*$/;
2118
2118
  var TIMESTAMP = /^\d+(\.\d+)?$/;
2119
- var REFUSAL_CODES = ["redirect", "too-large", "too-many-logs", "next-page"];
2119
+ var REFUSAL_CODES = {
2120
+ redirect: true,
2121
+ "too-large": true,
2122
+ "too-many-logs": true,
2123
+ "next-page": true,
2124
+ "too-slow": true,
2125
+ "too-long": true
2126
+ };
2127
+ var MIRROR_REFUSAL_CODES = Object.keys(REFUSAL_CODES);
2120
2128
  var MirrorAnswerRefused = class extends Error {
2121
2129
  constructor(code, message) {
2122
2130
  super(message);
@@ -2127,7 +2135,7 @@ var MirrorAnswerRefused = class extends Error {
2127
2135
  function mirrorRefusalOf(error) {
2128
2136
  if (!error || typeof error !== "object") return null;
2129
2137
  const { name, code } = error;
2130
- return name === "MirrorAnswerRefused" && typeof code === "string" && REFUSAL_CODES.includes(code) ? code : null;
2138
+ return name === "MirrorAnswerRefused" && typeof code === "string" && Object.prototype.hasOwnProperty.call(REFUSAL_CODES, code) ? code : null;
2131
2139
  }
2132
2140
  function pathLabel(path) {
2133
2141
  return path ? ` (${path.split("?")[0]})` : "";
@@ -2136,8 +2144,24 @@ var mirrorRefusal = {
2136
2144
  redirect: (path) => new MirrorAnswerRefused("redirect", `mirror node answered with a redirect, which is not followed${pathLabel(path)}`),
2137
2145
  tooLarge: (maxBytes, path) => new MirrorAnswerRefused("too-large", `mirror node answer is larger than ${maxBytes} bytes${pathLabel(path)}`),
2138
2146
  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")
2147
+ nextPage: () => new MirrorAnswerRefused("next-page", "mirror node gave a next page that is not this contract's log"),
2148
+ /** A page whose logs do not come after the last log read. */
2149
+ notForward: () => new MirrorAnswerRefused("next-page", "mirror node gave a next page that does not follow the last"),
2150
+ scanTooSlow: (budgetMs) => new MirrorAnswerRefused("too-slow", `mirror node log scan did not finish in ${budgetMs}ms`),
2151
+ scanTooManyRequests: (requests) => new MirrorAnswerRefused("too-long", `mirror node log scan passed ${requests} requests`),
2152
+ scanTooManyLogs: (logs) => new MirrorAnswerRefused("too-long", `mirror node log scan kept more than ${logs} logs`)
2153
+ };
2154
+ var rpcRefusal = {
2155
+ redirect: () => new MirrorAnswerRefused("redirect", "RPC endpoint answered with a redirect, which is not followed"),
2156
+ tooLarge: (maxBytes) => new MirrorAnswerRefused("too-large", `RPC endpoint answer is larger than ${maxBytes} bytes`),
2157
+ scanTooSlow: (budgetMs) => new MirrorAnswerRefused("too-slow", `RPC log scan did not finish in ${budgetMs}ms`),
2158
+ scanTooManyLogs: (logs) => new MirrorAnswerRefused("too-long", `RPC log scan kept more than ${logs} logs`)
2140
2159
  };
2160
+ var LOG_SCAN_BUDGET_TIMEOUTS = 60;
2161
+ var LOG_SCAN_MAX_REQUESTS = 1e4;
2162
+ var LOG_SCAN_MAX_KEPT_LOGS = 1e6;
2163
+ var KEPT_LOG_DATA_MAX_CHARS = 2 + 64 * 3;
2164
+ var KEPT_LOG_MAX_TOPICS = 3;
2141
2165
  function isMirrorRedirect(response) {
2142
2166
  return response.redirected === true || response.type === "opaqueredirect" || response.status >= 300 && response.status < 400;
2143
2167
  }
@@ -2253,6 +2277,9 @@ function parseLedgerWriteLog(log, expected) {
2253
2277
  }
2254
2278
 
2255
2279
  // ../shared/src/demo/independent-verify-records.ts
2280
+ var import_ethers12 = require("ethers");
2281
+
2282
+ // ../shared/src/chain/rpc-guarded-send.ts
2256
2283
  var import_ethers11 = require("ethers");
2257
2284
 
2258
2285
  // ../shared/src/chain/rpc-provider.ts
@@ -2369,13 +2396,34 @@ function redactRpcError(error, secrets) {
2369
2396
  }
2370
2397
  return new Error(cleanText(String(error), secrets));
2371
2398
  }
2399
+ function requestFor(url, options) {
2400
+ const request = new import_ethers10.FetchRequest(url);
2401
+ if (options.timeoutMs !== void 0) request.timeout = options.timeoutMs;
2402
+ options.prepareRequest?.(request);
2403
+ return request;
2404
+ }
2405
+ var CHAIN_ID_RESULT = /^0x[0-9a-f]{1,13}$/i;
2406
+ async function readRpcChainId(url, options = {}) {
2407
+ const secrets = rpcUrlSecrets(url);
2408
+ try {
2409
+ const request = requestFor(url, options);
2410
+ request.body = JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_chainId", params: [] });
2411
+ request.setHeader("content-type", "application/json");
2412
+ const response = await request.send();
2413
+ response.assertOk();
2414
+ const answer = response.bodyJson;
2415
+ const result = answer !== null && typeof answer === "object" ? answer.result : void 0;
2416
+ if (typeof result !== "string" || !CHAIN_ID_RESULT.test(result)) throw new Error("eth_chainId from the RPC is incomplete: not a chain id");
2417
+ return Number.parseInt(result, 16);
2418
+ } catch (error) {
2419
+ throw redactRpcError(error, secrets);
2420
+ }
2421
+ }
2372
2422
  var RedactingJsonRpcProvider = class extends import_ethers10.JsonRpcProvider {
2373
2423
  #secrets;
2374
2424
  constructor(url, network, options) {
2375
- const { timeoutMs, ...providerOptions } = options;
2376
- const request = new import_ethers10.FetchRequest(url);
2377
- if (timeoutMs !== void 0) request.timeout = timeoutMs;
2378
- super(request, network, providerOptions);
2425
+ const { timeoutMs, prepareRequest, ...providerOptions } = options;
2426
+ super(requestFor(url, { timeoutMs, prepareRequest }), network, providerOptions);
2379
2427
  this.#secrets = rpcUrlSecrets(url);
2380
2428
  }
2381
2429
  async _send(payload) {
@@ -2390,6 +2438,100 @@ function createRpcProvider(url, network, options = {}) {
2390
2438
  return new RedactingJsonRpcProvider(url, network, options);
2391
2439
  }
2392
2440
 
2441
+ // ../shared/src/chain/rpc-guarded-send.ts
2442
+ var RPC_READER_MAX_TRIES = 3;
2443
+ function basicAuthorization(username, password) {
2444
+ const decoded = (value) => {
2445
+ try {
2446
+ return decodeURIComponent(value);
2447
+ } catch {
2448
+ return value;
2449
+ }
2450
+ };
2451
+ const bytes2 = new TextEncoder().encode(`${decoded(username)}:${decoded(password)}`);
2452
+ let binary = "";
2453
+ for (const byte of bytes2) binary += String.fromCharCode(byte);
2454
+ return `Basic ${btoa(binary)}`;
2455
+ }
2456
+ function createGuardedRpcSend(options = {}) {
2457
+ const maxBytes = options.maxBytes ?? MIRROR_ANSWER_MAX_BYTES;
2458
+ return async (req, signal) => {
2459
+ if (signal?.cancelled) throw (0, import_ethers11.makeError)("request cancelled before sending", "CANCELLED");
2460
+ const fetchImpl = options.fetchImpl ?? fetch;
2461
+ const secrets = rpcUrlSecrets(req.url);
2462
+ const url = new URL(req.url);
2463
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
2464
+ throw (0, import_ethers11.makeError)(`unsupported protocol ${url.protocol.replace(/:$/, "")}`, "UNSUPPORTED_OPERATION", { operation: "request" });
2465
+ }
2466
+ const headers = {};
2467
+ for (const [name, value] of Object.entries(req.headers)) {
2468
+ const lower = name.toLowerCase();
2469
+ if (lower === "content-length" || lower === "accept-encoding") continue;
2470
+ headers[lower] = value;
2471
+ }
2472
+ if (url.username !== "" || url.password !== "") {
2473
+ if (headers.authorization === void 0) headers.authorization = basicAuthorization(url.username, url.password);
2474
+ url.username = "";
2475
+ url.password = "";
2476
+ }
2477
+ const controller = new AbortController();
2478
+ let timedOut = false;
2479
+ const timer = setTimeout(() => {
2480
+ timedOut = true;
2481
+ controller.abort();
2482
+ }, req.timeout);
2483
+ let cancelled = false;
2484
+ signal?.addListener(() => {
2485
+ cancelled = true;
2486
+ controller.abort();
2487
+ });
2488
+ try {
2489
+ const body = req.body;
2490
+ const response = await fetchImpl(url.toString(), {
2491
+ method: req.method,
2492
+ headers,
2493
+ ...body ? { body } : {},
2494
+ redirect: "manual",
2495
+ signal: controller.signal
2496
+ });
2497
+ if (isMirrorRedirect(response)) {
2498
+ await response.body?.cancel?.().catch(() => void 0);
2499
+ throw rpcRefusal.redirect();
2500
+ }
2501
+ let text;
2502
+ try {
2503
+ text = await readMirrorText(response, maxBytes);
2504
+ } catch (error) {
2505
+ if (mirrorRefusalOf(error) === "too-large") throw rpcRefusal.tooLarge(maxBytes);
2506
+ throw error;
2507
+ }
2508
+ const answered = {};
2509
+ response.headers.forEach((value, name) => {
2510
+ answered[name.toLowerCase()] = value;
2511
+ });
2512
+ return { statusCode: response.status, statusMessage: response.statusText, headers: answered, body: new TextEncoder().encode(replaceRpcSecrets(text, secrets)) };
2513
+ } catch (error) {
2514
+ if (mirrorRefusalOf(error)) throw error;
2515
+ if (cancelled) throw (0, import_ethers11.makeError)("request cancelled", "CANCELLED");
2516
+ if (timedOut) throw (0, import_ethers11.makeError)("request timeout", "TIMEOUT", { operation: "request.send", reason: "timeout" });
2517
+ throw error;
2518
+ } finally {
2519
+ clearTimeout(timer);
2520
+ }
2521
+ };
2522
+ }
2523
+ function retryAfterMs(value) {
2524
+ return typeof value === "string" && /^[1-9][0-9]*$/.test(value) ? Number.parseInt(value, 10) : null;
2525
+ }
2526
+ function holdRpcRequest(request, options = {}) {
2527
+ request.getUrlFunc = createGuardedRpcSend(options);
2528
+ request.retryFunc = async (req, response, attempt) => {
2529
+ if (attempt >= RPC_READER_MAX_TRIES - 1) return false;
2530
+ const wait = retryAfterMs(response.headers["retry-after"]);
2531
+ return wait === null || wait <= req.timeout;
2532
+ };
2533
+ }
2534
+
2393
2535
  // ../shared/src/demo/independent-verify-records.ts
2394
2536
  var RECORD_LANE_ABI_V38 = [
2395
2537
  "function getRecord(bytes32 recordKey) view returns (uint256)",
@@ -2401,8 +2543,8 @@ var RECORD_LANE_ABI_V38 = [
2401
2543
  "event RecordWritten(bytes32 indexed recordKey, address indexed operator, uint8 encodingVersion, uint256 previousWord, uint256 newWord)",
2402
2544
  "event LedgerHeadAdvanced(uint256 indexed batchId, bytes32 merkleRoot, bytes32 previousHead, bytes32 newHead)"
2403
2545
  ];
2404
- var LEDGER_HEAD_ADVANCED_TOPIC = import_ethers11.ethers.id("LedgerHeadAdvanced(uint256,bytes32,bytes32,bytes32)");
2405
- var RECORD_WRITTEN_TOPIC = import_ethers11.ethers.id("RecordWritten(bytes32,address,uint8,uint256,uint256)");
2546
+ var LEDGER_HEAD_ADVANCED_TOPIC = import_ethers12.ethers.id("LedgerHeadAdvanced(uint256,bytes32,bytes32,bytes32)");
2547
+ var RECORD_WRITTEN_TOPIC = import_ethers12.ethers.id("RecordWritten(bytes32,address,uint8,uint256,uint256)");
2406
2548
  var LAYOUT_NOT_REGISTERED = "layout-not-registered";
2407
2549
  function checkLayoutOnChain(onChainLayout, published) {
2408
2550
  const matchesPublished = !!published && onChainLayout.registered && onChainLayout.layoutDigest === published.digest;
@@ -2414,10 +2556,12 @@ function normalizeRpcUrl2(url) {
2414
2556
  if (trimmed.startsWith("ws://")) return trimmed.replace(/^ws:\/\//, "http://");
2415
2557
  return trimmed;
2416
2558
  }
2559
+ var ReadTimedOut = class extends Error {
2560
+ };
2417
2561
  async function withTimeout(p, ms, label) {
2418
2562
  let timer;
2419
2563
  const timeout = new Promise((_, reject) => {
2420
- timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), ms);
2564
+ timer = setTimeout(() => reject(new ReadTimedOut(`${label} timed out after ${ms}ms`)), ms);
2421
2565
  });
2422
2566
  try {
2423
2567
  return await Promise.race([p, timeout]);
@@ -2428,24 +2572,71 @@ async function withTimeout(p, ms, label) {
2428
2572
  function createRpcRecordChainReader(options) {
2429
2573
  const rpcUrl = normalizeRpcUrl2(options.rpcUrl);
2430
2574
  if (!rpcUrl) throw new Error("rpcUrl is required.");
2431
- const contractAddress = import_ethers11.ethers.getAddress(options.contractAddress).toLowerCase();
2575
+ const contractAddress = import_ethers12.ethers.getAddress(options.contractAddress).toLowerCase();
2432
2576
  const timeoutMs = Number(options.timeoutMs || 1e4);
2433
2577
  const chunk = Math.max(1, Number(options.logsChunkSize || 2e3));
2434
- const network = options.chainId != null ? new import_ethers11.ethers.Network(`chain-${options.chainId}`, options.chainId) : void 0;
2435
- const provider = network ? createRpcProvider(rpcUrl, network, { staticNetwork: network }) : createRpcProvider(rpcUrl);
2436
- const contract = new import_ethers11.ethers.Contract(contractAddress, RECORD_LANE_ABI_V38, provider);
2437
- const iface = new import_ethers11.ethers.Interface(RECORD_LANE_ABI_V38);
2578
+ const now = options.scan?.now ?? Date.now;
2579
+ const maxKeptLogs = options.scan?.maxKeptLogs ?? LOG_SCAN_MAX_KEPT_LOGS;
2580
+ const iface = new import_ethers12.ethers.Interface(RECORD_LANE_ABI_V38);
2581
+ const prepareRequest = (request) => holdRpcRequest(request);
2582
+ const endpointFor = (chainId) => {
2583
+ const network = new import_ethers12.ethers.Network(`chain-${chainId}`, chainId);
2584
+ const provider = createRpcProvider(rpcUrl, network, { staticNetwork: network, timeoutMs, prepareRequest });
2585
+ return { provider, contract: new import_ethers12.ethers.Contract(contractAddress, RECORD_LANE_ABI_V38, provider) };
2586
+ };
2587
+ let ready = options.chainId != null ? Promise.resolve(endpointFor(options.chainId)) : null;
2588
+ function endpoint() {
2589
+ if (!ready) {
2590
+ const pending = readRpcChainId(rpcUrl, { timeoutMs, prepareRequest }).then(endpointFor);
2591
+ ready = pending;
2592
+ pending.catch(() => {
2593
+ if (ready === pending) ready = null;
2594
+ });
2595
+ }
2596
+ return ready;
2597
+ }
2598
+ function keptLog(log, topic0) {
2599
+ return String(log.address).toLowerCase() === contractAddress && log.topics.length <= KEPT_LOG_MAX_TOPICS && String(log.topics[0] ?? "").toLowerCase() === topic0 && typeof log.data === "string" && log.data.length <= KEPT_LOG_DATA_MAX_CHARS;
2600
+ }
2438
2601
  async function scanLogs(topics, fromBlock, toBlock, label) {
2439
- const latest = toBlock === "latest" ? await withTimeout(provider.getBlockNumber(), timeoutMs, "getBlockNumber") : toBlock;
2602
+ const { provider } = await endpoint();
2603
+ const budgetMs = LOG_SCAN_BUDGET_TIMEOUTS * timeoutMs;
2604
+ const deadline = now() + budgetMs;
2605
+ const topic0 = String(topics[0] ?? "").toLowerCase();
2606
+ const ask = async (send, what) => {
2607
+ const left = deadline - now();
2608
+ if (left <= 0) throw rpcRefusal.scanTooSlow(budgetMs);
2609
+ const allowed = Math.min(timeoutMs, left);
2610
+ try {
2611
+ return await withTimeout(send(), allowed, what);
2612
+ } catch (error) {
2613
+ if (error instanceof ReadTimedOut && allowed < timeoutMs) throw rpcRefusal.scanTooSlow(budgetMs);
2614
+ if (!mirrorRefusalOf(error) && now() >= deadline) throw rpcRefusal.scanTooSlow(budgetMs);
2615
+ throw error;
2616
+ }
2617
+ };
2618
+ const latest = toBlock === "latest" ? await ask(() => provider.getBlockNumber(), "getBlockNumber") : toBlock;
2440
2619
  const out = [];
2620
+ const pending = [];
2441
2621
  for (let start = fromBlock; start <= latest; start += chunk) {
2442
- const end = Math.min(latest, start + chunk - 1);
2443
- const logs = await withTimeout(
2444
- provider.getLogs({ address: contractAddress, topics, fromBlock: start, toBlock: end }),
2445
- timeoutMs,
2446
- `getLogs ${label} (${start}-${end})`
2447
- );
2448
- out.push(...logs);
2622
+ pending.push([start, Math.min(latest, start + chunk - 1)]);
2623
+ while (pending.length > 0) {
2624
+ const [from, to] = pending.pop();
2625
+ let logs;
2626
+ try {
2627
+ logs = await ask(() => provider.getLogs({ address: contractAddress, topics, fromBlock: from, toBlock: to }), `getLogs ${label} (${from}-${to})`);
2628
+ } catch (error) {
2629
+ if (mirrorRefusalOf(error) !== "too-large" || from >= to) throw error;
2630
+ const middle = from + Math.floor((to - from) / 2);
2631
+ pending.push([middle + 1, to], [from, middle]);
2632
+ continue;
2633
+ }
2634
+ for (const log of logs) {
2635
+ if (!keptLog(log, topic0)) continue;
2636
+ if (out.length >= maxKeptLogs) throw rpcRefusal.scanTooManyLogs(maxKeptLogs);
2637
+ out.push(log);
2638
+ }
2639
+ }
2449
2640
  }
2450
2641
  return out;
2451
2642
  }
@@ -2453,10 +2644,12 @@ function createRpcRecordChainReader(options) {
2453
2644
  contractAddress,
2454
2645
  async getRecord(recordKey) {
2455
2646
  const key = normalizeProofHash(recordKey, "recordKey");
2647
+ const { contract } = await endpoint();
2456
2648
  const word = await withTimeout(contract.getRecord(key), timeoutMs, "getRecord");
2457
2649
  return hex256(BigInt(word));
2458
2650
  },
2459
2651
  async getLayout(layoutId) {
2652
+ const { contract } = await endpoint();
2460
2653
  const l = await withTimeout(contract.getLayout(layoutId), timeoutMs, "getLayout");
2461
2654
  return {
2462
2655
  layoutDigest: String(l[0]).toLowerCase(),
@@ -2466,10 +2659,12 @@ function createRpcRecordChainReader(options) {
2466
2659
  };
2467
2660
  },
2468
2661
  async getBatchRoot(batchId) {
2662
+ const { contract } = await endpoint();
2469
2663
  const root = await withTimeout(contract.getBatchRoot(BigInt(batchId)), timeoutMs, "getBatchRoot");
2470
2664
  return normalizeProofHash(String(root), "observedProofRoot");
2471
2665
  },
2472
2666
  async getLedgerHead() {
2667
+ const { contract } = await endpoint();
2473
2668
  const head = await withTimeout(contract.getLedgerHead(), timeoutMs, "getLedgerHead");
2474
2669
  return normalizeProofHash(String(head), "ledgerHead");
2475
2670
  },
@@ -2512,14 +2707,14 @@ function createRpcRecordChainReader(options) {
2512
2707
  },
2513
2708
  async findRecordWrites(recordKey, search) {
2514
2709
  const key = normalizeProofHash(recordKey, "recordKey");
2515
- const now = search.now ?? Date.now;
2516
- const deadline = now() + search.budgetMs;
2710
+ const now2 = search.now ?? Date.now;
2711
+ const deadline = now2() + search.budgetMs;
2517
2712
  const writes = [];
2518
2713
  const blockTimes = /* @__PURE__ */ new Map();
2519
2714
  let requests = 0;
2520
2715
  const CUT = Symbol("cut");
2521
2716
  const within2 = async (p) => {
2522
- const left = deadline - now();
2717
+ const left = deadline - now2();
2523
2718
  if (left <= 0) return CUT;
2524
2719
  let timer;
2525
2720
  const cut = new Promise((resolve3) => {
@@ -2534,12 +2729,15 @@ function createRpcRecordChainReader(options) {
2534
2729
  };
2535
2730
  const end = (ended) => ({ writes, ended, requests });
2536
2731
  if (search.maxRequests < 1) return end("limit");
2732
+ const found = await within2(endpoint());
2733
+ if (found === CUT) return end("timeout");
2734
+ const { provider } = found;
2537
2735
  requests += 1;
2538
2736
  const latest = await within2(provider.getBlockNumber());
2539
2737
  if (latest === CUT) return end("timeout");
2540
2738
  for (let to = latest; to >= 0; to -= chunk) {
2541
2739
  if (search.done(writes)) return end("done");
2542
- if (requests >= search.maxRequests || now() >= deadline) return end("limit");
2740
+ if (requests >= search.maxRequests || now2() >= deadline) return end("limit");
2543
2741
  requests += 1;
2544
2742
  const logs = await within2(provider.getLogs({ address: contractAddress, topics: [RECORD_WRITTEN_TOPIC, key], fromBlock: Math.max(0, to - chunk + 1), toBlock: to }));
2545
2743
  if (logs === CUT) return end("timeout");
@@ -2548,7 +2746,7 @@ function createRpcRecordChainReader(options) {
2548
2746
  if (!parsed) continue;
2549
2747
  let committedAt = blockTimes.get(log.blockNumber);
2550
2748
  if (committedAt === void 0) {
2551
- if (requests >= search.maxRequests || now() >= deadline) return end("limit");
2749
+ if (requests >= search.maxRequests || now2() >= deadline) return end("limit");
2552
2750
  requests += 1;
2553
2751
  const block = await within2(provider.getBlock(log.blockNumber));
2554
2752
  if (block === CUT) return end("timeout");
@@ -2593,7 +2791,7 @@ async function readLedgerMaterial(reader, log, options) {
2593
2791
  log,
2594
2792
  `eth_getLogs LedgerHeadAdvanced from block ${options.fromBlock ?? 0}`
2595
2793
  );
2596
- const genesisHead = options.genesisHead ?? (advances[0]?.previousHead ?? import_ethers11.ethers.ZeroHash);
2794
+ const genesisHead = options.genesisHead ?? (advances[0]?.previousHead ?? import_ethers12.ethers.ZeroHash);
2597
2795
  return {
2598
2796
  genesisHead,
2599
2797
  batches: advances.map((a) => ({ batchId: a.batchId, merkleRoot: a.merkleRoot })),
@@ -2659,12 +2857,32 @@ function committedAtOf(timestamp) {
2659
2857
  return new Date(Number(seconds) * 1e3 + Number(fraction.slice(0, 3))).toISOString();
2660
2858
  }
2661
2859
  var KEPT_TOPICS = [RECORD_WRITTEN_TOPIC.toLowerCase(), LEDGER_HEAD_ADVANCED_TOPIC.toLowerCase()];
2662
- function keptMirrorLog(raw) {
2860
+ var HEX_DATA2 = /^0x[0-9a-fA-F]*$/;
2861
+ function mirrorLogPosition(raw) {
2862
+ if (!raw || typeof raw !== "object") return null;
2863
+ const { timestamp, index } = raw;
2864
+ if (typeof timestamp !== "string" || !CONSENSUS_TIMESTAMP.test(timestamp)) return null;
2865
+ if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) return null;
2866
+ const [seconds, fraction] = timestamp.split(".");
2867
+ return { nanos: BigInt(seconds) * 1000000000n + BigInt(fraction), index };
2868
+ }
2869
+ function mirrorLogFollows(last, next) {
2870
+ return last === null || next.nanos > last.nanos || next.nanos === last.nanos && next.index > last.index;
2871
+ }
2872
+ function keptMirrorLog(raw, contract) {
2663
2873
  if (!raw || typeof raw !== "object") return null;
2664
2874
  const log = raw;
2665
2875
  if (!Array.isArray(log.topics) || typeof log.data !== "string") return null;
2876
+ if (log.topics.length > KEPT_LOG_MAX_TOPICS || log.data.length > KEPT_LOG_DATA_MAX_CHARS || !HEX_DATA2.test(log.data)) return null;
2666
2877
  const topics = log.topics.map((topic) => String(topic));
2667
2878
  if (!KEPT_TOPICS.includes((topics[0] ?? "").toLowerCase())) return null;
2879
+ if (topics.some((topic) => topic.length > 66)) return null;
2880
+ if (contract !== void 0) {
2881
+ if (typeof log.address !== "string" || log.address.toLowerCase() !== contract) return null;
2882
+ if (!mirrorLogPosition(raw)) return null;
2883
+ if (typeof log.block_number !== "number" || !Number.isSafeInteger(log.block_number)) return null;
2884
+ if (typeof log.transaction_hash !== "string" || log.transaction_hash.length > 98) return null;
2885
+ }
2668
2886
  return {
2669
2887
  address: log.address,
2670
2888
  data: log.data,
@@ -2679,18 +2897,25 @@ function createMirrorNodeRecordChainReader(options) {
2679
2897
  const chainId = options.chainId ?? 296;
2680
2898
  const base = (options.mirrorBaseUrl ?? MIRROR_NODE_BY_CHAIN[chainId] ?? "").replace(/\/+$/, "");
2681
2899
  if (!base) throw new Error(`No mirror node known for chain ${chainId}; pass mirrorBaseUrl.`);
2682
- const contractAddress = import_ethers12.ethers.getAddress(options.contractAddress).toLowerCase();
2900
+ const contractAddress = import_ethers13.ethers.getAddress(options.contractAddress).toLowerCase();
2683
2901
  const timeoutMs = Number(options.timeoutMs || 1e4);
2684
2902
  const pageSize = Math.min(100, Math.max(1, Number(options.pageSize || 100)));
2685
2903
  const attempts = Math.max(1, options.attempts ?? 3);
2686
2904
  const fetchImpl = options.fetchImpl ?? fetch;
2687
- const iface = new import_ethers12.ethers.Interface(RECORD_LANE_ABI_V38);
2688
- async function request(path, init) {
2905
+ const iface = new import_ethers13.ethers.Interface(RECORD_LANE_ABI_V38);
2906
+ const now = options.scan?.now ?? Date.now;
2907
+ const maxScanRequests = options.scan?.maxRequests ?? LOG_SCAN_MAX_REQUESTS;
2908
+ const maxKeptLogs = options.scan?.maxKeptLogs ?? LOG_SCAN_MAX_KEPT_LOGS;
2909
+ const scanBudgetMs = LOG_SCAN_BUDGET_TIMEOUTS * timeoutMs;
2910
+ async function request(path, init, deadline) {
2689
2911
  const url = `${base}${path}`;
2690
2912
  let lastError = null;
2691
2913
  for (let attempt = 1; attempt <= attempts; attempt += 1) {
2914
+ const left = deadline === void 0 ? timeoutMs : deadline - now();
2915
+ if (left <= 0) throw mirrorRefusal.scanTooSlow(scanBudgetMs);
2916
+ const allowed = Math.min(timeoutMs, left);
2692
2917
  const controller = new AbortController();
2693
- const timer = setTimeout(() => controller.abort(), timeoutMs);
2918
+ const timer = setTimeout(() => controller.abort(), allowed);
2694
2919
  try {
2695
2920
  const response = await fetchImpl(url, { ...init, redirect: "manual", signal: controller.signal });
2696
2921
  if (isMirrorRedirect(response)) {
@@ -2708,14 +2933,17 @@ function createMirrorNodeRecordChainReader(options) {
2708
2933
  }
2709
2934
  } catch (error) {
2710
2935
  if (mirrorRefusalOf(error)) throw error;
2711
- if (error.name === "AbortError") lastError = new Error(`mirror node request timed out after ${timeoutMs}ms (${path})`);
2712
- else if (/^mirror node \d{3} for/.test(error.message) && !/^mirror node (429|5\d\d)/.test(error.message)) throw error;
2936
+ if (error.name === "AbortError") {
2937
+ if (deadline !== void 0 && allowed < timeoutMs) throw mirrorRefusal.scanTooSlow(scanBudgetMs);
2938
+ lastError = new Error(`mirror node request timed out after ${timeoutMs}ms (${path})`);
2939
+ } else if (/^mirror node \d{3} for/.test(error.message) && !/^mirror node (429|5\d\d)/.test(error.message)) throw error;
2713
2940
  else lastError = error;
2714
2941
  } finally {
2715
2942
  clearTimeout(timer);
2716
2943
  }
2717
2944
  if (attempt < attempts) await new Promise((resolve3) => setTimeout(resolve3, 250 * attempt));
2718
2945
  }
2946
+ if (deadline !== void 0 && now() >= deadline) throw mirrorRefusal.scanTooSlow(scanBudgetMs);
2719
2947
  throw lastError ?? new Error(`mirror node request failed (${path})`);
2720
2948
  }
2721
2949
  async function call(fn, args = []) {
@@ -2751,16 +2979,23 @@ function createMirrorNodeRecordChainReader(options) {
2751
2979
  params.set("limit", String(pageSize));
2752
2980
  let next = `${contractLogPath(contractAddress)}?${params.toString()}`;
2753
2981
  const out = [];
2754
- let pages = 0;
2982
+ const scan = { deadline: now() + scanBudgetMs, requests: 0 };
2983
+ let last = null;
2755
2984
  let size = pageSize;
2756
2985
  while (next) {
2757
- const { page, asked } = await readLogPage(next, size);
2986
+ const { page, asked } = await readLogPage(next, size, scan);
2758
2987
  size = Math.min(pageSize, asked * 2);
2759
2988
  const logs = Array.isArray(page.logs) ? page.logs : [...page.logs ?? []];
2760
2989
  if (logs.length > asked) throw mirrorRefusal.tooManyLogs(asked, next);
2761
2990
  for (const raw of logs) {
2762
- const log = keptMirrorLog(raw);
2763
- if (log) out.push(log);
2991
+ const position = mirrorLogPosition(raw);
2992
+ if (!position) continue;
2993
+ if (!mirrorLogFollows(last, position)) throw mirrorRefusal.notForward();
2994
+ last = position;
2995
+ const log = keptMirrorLog(raw, contractAddress);
2996
+ if (!log) continue;
2997
+ if (out.length >= maxKeptLogs) throw mirrorRefusal.scanTooManyLogs(maxKeptLogs);
2998
+ out.push(log);
2764
2999
  }
2765
3000
  const link = page.links?.next;
2766
3001
  if (link === null || link === void 0 || link === "") {
@@ -2770,16 +3005,16 @@ function createMirrorNodeRecordChainReader(options) {
2770
3005
  if (!path) throw mirrorRefusal.nextPage();
2771
3006
  next = withLogPageLimit(path, size);
2772
3007
  }
2773
- pages += 1;
2774
- if (pages > 1e4) throw new Error("mirror node log scan exceeded 10,000 pages");
2775
3008
  }
2776
3009
  return out;
2777
3010
  }
2778
- async function readLogPage(path, start) {
3011
+ async function readLogPage(path, start, scan) {
2779
3012
  let asked = start;
2780
3013
  for (; ; ) {
3014
+ if (scan.requests >= maxScanRequests) throw mirrorRefusal.scanTooManyRequests(maxScanRequests);
3015
+ scan.requests += 1;
2781
3016
  try {
2782
- return { page: await request(withLogPageLimit(path, asked)), asked };
3017
+ return { page: await request(withLogPageLimit(path, asked), void 0, scan.deadline), asked };
2783
3018
  } catch (error) {
2784
3019
  if (mirrorRefusalOf(error) !== "too-large" || asked <= 1) throw error;
2785
3020
  asked = Math.max(1, Math.floor(asked / 2));
@@ -2881,10 +3116,10 @@ function createMirrorNodeRecordChainReader(options) {
2881
3116
  async findRecordWrites(recordKey, search) {
2882
3117
  const key = normalizeProofHash(recordKey, "recordKey").toLowerCase();
2883
3118
  const topic0 = RECORD_WRITTEN_TOPIC.toLowerCase();
2884
- const now = search.now ?? Date.now;
2885
- const deadline = now() + search.budgetMs;
3119
+ const now2 = search.now ?? Date.now;
3120
+ const deadline = now2() + search.budgetMs;
2886
3121
  const windowSeconds = Math.max(1, Math.floor(search.windowSeconds ?? RECORD_WRITE_SEARCH_WINDOW_SECONDS));
2887
- const nowSeconds = Math.floor(now() / 1e3);
3122
+ const nowSeconds = Math.floor(now2() / 1e3);
2888
3123
  const hint = search.startAt ? Date.parse(search.startAt) : Number.NaN;
2889
3124
  let upper = Math.min(Number.isFinite(hint) ? Math.floor(hint / 1e3) : nowSeconds, nowSeconds) + DAY_SECONDS;
2890
3125
  const writes = [];
@@ -2895,7 +3130,7 @@ function createMirrorNodeRecordChainReader(options) {
2895
3130
  const lower = Math.max(0, upper - windowSeconds);
2896
3131
  let path = ledgerWriteSearchPath({ contractAddress, topic0, recordKey: key, lower, upper });
2897
3132
  while (path) {
2898
- const left = deadline - now();
3133
+ const left = deadline - now2();
2899
3134
  if (requests >= search.maxRequests || left <= 0) return end("limit");
2900
3135
  requests += 1;
2901
3136
  const page = await searchPage(path, left);
@@ -3151,7 +3386,7 @@ var hasOnly = (v, required, optional = []) => required.every((k) => Object.proto
3151
3386
  function computeSealHistoryDigestV1(form) {
3152
3387
  const rest = { ...form };
3153
3388
  delete rest.digest;
3154
- return import_ethers13.ethers.keccak256(import_ethers13.ethers.toUtf8Bytes(canonicalizeJcs(rest)));
3389
+ return import_ethers14.ethers.keccak256(import_ethers14.ethers.toUtf8Bytes(canonicalizeJcs(rest)));
3155
3390
  }
3156
3391
  function entryShapeOk2(e) {
3157
3392
  if (!isPlainObject4(e) || !hasOnly(e, ENTRY_KEYS, ["recordHash"])) return false;
@@ -3643,7 +3878,9 @@ var SOURCE_REFUSAL_REASONS = {
3643
3878
  redirect: "its source answered with a redirect, which is not followed",
3644
3879
  "too-large": "its source gave an answer larger than this checker reads",
3645
3880
  "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"
3881
+ "next-page": "its source pointed somewhere else for the next page",
3882
+ "too-slow": "its source did not finish answering in the time allowed",
3883
+ "too-long": "it holds more than this checker reads in one run"
3647
3884
  };
3648
3885
  var ENCRYPTED_OPENED_SENTENCE = "Each entry was opened on this machine and matches its sealed record hash.";
3649
3886
  function refusedUnopenedSentence(k) {
@@ -3812,7 +4049,7 @@ function statementFingerprintOf(given, intact, fingerprint) {
3812
4049
  function heldFileField(held) {
3813
4050
  return held ? { matched: held.matched, entries: held.entries, blinded: held.blinded } : void 0;
3814
4051
  }
3815
- function buildReport(input) {
4052
+ function buildReportWithFacts(input) {
3816
4053
  const history = input.verification.history;
3817
4054
  const matched = history?.verifiedRecords ?? 0;
3818
4055
  const entries = history?.expectedRecords ?? (history ? matched : null);
@@ -3830,7 +4067,7 @@ function buildReport(input) {
3830
4067
  exportedAt: input.exportedAt
3831
4068
  };
3832
4069
  const statementFingerprint = statementFingerprintOf(input.statementFingerprint, intact, file.fingerprint);
3833
- const passed = input.verification.verified && (input.source.compared ? input.source.matches : true);
4070
+ const entriesMatch = input.verification.verified && (input.source.compared ? input.source.matches : true);
3834
4071
  const sentences = [];
3835
4072
  if (!intact) {
3836
4073
  sentences.push(FILE_CHANGED_SENTENCE);
@@ -3848,16 +4085,16 @@ function buildReport(input) {
3848
4085
  const fingerprintLine = fingerprintSentence(intact, statementFingerprint);
3849
4086
  if (fingerprintLine) sentences.push(fingerprintLine);
3850
4087
  if (input.heldFile) sentences.push(...heldFileSentences(input.heldFile));
3851
- const failed = !passed || input.dailyStatement?.matches === false || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
4088
+ const failed = !entriesMatch || input.dailyStatement?.matches === false || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
3852
4089
  const unreachable = !input.source.compared && input.source.reason === "unreachable";
3853
4090
  const exitCode = exitCodeOf(unreachable, failed);
3854
4091
  if (closesWithBoundary(exitCode)) sentences.push(HONESTY_SENTENCE);
3855
- return {
4092
+ const report = {
3856
4093
  schema: REPORT_SCHEMA,
3857
4094
  checker: input.checker,
3858
4095
  ...input.form ? { form: input.form } : {},
3859
4096
  record,
3860
- passed,
4097
+ passed: exitCode === 0,
3861
4098
  file,
3862
4099
  source: input.source,
3863
4100
  dailyStatement: input.dailyStatement,
@@ -3867,8 +4104,9 @@ function buildReport(input) {
3867
4104
  sentences,
3868
4105
  exitCode
3869
4106
  };
4107
+ return { report, entriesMatch };
3870
4108
  }
3871
- function buildSealsReport(input) {
4109
+ function buildSealsReportWithFacts(input) {
3872
4110
  const v = input.verification;
3873
4111
  const failedCount = v.failedSeq.length;
3874
4112
  const record = {
@@ -3884,7 +4122,7 @@ function buildSealsReport(input) {
3884
4122
  const verdict = sealsVerdict(input.entries, v, input.queued);
3885
4123
  const disclosure = input.disclosure;
3886
4124
  const disclosureOk = !disclosure || disclosure.kind === "verified";
3887
- const passed = verdict.passed && v.verified && (input.source.compared ? input.source.matches : true) && disclosureOk;
4125
+ const entriesMatch = verdict.passed && v.verified && (input.source.compared ? input.source.matches : true) && disclosureOk;
3888
4126
  const sentences = [intact ? verdict.sentence : FILE_CHANGED_SENTENCE];
3889
4127
  if (disclosure?.kind === "verified") {
3890
4128
  sentences.push(revealedLine(disclosure.revealed.length, input.entries ?? disclosure.revealed.length));
@@ -3898,16 +4136,16 @@ function buildSealsReport(input) {
3898
4136
  const fingerprintLine = fingerprintSentence(intact, statementFingerprint);
3899
4137
  if (fingerprintLine) sentences.push(fingerprintLine);
3900
4138
  if (input.heldFile && disclosure?.kind === "verified") sentences.push(...heldFileSentences(input.heldFile));
3901
- const failed = !passed || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
4139
+ const failed = !entriesMatch || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
3902
4140
  const unreachable = !input.source.compared && input.source.reason === "unreachable" || disclosure?.kind === "root-not-read";
3903
4141
  const exitCode = exitCodeOf(unreachable, failed);
3904
4142
  if (closesWithBoundary(exitCode)) sentences.push(SEALS_BOUNDARY_SENTENCE);
3905
- return {
4143
+ const report = {
3906
4144
  schema: REPORT_SCHEMA,
3907
4145
  checker: input.checker,
3908
4146
  form: input.form,
3909
4147
  record,
3910
- passed,
4148
+ passed: exitCode === 0,
3911
4149
  file,
3912
4150
  source: input.source,
3913
4151
  dailyStatement: null,
@@ -3918,6 +4156,7 @@ function buildSealsReport(input) {
3918
4156
  sentences,
3919
4157
  exitCode
3920
4158
  };
4159
+ return { report, entriesMatch };
3921
4160
  }
3922
4161
  var WRITES_HEADING = "Where each entry was committed on the proof layer:";
3923
4162
  var WRITES_NOT_READ_SENTENCE = "Where each entry was committed could not be read from the proof layer this time. The check above does not depend on it.";
@@ -4088,7 +4327,7 @@ async function lookUpWrites(input) {
4088
4327
 
4089
4328
  // src/check.ts
4090
4329
  var CHECKER_NAME = "@pacspace-io/check";
4091
- var CHECKER_VERSION = true ? "0.5.5" : "0.0.0-dev";
4330
+ var CHECKER_VERSION = true ? "0.5.6" : "0.0.0-dev";
4092
4331
  var HISTORY_SCHEMAS = [
4093
4332
  RECORD_HISTORY_BUNDLE_SCHEMA_V1,
4094
4333
  RECORD_HISTORY_BUNDLE_SCHEMA_V2,
@@ -4200,8 +4439,9 @@ function readerFor(chain, options) {
4200
4439
  readsFrom: mirrorBaseUrl
4201
4440
  };
4202
4441
  }
4203
- async function withWrites(report, bundle, verification, reader, options) {
4204
- if (!options.writes || !reader || !report.passed || !report.file.intact || !report.source.compared || !report.source.matches) return report;
4442
+ async function withWrites(checked, bundle, verification, reader, options) {
4443
+ const { report } = checked;
4444
+ if (!options.writes || !reader || !checked.entriesMatch || !report.file.intact || !report.source.compared || !report.source.matches) return checked;
4205
4445
  let writes;
4206
4446
  try {
4207
4447
  const source = options.source ?? "mirror";
@@ -4221,7 +4461,7 @@ async function withWrites(report, bundle, verification, reader, options) {
4221
4461
  } catch {
4222
4462
  writes = { read: false, reason: "unreachable" };
4223
4463
  }
4224
- return { ...report, writes };
4464
+ return { ...checked, report: { ...report, writes } };
4225
4465
  }
4226
4466
  var PAYLOAD_POINTER = /^\/payloads\/(0|[1-9][0-9]*)$/;
4227
4467
  function disclosureNamesAFile(disclosure) {
@@ -4252,6 +4492,9 @@ function refuseLayoutNotRead(result) {
4252
4492
  if (result.code === RECORDS_LAYOUT_NOT_READ) throw new HistoryFileError(RECORDS_LAYOUT_NOT_READ_SENTENCE);
4253
4493
  }
4254
4494
  async function checkHistory(file, options = {}) {
4495
+ return (await checkHistoryWithFacts(file, options)).report;
4496
+ }
4497
+ async function checkHistoryWithFacts(file, options = {}) {
4255
4498
  if (options.source === "offline" && needsLedgerRoots(file)) throw new HistoryFileError(DISCLOSURE_OFFLINE_SENTENCE);
4256
4499
  if (options.heldFile && !revealsFileFingerprint(file)) throw new HistoryFileError(NOTHING_REVEALED_SENTENCE);
4257
4500
  if (options.recordKey && file.schema !== RECORD_HISTORY_BUNDLE_SCHEMA_V3) throw new HistoryFileError(KEY_ONLY_FOR_ENCRYPTED_SENTENCE);
@@ -4376,7 +4619,7 @@ async function checkBundle(file, options) {
4376
4619
  };
4377
4620
  const heldOf = (verification2, offlineRun) => options.heldFile ? heldFileOutcome(options.heldFile, verifiedPayloads(file, verification2), offlineRun) : null;
4378
4621
  if (options.source === "offline" || !offline.schemaOk || !offline.digestOk) {
4379
- return buildReport({
4622
+ return buildReportWithFacts({
4380
4623
  ...base,
4381
4624
  verification: offline,
4382
4625
  source: { compared: false, reason: "offline" },
@@ -4412,7 +4655,7 @@ async function checkBundle(file, options) {
4412
4655
  if (error instanceof HistoryFileError) throw error;
4413
4656
  source = notReached(error);
4414
4657
  }
4415
- const report = buildReport({
4658
+ const report = buildReportWithFacts({
4416
4659
  ...base,
4417
4660
  verification,
4418
4661
  source,
@@ -4462,7 +4705,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4462
4705
  const refused = (refusal) => {
4463
4706
  refuseLayoutNotRead(refusal);
4464
4707
  if (refusal.code === "RECORD_HISTORY_DIGEST") {
4465
- return buildReport({
4708
+ return buildReportWithFacts({
4466
4709
  ...base,
4467
4710
  verification: { verified: false, digestOk: false, reason: "", history: null },
4468
4711
  source: { compared: false, reason: "offline" },
@@ -4471,7 +4714,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4471
4714
  }
4472
4715
  const sentence = encryptedRefusalSentence(refusal);
4473
4716
  if (sentence === null) throw new HistoryFileError(notThisForm);
4474
- return buildReport({
4717
+ return buildReportWithFacts({
4475
4718
  ...base,
4476
4719
  verification: { verified: false, digestOk: true, reason: sentence, history: null },
4477
4720
  source: { compared: false, reason: "offline" },
@@ -4488,7 +4731,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4488
4731
  if (!offline.ok) return refused(offline);
4489
4732
  const encrypted = { refusedUnopened: offline.refused.filter((r) => !r.opened).length };
4490
4733
  if (options.source === "offline" || !offline.verification.schemaOk || !offline.verification.digestOk) {
4491
- return buildReport({
4734
+ return buildReportWithFacts({
4492
4735
  ...base,
4493
4736
  verification: offline.verification,
4494
4737
  source: { compared: false, reason: "offline" },
@@ -4535,7 +4778,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4535
4778
  if (error instanceof HistoryFileError) throw error;
4536
4779
  source = notReached(error);
4537
4780
  }
4538
- const report = buildReport({
4781
+ const report = buildReportWithFacts({
4539
4782
  ...base,
4540
4783
  verification: result.verification,
4541
4784
  source,
@@ -4640,7 +4883,7 @@ async function checkSeals(formName, form, disclosure, options) {
4640
4883
  };
4641
4884
  const entries = entryCountOf(form, layouts);
4642
4885
  if (options.source === "offline" || !verification.schemaOk || !verification.digestOk) {
4643
- return buildSealsReport({
4886
+ return buildSealsReportWithFacts({
4644
4887
  ...base,
4645
4888
  entries,
4646
4889
  verification,
@@ -4678,7 +4921,7 @@ async function checkSeals(formName, form, disclosure, options) {
4678
4921
  disclosureOutcome = verification.verified ? await checkDisclosure(form, disclosure, reader, options.onRevealed) : { kind: "not-checked" };
4679
4922
  }
4680
4923
  const held = options.heldFile ? heldFileOutcome(options.heldFile, disclosureOutcome?.kind === "verified" ? disclosureOutcome.payloads : [], false) : null;
4681
- return buildSealsReport({
4924
+ return buildSealsReportWithFacts({
4682
4925
  ...base,
4683
4926
  entries,
4684
4927
  verification,
@@ -5217,13 +5460,14 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
5217
5460
  }
5218
5461
  base.commit = manifest.commit;
5219
5462
  let report;
5463
+ let entriesMatch;
5220
5464
  try {
5221
- report = await checkHistory(history, {
5465
+ ({ report, entriesMatch } = await checkHistoryWithFacts(history, {
5222
5466
  source: source ?? "mirror",
5223
5467
  timeoutMs,
5224
5468
  fetchImpl,
5225
5469
  heldFile: { sha256: await sha256Hex(manifestRead.bytes), byteLength: String(manifestRead.bytes.length) }
5226
- });
5470
+ }));
5227
5471
  } catch (error) {
5228
5472
  if (error instanceof HistoryFileError) return differs([{ kind: "differs", path: historyPath }]);
5229
5473
  throw error;
@@ -5231,7 +5475,7 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
5231
5475
  if (report.exitCode === 3 || report.source.compared === false && report.source.reason === "unreachable") {
5232
5476
  return unreachable(refusedOf(report.source));
5233
5477
  }
5234
- if (!report.passed) return differs([{ kind: "differs", path: historyPath }]);
5478
+ if (!entriesMatch) return differs([{ kind: "differs", path: historyPath }]);
5235
5479
  const latest = report.record.entries;
5236
5480
  base.latestEntry = latest;
5237
5481
  const matched = report.heldFile?.entries ?? [];