@fangorn-network/sdk 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli/cli.js CHANGED
@@ -5,6 +5,7 @@ import { Fangorn } from "../fangorn.js";
5
5
  import { sealRecords } from "./sell.js";
6
6
  import { fileToRecords, walk } from "./stage.js";
7
7
  import { handleCancel, selectChain } from "./index.js";
8
+ import { createRequire } from "node:module";
8
9
  import { createPublicClient, formatEther, http, isAddress, parseUnits } from "viem";
9
10
  import { privateKeyToAccount } from "viem/accounts";
10
11
  import { Command } from "commander";
@@ -161,7 +162,7 @@ var LocalRepo = class LocalRepo {
161
162
  }
162
163
  };
163
164
  const program = new Command();
164
- program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
165
+ program.name("fangorn").description("Fangorn Network CLI").version(createRequire(import.meta.url)("../../package.json").version);
165
166
  program.command("init").description("Configure your Fangorn credentials").action(async () => {
166
167
  intro("Fangorn Setup");
167
168
  const chainName = await selectChain();
@@ -447,6 +448,25 @@ program.command("show").description("Show a commit and what it changed vs. its p
447
448
  process.exit(1);
448
449
  }
449
450
  });
451
+ program.command("stitch").description("Stitch repos into one tree from the update log, or update a stitch with --from. A pattern is `publisher/repo`, a repo name (every publisher's), '*' (every repo; quote it), or '/regex/' on `publisher/repo`").argument("<patterns...>").option("--from <stitch>", "The previous stitch to update (same patterns)").option("--verify <stitch>", "Check a stitch against the chain instead of building one").action(async (patterns, opts) => {
452
+ try {
453
+ const fangorn = getFangorn();
454
+ if (opts.verify) {
455
+ const ok = await fangorn.verifyStitch(opts.verify, patterns);
456
+ console.log(ok ? "valid" : "INVALID");
457
+ process.exit(ok ? 0 : 1);
458
+ }
459
+ const stitch = await fangorn.restitch(patterns, opts.from);
460
+ const { root, n, logRoot } = await fangorn.readStitch(stitch);
461
+ console.log(`stitch ${stitch}`);
462
+ console.log(`root ${root}`);
463
+ console.log(`log ${String(n)} entries, root ${logRoot}`);
464
+ process.exit(0);
465
+ } catch (err) {
466
+ console.error("Failed:", err.message);
467
+ process.exit(1);
468
+ }
469
+ });
450
470
  program.command("clone").description("Track an existing on-chain namespace by reconstructing its tip locally").argument("<owner>", "Owner (publisher) address").argument("<namespace>", "Namespace name").option("--dir <path>", "Directory to create the repo in (default: current dir)").action(async (owner, namespace, options) => {
451
471
  try {
452
472
  const fangorn = getFangorn();
@@ -72,6 +72,10 @@ declare const DATA_REGISTRY_ABI: readonly [{
72
72
  readonly name: "parent";
73
73
  readonly type: "bytes32";
74
74
  readonly internalType: "bytes32";
75
+ }, {
76
+ readonly name: "diff";
77
+ readonly type: "bytes32";
78
+ readonly internalType: "bytes32";
75
79
  }, {
76
80
  readonly name: "root";
77
81
  readonly type: "bytes32";
@@ -240,6 +244,10 @@ declare const DATA_REGISTRY_ABI: readonly [{
240
244
  readonly name: "parent";
241
245
  readonly type: "bytes32";
242
246
  readonly internalType: "bytes32";
247
+ }, {
248
+ readonly name: "diff";
249
+ readonly type: "bytes32";
250
+ readonly internalType: "bytes32";
243
251
  }, {
244
252
  readonly name: "root";
245
253
  readonly type: "bytes32";
@@ -274,6 +282,10 @@ declare const DATA_REGISTRY_ABI: readonly [{
274
282
  readonly name: "parent";
275
283
  readonly type: "bytes32";
276
284
  readonly internalType: "bytes32";
285
+ }, {
286
+ readonly name: "diff";
287
+ readonly type: "bytes32";
288
+ readonly internalType: "bytes32";
277
289
  }, {
278
290
  readonly name: "root";
279
291
  readonly type: "bytes32";
@@ -83,6 +83,11 @@ const DATA_REGISTRY_ABI = [
83
83
  type: "bytes32",
84
84
  internalType: "bytes32"
85
85
  },
86
+ {
87
+ name: "diff",
88
+ type: "bytes32",
89
+ internalType: "bytes32"
90
+ },
86
91
  {
87
92
  name: "root",
88
93
  type: "bytes32",
@@ -269,6 +274,11 @@ const DATA_REGISTRY_ABI = [
269
274
  type: "bytes32",
270
275
  internalType: "bytes32"
271
276
  },
277
+ {
278
+ name: "diff",
279
+ type: "bytes32",
280
+ internalType: "bytes32"
281
+ },
272
282
  {
273
283
  name: "root",
274
284
  type: "bytes32",
@@ -311,6 +321,11 @@ const DATA_REGISTRY_ABI = [
311
321
  type: "bytes32",
312
322
  internalType: "bytes32"
313
323
  },
324
+ {
325
+ name: "diff",
326
+ type: "bytes32",
327
+ internalType: "bytes32"
328
+ },
314
329
  {
315
330
  name: "root",
316
331
  type: "bytes32",
@@ -16,6 +16,8 @@ interface CommitUpdate {
16
16
  epoch: number;
17
17
  /** digest of the parent commit, or ZERO_HEAD */
18
18
  parent: Hex;
19
+ /** digest of the event's diff tree */
20
+ diff: Hex;
19
21
  /** digest of the state root */
20
22
  root: Hex;
21
23
  /** the CAR's CID, as bytes */
@@ -34,6 +36,9 @@ declare const UPDATE_TYPES: {
34
36
  }, {
35
37
  readonly name: "parent";
36
38
  readonly type: "bytes32";
39
+ }, {
40
+ readonly name: "diff";
41
+ readonly type: "bytes32";
37
42
  }, {
38
43
  readonly name: "root";
39
44
  readonly type: "bytes32";
@@ -48,6 +53,7 @@ declare const updateMessage: (publisher: Address, u: CommitUpdate) => {
48
53
  repo: string;
49
54
  epoch: bigint;
50
55
  parent: `0x${string}`;
56
+ diff: `0x${string}`;
51
57
  root: `0x${string}`;
52
58
  car: `0x${string}`;
53
59
  };
@@ -81,6 +87,11 @@ interface Registry {
81
87
  epoch(): Promise<number>;
82
88
  /** H(ρ): the committed head, or ZERO_HEAD for a repo never written. */
83
89
  head(ref: RepoRef): Promise<Hex>;
90
+ /** H(ρ) with its position (the repo's generation, from 1); (0, ZERO_HEAD) if never written. */
91
+ headAt(ref: RepoRef): Promise<{
92
+ pos: number;
93
+ head: Hex;
94
+ }>;
84
95
  /** Moves the signer's repo to the commit `u`. Valid only while `u.parent` is the head (Theorem 3). */
85
96
  update(u: CommitUpdate): Promise<Hash>;
86
97
  /** `update` as an unsigned transaction for `publisher` to sign. */
@@ -89,6 +100,8 @@ interface Registry {
89
100
  signUpdate(u: CommitUpdate): Promise<Hex>;
90
101
  /** `update` for `publisher`, on its signature. Anyone may submit it. */
91
102
  updateBySig(publisher: Address, u: CommitUpdate, signature: Hex): Promise<Hash>;
103
+ /** The update log's mountain range root as of clock `at` (default: now). */
104
+ logRoot(at?: bigint): Promise<Hex>;
92
105
  /** The entries of a log between two clock values, oldest first. */
93
106
  log(filter: LogFilter, from: bigint, to?: bigint): Promise<UpdateEntry[]>;
94
107
  /** Follow the log live. Returns an unsubscribe function. */
@@ -114,6 +127,11 @@ declare class ChainRegistry implements Registry {
114
127
  constructor(config: ChainRegistryConfig, publicClient: PublicClient, walletClient?: WalletClient | undefined);
115
128
  epoch(): Promise<number>;
116
129
  head(ref: RepoRef): Promise<Hex>;
130
+ headAt(ref: RepoRef): Promise<{
131
+ pos: number;
132
+ head: Hex;
133
+ }>;
134
+ logRoot(at?: bigint): Promise<Hex>;
117
135
  update(u: CommitUpdate): Promise<Hash>;
118
136
  prepareUpdate(publisher: Address, u: CommitUpdate): Promise<PreparedTx>;
119
137
  signUpdate(u: CommitUpdate): Promise<Hex>;
@@ -33,6 +33,10 @@ const UPDATE_TYPES = { Update: [
33
33
  name: "parent",
34
34
  type: "bytes32"
35
35
  },
36
+ {
37
+ name: "diff",
38
+ type: "bytes32"
39
+ },
36
40
  {
37
41
  name: "root",
38
42
  type: "bytes32"
@@ -53,6 +57,7 @@ const updateMessage = (publisher, u) => ({
53
57
  repo: u.repo,
54
58
  epoch: BigInt(u.epoch),
55
59
  parent: u.parent,
60
+ diff: u.diff,
56
61
  root: u.root,
57
62
  car: u.car
58
63
  });
@@ -75,13 +80,27 @@ var ChainRegistry = class {
75
80
  return epochOf((await this.publicClient.getBlock()).timestamp);
76
81
  }
77
82
  async head(ref) {
78
- const [, head] = await this.publicClient.readContract({
83
+ return (await this.headAt(ref)).head;
84
+ }
85
+ async headAt(ref) {
86
+ const [pos, head] = await this.publicClient.readContract({
79
87
  address: this.data,
80
88
  abi: DATA_REGISTRY_ABI,
81
89
  functionName: "getHead",
82
90
  args: [ref.publisher, repoId(ref.repo)]
83
91
  });
84
- return head;
92
+ return {
93
+ pos: Number(pos),
94
+ head
95
+ };
96
+ }
97
+ logRoot(at) {
98
+ return this.publicClient.readContract({
99
+ address: this.data,
100
+ abi: DATA_REGISTRY_ABI,
101
+ functionName: "logRoot",
102
+ ...at === void 0 ? {} : { blockNumber: at }
103
+ });
85
104
  }
86
105
  update(u) {
87
106
  return this.write("update", updateArgs(u));
@@ -162,6 +181,7 @@ function updateArgs(u) {
162
181
  u.repo,
163
182
  BigInt(u.epoch),
164
183
  u.parent,
184
+ u.diff,
165
185
  u.root,
166
186
  u.car
167
187
  ];
@@ -0,0 +1,23 @@
1
+ import { UpdateEntry } from "./index.js";
2
+ import { Hex } from "viem";
3
+
4
+ //#region src/contracts/data-registry/mmr.d.ts
5
+ /** The leaf the contract appended for one log entry. */
6
+ declare const logLeaf: (e: UpdateEntry) => Hex;
7
+ /** A mountain range as its length and peaks; `peaks[h]` is live where bit h of n is set. */
8
+ interface Mmr {
9
+ n: number;
10
+ peaks: (Hex | null)[];
11
+ }
12
+ declare const EMPTY_MMR: Mmr;
13
+ declare function mmrAppend({
14
+ n,
15
+ peaks
16
+ }: Mmr, leaf: Hex): Mmr;
17
+ /** `logRoot()` for this range. */
18
+ declare function mmrRoot({
19
+ n,
20
+ peaks
21
+ }: Mmr): Hex;
22
+ //#endregion
23
+ export { EMPTY_MMR, Mmr, logLeaf, mmrAppend, mmrRoot };
@@ -0,0 +1,65 @@
1
+ import { repoId } from "./index.js";
2
+ import { encodeAbiParameters, keccak256, stringToHex, zeroHash } from "viem";
3
+
4
+ //#region src/contracts/data-registry/mmr.ts
5
+ const tag = (s) => stringToHex(s, { size: 32 });
6
+ /** The leaf the contract appended for one log entry. */
7
+ const logLeaf = (e) => keccak256(encodeAbiParameters([
8
+ { type: "bytes32" },
9
+ { type: "address" },
10
+ { type: "bytes32" },
11
+ { type: "uint64" },
12
+ { type: "bytes32" },
13
+ { type: "uint64" }
14
+ ], [
15
+ tag("leaf"),
16
+ e.publisher,
17
+ repoId(e.repo),
18
+ BigInt(e.pos),
19
+ e.head,
20
+ e.timestamp
21
+ ]));
22
+ const EMPTY_MMR = {
23
+ n: 0,
24
+ peaks: []
25
+ };
26
+ function mmrAppend({ n, peaks }, leaf) {
27
+ const next = [...peaks];
28
+ let node = leaf;
29
+ let h = 0;
30
+ while (n >> h & 1) {
31
+ node = keccak256(encodeAbiParameters([
32
+ { type: "bytes32" },
33
+ { type: "bytes32" },
34
+ { type: "bytes32" }
35
+ ], [
36
+ tag("node"),
37
+ next[h] ?? zeroHash,
38
+ node
39
+ ]));
40
+ next[h] = null;
41
+ h++;
42
+ }
43
+ next[h] = node;
44
+ return {
45
+ n: n + 1,
46
+ peaks: next
47
+ };
48
+ }
49
+ /** `logRoot()` for this range. */
50
+ function mmrRoot({ n, peaks }) {
51
+ const live = [];
52
+ for (let h = peaks.length - 1; h >= 0; h--) if (n >> h & 1) live.push(peaks[h] ?? zeroHash);
53
+ return keccak256(encodeAbiParameters([
54
+ { type: "bytes32" },
55
+ { type: "uint64" },
56
+ { type: "bytes32[]" }
57
+ ], [
58
+ tag("mmr"),
59
+ BigInt(n),
60
+ live
61
+ ]));
62
+ }
63
+
64
+ //#endregion
65
+ export { EMPTY_MMR, logLeaf, mmrAppend, mmrRoot };
@@ -3,4 +3,5 @@ import { ChainRegistry, ChainRegistryConfig, CommitUpdate, EPOCH_SECONDS, LogFil
3
3
  import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
4
4
  import { RegisterArgs, SettleArgs, SettlementPayment, SettlementRegistryClient, TERMS_TYPES, Terms, TermsJson, WHOLE_REPO, recordKey, registerNonce, settlementDomain, subjectOf, termsFromJson, termsToJson } from "./settlement-registry/index.js";
5
5
  import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
6
- export { ChainRegistry, ChainRegistryConfig, CommitUpdate, DATA_REGISTRY_ABI, EPOCH_SECONDS, LogFilter, type PreparedTx, RegisterArgs, Registry, RepoRef, SETTLEMENT_REGISTRY_ABI, SettleArgs, SettlementPayment, SettlementRegistryClient, TERMS_TYPES, Terms, TermsJson, UPDATE_TYPES, UpdateEntry, WHOLE_REPO, WINDOW, ZERO_HEAD, dataDomain, epochOf, recordKey, registerNonce, repoId, settlementDomain, subjectOf, termsFromJson, termsToJson, updateMessage };
6
+ import { EMPTY_MMR, Mmr, logLeaf, mmrAppend, mmrRoot } from "./data-registry/mmr.js";
7
+ export { ChainRegistry, ChainRegistryConfig, CommitUpdate, DATA_REGISTRY_ABI, EMPTY_MMR, EPOCH_SECONDS, LogFilter, Mmr, type PreparedTx, RegisterArgs, Registry, RepoRef, SETTLEMENT_REGISTRY_ABI, SettleArgs, SettlementPayment, SettlementRegistryClient, TERMS_TYPES, Terms, TermsJson, UPDATE_TYPES, UpdateEntry, WHOLE_REPO, WINDOW, ZERO_HEAD, dataDomain, epochOf, logLeaf, mmrAppend, mmrRoot, recordKey, registerNonce, repoId, settlementDomain, subjectOf, termsFromJson, termsToJson, updateMessage };
@@ -2,5 +2,6 @@ import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
2
2
  import { ChainRegistry, EPOCH_SECONDS, UPDATE_TYPES, WINDOW, ZERO_HEAD, dataDomain, epochOf, repoId, updateMessage } from "./data-registry/index.js";
3
3
  import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
4
4
  import { SettlementRegistryClient, TERMS_TYPES, WHOLE_REPO, recordKey, registerNonce, settlementDomain, subjectOf, termsFromJson, termsToJson } from "./settlement-registry/index.js";
5
+ import { EMPTY_MMR, logLeaf, mmrAppend, mmrRoot } from "./data-registry/mmr.js";
5
6
 
6
- export { ChainRegistry, DATA_REGISTRY_ABI, EPOCH_SECONDS, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, TERMS_TYPES, UPDATE_TYPES, WHOLE_REPO, WINDOW, ZERO_HEAD, dataDomain, epochOf, recordKey, registerNonce, repoId, settlementDomain, subjectOf, termsFromJson, termsToJson, updateMessage };
7
+ export { ChainRegistry, DATA_REGISTRY_ABI, EMPTY_MMR, EPOCH_SECONDS, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, TERMS_TYPES, UPDATE_TYPES, WHOLE_REPO, WINDOW, ZERO_HEAD, dataDomain, epochOf, logLeaf, mmrAppend, mmrRoot, recordKey, registerNonce, repoId, settlementDomain, subjectOf, termsFromJson, termsToJson, updateMessage };
@@ -1,7 +1,7 @@
1
1
  import { CommitUpdate, Registry } from "../contracts/data-registry/index.js";
2
2
  import "../contracts/index.js";
3
3
  import { MetadataStorage } from "../providers/storage/types.js";
4
- import { CommitBlock, Ref } from "./records.js";
4
+ import { CommitBlock, Ref, Stitch } from "./records.js";
5
5
  import { Address, Hash, Hex } from "viem";
6
6
  import { CID } from "multiformats/cid";
7
7
 
@@ -21,8 +21,13 @@ interface StoredRecord {
21
21
  type: RecordType;
22
22
  payload: Record<string, unknown>;
23
23
  }
24
- /** A decoded commit, γ = (e, parent, root) plus its repo name and CAR (see CommitBlock). */
25
- type CommitObject = CommitBlock;
24
+ /**
25
+ * A decoded commit: the event (e, parent, diff, root) plus its repo name and CAR
26
+ * (see CommitBlock). `diff` is null for commits written before events carried one.
27
+ */
28
+ type CommitObject = Omit<CommitBlock, "diff"> & {
29
+ diff: CID | null;
30
+ };
26
31
  interface RepoContents {
27
32
  records: StoredRecord[];
28
33
  }
@@ -45,8 +50,9 @@ declare const MAX_REPO_NAME_LENGTH = 256;
45
50
  * The root of the graph, committed to IPFS, as hex
46
51
  */
47
52
  declare function rootHexFromCid(commitCid: CID): Hex;
53
+ declare function cidFromDigest(digest: Hex): CID;
48
54
  /** The update that settles `commit`. */
49
- declare function commitUpdate(commit: CommitBlock): CommitUpdate;
55
+ declare function commitUpdate(commit: CommitObject): CommitUpdate;
50
56
  /** The head the registry computes for `u`. */
51
57
  declare function commitHead(u: CommitUpdate): Promise<Hex>;
52
58
  /** A commit's update, signed by its publisher for anyone to submit. */
@@ -115,11 +121,15 @@ declare class FangornEngine {
115
121
  private hexToRootCid;
116
122
  /** Read and decode a commit object by CID (directly addressable — no CAR needed). */
117
123
  getCommit(commitCid: CID): Promise<CommitObject>;
118
- /** Pull every block of `commit`'s CAR into the local cache. */
124
+ /** A block stored on its own (a commit or stitch block), hash-checked and cached. */
125
+ private directBlock;
126
+ /** The packfile and parent of a link in a chain: a commit, or a stitch. */
127
+ private chainLink;
128
+ /** Pull every block of a chain link's CAR into the local cache. */
119
129
  private loadCar;
120
130
  /**
121
- * Resolve a data block: local cache first, then walk the commit chain from
122
- * `hint`, loading one ancestor CAR at a time until the block turns up.
131
+ * Resolve a data block: local cache first, then walk the chain (commits, or
132
+ * stitches) from `hint`, loading one ancestor CAR at a time until the block turns up.
123
133
  */
124
134
  private getBlock;
125
135
  private putLocal;
@@ -176,20 +186,80 @@ declare class FangornEngine {
176
186
  rootHexFromCommitCid(commitCid: string): Hex;
177
187
  /** Decode a record block, checking it is filed under its own id. */
178
188
  private decodeRecord;
189
+ /** The diff an event carries: id → new record CID, or null where the record was deleted. */
190
+ eventDiff(commitCid: CID): Promise<Map<string, CID | null>>;
191
+ /**
192
+ * The events after `old` up to `tip`, composed into one id → CID | null map, newest write
193
+ * winning. Null when `old` is not an ancestor of `tip`, or an event between them has no diff.
194
+ */
195
+ private eventsSince;
179
196
  /**
180
197
  * Net change to a single repo between two on-chain roots — the core of
181
- * the subscription light-client. A plain comparison of the two id → CID
182
- * maps; only records that actually changed are decoded.
198
+ * the subscription light-client. Only records that actually changed are decoded.
183
199
  *
184
- * Diffing root-to-root (rather than walking commits) is deliberately robust:
185
- * it yields the correct net delta even across a force-push / non-fast-forward
186
- * reorg — exactly what an index builder needs (what to (re)embed, what to evict).
187
- * Reads only the nodes on changed paths (`diffMst`): 10 new records in a
188
- * 50k-record repo cost ~10 × depth nodes, not two 50k-key walks.
200
+ * When `old` is an ancestor of `new`, this reads the diffs the events carry (WHITEPAPER_1 §3.3,
201
+ * Following) and looks each changed id up in the old tree. Otherwise, across a reset to another
202
+ * chain or a commit from before diff events, it diffs the two trees (`diffMst`). Either way the
203
+ * result is the net delta an index builder needs: what to (re)embed, what to evict.
189
204
  */
190
205
  repoDiff(oldRootHex: string | null, newRootHex: string): Promise<RepoDiff>;
191
- /** Diff a commit against its parent. */
206
+ /** Diff a commit against its parent: its event's diff, or two full states for an older commit. */
192
207
  diffCommit(commitCid: CID): Promise<CommitDiff>;
208
+ /** A stitch to the current head of (publisher, repo), at `key` if given. One `getHead` read, no logs. */
209
+ stitchTo(publisher: Address, repo: RepoName, key?: string): Promise<Stitch>;
210
+ /**
211
+ * A stitch across repos: an MST of `publisher/repo` → head commit, folded from the
212
+ * update log up to entry n and tagged with the log's root there. Pass the previous
213
+ * stitch to read only the log since it, and upload only the nodes it doesn't have
214
+ * (one CAR). Returns the stitch block's CID, its name; with nothing new, `prev`.
215
+ * Use the same `filter` every time for one stitch. `fromBlock` is where the log
216
+ * starts (the registry's deploy block).
217
+ * ponytail: rehashes the whole tree (O(repos)); and readers walk back one CAR per
218
+ * stitch to find old nodes, so checkpoint with a full CAR (`prev = null`) when the
219
+ * chain gets long.
220
+ */
221
+ restitch(prev: CID | null, filter?: (publisher: Address, repo: RepoName) => boolean, fromBlock?: bigint): Promise<CID>;
222
+ /** A stitch block: its tree root, and the log it was folded from (n entries, root `logRoot`). */
223
+ readStitch(stitch: CID): Promise<{
224
+ root: CID;
225
+ n: number;
226
+ t: bigint;
227
+ peaks: (Hex | null)[];
228
+ logRoot: Hex;
229
+ }>;
230
+ /**
231
+ * The head commit a stitch holds for (publisher, repo), or null if it doesn't
232
+ * include the repo. Every node read is hash-checked.
233
+ * ponytail: like `lookupMst`, trusts key order on the path; `readMst` proves absence.
234
+ */
235
+ stitchedHead(stitch: CID, publisher: Address, repo: RepoName): Promise<CID | null>;
236
+ /** Every (publisher, repo) → head commit a stitch holds: what an indexer follows. */
237
+ stitchHeads(stitch: CID): Promise<{
238
+ publisher: Address;
239
+ repo: RepoName;
240
+ head: CID;
241
+ }[]>;
242
+ /**
243
+ * Check a stitch without trusting whoever built it: replay the whole log, check it
244
+ * against the contract's log root, and rebuild the stitch from its first n entries
245
+ * under the same `filter`. Reads no stitch nodes, only the stitch block.
246
+ * ponytail: O(log) per check; store log roots on chain if that gets slow.
247
+ */
248
+ verifyStitch(stitch: CID, filter?: (publisher: Address, repo: RepoName) => boolean, fromBlock?: bigint): Promise<boolean>;
249
+ /**
250
+ * Check a stitch against the registry (WHITEPAPER_1 Proposition 4.2) and resolve it:
251
+ * the record at its key as of that position (null if absent), or, with no key, the event's diff.
252
+ * Throws if the repo never had `head` at `pos`. `latest` says whether the repo has moved on.
253
+ * A stitch at the current generation is checked with one `getHead` read.
254
+ * ponytail: an older stitch still scans the log from `fromBlock` (and trusts the RPC).
255
+ * Upgrade: walk parents back from the on-chain head, recomputing `commitHead` each hop
256
+ * (O(distance), no logs), or an MMR opening against `logRoot()` (O(log n), needs a proof server).
257
+ */
258
+ checkStitch(s: Stitch, fromBlock?: bigint): Promise<{
259
+ latest: boolean;
260
+ record?: StoredRecord | null;
261
+ diff?: Map<string, CID | null>;
262
+ }>;
193
263
  /** check if the repo already exists (head resolves) */
194
264
  repoExists(publisher: Address, repo: RepoName): Promise<boolean>;
195
265
  /** Lists every record currently committed under a repo, resolved from the on-chain root. */
@@ -203,4 +273,4 @@ declare class FangornEngine {
203
273
  readRecord(publisher: Address, repo: RepoName, id: string): Promise<StoredRecord | null>;
204
274
  }
205
275
  //#endregion
206
- export { CommitDiff, CommitObject, CreateCommitOptions, FangornEngine, MAX_REPO_NAME_LENGTH, RecordInput, RecordType, type Ref, RepoContents, RepoDiff, RepoName, SignedUpdate, StoredRecord, assertValidRepoName, commitHead, commitUpdate, fileCid, rootHexFromCid };
276
+ export { CommitDiff, CommitObject, CreateCommitOptions, FangornEngine, MAX_REPO_NAME_LENGTH, RecordInput, RecordType, type Ref, RepoContents, RepoDiff, RepoName, SignedUpdate, type Stitch, StoredRecord, assertValidRepoName, cidFromDigest, commitHead, commitUpdate, fileCid, rootHexFromCid };