@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/index.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((resolve) => {
@@ -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((resolve) => setTimeout(resolve, 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;
@@ -3496,7 +3731,9 @@ var SOURCE_REFUSAL_REASONS = {
3496
3731
  redirect: "its source answered with a redirect, which is not followed",
3497
3732
  "too-large": "its source gave an answer larger than this checker reads",
3498
3733
  "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"
3734
+ "next-page": "its source pointed somewhere else for the next page",
3735
+ "too-slow": "its source did not finish answering in the time allowed",
3736
+ "too-long": "it holds more than this checker reads in one run"
3500
3737
  };
3501
3738
  var ENCRYPTED_OPENED_SENTENCE = "Each entry was opened on this machine and matches its sealed record hash.";
3502
3739
  function refusedUnopenedSentence(k) {
@@ -3665,6 +3902,9 @@ function heldFileField(held) {
3665
3902
  return held ? { matched: held.matched, entries: held.entries, blinded: held.blinded } : void 0;
3666
3903
  }
3667
3904
  function buildReport(input) {
3905
+ return buildReportWithFacts(input).report;
3906
+ }
3907
+ function buildReportWithFacts(input) {
3668
3908
  const history = input.verification.history;
3669
3909
  const matched = history?.verifiedRecords ?? 0;
3670
3910
  const entries = history?.expectedRecords ?? (history ? matched : null);
@@ -3682,7 +3922,7 @@ function buildReport(input) {
3682
3922
  exportedAt: input.exportedAt
3683
3923
  };
3684
3924
  const statementFingerprint = statementFingerprintOf(input.statementFingerprint, intact, file.fingerprint);
3685
- const passed = input.verification.verified && (input.source.compared ? input.source.matches : true);
3925
+ const entriesMatch = input.verification.verified && (input.source.compared ? input.source.matches : true);
3686
3926
  const sentences = [];
3687
3927
  if (!intact) {
3688
3928
  sentences.push(FILE_CHANGED_SENTENCE);
@@ -3700,16 +3940,16 @@ function buildReport(input) {
3700
3940
  const fingerprintLine = fingerprintSentence(intact, statementFingerprint);
3701
3941
  if (fingerprintLine) sentences.push(fingerprintLine);
3702
3942
  if (input.heldFile) sentences.push(...heldFileSentences(input.heldFile));
3703
- const failed = !passed || input.dailyStatement?.matches === false || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
3943
+ const failed = !entriesMatch || input.dailyStatement?.matches === false || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
3704
3944
  const unreachable = !input.source.compared && input.source.reason === "unreachable";
3705
3945
  const exitCode = exitCodeOf(unreachable, failed);
3706
3946
  if (closesWithBoundary(exitCode)) sentences.push(HONESTY_SENTENCE);
3707
- return {
3947
+ const report = {
3708
3948
  schema: REPORT_SCHEMA,
3709
3949
  checker: input.checker,
3710
3950
  ...input.form ? { form: input.form } : {},
3711
3951
  record,
3712
- passed,
3952
+ passed: exitCode === 0,
3713
3953
  file,
3714
3954
  source: input.source,
3715
3955
  dailyStatement: input.dailyStatement,
@@ -3719,8 +3959,12 @@ function buildReport(input) {
3719
3959
  sentences,
3720
3960
  exitCode
3721
3961
  };
3962
+ return { report, entriesMatch };
3722
3963
  }
3723
3964
  function buildSealsReport(input) {
3965
+ return buildSealsReportWithFacts(input).report;
3966
+ }
3967
+ function buildSealsReportWithFacts(input) {
3724
3968
  const v = input.verification;
3725
3969
  const failedCount = v.failedSeq.length;
3726
3970
  const record = {
@@ -3736,7 +3980,7 @@ function buildSealsReport(input) {
3736
3980
  const verdict = sealsVerdict(input.entries, v, input.queued);
3737
3981
  const disclosure = input.disclosure;
3738
3982
  const disclosureOk = !disclosure || disclosure.kind === "verified";
3739
- const passed = verdict.passed && v.verified && (input.source.compared ? input.source.matches : true) && disclosureOk;
3983
+ const entriesMatch = verdict.passed && v.verified && (input.source.compared ? input.source.matches : true) && disclosureOk;
3740
3984
  const sentences = [intact ? verdict.sentence : FILE_CHANGED_SENTENCE];
3741
3985
  if (disclosure?.kind === "verified") {
3742
3986
  sentences.push(revealedLine(disclosure.revealed.length, input.entries ?? disclosure.revealed.length));
@@ -3750,16 +3994,16 @@ function buildSealsReport(input) {
3750
3994
  const fingerprintLine = fingerprintSentence(intact, statementFingerprint);
3751
3995
  if (fingerprintLine) sentences.push(fingerprintLine);
3752
3996
  if (input.heldFile && disclosure?.kind === "verified") sentences.push(...heldFileSentences(input.heldFile));
3753
- const failed = !passed || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
3997
+ const failed = !entriesMatch || statementFingerprint !== null && !statementFingerprint.matches || !!input.heldFile && !input.heldFile.matched;
3754
3998
  const unreachable = !input.source.compared && input.source.reason === "unreachable" || disclosure?.kind === "root-not-read";
3755
3999
  const exitCode = exitCodeOf(unreachable, failed);
3756
4000
  if (closesWithBoundary(exitCode)) sentences.push(SEALS_BOUNDARY_SENTENCE);
3757
- return {
4001
+ const report = {
3758
4002
  schema: REPORT_SCHEMA,
3759
4003
  checker: input.checker,
3760
4004
  form: input.form,
3761
4005
  record,
3762
- passed,
4006
+ passed: exitCode === 0,
3763
4007
  file,
3764
4008
  source: input.source,
3765
4009
  dailyStatement: null,
@@ -3770,6 +4014,7 @@ function buildSealsReport(input) {
3770
4014
  sentences,
3771
4015
  exitCode
3772
4016
  };
4017
+ return { report, entriesMatch };
3773
4018
  }
3774
4019
  var WRITES_HEADING = "Where each entry was committed on the proof layer:";
3775
4020
  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.";
@@ -3940,7 +4185,7 @@ async function lookUpWrites(input) {
3940
4185
 
3941
4186
  // src/check.ts
3942
4187
  var CHECKER_NAME = "@pacspace-io/check";
3943
- var CHECKER_VERSION = true ? "0.5.5" : "0.0.0-dev";
4188
+ var CHECKER_VERSION = true ? "0.5.6" : "0.0.0-dev";
3944
4189
  var HISTORY_SCHEMAS = [
3945
4190
  RECORD_HISTORY_BUNDLE_SCHEMA_V1,
3946
4191
  RECORD_HISTORY_BUNDLE_SCHEMA_V2,
@@ -4052,8 +4297,9 @@ function readerFor(chain, options) {
4052
4297
  readsFrom: mirrorBaseUrl
4053
4298
  };
4054
4299
  }
4055
- async function withWrites(report, bundle, verification, reader, options) {
4056
- if (!options.writes || !reader || !report.passed || !report.file.intact || !report.source.compared || !report.source.matches) return report;
4300
+ async function withWrites(checked, bundle, verification, reader, options) {
4301
+ const { report } = checked;
4302
+ if (!options.writes || !reader || !checked.entriesMatch || !report.file.intact || !report.source.compared || !report.source.matches) return checked;
4057
4303
  let writes;
4058
4304
  try {
4059
4305
  const source = options.source ?? "mirror";
@@ -4073,7 +4319,7 @@ async function withWrites(report, bundle, verification, reader, options) {
4073
4319
  } catch {
4074
4320
  writes = { read: false, reason: "unreachable" };
4075
4321
  }
4076
- return { ...report, writes };
4322
+ return { ...checked, report: { ...report, writes } };
4077
4323
  }
4078
4324
  var PAYLOAD_POINTER = /^\/payloads\/(0|[1-9][0-9]*)$/;
4079
4325
  function disclosureNamesAFile(disclosure) {
@@ -4104,6 +4350,9 @@ function refuseLayoutNotRead(result) {
4104
4350
  if (result.code === RECORDS_LAYOUT_NOT_READ) throw new HistoryFileError(RECORDS_LAYOUT_NOT_READ_SENTENCE);
4105
4351
  }
4106
4352
  async function checkHistory(file, options = {}) {
4353
+ return (await checkHistoryWithFacts(file, options)).report;
4354
+ }
4355
+ async function checkHistoryWithFacts(file, options = {}) {
4107
4356
  if (options.source === "offline" && needsLedgerRoots(file)) throw new HistoryFileError(DISCLOSURE_OFFLINE_SENTENCE);
4108
4357
  if (options.heldFile && !revealsFileFingerprint(file)) throw new HistoryFileError(NOTHING_REVEALED_SENTENCE);
4109
4358
  if (options.recordKey && file.schema !== RECORD_HISTORY_BUNDLE_SCHEMA_V3) throw new HistoryFileError(KEY_ONLY_FOR_ENCRYPTED_SENTENCE);
@@ -4228,7 +4477,7 @@ async function checkBundle(file, options) {
4228
4477
  };
4229
4478
  const heldOf = (verification2, offlineRun) => options.heldFile ? heldFileOutcome(options.heldFile, verifiedPayloads(file, verification2), offlineRun) : null;
4230
4479
  if (options.source === "offline" || !offline.schemaOk || !offline.digestOk) {
4231
- return buildReport({
4480
+ return buildReportWithFacts({
4232
4481
  ...base,
4233
4482
  verification: offline,
4234
4483
  source: { compared: false, reason: "offline" },
@@ -4264,7 +4513,7 @@ async function checkBundle(file, options) {
4264
4513
  if (error instanceof HistoryFileError) throw error;
4265
4514
  source = notReached(error);
4266
4515
  }
4267
- const report = buildReport({
4516
+ const report = buildReportWithFacts({
4268
4517
  ...base,
4269
4518
  verification,
4270
4519
  source,
@@ -4314,7 +4563,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4314
4563
  const refused = (refusal) => {
4315
4564
  refuseLayoutNotRead(refusal);
4316
4565
  if (refusal.code === "RECORD_HISTORY_DIGEST") {
4317
- return buildReport({
4566
+ return buildReportWithFacts({
4318
4567
  ...base,
4319
4568
  verification: { verified: false, digestOk: false, reason: "", history: null },
4320
4569
  source: { compared: false, reason: "offline" },
@@ -4323,7 +4572,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4323
4572
  }
4324
4573
  const sentence = encryptedRefusalSentence(refusal);
4325
4574
  if (sentence === null) throw new HistoryFileError(notThisForm);
4326
- return buildReport({
4575
+ return buildReportWithFacts({
4327
4576
  ...base,
4328
4577
  verification: { verified: false, digestOk: true, reason: sentence, history: null },
4329
4578
  source: { compared: false, reason: "offline" },
@@ -4340,7 +4589,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4340
4589
  if (!offline.ok) return refused(offline);
4341
4590
  const encrypted = { refusedUnopened: offline.refused.filter((r) => !r.opened).length };
4342
4591
  if (options.source === "offline" || !offline.verification.schemaOk || !offline.verification.digestOk) {
4343
- return buildReport({
4592
+ return buildReportWithFacts({
4344
4593
  ...base,
4345
4594
  verification: offline.verification,
4346
4595
  source: { compared: false, reason: "offline" },
@@ -4387,7 +4636,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4387
4636
  if (error instanceof HistoryFileError) throw error;
4388
4637
  source = notReached(error);
4389
4638
  }
4390
- const report = buildReport({
4639
+ const report = buildReportWithFacts({
4391
4640
  ...base,
4392
4641
  verification: result.verification,
4393
4642
  source,
@@ -4492,7 +4741,7 @@ async function checkSeals(formName, form, disclosure, options) {
4492
4741
  };
4493
4742
  const entries = entryCountOf(form, layouts);
4494
4743
  if (options.source === "offline" || !verification.schemaOk || !verification.digestOk) {
4495
- return buildSealsReport({
4744
+ return buildSealsReportWithFacts({
4496
4745
  ...base,
4497
4746
  entries,
4498
4747
  verification,
@@ -4530,7 +4779,7 @@ async function checkSeals(formName, form, disclosure, options) {
4530
4779
  disclosureOutcome = verification.verified ? await checkDisclosure(form, disclosure, reader, options.onRevealed) : { kind: "not-checked" };
4531
4780
  }
4532
4781
  const held = options.heldFile ? heldFileOutcome(options.heldFile, disclosureOutcome?.kind === "verified" ? disclosureOutcome.payloads : [], false) : null;
4533
- return buildSealsReport({
4782
+ return buildSealsReportWithFacts({
4534
4783
  ...base,
4535
4784
  entries,
4536
4785
  verification,
@@ -4748,13 +4997,14 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
4748
4997
  }
4749
4998
  base.commit = manifest.commit;
4750
4999
  let report;
5000
+ let entriesMatch;
4751
5001
  try {
4752
- report = await checkHistory(history, {
5002
+ ({ report, entriesMatch } = await checkHistoryWithFacts(history, {
4753
5003
  source: source ?? "mirror",
4754
5004
  timeoutMs,
4755
5005
  fetchImpl,
4756
5006
  heldFile: { sha256: await sha256Hex(manifestRead.bytes), byteLength: String(manifestRead.bytes.length) }
4757
- });
5007
+ }));
4758
5008
  } catch (error) {
4759
5009
  if (error instanceof HistoryFileError) return differs([{ kind: "differs", path: historyPath }]);
4760
5010
  throw error;
@@ -4762,7 +5012,7 @@ async function checkPinned(origin, anchors, fetchImpl, rawGet, timeoutMs, source
4762
5012
  if (report.exitCode === 3 || report.source.compared === false && report.source.reason === "unreachable") {
4763
5013
  return unreachable(refusedOf(report.source));
4764
5014
  }
4765
- if (!report.passed) return differs([{ kind: "differs", path: historyPath }]);
5015
+ if (!entriesMatch) return differs([{ kind: "differs", path: historyPath }]);
4766
5016
  const latest = report.record.entries;
4767
5017
  base.latestEntry = latest;
4768
5018
  const matched = report.heldFile?.entries ?? [];