@pacspace-io/check 0.5.3 → 0.5.4

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.4 - 2026-11-16
4
+
5
+ ### Added
6
+
7
+ - After a history file passes and matches the proof layer, the report lists where each entry was committed: the time, and a link to the write on an explorer of the proof layer. `--json` carries the same in a new `writes` field. This is information only: when it cannot be read the report says so, and the result and the exit code are what they were. `--no-lookup` leaves it out, `--offline` never makes it, and `release` and `open` do not make it.
8
+
3
9
  ## 0.5.3 - 2026-11-15
4
10
 
5
11
  ### Changed
package/README.md CHANGED
@@ -34,11 +34,25 @@ Proof layer <the proof layer mirror the record names>
34
34
 
35
35
  This record has 3 entries. All 3 are here, and all 3 match what was committed.
36
36
  Compared with the proof layer for this record: it matches.
37
+ Where each entry was committed on the proof layer:
38
+ Entry 1: committed 11 September 2026, 23:58:07 UTC
39
+ https://hashscan.io/mainnet/transaction/0x5d1c...9a3e
40
+ Entries 2 and 3: committed 12 September 2026, 00:41:19 UTC
41
+ https://hashscan.io/mainnet/transaction/0x81f0...c27b
37
42
  Daily statement of 12 September 2026 (UTC): matches.
38
43
  The fingerprint you gave names this file.
39
44
  The check shows the record is unchanged since it was committed. It does not show that what was recorded was true.
40
45
  ```
41
46
 
47
+ After a history file passes and matches the proof layer, the report lists
48
+ where each entry was committed: the time, and a link to the write. The
49
+ link opens that write on an explorer of the proof layer, which shows the
50
+ same time in your own time zone. `--json` carries the same in a `writes`
51
+ field. This is information only: when it cannot be read the report says
52
+ so, and the result and the exit code are what they were. `--no-lookup`
53
+ leaves it out, `--offline` never makes it, and `release` and `open` do
54
+ not make it.
55
+
42
56
  ## What it checks
43
57
 
44
58
  1. The file against its own fingerprint. A history file carries the
@@ -95,6 +109,7 @@ release reads each file three ways, as the host sends it, and checks each answer
95
109
  --source <url> read the proof layer from this mirror
96
110
  --rpc <url> read the proof layer over JSON-RPC at this URL
97
111
  --full also read every daily statement
112
+ --no-lookup do not look up where each entry was committed
98
113
  --timeout <ms> network timeout per read (default 10000)
99
114
  --json print the report as JSON
100
115
  ```
package/dist/check.d.ts CHANGED
@@ -54,6 +54,15 @@ export interface CheckOptions {
54
54
  recordKey?: Uint8Array;
55
55
  /** Called with a disclosure's revealed fields once they verified; never for fields that failed. */
56
56
  onRevealed?: (entries: RevealedEntry[]) => void;
57
+ /**
58
+ * After a words history or kept copy passes and matches the proof layer, also look up where each
59
+ * entry was committed and carry it in the report's `writes`. Off unless passed. Information only:
60
+ * the verdict, the sentences and the exit code are built first and are what they would be without it.
61
+ */
62
+ writes?: boolean;
63
+ /** Test seams for the lookup: its window and its clock. */
64
+ writesWindowSeconds?: number;
65
+ writesNow?: () => number;
57
66
  }
58
67
  /** One disclosed entry's fields as the reader sees them: entries count from 1. */
59
68
  export interface RevealedEntry {
package/dist/cli.d.ts CHANGED
@@ -14,8 +14,10 @@ export interface CliArgs {
14
14
  history: string | null;
15
15
  /** A path, or `-` for stdin; never the key itself. */
16
16
  key: string | null;
17
+ /** `--no-lookup`: do not look up where each entry was committed. */
18
+ noLookup: boolean;
17
19
  }
18
- export declare const USAGE = "Usage: pacspace-check <history.json> [options]\n pacspace-check <history.json> --key <path>\n pacspace-check open [--link-file <path>] [--access-code-file <path>] [--copy <path>] [--html <path>] [--source <url> | --rpc <url>] [--timeout <ms>] [--json]\n pacspace-check release [--origin <url>] [--source <url> | --rpc <url>] [--timeout <ms>] [--json]\n pacspace-check release --origin <url> --release-record <record key>,<network id>,<contract>\n\nChecks a PacSpace record history file: every entry against what was\ncommitted, the file against its own fingerprint, and the record against\nthe 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.\n\nOptions:\n --fingerprint <0x...> the fingerprint printed on a statement; the checker\n says whether it names this file\n --held-file <path> check whether a verified entry names a file you hold\n --blinding <path> the blinding file for the file you hold, when its entry is blinded\n --history <path> the seal history or kept copy a disclosure is checked against\n --key <path> the record key for an encrypted history, read from this file (- for stdin)\n --link-file <path> open: read the link from this file instead of asking\n --access-code-file <path> open: read the access code from this file instead of asking\n --copy <path> open: save a kept copy of what the link shows to a new file\n --html <path> open: save the report as a page that opens without a network connection\n --offline check the file alone; do not read the proof layer\n --source <url> read the proof layer from this mirror instead of\n the one known for the record's network\n --rpc <url> read the proof layer over JSON-RPC at this URL\n --full also read every daily statement\n --timeout <ms> network timeout per read (default 10000)\n --json print the report as JSON\n --version print the checker's version\n --help print this text\n\nExit codes: 0 the check passed as asked; 1 it did not, or the file you hold is not in it; 2 the history file, the link, a key, the file you hold, its blinding file or the arguments could not be used; 3 the proof layer or the link's host could not be reached. When more than one applies, 2 comes before 3, and 3 before 1.\n";
20
+ export declare const USAGE = "Usage: pacspace-check <history.json> [options]\n pacspace-check <history.json> --key <path>\n pacspace-check open [--link-file <path>] [--access-code-file <path>] [--copy <path>] [--html <path>] [--source <url> | --rpc <url>] [--timeout <ms>] [--json]\n pacspace-check release [--origin <url>] [--source <url> | --rpc <url>] [--timeout <ms>] [--json]\n pacspace-check release --origin <url> --release-record <record key>,<network id>,<contract>\n\nChecks a PacSpace record history file: every entry against what was\ncommitted, the file against its own fingerprint, and the record against\nthe 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.\n\nOptions:\n --fingerprint <0x...> the fingerprint printed on a statement; the checker\n says whether it names this file\n --held-file <path> check whether a verified entry names a file you hold\n --blinding <path> the blinding file for the file you hold, when its entry is blinded\n --history <path> the seal history or kept copy a disclosure is checked against\n --key <path> the record key for an encrypted history, read from this file (- for stdin)\n --link-file <path> open: read the link from this file instead of asking\n --access-code-file <path> open: read the access code from this file instead of asking\n --copy <path> open: save a kept copy of what the link shows to a new file\n --html <path> open: save the report as a page that opens without a network connection\n --offline check the file alone; do not read the proof layer\n --source <url> read the proof layer from this mirror instead of\n the one known for the record's network\n --rpc <url> read the proof layer over JSON-RPC at this URL\n --full also read every daily statement\n --no-lookup do not look up where each entry was committed\n --timeout <ms> network timeout per read (default 10000)\n --json print the report as JSON\n --version print the checker's version\n --help print this text\n\nExit codes: 0 the check passed as asked; 1 it did not, or the file you hold is not in it; 2 the history file, the link, a key, the file you hold, its blinding file or the arguments could not be used; 3 the proof layer or the link's host could not be reached. When more than one applies, 2 comes before 3, and 3 before 1.\n";
19
21
  export declare const BLINDING_FILE_INVALID_SENTENCE = "This is not a valid blinding file.";
20
22
  export declare const BLINDING_NEEDS_HELD_FILE_SENTENCE = "--blinding needs --held-file.";
21
23
  export declare const HISTORY_ONLY_FOR_DISCLOSURE_SENTENCE = "--history is used only with a disclosure file.";
package/dist/cli.js CHANGED
@@ -2108,6 +2108,50 @@ var MIRROR_NODE_BY_CHAIN = Object.freeze({
2108
2108
  295: "https://mainnet-public.mirrornode.hedera.com"
2109
2109
  });
2110
2110
 
2111
+ // ../shared/src/records/ledger-write-search-v1.ts
2112
+ var LEDGER_WRITE_SEARCH_WINDOW_LIMIT_SECONDS = 7 * 24 * 60 * 60;
2113
+ var HEX642 = /^0x[0-9a-f]{64}$/;
2114
+ var HEX_DATA = /^0x[0-9a-f]*$/;
2115
+ var TIMESTAMP = /^\d+(\.\d+)?$/;
2116
+ var NEXT_PATH = /^\/api\/v1\/contracts\//;
2117
+ function ledgerWriteSearchPath(input) {
2118
+ const query = `topic0=${input.topic0}&topic1=${input.recordKey}&timestamp=gte:${input.lower}&timestamp=lt:${input.upper}&order=desc&limit=100`;
2119
+ return `/api/v1/contracts/${input.contractAddress}/results/logs?${query}`;
2120
+ }
2121
+ function nextLedgerWritePath(next) {
2122
+ return typeof next === "string" && NEXT_PATH.test(next) ? next : null;
2123
+ }
2124
+ function parseLedgerWriteLog(log, expected) {
2125
+ if (!log || typeof log !== "object") return null;
2126
+ const raw = log;
2127
+ const topics = Array.isArray(raw.topics) ? raw.topics.map((topic) => String(topic).toLowerCase()) : [];
2128
+ if (topics[0] !== expected.topic0 || topics[1] !== expected.recordKey) return null;
2129
+ const data = typeof raw.data === "string" ? raw.data.toLowerCase() : "";
2130
+ const transactionHash = typeof raw.transaction_hash === "string" ? raw.transaction_hash.toLowerCase() : "";
2131
+ const timestamp = typeof raw.timestamp === "string" ? raw.timestamp : "";
2132
+ if (!HEX_DATA.test(data) || data.length < 2 + 64 * 3) return null;
2133
+ if (!HEX642.test(transactionHash) || !TIMESTAMP.test(timestamp)) return null;
2134
+ const encodingVersion = Number.parseInt(data.slice(2, 2 + 64).slice(-8), 16);
2135
+ const previousWord = data.slice(2 + 64, 2 + 64 * 2);
2136
+ const newWord = data.slice(2 + 64 * 2, 2 + 64 * 3);
2137
+ const [seconds, fraction = ""] = timestamp.split(".");
2138
+ const ms = Number(seconds) * 1e3 + Number(fraction.slice(0, 3).padEnd(3, "0"));
2139
+ if (!Number.isFinite(ms) || Math.abs(ms) > 864e13) return null;
2140
+ const address = typeof raw.address === "string" ? raw.address.toLowerCase() : null;
2141
+ return {
2142
+ transactionHash,
2143
+ timestamp,
2144
+ committedAt: new Date(ms).toISOString(),
2145
+ previousWord: `0x${previousWord}`,
2146
+ newWord: `0x${newWord}`,
2147
+ operator: HEX642.test(topics[2] ?? "") ? `0x${topics[2].slice(26)}` : "",
2148
+ encodingVersion,
2149
+ address,
2150
+ blockNumber: Number.isSafeInteger(raw.block_number) ? raw.block_number : null,
2151
+ logIndex: Number.isSafeInteger(raw.index) ? raw.index : null
2152
+ };
2153
+ }
2154
+
2111
2155
  // ../shared/src/demo/independent-verify-records.ts
2112
2156
  var import_ethers11 = require("ethers");
2113
2157
 
@@ -2365,6 +2409,67 @@ function createRpcRecordChainReader(options) {
2365
2409
  });
2366
2410
  }
2367
2411
  return out;
2412
+ },
2413
+ async findRecordWrites(recordKey, search) {
2414
+ const key = normalizeProofHash(recordKey, "recordKey");
2415
+ const now = search.now ?? Date.now;
2416
+ const deadline = now() + search.budgetMs;
2417
+ const writes = [];
2418
+ const blockTimes = /* @__PURE__ */ new Map();
2419
+ let requests = 0;
2420
+ const CUT = Symbol("cut");
2421
+ const within2 = async (p) => {
2422
+ const left = deadline - now();
2423
+ if (left <= 0) return CUT;
2424
+ let timer;
2425
+ const cut = new Promise((resolve3) => {
2426
+ timer = setTimeout(() => resolve3(CUT), left);
2427
+ });
2428
+ p.catch(() => void 0);
2429
+ try {
2430
+ return await Promise.race([p, cut]);
2431
+ } finally {
2432
+ if (timer) clearTimeout(timer);
2433
+ }
2434
+ };
2435
+ const end = (ended) => ({ writes, ended, requests });
2436
+ if (search.maxRequests < 1) return end("limit");
2437
+ requests += 1;
2438
+ const latest = await within2(provider.getBlockNumber());
2439
+ if (latest === CUT) return end("timeout");
2440
+ for (let to = latest; to >= 0; to -= chunk) {
2441
+ if (search.done(writes)) return end("done");
2442
+ if (requests >= search.maxRequests || now() >= deadline) return end("limit");
2443
+ requests += 1;
2444
+ const logs = await within2(provider.getLogs({ address: contractAddress, topics: [RECORD_WRITTEN_TOPIC, key], fromBlock: Math.max(0, to - chunk + 1), toBlock: to }));
2445
+ if (logs === CUT) return end("timeout");
2446
+ for (const log of [...logs].reverse()) {
2447
+ const parsed = iface.parseLog({ topics: [...log.topics], data: log.data });
2448
+ if (!parsed) continue;
2449
+ let committedAt = blockTimes.get(log.blockNumber);
2450
+ if (committedAt === void 0) {
2451
+ if (requests >= search.maxRequests || now() >= deadline) return end("limit");
2452
+ requests += 1;
2453
+ const block = await within2(provider.getBlock(log.blockNumber));
2454
+ if (block === CUT) return end("timeout");
2455
+ if (!block || !Number.isSafeInteger(block.timestamp)) throw new Error(`getBlock ${log.blockNumber} returned no time`);
2456
+ committedAt = new Date(block.timestamp * 1e3).toISOString();
2457
+ blockTimes.set(log.blockNumber, committedAt);
2458
+ }
2459
+ writes.push({
2460
+ previousWord: hex256(BigInt(parsed.args.previousWord)),
2461
+ newWord: hex256(BigInt(parsed.args.newWord)),
2462
+ operator: String(parsed.args.operator).toLowerCase(),
2463
+ encodingVersion: Number(parsed.args.encodingVersion),
2464
+ blockNumber: log.blockNumber,
2465
+ transactionHash: String(log.transactionHash).toLowerCase(),
2466
+ logIndex: log.index,
2467
+ committedAt,
2468
+ contractAddress: String(log.address).toLowerCase()
2469
+ });
2470
+ }
2471
+ }
2472
+ return end(search.done(writes) ? "done" : "limit");
2368
2473
  }
2369
2474
  };
2370
2475
  }
@@ -2445,6 +2550,14 @@ async function verifyBundleWithPublicLayer(input) {
2445
2550
  }
2446
2551
 
2447
2552
  // ../shared/src/demo/mirror-node-record-chain-reader.ts
2553
+ var RECORD_WRITE_SEARCH_WINDOW_SECONDS = 6 * 24 * 60 * 60;
2554
+ var DAY_SECONDS = 24 * 60 * 60;
2555
+ var CONSENSUS_TIMESTAMP = /^\d{1,12}\.\d{9}$/;
2556
+ function committedAtOf(timestamp) {
2557
+ if (typeof timestamp !== "string" || !CONSENSUS_TIMESTAMP.test(timestamp)) return void 0;
2558
+ const [seconds, fraction] = timestamp.split(".");
2559
+ return new Date(Number(seconds) * 1e3 + Number(fraction.slice(0, 3))).toISOString();
2560
+ }
2448
2561
  function createMirrorNodeRecordChainReader(options) {
2449
2562
  const chainId = options.chainId ?? 296;
2450
2563
  const base = (options.mirrorBaseUrl ?? MIRROR_NODE_BY_CHAIN[chainId] ?? "").replace(/\/+$/, "");
@@ -2498,7 +2611,18 @@ function createMirrorNodeRecordChainReader(options) {
2498
2611
  function matchesTopics(log, topics) {
2499
2612
  return topics.every((topic, index) => !topic || (log.topics[index] ?? "").toLowerCase() === topic.toLowerCase());
2500
2613
  }
2501
- async function scanLogs(topics, fromBlock, toBlock) {
2614
+ let keptLogs = null;
2615
+ function readAllLogs() {
2616
+ if (!options.keepLogPages) return readAllLogPages();
2617
+ if (!keptLogs) {
2618
+ keptLogs = readAllLogPages();
2619
+ keptLogs.catch(() => {
2620
+ keptLogs = null;
2621
+ });
2622
+ }
2623
+ return keptLogs;
2624
+ }
2625
+ async function readAllLogPages() {
2502
2626
  const params = new URLSearchParams();
2503
2627
  params.set("order", "asc");
2504
2628
  params.set("limit", String(pageSize));
@@ -2507,19 +2631,38 @@ function createMirrorNodeRecordChainReader(options) {
2507
2631
  let pages = 0;
2508
2632
  while (next) {
2509
2633
  const page = await request(next);
2510
- for (const log of page.logs ?? []) {
2511
- if (!matchesTopics(log, topics)) continue;
2512
- if (log.block_number < fromBlock) continue;
2513
- if (toBlock !== "latest" && log.block_number > toBlock) continue;
2514
- out.push(log);
2515
- }
2634
+ out.push(...page.logs ?? []);
2516
2635
  next = page.links?.next ?? null;
2517
2636
  pages += 1;
2518
2637
  if (pages > 1e4) throw new Error("mirror node log scan exceeded 10,000 pages");
2519
2638
  }
2639
+ return out;
2640
+ }
2641
+ async function scanLogs(topics, fromBlock, toBlock) {
2642
+ const out = [];
2643
+ for (const log of await readAllLogs()) {
2644
+ if (!matchesTopics(log, topics)) continue;
2645
+ if (log.block_number < fromBlock) continue;
2646
+ if (toBlock !== "latest" && log.block_number > toBlock) continue;
2647
+ out.push(log);
2648
+ }
2520
2649
  out.sort((a, b) => a.block_number - b.block_number || a.index - b.index);
2521
2650
  return out;
2522
2651
  }
2652
+ async function searchPage(path, ms) {
2653
+ const controller = new AbortController();
2654
+ const timer = setTimeout(() => controller.abort(), ms);
2655
+ try {
2656
+ const response = await fetchImpl(`${base}${path}`, { headers: { accept: "application/json" }, redirect: "error", signal: controller.signal });
2657
+ if (!response.ok) throw new Error(`mirror node ${response.status} for a record's writes`);
2658
+ return await response.json();
2659
+ } catch (error) {
2660
+ if (controller.signal.aborted) return "timeout";
2661
+ throw error;
2662
+ } finally {
2663
+ clearTimeout(timer);
2664
+ }
2665
+ }
2523
2666
  return {
2524
2667
  contractAddress,
2525
2668
  async getRecord(recordKey) {
@@ -2577,10 +2720,56 @@ function createMirrorNodeRecordChainReader(options) {
2577
2720
  encodingVersion: Number(parsed.args.encodingVersion),
2578
2721
  blockNumber: log.block_number,
2579
2722
  transactionHash: log.transaction_hash,
2580
- logIndex: log.index
2723
+ logIndex: log.index,
2724
+ committedAt: committedAtOf(log.timestamp),
2725
+ contractAddress: typeof log.address === "string" ? log.address.toLowerCase() : void 0
2581
2726
  });
2582
2727
  }
2583
2728
  return out;
2729
+ },
2730
+ async findRecordWrites(recordKey, search) {
2731
+ const key = normalizeProofHash(recordKey, "recordKey").toLowerCase();
2732
+ const topic0 = RECORD_WRITTEN_TOPIC.toLowerCase();
2733
+ const now = search.now ?? Date.now;
2734
+ const deadline = now() + search.budgetMs;
2735
+ const windowSeconds = Math.max(1, Math.floor(search.windowSeconds ?? RECORD_WRITE_SEARCH_WINDOW_SECONDS));
2736
+ const nowSeconds = Math.floor(now() / 1e3);
2737
+ const hint = search.startAt ? Date.parse(search.startAt) : Number.NaN;
2738
+ let upper = Math.min(Number.isFinite(hint) ? Math.floor(hint / 1e3) : nowSeconds, nowSeconds) + DAY_SECONDS;
2739
+ const writes = [];
2740
+ let requests = 0;
2741
+ const end = (ended) => ({ writes, ended, requests });
2742
+ while (!search.done(writes)) {
2743
+ if (upper <= 0) return end("limit");
2744
+ const lower = Math.max(0, upper - windowSeconds);
2745
+ let path = ledgerWriteSearchPath({ contractAddress, topic0, recordKey: key, lower, upper });
2746
+ while (path) {
2747
+ const left = deadline - now();
2748
+ if (requests >= search.maxRequests || left <= 0) return end("limit");
2749
+ requests += 1;
2750
+ const page = await searchPage(path, left);
2751
+ if (page === "timeout") return end("timeout");
2752
+ for (const log of Array.isArray(page.logs) ? page.logs : []) {
2753
+ const write = parseLedgerWriteLog(log, { topic0, recordKey: key });
2754
+ if (!write || write.address !== contractAddress || !CONSENSUS_TIMESTAMP.test(write.timestamp)) continue;
2755
+ writes.push({
2756
+ previousWord: write.previousWord,
2757
+ newWord: write.newWord,
2758
+ operator: write.operator,
2759
+ encodingVersion: write.encodingVersion,
2760
+ blockNumber: write.blockNumber ?? void 0,
2761
+ transactionHash: write.transactionHash,
2762
+ logIndex: write.logIndex ?? void 0,
2763
+ committedAt: write.committedAt,
2764
+ contractAddress: write.address
2765
+ });
2766
+ }
2767
+ if (search.done(writes)) return end("done");
2768
+ path = nextLedgerWritePath(page.links?.next);
2769
+ }
2770
+ upper = lower;
2771
+ }
2772
+ return end("done");
2584
2773
  }
2585
2774
  };
2586
2775
  }
@@ -3567,7 +3756,45 @@ function buildSealsReport(input) {
3567
3756
  exitCode
3568
3757
  };
3569
3758
  }
3570
- function renderReport(report) {
3759
+ var WRITES_HEADING = "Where each entry was committed on the proof layer:";
3760
+ 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.";
3761
+ var WRITES_LISTED_MAX = 25;
3762
+ function entriesLabel(numbers) {
3763
+ const sorted = [...numbers].sort((a, b) => a - b);
3764
+ const inARow = sorted.every((n, i) => i === 0 || n === sorted[i - 1] + 1);
3765
+ if (sorted.length >= 3 && inARow) return `Entries ${sorted[0]} to ${sorted[sorted.length - 1]}`;
3766
+ return listEntries(sorted);
3767
+ }
3768
+ function committedWhen(iso) {
3769
+ return `${dayOfUtc(iso)}, ${iso.slice(11, 19)} UTC`;
3770
+ }
3771
+ function writesNotFoundSentence(notFound, suggestFull) {
3772
+ const one = notFound.length === 1;
3773
+ return [
3774
+ `${entriesLabel(notFound)}: where ${one ? "it was" : "they were"} committed was not found in this read of the proof layer.`,
3775
+ ...suggestFull ? ["--full reads the record's whole history."] : [],
3776
+ "The check above does not depend on it."
3777
+ ].join(" ");
3778
+ }
3779
+ function writesNotListedSentence(count) {
3780
+ return `${count} more ${entryWord(count)} ${isAre(count)} not listed here. --json lists them all.`;
3781
+ }
3782
+ function writesLines(writes, suggestFull = true) {
3783
+ if (!writes) return [];
3784
+ if (!writes.read) return [WRITES_NOT_READ_SENTENCE];
3785
+ if (writes.entries.length === 0 && writes.notFound.length === 0) return [];
3786
+ const lines = [WRITES_HEADING];
3787
+ for (const write of writes.entries.slice(0, WRITES_LISTED_MAX)) {
3788
+ const line = `${entriesLabel(write.entries)}: committed ${committedWhen(write.committedAt)}`;
3789
+ if (write.link) lines.push(line, ` ${write.link}`);
3790
+ else lines.push(`${line}, write ${write.transactionHash}`);
3791
+ }
3792
+ const unlisted = writes.entries.slice(WRITES_LISTED_MAX).reduce((sum, write) => sum + write.entries.length, 0);
3793
+ if (unlisted > 0) lines.push(writesNotListedSentence(unlisted));
3794
+ if (writes.notFound.length > 0) lines.push(writesNotFoundSentence(writes.notFound, suggestFull));
3795
+ return lines;
3796
+ }
3797
+ function renderReport(report, options = {}) {
3571
3798
  const facts = [
3572
3799
  ["Reference", report.record.reference],
3573
3800
  ["Fingerprint of this history", report.file.fingerprint ?? "none"]
@@ -3577,14 +3804,128 @@ function renderReport(report) {
3577
3804
  const width = Math.max(...facts.map(([label]) => label.length));
3578
3805
  const lines = facts.map(([label, value]) => `${label.padEnd(width)} ${value}`);
3579
3806
  lines.push("");
3580
- lines.push(...report.sentences);
3807
+ const where = writesLines(report.writes, options.suggestFull ?? true);
3808
+ const after = where.length ? report.sentences.indexOf(sourceSentence(report.source)) : -1;
3809
+ if (after >= 0) lines.push(...report.sentences.slice(0, after + 1), ...where, ...report.sentences.slice(after + 1));
3810
+ else lines.push(...report.sentences, ...where);
3581
3811
  return `${lines.join("\n")}
3582
3812
  `;
3583
3813
  }
3584
3814
 
3815
+ // src/writes.ts
3816
+ var WRITES_LOOKUP_MAX_REQUESTS = 40;
3817
+ var WRITES_LOOKUP_DEFAULT_BUDGET_MS = 1e4;
3818
+ var HEX643 = /^0x[0-9a-f]{64}$/;
3819
+ var HEX40 = /^0x[0-9a-f]{40}$/;
3820
+ var ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
3821
+ var WRITE_EXPLORERS = Object.freeze({
3822
+ 295: "https://hashscan.io/mainnet/transaction/",
3823
+ 296: "https://hashscan.io/testnet/transaction/"
3824
+ });
3825
+ function writeLinkFor(source, chainId) {
3826
+ const base = (source ?? "mirror") === "mirror" && typeof chainId === "number" && Object.prototype.hasOwnProperty.call(WRITE_EXPLORERS, chainId) ? WRITE_EXPLORERS[chainId] : null;
3827
+ return (transactionHash) => base === null || !HEX643.test(transactionHash) ? null : `${base}${transactionHash}`;
3828
+ }
3829
+ function wantedEntriesOf(receipts, verifiedSeqs) {
3830
+ const out = [];
3831
+ for (const receipt of Array.isArray(receipts) ? receipts : []) {
3832
+ const { seq, previousWord, newWord } = receipt ?? {};
3833
+ if (typeof seq !== "number" || !Number.isSafeInteger(seq) || seq < 0 || !verifiedSeqs.has(seq)) continue;
3834
+ if (typeof previousWord !== "string" || typeof newWord !== "string") continue;
3835
+ const previous = previousWord.toLowerCase();
3836
+ const next = newWord.toLowerCase();
3837
+ if (!HEX643.test(previous) || !HEX643.test(next)) continue;
3838
+ out.push({ entry: seq + 1, previousWord: previous, newWord: next });
3839
+ }
3840
+ return out.sort((a, b) => a.entry - b.entry);
3841
+ }
3842
+ function printable(write, contractAddress) {
3843
+ return !!write && typeof write === "object" && typeof write.contractAddress === "string" && write.contractAddress.toLowerCase() === contractAddress && typeof write.transactionHash === "string" && HEX643.test(write.transactionHash.toLowerCase()) && typeof write.committedAt === "string" && ISO_INSTANT.test(write.committedAt) && Number.isFinite(Date.parse(write.committedAt)) && typeof write.previousWord === "string" && typeof write.newWord === "string" && HEX643.test(write.previousWord.toLowerCase()) && HEX643.test(write.newWord.toLowerCase());
3844
+ }
3845
+ function hitsFor(entry, writes, contractAddress) {
3846
+ const seen = /* @__PURE__ */ new Map();
3847
+ for (const write of Array.isArray(writes) ? writes : []) {
3848
+ if (!printable(write, contractAddress)) continue;
3849
+ if (write.previousWord.toLowerCase() !== entry.previousWord || write.newWord.toLowerCase() !== entry.newWord) continue;
3850
+ seen.set(`${write.transactionHash.toLowerCase()}:${write.logIndex ?? ""}`, write);
3851
+ }
3852
+ return [...seen.values()];
3853
+ }
3854
+ async function within(p, ms) {
3855
+ let timer;
3856
+ const cut = new Promise((resolve3) => {
3857
+ timer = setTimeout(() => resolve3("cut"), Math.max(0, ms));
3858
+ });
3859
+ p.catch(() => void 0);
3860
+ try {
3861
+ return await Promise.race([p, cut]);
3862
+ } finally {
3863
+ if (timer) clearTimeout(timer);
3864
+ }
3865
+ }
3866
+ async function lookUpWrites(input) {
3867
+ try {
3868
+ const contractAddress = String(input.contractAddress ?? "").toLowerCase();
3869
+ if (!HEX40.test(contractAddress)) return { read: false, reason: "unreachable" };
3870
+ if (input.wanted.length === 0) return { read: true, entries: [], notFound: [] };
3871
+ const done = (writes2) => input.wanted.every((entry) => hitsFor(entry, writes2, contractAddress).length > 0);
3872
+ let writes;
3873
+ let cutOff = false;
3874
+ if (input.whole) {
3875
+ const all = await within(input.reader.getRecordWrites(input.recordKey), input.budgetMs);
3876
+ if (all === "cut") return { read: false, reason: "timeout" };
3877
+ writes = all;
3878
+ } else {
3879
+ if (!input.reader.findRecordWrites) return { read: false, reason: "unreachable" };
3880
+ const result = await within(
3881
+ input.reader.findRecordWrites(input.recordKey, {
3882
+ startAt: input.startAt,
3883
+ done,
3884
+ budgetMs: input.budgetMs,
3885
+ maxRequests: WRITES_LOOKUP_MAX_REQUESTS,
3886
+ windowSeconds: input.windowSeconds,
3887
+ now: input.now
3888
+ }),
3889
+ input.budgetMs + 250
3890
+ );
3891
+ if (result === "cut") return { read: false, reason: "timeout" };
3892
+ writes = result.writes;
3893
+ cutOff = result.ended === "timeout";
3894
+ }
3895
+ const byTransaction = /* @__PURE__ */ new Map();
3896
+ const notFound = [];
3897
+ for (const entry of input.wanted) {
3898
+ const hits = hitsFor(entry, writes, contractAddress);
3899
+ if (hits.length !== 1) {
3900
+ notFound.push(entry.entry);
3901
+ continue;
3902
+ }
3903
+ const transactionHash = hits[0].transactionHash.toLowerCase();
3904
+ const group = byTransaction.get(transactionHash);
3905
+ if (group) {
3906
+ group.entries.push(entry.entry);
3907
+ continue;
3908
+ }
3909
+ const link = input.linkFor(transactionHash);
3910
+ byTransaction.set(transactionHash, {
3911
+ entries: [entry.entry],
3912
+ committedAt: hits[0].committedAt,
3913
+ transactionHash,
3914
+ blockNumber: Number.isSafeInteger(hits[0].blockNumber) ? hits[0].blockNumber : null,
3915
+ link: typeof link === "string" ? link : null
3916
+ });
3917
+ }
3918
+ const entries = [...byTransaction.values()].sort((a, b) => a.entries[0] - b.entries[0]);
3919
+ if (cutOff && entries.length === 0) return { read: false, reason: "timeout" };
3920
+ return { read: true, entries, notFound };
3921
+ } catch {
3922
+ return { read: false, reason: "unreachable" };
3923
+ }
3924
+ }
3925
+
3585
3926
  // src/check.ts
3586
3927
  var CHECKER_NAME = "@pacspace-io/check";
3587
- var CHECKER_VERSION = true ? "0.5.3" : "0.0.0-dev";
3928
+ var CHECKER_VERSION = true ? "0.5.4" : "0.0.0-dev";
3588
3929
  var HISTORY_SCHEMAS = [
3589
3930
  RECORD_HISTORY_BUNDLE_SCHEMA_V1,
3590
3931
  RECORD_HISTORY_BUNDLE_SCHEMA_V2,
@@ -3689,11 +4030,36 @@ function readerFor(chain, options) {
3689
4030
  chainId,
3690
4031
  contractAddress,
3691
4032
  timeoutMs: options.timeoutMs,
3692
- fetchImpl: options.fetchImpl
4033
+ fetchImpl: options.fetchImpl,
4034
+ // With --full the run reads the contract's whole log once; the lookup then asks nothing more.
4035
+ keepLogPages: !!options.writes && !!options.full
3693
4036
  }),
3694
4037
  readsFrom: mirrorBaseUrl
3695
4038
  };
3696
4039
  }
4040
+ async function withWrites(report, bundle, verification, reader, options) {
4041
+ if (!options.writes || !reader || !report.passed || !report.file.intact || !report.source.compared || !report.source.matches) return report;
4042
+ let writes;
4043
+ try {
4044
+ const source = options.source ?? "mirror";
4045
+ const verified = new Set((verification.history?.perReceipt ?? []).filter((row) => row.result.verified).map((row) => row.seq));
4046
+ writes = await lookUpWrites({
4047
+ reader,
4048
+ recordKey: String(bundle.recordKey),
4049
+ contractAddress: String(bundle.chain?.contractAddress ?? ""),
4050
+ wanted: wantedEntriesOf(bundle.receipts, verified),
4051
+ startAt: typeof bundle.exportedAt === "string" ? bundle.exportedAt : null,
4052
+ whole: !!options.full && typeof source === "string",
4053
+ budgetMs: options.timeoutMs ?? WRITES_LOOKUP_DEFAULT_BUDGET_MS,
4054
+ linkFor: writeLinkFor(source, bundle.chain?.chainId),
4055
+ windowSeconds: options.writesWindowSeconds,
4056
+ now: options.writesNow
4057
+ });
4058
+ } catch {
4059
+ writes = { read: false, reason: "unreachable" };
4060
+ }
4061
+ return { ...report, writes };
4062
+ }
3697
4063
  var PAYLOAD_POINTER = /^\/payloads\/(0|[1-9][0-9]*)$/;
3698
4064
  function disclosureNamesAFile(disclosure) {
3699
4065
  const entries = disclosure?.entries;
@@ -3858,9 +4224,11 @@ async function checkBundle(file, options) {
3858
4224
  let source;
3859
4225
  let verification = offline;
3860
4226
  let sequence = null;
4227
+ let sourceReader = null;
3861
4228
  try {
3862
4229
  const found = readerFor(bundle.chain, options);
3863
4230
  const reader = options.full ? memoizeSequenceReads(found.reader) : found.reader;
4231
+ sourceReader = reader;
3864
4232
  const level = options.full ? "ledger" : "semantic";
3865
4233
  const live = v2 ? await verifyBundleV2WithSource(reader, file, level, layouts) : await verifyBundleWithPublicLayer({ reader, bundle, level, layouts });
3866
4234
  if (options.full) {
@@ -3881,13 +4249,14 @@ async function checkBundle(file, options) {
3881
4249
  if (error instanceof HistoryFileError) throw error;
3882
4250
  source = { compared: false, reason: "unreachable", detail: error.message };
3883
4251
  }
3884
- return buildReport({
4252
+ const report = buildReport({
3885
4253
  ...base,
3886
4254
  verification,
3887
4255
  source,
3888
4256
  dailyStatement: dailyStatementOf(file, verification.verified, sequence),
3889
4257
  heldFile: heldOf(verification, false)
3890
4258
  });
4259
+ return withWrites(report, bundle, verification, sourceReader, options);
3891
4260
  }
3892
4261
  function encryptedRefusalSentence(refusal) {
3893
4262
  const entry = typeof refusal.seq === "number" ? refusal.seq + 1 : null;
@@ -3968,9 +4337,11 @@ async function checkEncrypted(file, bundle, recordKey, options) {
3968
4337
  let source;
3969
4338
  let result = offline;
3970
4339
  let sequence = null;
4340
+ let sourceReader = null;
3971
4341
  try {
3972
4342
  const found = readerFor(bundle.chain, options);
3973
4343
  const reader = options.full ? memoizeSequenceReads(found.reader) : found.reader;
4344
+ sourceReader = reader;
3974
4345
  const contractMatches = !!bundle.chain?.contractAddress && bundle.chain.contractAddress.toLowerCase() === reader.contractAddress.toLowerCase();
3975
4346
  const chainWord = await reader.getRecord(bundle.recordKey);
3976
4347
  const onChainLayout = await reader.getLayout(bundle.layout.layoutId);
@@ -4001,7 +4372,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4001
4372
  if (error instanceof HistoryFileError) throw error;
4002
4373
  source = { compared: false, reason: "unreachable", detail: error.message };
4003
4374
  }
4004
- return buildReport({
4375
+ const report = buildReport({
4005
4376
  ...base,
4006
4377
  verification: result.verification,
4007
4378
  source,
@@ -4009,6 +4380,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
4009
4380
  heldFile: heldOf(result.verification, result.opened, false),
4010
4381
  encrypted
4011
4382
  });
4383
+ return withWrites(report, bundle, result.verification, sourceReader, options);
4012
4384
  }
4013
4385
  function entryCountOf(form, layouts) {
4014
4386
  if (!form || typeof form.currentWord !== "string") return null;
@@ -4792,6 +5164,7 @@ Options:
4792
5164
  the one known for the record's network
4793
5165
  --rpc <url> read the proof layer over JSON-RPC at this URL
4794
5166
  --full also read every daily statement
5167
+ --no-lookup do not look up where each entry was committed
4795
5168
  --timeout <ms> network timeout per read (default 10000)
4796
5169
  --json print the report as JSON
4797
5170
  --version print the checker's version
@@ -4815,7 +5188,8 @@ function parseArgs(argv) {
4815
5188
  heldFile: null,
4816
5189
  blinding: null,
4817
5190
  history: null,
4818
- key: null
5191
+ key: null,
5192
+ noLookup: false
4819
5193
  };
4820
5194
  const takeValue = (flag, index) => {
4821
5195
  const value = argv[index + 1];
@@ -4841,6 +5215,9 @@ function parseArgs(argv) {
4841
5215
  case "--full":
4842
5216
  args.full = true;
4843
5217
  break;
5218
+ case "--no-lookup":
5219
+ args.noLookup = true;
5220
+ break;
4844
5221
  case "--fingerprint":
4845
5222
  args.statementFingerprint = takeValue(arg, index);
4846
5223
  index += 1;
@@ -5144,10 +5521,13 @@ ${USAGE}`.trimEnd());
5144
5521
  fetchImpl: io.fetchImpl,
5145
5522
  history,
5146
5523
  heldFile,
5147
- recordKey
5524
+ recordKey,
5525
+ // Where each entry was committed: asked only here, for a check that reads the proof layer.
5526
+ writes: args.source !== "offline" && !args.noLookup
5148
5527
  });
5528
+ const suggestFull = !(args.full && typeof args.source === "string");
5149
5529
  io.stdout(args.json ? `${JSON.stringify(report, null, 2)}
5150
- ` : renderReport(report));
5530
+ ` : renderReport(report, { suggestFull }));
5151
5531
  return report.exitCode;
5152
5532
  } finally {
5153
5533
  recordKey?.fill(0);
package/dist/index.d.ts CHANGED
@@ -9,4 +9,4 @@ export type { CheckOptions, HistoryFile, HistorySchema, StatementSequence } from
9
9
  export { checkRelease, DEFAULT_RELEASE_ORIGIN, releaseWords, RELEASES_SCHEMA, RELEASE_MANIFEST_FORMAT } from './release';
10
10
  export type { ReleaseDifference, ReleaseOptions, ReleaseReport } from './release';
11
11
  export { buildReport, buildSealsReport, countedSentence, dailyStatementSentence, dayOfUtc, fingerprintSentence, FILE_CHANGED_SENTENCE, HONESTY_SENTENCE, renderReport, REPORT_SCHEMA, SEALS_BOUNDARY_SENTENCE, sourceSentence, } from './report';
12
- export type { CheckReport, DailyStatementOutcome, DisclosureOutcome, HeldFileOutcome, ReportInput, SealsReportInput, SourceOutcome, VerificationFacts, } from './report';
12
+ export type { CheckReport, DailyStatementOutcome, DisclosureOutcome, HeldFileOutcome, ReportInput, SealsReportInput, SourceOutcome, VerificationFacts, EntryWrite, WritesOutcome, } from './report';
package/dist/index.js CHANGED
@@ -2108,6 +2108,50 @@ var MIRROR_NODE_BY_CHAIN = Object.freeze({
2108
2108
  295: "https://mainnet-public.mirrornode.hedera.com"
2109
2109
  });
2110
2110
 
2111
+ // ../shared/src/records/ledger-write-search-v1.ts
2112
+ var LEDGER_WRITE_SEARCH_WINDOW_LIMIT_SECONDS = 7 * 24 * 60 * 60;
2113
+ var HEX642 = /^0x[0-9a-f]{64}$/;
2114
+ var HEX_DATA = /^0x[0-9a-f]*$/;
2115
+ var TIMESTAMP = /^\d+(\.\d+)?$/;
2116
+ var NEXT_PATH = /^\/api\/v1\/contracts\//;
2117
+ function ledgerWriteSearchPath(input) {
2118
+ const query = `topic0=${input.topic0}&topic1=${input.recordKey}&timestamp=gte:${input.lower}&timestamp=lt:${input.upper}&order=desc&limit=100`;
2119
+ return `/api/v1/contracts/${input.contractAddress}/results/logs?${query}`;
2120
+ }
2121
+ function nextLedgerWritePath(next) {
2122
+ return typeof next === "string" && NEXT_PATH.test(next) ? next : null;
2123
+ }
2124
+ function parseLedgerWriteLog(log, expected) {
2125
+ if (!log || typeof log !== "object") return null;
2126
+ const raw = log;
2127
+ const topics = Array.isArray(raw.topics) ? raw.topics.map((topic) => String(topic).toLowerCase()) : [];
2128
+ if (topics[0] !== expected.topic0 || topics[1] !== expected.recordKey) return null;
2129
+ const data = typeof raw.data === "string" ? raw.data.toLowerCase() : "";
2130
+ const transactionHash = typeof raw.transaction_hash === "string" ? raw.transaction_hash.toLowerCase() : "";
2131
+ const timestamp = typeof raw.timestamp === "string" ? raw.timestamp : "";
2132
+ if (!HEX_DATA.test(data) || data.length < 2 + 64 * 3) return null;
2133
+ if (!HEX642.test(transactionHash) || !TIMESTAMP.test(timestamp)) return null;
2134
+ const encodingVersion = Number.parseInt(data.slice(2, 2 + 64).slice(-8), 16);
2135
+ const previousWord = data.slice(2 + 64, 2 + 64 * 2);
2136
+ const newWord = data.slice(2 + 64 * 2, 2 + 64 * 3);
2137
+ const [seconds, fraction = ""] = timestamp.split(".");
2138
+ const ms = Number(seconds) * 1e3 + Number(fraction.slice(0, 3).padEnd(3, "0"));
2139
+ if (!Number.isFinite(ms) || Math.abs(ms) > 864e13) return null;
2140
+ const address = typeof raw.address === "string" ? raw.address.toLowerCase() : null;
2141
+ return {
2142
+ transactionHash,
2143
+ timestamp,
2144
+ committedAt: new Date(ms).toISOString(),
2145
+ previousWord: `0x${previousWord}`,
2146
+ newWord: `0x${newWord}`,
2147
+ operator: HEX642.test(topics[2] ?? "") ? `0x${topics[2].slice(26)}` : "",
2148
+ encodingVersion,
2149
+ address,
2150
+ blockNumber: Number.isSafeInteger(raw.block_number) ? raw.block_number : null,
2151
+ logIndex: Number.isSafeInteger(raw.index) ? raw.index : null
2152
+ };
2153
+ }
2154
+
2111
2155
  // ../shared/src/demo/independent-verify-records.ts
2112
2156
  var import_ethers11 = require("ethers");
2113
2157
 
@@ -2365,6 +2409,67 @@ function createRpcRecordChainReader(options) {
2365
2409
  });
2366
2410
  }
2367
2411
  return out;
2412
+ },
2413
+ async findRecordWrites(recordKey, search) {
2414
+ const key = normalizeProofHash(recordKey, "recordKey");
2415
+ const now = search.now ?? Date.now;
2416
+ const deadline = now() + search.budgetMs;
2417
+ const writes = [];
2418
+ const blockTimes = /* @__PURE__ */ new Map();
2419
+ let requests = 0;
2420
+ const CUT = Symbol("cut");
2421
+ const within2 = async (p) => {
2422
+ const left = deadline - now();
2423
+ if (left <= 0) return CUT;
2424
+ let timer;
2425
+ const cut = new Promise((resolve) => {
2426
+ timer = setTimeout(() => resolve(CUT), left);
2427
+ });
2428
+ p.catch(() => void 0);
2429
+ try {
2430
+ return await Promise.race([p, cut]);
2431
+ } finally {
2432
+ if (timer) clearTimeout(timer);
2433
+ }
2434
+ };
2435
+ const end = (ended) => ({ writes, ended, requests });
2436
+ if (search.maxRequests < 1) return end("limit");
2437
+ requests += 1;
2438
+ const latest = await within2(provider.getBlockNumber());
2439
+ if (latest === CUT) return end("timeout");
2440
+ for (let to = latest; to >= 0; to -= chunk) {
2441
+ if (search.done(writes)) return end("done");
2442
+ if (requests >= search.maxRequests || now() >= deadline) return end("limit");
2443
+ requests += 1;
2444
+ const logs = await within2(provider.getLogs({ address: contractAddress, topics: [RECORD_WRITTEN_TOPIC, key], fromBlock: Math.max(0, to - chunk + 1), toBlock: to }));
2445
+ if (logs === CUT) return end("timeout");
2446
+ for (const log of [...logs].reverse()) {
2447
+ const parsed = iface.parseLog({ topics: [...log.topics], data: log.data });
2448
+ if (!parsed) continue;
2449
+ let committedAt = blockTimes.get(log.blockNumber);
2450
+ if (committedAt === void 0) {
2451
+ if (requests >= search.maxRequests || now() >= deadline) return end("limit");
2452
+ requests += 1;
2453
+ const block = await within2(provider.getBlock(log.blockNumber));
2454
+ if (block === CUT) return end("timeout");
2455
+ if (!block || !Number.isSafeInteger(block.timestamp)) throw new Error(`getBlock ${log.blockNumber} returned no time`);
2456
+ committedAt = new Date(block.timestamp * 1e3).toISOString();
2457
+ blockTimes.set(log.blockNumber, committedAt);
2458
+ }
2459
+ writes.push({
2460
+ previousWord: hex256(BigInt(parsed.args.previousWord)),
2461
+ newWord: hex256(BigInt(parsed.args.newWord)),
2462
+ operator: String(parsed.args.operator).toLowerCase(),
2463
+ encodingVersion: Number(parsed.args.encodingVersion),
2464
+ blockNumber: log.blockNumber,
2465
+ transactionHash: String(log.transactionHash).toLowerCase(),
2466
+ logIndex: log.index,
2467
+ committedAt,
2468
+ contractAddress: String(log.address).toLowerCase()
2469
+ });
2470
+ }
2471
+ }
2472
+ return end(search.done(writes) ? "done" : "limit");
2368
2473
  }
2369
2474
  };
2370
2475
  }
@@ -2445,6 +2550,14 @@ async function verifyBundleWithPublicLayer(input) {
2445
2550
  }
2446
2551
 
2447
2552
  // ../shared/src/demo/mirror-node-record-chain-reader.ts
2553
+ var RECORD_WRITE_SEARCH_WINDOW_SECONDS = 6 * 24 * 60 * 60;
2554
+ var DAY_SECONDS = 24 * 60 * 60;
2555
+ var CONSENSUS_TIMESTAMP = /^\d{1,12}\.\d{9}$/;
2556
+ function committedAtOf(timestamp) {
2557
+ if (typeof timestamp !== "string" || !CONSENSUS_TIMESTAMP.test(timestamp)) return void 0;
2558
+ const [seconds, fraction] = timestamp.split(".");
2559
+ return new Date(Number(seconds) * 1e3 + Number(fraction.slice(0, 3))).toISOString();
2560
+ }
2448
2561
  function createMirrorNodeRecordChainReader(options) {
2449
2562
  const chainId = options.chainId ?? 296;
2450
2563
  const base = (options.mirrorBaseUrl ?? MIRROR_NODE_BY_CHAIN[chainId] ?? "").replace(/\/+$/, "");
@@ -2498,7 +2611,18 @@ function createMirrorNodeRecordChainReader(options) {
2498
2611
  function matchesTopics(log, topics) {
2499
2612
  return topics.every((topic, index) => !topic || (log.topics[index] ?? "").toLowerCase() === topic.toLowerCase());
2500
2613
  }
2501
- async function scanLogs(topics, fromBlock, toBlock) {
2614
+ let keptLogs = null;
2615
+ function readAllLogs() {
2616
+ if (!options.keepLogPages) return readAllLogPages();
2617
+ if (!keptLogs) {
2618
+ keptLogs = readAllLogPages();
2619
+ keptLogs.catch(() => {
2620
+ keptLogs = null;
2621
+ });
2622
+ }
2623
+ return keptLogs;
2624
+ }
2625
+ async function readAllLogPages() {
2502
2626
  const params = new URLSearchParams();
2503
2627
  params.set("order", "asc");
2504
2628
  params.set("limit", String(pageSize));
@@ -2507,19 +2631,38 @@ function createMirrorNodeRecordChainReader(options) {
2507
2631
  let pages = 0;
2508
2632
  while (next) {
2509
2633
  const page = await request(next);
2510
- for (const log of page.logs ?? []) {
2511
- if (!matchesTopics(log, topics)) continue;
2512
- if (log.block_number < fromBlock) continue;
2513
- if (toBlock !== "latest" && log.block_number > toBlock) continue;
2514
- out.push(log);
2515
- }
2634
+ out.push(...page.logs ?? []);
2516
2635
  next = page.links?.next ?? null;
2517
2636
  pages += 1;
2518
2637
  if (pages > 1e4) throw new Error("mirror node log scan exceeded 10,000 pages");
2519
2638
  }
2639
+ return out;
2640
+ }
2641
+ async function scanLogs(topics, fromBlock, toBlock) {
2642
+ const out = [];
2643
+ for (const log of await readAllLogs()) {
2644
+ if (!matchesTopics(log, topics)) continue;
2645
+ if (log.block_number < fromBlock) continue;
2646
+ if (toBlock !== "latest" && log.block_number > toBlock) continue;
2647
+ out.push(log);
2648
+ }
2520
2649
  out.sort((a, b) => a.block_number - b.block_number || a.index - b.index);
2521
2650
  return out;
2522
2651
  }
2652
+ async function searchPage(path, ms) {
2653
+ const controller = new AbortController();
2654
+ const timer = setTimeout(() => controller.abort(), ms);
2655
+ try {
2656
+ const response = await fetchImpl(`${base}${path}`, { headers: { accept: "application/json" }, redirect: "error", signal: controller.signal });
2657
+ if (!response.ok) throw new Error(`mirror node ${response.status} for a record's writes`);
2658
+ return await response.json();
2659
+ } catch (error) {
2660
+ if (controller.signal.aborted) return "timeout";
2661
+ throw error;
2662
+ } finally {
2663
+ clearTimeout(timer);
2664
+ }
2665
+ }
2523
2666
  return {
2524
2667
  contractAddress,
2525
2668
  async getRecord(recordKey) {
@@ -2577,10 +2720,56 @@ function createMirrorNodeRecordChainReader(options) {
2577
2720
  encodingVersion: Number(parsed.args.encodingVersion),
2578
2721
  blockNumber: log.block_number,
2579
2722
  transactionHash: log.transaction_hash,
2580
- logIndex: log.index
2723
+ logIndex: log.index,
2724
+ committedAt: committedAtOf(log.timestamp),
2725
+ contractAddress: typeof log.address === "string" ? log.address.toLowerCase() : void 0
2581
2726
  });
2582
2727
  }
2583
2728
  return out;
2729
+ },
2730
+ async findRecordWrites(recordKey, search) {
2731
+ const key = normalizeProofHash(recordKey, "recordKey").toLowerCase();
2732
+ const topic0 = RECORD_WRITTEN_TOPIC.toLowerCase();
2733
+ const now = search.now ?? Date.now;
2734
+ const deadline = now() + search.budgetMs;
2735
+ const windowSeconds = Math.max(1, Math.floor(search.windowSeconds ?? RECORD_WRITE_SEARCH_WINDOW_SECONDS));
2736
+ const nowSeconds = Math.floor(now() / 1e3);
2737
+ const hint = search.startAt ? Date.parse(search.startAt) : Number.NaN;
2738
+ let upper = Math.min(Number.isFinite(hint) ? Math.floor(hint / 1e3) : nowSeconds, nowSeconds) + DAY_SECONDS;
2739
+ const writes = [];
2740
+ let requests = 0;
2741
+ const end = (ended) => ({ writes, ended, requests });
2742
+ while (!search.done(writes)) {
2743
+ if (upper <= 0) return end("limit");
2744
+ const lower = Math.max(0, upper - windowSeconds);
2745
+ let path = ledgerWriteSearchPath({ contractAddress, topic0, recordKey: key, lower, upper });
2746
+ while (path) {
2747
+ const left = deadline - now();
2748
+ if (requests >= search.maxRequests || left <= 0) return end("limit");
2749
+ requests += 1;
2750
+ const page = await searchPage(path, left);
2751
+ if (page === "timeout") return end("timeout");
2752
+ for (const log of Array.isArray(page.logs) ? page.logs : []) {
2753
+ const write = parseLedgerWriteLog(log, { topic0, recordKey: key });
2754
+ if (!write || write.address !== contractAddress || !CONSENSUS_TIMESTAMP.test(write.timestamp)) continue;
2755
+ writes.push({
2756
+ previousWord: write.previousWord,
2757
+ newWord: write.newWord,
2758
+ operator: write.operator,
2759
+ encodingVersion: write.encodingVersion,
2760
+ blockNumber: write.blockNumber ?? void 0,
2761
+ transactionHash: write.transactionHash,
2762
+ logIndex: write.logIndex ?? void 0,
2763
+ committedAt: write.committedAt,
2764
+ contractAddress: write.address
2765
+ });
2766
+ }
2767
+ if (search.done(writes)) return end("done");
2768
+ path = nextLedgerWritePath(page.links?.next);
2769
+ }
2770
+ upper = lower;
2771
+ }
2772
+ return end("done");
2584
2773
  }
2585
2774
  };
2586
2775
  }
@@ -3419,7 +3608,45 @@ function buildSealsReport(input) {
3419
3608
  exitCode
3420
3609
  };
3421
3610
  }
3422
- function renderReport(report) {
3611
+ var WRITES_HEADING = "Where each entry was committed on the proof layer:";
3612
+ 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.";
3613
+ var WRITES_LISTED_MAX = 25;
3614
+ function entriesLabel(numbers) {
3615
+ const sorted = [...numbers].sort((a, b) => a - b);
3616
+ const inARow = sorted.every((n, i) => i === 0 || n === sorted[i - 1] + 1);
3617
+ if (sorted.length >= 3 && inARow) return `Entries ${sorted[0]} to ${sorted[sorted.length - 1]}`;
3618
+ return listEntries(sorted);
3619
+ }
3620
+ function committedWhen(iso) {
3621
+ return `${dayOfUtc(iso)}, ${iso.slice(11, 19)} UTC`;
3622
+ }
3623
+ function writesNotFoundSentence(notFound, suggestFull) {
3624
+ const one = notFound.length === 1;
3625
+ return [
3626
+ `${entriesLabel(notFound)}: where ${one ? "it was" : "they were"} committed was not found in this read of the proof layer.`,
3627
+ ...suggestFull ? ["--full reads the record's whole history."] : [],
3628
+ "The check above does not depend on it."
3629
+ ].join(" ");
3630
+ }
3631
+ function writesNotListedSentence(count) {
3632
+ return `${count} more ${entryWord(count)} ${isAre(count)} not listed here. --json lists them all.`;
3633
+ }
3634
+ function writesLines(writes, suggestFull = true) {
3635
+ if (!writes) return [];
3636
+ if (!writes.read) return [WRITES_NOT_READ_SENTENCE];
3637
+ if (writes.entries.length === 0 && writes.notFound.length === 0) return [];
3638
+ const lines = [WRITES_HEADING];
3639
+ for (const write of writes.entries.slice(0, WRITES_LISTED_MAX)) {
3640
+ const line = `${entriesLabel(write.entries)}: committed ${committedWhen(write.committedAt)}`;
3641
+ if (write.link) lines.push(line, ` ${write.link}`);
3642
+ else lines.push(`${line}, write ${write.transactionHash}`);
3643
+ }
3644
+ const unlisted = writes.entries.slice(WRITES_LISTED_MAX).reduce((sum, write) => sum + write.entries.length, 0);
3645
+ if (unlisted > 0) lines.push(writesNotListedSentence(unlisted));
3646
+ if (writes.notFound.length > 0) lines.push(writesNotFoundSentence(writes.notFound, suggestFull));
3647
+ return lines;
3648
+ }
3649
+ function renderReport(report, options = {}) {
3423
3650
  const facts = [
3424
3651
  ["Reference", report.record.reference],
3425
3652
  ["Fingerprint of this history", report.file.fingerprint ?? "none"]
@@ -3429,14 +3656,128 @@ function renderReport(report) {
3429
3656
  const width = Math.max(...facts.map(([label]) => label.length));
3430
3657
  const lines = facts.map(([label, value]) => `${label.padEnd(width)} ${value}`);
3431
3658
  lines.push("");
3432
- lines.push(...report.sentences);
3659
+ const where = writesLines(report.writes, options.suggestFull ?? true);
3660
+ const after = where.length ? report.sentences.indexOf(sourceSentence(report.source)) : -1;
3661
+ if (after >= 0) lines.push(...report.sentences.slice(0, after + 1), ...where, ...report.sentences.slice(after + 1));
3662
+ else lines.push(...report.sentences, ...where);
3433
3663
  return `${lines.join("\n")}
3434
3664
  `;
3435
3665
  }
3436
3666
 
3667
+ // src/writes.ts
3668
+ var WRITES_LOOKUP_MAX_REQUESTS = 40;
3669
+ var WRITES_LOOKUP_DEFAULT_BUDGET_MS = 1e4;
3670
+ var HEX643 = /^0x[0-9a-f]{64}$/;
3671
+ var HEX40 = /^0x[0-9a-f]{40}$/;
3672
+ var ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
3673
+ var WRITE_EXPLORERS = Object.freeze({
3674
+ 295: "https://hashscan.io/mainnet/transaction/",
3675
+ 296: "https://hashscan.io/testnet/transaction/"
3676
+ });
3677
+ function writeLinkFor(source, chainId) {
3678
+ const base = (source ?? "mirror") === "mirror" && typeof chainId === "number" && Object.prototype.hasOwnProperty.call(WRITE_EXPLORERS, chainId) ? WRITE_EXPLORERS[chainId] : null;
3679
+ return (transactionHash) => base === null || !HEX643.test(transactionHash) ? null : `${base}${transactionHash}`;
3680
+ }
3681
+ function wantedEntriesOf(receipts, verifiedSeqs) {
3682
+ const out = [];
3683
+ for (const receipt of Array.isArray(receipts) ? receipts : []) {
3684
+ const { seq, previousWord, newWord } = receipt ?? {};
3685
+ if (typeof seq !== "number" || !Number.isSafeInteger(seq) || seq < 0 || !verifiedSeqs.has(seq)) continue;
3686
+ if (typeof previousWord !== "string" || typeof newWord !== "string") continue;
3687
+ const previous = previousWord.toLowerCase();
3688
+ const next = newWord.toLowerCase();
3689
+ if (!HEX643.test(previous) || !HEX643.test(next)) continue;
3690
+ out.push({ entry: seq + 1, previousWord: previous, newWord: next });
3691
+ }
3692
+ return out.sort((a, b) => a.entry - b.entry);
3693
+ }
3694
+ function printable(write, contractAddress) {
3695
+ return !!write && typeof write === "object" && typeof write.contractAddress === "string" && write.contractAddress.toLowerCase() === contractAddress && typeof write.transactionHash === "string" && HEX643.test(write.transactionHash.toLowerCase()) && typeof write.committedAt === "string" && ISO_INSTANT.test(write.committedAt) && Number.isFinite(Date.parse(write.committedAt)) && typeof write.previousWord === "string" && typeof write.newWord === "string" && HEX643.test(write.previousWord.toLowerCase()) && HEX643.test(write.newWord.toLowerCase());
3696
+ }
3697
+ function hitsFor(entry, writes, contractAddress) {
3698
+ const seen = /* @__PURE__ */ new Map();
3699
+ for (const write of Array.isArray(writes) ? writes : []) {
3700
+ if (!printable(write, contractAddress)) continue;
3701
+ if (write.previousWord.toLowerCase() !== entry.previousWord || write.newWord.toLowerCase() !== entry.newWord) continue;
3702
+ seen.set(`${write.transactionHash.toLowerCase()}:${write.logIndex ?? ""}`, write);
3703
+ }
3704
+ return [...seen.values()];
3705
+ }
3706
+ async function within(p, ms) {
3707
+ let timer;
3708
+ const cut = new Promise((resolve) => {
3709
+ timer = setTimeout(() => resolve("cut"), Math.max(0, ms));
3710
+ });
3711
+ p.catch(() => void 0);
3712
+ try {
3713
+ return await Promise.race([p, cut]);
3714
+ } finally {
3715
+ if (timer) clearTimeout(timer);
3716
+ }
3717
+ }
3718
+ async function lookUpWrites(input) {
3719
+ try {
3720
+ const contractAddress = String(input.contractAddress ?? "").toLowerCase();
3721
+ if (!HEX40.test(contractAddress)) return { read: false, reason: "unreachable" };
3722
+ if (input.wanted.length === 0) return { read: true, entries: [], notFound: [] };
3723
+ const done = (writes2) => input.wanted.every((entry) => hitsFor(entry, writes2, contractAddress).length > 0);
3724
+ let writes;
3725
+ let cutOff = false;
3726
+ if (input.whole) {
3727
+ const all = await within(input.reader.getRecordWrites(input.recordKey), input.budgetMs);
3728
+ if (all === "cut") return { read: false, reason: "timeout" };
3729
+ writes = all;
3730
+ } else {
3731
+ if (!input.reader.findRecordWrites) return { read: false, reason: "unreachable" };
3732
+ const result = await within(
3733
+ input.reader.findRecordWrites(input.recordKey, {
3734
+ startAt: input.startAt,
3735
+ done,
3736
+ budgetMs: input.budgetMs,
3737
+ maxRequests: WRITES_LOOKUP_MAX_REQUESTS,
3738
+ windowSeconds: input.windowSeconds,
3739
+ now: input.now
3740
+ }),
3741
+ input.budgetMs + 250
3742
+ );
3743
+ if (result === "cut") return { read: false, reason: "timeout" };
3744
+ writes = result.writes;
3745
+ cutOff = result.ended === "timeout";
3746
+ }
3747
+ const byTransaction = /* @__PURE__ */ new Map();
3748
+ const notFound = [];
3749
+ for (const entry of input.wanted) {
3750
+ const hits = hitsFor(entry, writes, contractAddress);
3751
+ if (hits.length !== 1) {
3752
+ notFound.push(entry.entry);
3753
+ continue;
3754
+ }
3755
+ const transactionHash = hits[0].transactionHash.toLowerCase();
3756
+ const group = byTransaction.get(transactionHash);
3757
+ if (group) {
3758
+ group.entries.push(entry.entry);
3759
+ continue;
3760
+ }
3761
+ const link = input.linkFor(transactionHash);
3762
+ byTransaction.set(transactionHash, {
3763
+ entries: [entry.entry],
3764
+ committedAt: hits[0].committedAt,
3765
+ transactionHash,
3766
+ blockNumber: Number.isSafeInteger(hits[0].blockNumber) ? hits[0].blockNumber : null,
3767
+ link: typeof link === "string" ? link : null
3768
+ });
3769
+ }
3770
+ const entries = [...byTransaction.values()].sort((a, b) => a.entries[0] - b.entries[0]);
3771
+ if (cutOff && entries.length === 0) return { read: false, reason: "timeout" };
3772
+ return { read: true, entries, notFound };
3773
+ } catch {
3774
+ return { read: false, reason: "unreachable" };
3775
+ }
3776
+ }
3777
+
3437
3778
  // src/check.ts
3438
3779
  var CHECKER_NAME = "@pacspace-io/check";
3439
- var CHECKER_VERSION = true ? "0.5.3" : "0.0.0-dev";
3780
+ var CHECKER_VERSION = true ? "0.5.4" : "0.0.0-dev";
3440
3781
  var HISTORY_SCHEMAS = [
3441
3782
  RECORD_HISTORY_BUNDLE_SCHEMA_V1,
3442
3783
  RECORD_HISTORY_BUNDLE_SCHEMA_V2,
@@ -3541,11 +3882,36 @@ function readerFor(chain, options) {
3541
3882
  chainId,
3542
3883
  contractAddress,
3543
3884
  timeoutMs: options.timeoutMs,
3544
- fetchImpl: options.fetchImpl
3885
+ fetchImpl: options.fetchImpl,
3886
+ // With --full the run reads the contract's whole log once; the lookup then asks nothing more.
3887
+ keepLogPages: !!options.writes && !!options.full
3545
3888
  }),
3546
3889
  readsFrom: mirrorBaseUrl
3547
3890
  };
3548
3891
  }
3892
+ async function withWrites(report, bundle, verification, reader, options) {
3893
+ if (!options.writes || !reader || !report.passed || !report.file.intact || !report.source.compared || !report.source.matches) return report;
3894
+ let writes;
3895
+ try {
3896
+ const source = options.source ?? "mirror";
3897
+ const verified = new Set((verification.history?.perReceipt ?? []).filter((row) => row.result.verified).map((row) => row.seq));
3898
+ writes = await lookUpWrites({
3899
+ reader,
3900
+ recordKey: String(bundle.recordKey),
3901
+ contractAddress: String(bundle.chain?.contractAddress ?? ""),
3902
+ wanted: wantedEntriesOf(bundle.receipts, verified),
3903
+ startAt: typeof bundle.exportedAt === "string" ? bundle.exportedAt : null,
3904
+ whole: !!options.full && typeof source === "string",
3905
+ budgetMs: options.timeoutMs ?? WRITES_LOOKUP_DEFAULT_BUDGET_MS,
3906
+ linkFor: writeLinkFor(source, bundle.chain?.chainId),
3907
+ windowSeconds: options.writesWindowSeconds,
3908
+ now: options.writesNow
3909
+ });
3910
+ } catch {
3911
+ writes = { read: false, reason: "unreachable" };
3912
+ }
3913
+ return { ...report, writes };
3914
+ }
3549
3915
  var PAYLOAD_POINTER = /^\/payloads\/(0|[1-9][0-9]*)$/;
3550
3916
  function disclosureNamesAFile(disclosure) {
3551
3917
  const entries = disclosure?.entries;
@@ -3710,9 +4076,11 @@ async function checkBundle(file, options) {
3710
4076
  let source;
3711
4077
  let verification = offline;
3712
4078
  let sequence = null;
4079
+ let sourceReader = null;
3713
4080
  try {
3714
4081
  const found = readerFor(bundle.chain, options);
3715
4082
  const reader = options.full ? memoizeSequenceReads(found.reader) : found.reader;
4083
+ sourceReader = reader;
3716
4084
  const level = options.full ? "ledger" : "semantic";
3717
4085
  const live = v2 ? await verifyBundleV2WithSource(reader, file, level, layouts) : await verifyBundleWithPublicLayer({ reader, bundle, level, layouts });
3718
4086
  if (options.full) {
@@ -3733,13 +4101,14 @@ async function checkBundle(file, options) {
3733
4101
  if (error instanceof HistoryFileError) throw error;
3734
4102
  source = { compared: false, reason: "unreachable", detail: error.message };
3735
4103
  }
3736
- return buildReport({
4104
+ const report = buildReport({
3737
4105
  ...base,
3738
4106
  verification,
3739
4107
  source,
3740
4108
  dailyStatement: dailyStatementOf(file, verification.verified, sequence),
3741
4109
  heldFile: heldOf(verification, false)
3742
4110
  });
4111
+ return withWrites(report, bundle, verification, sourceReader, options);
3743
4112
  }
3744
4113
  function encryptedRefusalSentence(refusal) {
3745
4114
  const entry = typeof refusal.seq === "number" ? refusal.seq + 1 : null;
@@ -3820,9 +4189,11 @@ async function checkEncrypted(file, bundle, recordKey, options) {
3820
4189
  let source;
3821
4190
  let result = offline;
3822
4191
  let sequence = null;
4192
+ let sourceReader = null;
3823
4193
  try {
3824
4194
  const found = readerFor(bundle.chain, options);
3825
4195
  const reader = options.full ? memoizeSequenceReads(found.reader) : found.reader;
4196
+ sourceReader = reader;
3826
4197
  const contractMatches = !!bundle.chain?.contractAddress && bundle.chain.contractAddress.toLowerCase() === reader.contractAddress.toLowerCase();
3827
4198
  const chainWord = await reader.getRecord(bundle.recordKey);
3828
4199
  const onChainLayout = await reader.getLayout(bundle.layout.layoutId);
@@ -3853,7 +4224,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
3853
4224
  if (error instanceof HistoryFileError) throw error;
3854
4225
  source = { compared: false, reason: "unreachable", detail: error.message };
3855
4226
  }
3856
- return buildReport({
4227
+ const report = buildReport({
3857
4228
  ...base,
3858
4229
  verification: result.verification,
3859
4230
  source,
@@ -3861,6 +4232,7 @@ async function checkEncrypted(file, bundle, recordKey, options) {
3861
4232
  heldFile: heldOf(result.verification, result.opened, false),
3862
4233
  encrypted
3863
4234
  });
4235
+ return withWrites(report, bundle, result.verification, sourceReader, options);
3864
4236
  }
3865
4237
  function entryCountOf(form, layouts) {
3866
4238
  if (!form || typeof form.currentWord !== "string") return null;
package/dist/inputs.txt CHANGED
@@ -29,6 +29,7 @@
29
29
  ../shared/src/records/layout-not-read.ts
30
30
  ../shared/src/records/layouts.generated.ts
31
31
  ../shared/src/records/layouts.ts
32
+ ../shared/src/records/ledger-write-search-v1.ts
32
33
  ../shared/src/records/model-record-link-v1.ts
33
34
  ../shared/src/records/record-content-v1.ts
34
35
  ../shared/src/records/record-entry-kind-v1.ts
@@ -43,3 +44,4 @@ src/cli.ts
43
44
  src/open.ts
44
45
  src/release.ts
45
46
  src/report.ts
47
+ src/writes.ts
package/dist/report.d.ts CHANGED
@@ -63,6 +63,30 @@ export type DisclosureOutcome = {
63
63
  items: unknown[];
64
64
  }>;
65
65
  };
66
+ /** Where one or more entries were committed: one write on the proof layer. */
67
+ export interface EntryWrite {
68
+ /** Entry numbers (1-based) committed together. */
69
+ entries: number[];
70
+ /** When the proof layer committed them, ISO 8601 (UTC). */
71
+ committedAt: string;
72
+ transactionHash: string;
73
+ blockNumber: number | null;
74
+ /** The write on an explorer of the proof layer; null when the checker has none for the source it read. */
75
+ link: string | null;
76
+ }
77
+ /**
78
+ * Where each entry was committed, looked up after the check had its verdict. Information only: it is
79
+ * never read by the verdict, the sentences or the exit code.
80
+ */
81
+ export type WritesOutcome = {
82
+ read: true;
83
+ entries: EntryWrite[];
84
+ /** Entry numbers (1-based) whose write this read of the proof layer did not find. */
85
+ notFound: number[];
86
+ } | {
87
+ read: false;
88
+ reason: 'unreachable' | 'timeout';
89
+ };
66
90
  export interface CheckReport {
67
91
  schema: typeof REPORT_SCHEMA;
68
92
  checker: {
@@ -109,6 +133,8 @@ export interface CheckReport {
109
133
  sentences: string[];
110
134
  /** 0 the check passed as asked; 1 it did not; 3 the proof layer could not be reached. */
111
135
  exitCode: 0 | 1 | 3;
136
+ /** Present only when the lookup ran: where each entry was committed. */
137
+ writes?: WritesOutcome;
112
138
  }
113
139
  /** The subset of the shared verifier's result the report reads. */
114
140
  export interface VerificationFacts {
@@ -238,5 +264,23 @@ export interface SealsReportInput {
238
264
  }
239
265
  /** A seal history's report, alone or in a kept copy, with any disclosure checked against it. */
240
266
  export declare function buildSealsReport(input: SealsReportInput): CheckReport;
241
- /** The report as the terminal prints it: labeled facts in a column, then the sentences. */
242
- export declare function renderReport(report: CheckReport): string;
267
+ export declare const WRITES_HEADING = "Where each entry was committed on the proof layer:";
268
+ export declare const 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.";
269
+ /** The text report lists at most this many writes; `--json` lists all. */
270
+ export declare const WRITES_LISTED_MAX = 25;
271
+ /** "16 November 2026, 13:15:42 UTC" for an ISO instant. */
272
+ export declare function committedWhen(iso: string): string;
273
+ export declare function writesNotFoundSentence(notFound: number[], suggestFull: boolean): string;
274
+ export declare function writesNotListedSentence(count: number): string;
275
+ /**
276
+ * The lines that say where each entry was committed, or none when the lookup did not run or found
277
+ * nothing to say. `suggestFull` is false when the run already read the record's whole history.
278
+ */
279
+ export declare function writesLines(writes: WritesOutcome | undefined, suggestFull?: boolean): string[];
280
+ /**
281
+ * The report as the terminal prints it: labeled facts in a column, then the sentences. Where each
282
+ * entry was committed, when it was looked up, follows the line that compares the file with the proof layer.
283
+ */
284
+ export declare function renderReport(report: CheckReport, options?: {
285
+ suggestFull?: boolean;
286
+ }): string;
@@ -0,0 +1,55 @@
1
+ import type { RecordChainReader } from '@pacspace/shared';
2
+ import type { WritesOutcome } from './report';
3
+ /**
4
+ * Where each entry was committed, read from the proof layer after the check
5
+ * has its verdict. Information only: nothing here can change what the check
6
+ * found, and every failure ends as "not read".
7
+ */
8
+ /** At most this many requests for one lookup, one at a time, one attempt each. */
9
+ export declare const WRITES_LOOKUP_MAX_REQUESTS = 40;
10
+ /** The lookup's whole budget when `--timeout` is not given, milliseconds. */
11
+ export declare const WRITES_LOOKUP_DEFAULT_BUDGET_MS = 10000;
12
+ /**
13
+ * Where an explorer of the proof layer shows a write, by network. Kept here, not read from the
14
+ * platform's chain settings, so the package carries nothing else of them; a test holds the two equal.
15
+ */
16
+ export declare const WRITE_EXPLORERS: Readonly<Record<number, string>>;
17
+ /**
18
+ * The explorer address of a write, or null. The checker links a write only when it read the mirror it
19
+ * knows for one of the two networks it knows: with `--source`, `--rpc` or any other network, the
20
+ * explorer may not be showing what was read, so none is named.
21
+ */
22
+ export declare function writeLinkFor(source: 'mirror' | 'offline' | string | {
23
+ rpc: string;
24
+ } | undefined, chainId: unknown): (transactionHash: string) => string | null;
25
+ /** One committed entry of the file: its number (from 1) and the two words its write carries. */
26
+ export interface WantedEntry {
27
+ entry: number;
28
+ previousWord: string;
29
+ newWord: string;
30
+ }
31
+ export interface WritesLookupInput {
32
+ reader: RecordChainReader;
33
+ recordKey: string;
34
+ /** The contract the file names; a write counts only when its log names the same one. */
35
+ contractAddress: string;
36
+ wanted: WantedEntry[];
37
+ /** The file's export time, a hint for where the search starts. */
38
+ startAt: string | null;
39
+ /** True when this run already read the record's whole history (`--full` on a mirror), so nothing more is asked. */
40
+ whole: boolean;
41
+ budgetMs: number;
42
+ /** The explorer address for a write, or null when the checker has none for this source. */
43
+ linkFor: (transactionHash: string) => string | null;
44
+ /** Test seams. */
45
+ windowSeconds?: number;
46
+ now?: () => number;
47
+ }
48
+ /** The committed entries of a history's receipts that passed the check, with the words their writes carry. */
49
+ export declare function wantedEntriesOf(receipts: unknown, verifiedSeqs: ReadonlySet<number>): WantedEntry[];
50
+ /**
51
+ * Look up where each wanted entry was committed. One log per entry or the
52
+ * entry is listed as not found; a refused or failed read, or one that the
53
+ * budget cut off before anything was found, is "not read". Never throws.
54
+ */
55
+ export declare function lookUpWrites(input: WritesLookupInput): Promise<WritesOutcome>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pacspace-io/check",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Checks a PacSpace record history file against the proof layer. Runs without PacSpace.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",