@fangorn-network/sdk 2026.7.1-2.1 → 2026.7.1-4.0

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.
Files changed (72) hide show
  1. package/README.md +104 -69
  2. package/lib/cli/cli.js +25 -18
  3. package/lib/cli/index.d.ts +13 -13
  4. package/lib/config.d.ts +17 -16
  5. package/lib/contracts/data-registry/abi.d.ts +207 -35
  6. package/lib/contracts/data-registry/index.js +4 -4
  7. package/lib/contracts/index.d.ts +3 -1
  8. package/lib/contracts/index.js +3 -1
  9. package/lib/contracts/settlement-registry/abi.d.ts +47 -0
  10. package/lib/contracts/settlement-registry/abi.js +48 -0
  11. package/lib/contracts/settlement-registry/index.d.ts +25 -0
  12. package/lib/contracts/settlement-registry/index.js +40 -0
  13. package/lib/crypto/aes.d.ts +1 -8
  14. package/lib/crypto/aes.js +2 -34
  15. package/lib/crypto/encryption.d.ts +112 -26
  16. package/lib/crypto/encryption.js +105 -21
  17. package/lib/engine/car.d.ts +10 -0
  18. package/lib/engine/car.js +37 -0
  19. package/lib/engine/graph.d.ts +70 -0
  20. package/lib/engine/graph.js +73 -0
  21. package/lib/engine/index.d.ts +109 -70
  22. package/lib/engine/index.js +296 -226
  23. package/lib/engine/test-helpers.d.ts +43 -0
  24. package/lib/engine/test-helpers.js +69 -0
  25. package/lib/fangorn.d.ts +28 -25
  26. package/lib/fangorn.js +118 -83
  27. package/lib/harness/index.d.ts +4 -3
  28. package/lib/harness/index.js +9 -3
  29. package/lib/index.d.ts +4 -4
  30. package/lib/index.js +3 -3
  31. package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/_polyval.js +1 -1
  32. package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/aes.js +1 -1
  33. package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/utils.js +1 -1
  34. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/curve.js +1 -1
  35. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/edwards.js +1 -1
  36. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/modular.js +1 -1
  37. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/montgomery.js +1 -1
  38. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/ed25519.js +1 -1
  39. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/utils.js +1 -1
  40. package/lib/providers/storage/car.js +2 -1
  41. package/lib/providers/storage/pinata.d.ts +16 -9
  42. package/lib/providers/storage/pinata.js +34 -25
  43. package/lib/providers/storage/types.d.ts +18 -8
  44. package/lib/{roles/repo → repo}/index.d.ts +1 -1
  45. package/lib/{roles/repo → repo}/index.js +1 -1
  46. package/lib/test/testbed.d.ts +9 -7
  47. package/lib/test/testbed.js +3 -2
  48. package/package.json +3 -9
  49. package/lib/ crypto/constants.d.ts +0 -4
  50. package/lib/ crypto/constants.js +0 -5
  51. package/lib/ crypto/merkle.d.ts +0 -10
  52. package/lib/ crypto/merkle.js +0 -34
  53. package/lib/ crypto/utils.d.ts +0 -1
  54. package/lib/ crypto/utils.js +0 -1
  55. package/lib/builders/a2aCardBuilder.d.ts +0 -28
  56. package/lib/builders/a2aCardBuilder.js +0 -105
  57. package/lib/engine/blockstore.d.ts +0 -24
  58. package/lib/engine/blockstore.js +0 -85
  59. package/lib/roles/index.d.ts +0 -1
  60. package/lib/roles/index.js +0 -1
  61. package/lib/test/car_smoke.d.ts +0 -1
  62. package/lib/test/car_smoke.js +0 -81
  63. package/lib/test/cleanup-embeddings-testdata.d.ts +0 -1
  64. package/lib/test/cleanup-embeddings-testdata.js +0 -75
  65. package/lib/test/index.d.ts +0 -10
  66. package/lib/test/index.js +0 -27
  67. package/lib/test/setup-embeddings-testdata.d.ts +0 -11
  68. package/lib/test/setup-embeddings-testdata.js +0 -155
  69. package/lib/utils/index.d.ts +0 -11
  70. package/lib/utils/index.js +0 -29
  71. package/lib/utils/manifest.d.ts +0 -23
  72. package/lib/utils/manifest.js +0 -77
package/README.md CHANGED
@@ -1,16 +1,14 @@
1
1
  # Fangorn SDK
2
2
 
3
- commit → push → discover → fetch
4
-
5
3
  Intent-bound data for the agentic web.
6
4
 
7
5
  Fangorn lets you publish content-addressed graph data, organized into namespaces, so that agents can discover and verify it across any number of publishers. Content is stored in your own storage backend (IPFS via Pinata today); the on-chain **DataRegistry** holds only a single cryptographic pointer per publisher. The protocol coordinates commitment and discovery without ever touching your content directly.
8
6
 
9
- Each publisher owns exactly **one on-chain state root** — the root of a content-addressed Pail tree (`@web3-storage/pail`), wrapped in a commit. Everything you publish lives as key-prefixed **namespaces** inside that one tree. Advancing the root is a compare-and-swap: it *is* a git ref update.
7
+ Each publisher owns exactly **one on-chain state root** — the digest of a commit block wrapping a native IPLD DAG. Everything you publish lives as **namespaces** inside that one root map. Advancing the root is a compare-and-swap: it _is_ a git ref update.
10
8
 
11
- Data is a **metagraph** — **vertices** (a JSON payload tagged by a free-form schema id) and **edges** (a labeled relation between two vertex CIDs) — committed under a namespace.
9
+ Data is a **metagraph** — **vertices** (a JSON payload tagged by a free-form schema id) and **edges** (a labeled relation between two vertices, as native IPLD links) — committed under a namespace.
12
10
 
13
- Datasets are versioned like git: each update is a **commit** that points at its parent, the registry stores only the pointer to the latest commit, and full history lives in IPFS — reconstructible from the on-chain tip alone, no indexer required. `commit` builds locally (permissionless); `push` moves the on-chain pointer (the single permissioned step, fast-forward checked).
11
+ Datasets are versioned like git, down to the storage model: each update is a **commit** that points at its parent and at a single **CAR file** (a packfile) holding only the blocks that commit introduced. The registry stores only the pointer to the latest commit; full history lives in IPFS — reconstructible from the on-chain tip alone, no indexer required. `commit` builds the graph in memory and persists it as **exactly two uploads** (one CAR + one small commit block), regardless of graph size; `push` moves the on-chain pointer (the single permissioned step, fast-forward checked). Unchanged data re-derives identical CIDs and is never re-uploaded.
14
12
 
15
13
  > **Note:** access-controlled (encrypted) fields and the purchase → claim → fetch settlement flow are being built on top of this registry and are **not available in the current release**. Registration, namespaces, and the git-native commit / push / log / clone rail are live.
16
14
 
@@ -38,6 +36,7 @@ fangorn init
38
36
  ```
39
37
 
40
38
  `fangorn init` prompts for:
39
+
41
40
  - Wallet private key
42
41
  - Pinata JWT + gateway URL (content + commit-object storage)
43
42
  - Fangorn access worker URL (reserved for the upcoming access-control flow)
@@ -64,7 +63,7 @@ fangorn register
64
63
 
65
64
  ### Track a namespace (git-native repo)
66
65
 
67
- A **namespace** is a key prefix inside your on-chain tree. `repo init` allocates it and starts tracking it in a local `.fangorn/` pointer file (just a HEAD ref — there is no local object store; commit objects live in IPFS).
66
+ A **namespace** is an entry in your on-chain root map. `repo init` allocates it and starts tracking it in a local `.fangorn/` pointer file (just a HEAD ref — there is no local object store; commit objects and their CARs live in IPFS).
68
67
 
69
68
  ```sh
70
69
  # Allocate a namespace on-chain (no-op if it already exists) and track it here
@@ -73,7 +72,7 @@ fangorn repo init rusty-anchor
73
72
 
74
73
  ### Commit → push
75
74
 
76
- `commit` snapshots a namespace's vertices/edges into a new commit **locally** (pins the blocks to IPFS, advances your local HEAD) — it does **not** touch the chain. `push` fast-forwards the on-chain state root to your local tip: the single permissioned step.
75
+ `commit` snapshots a namespace's vertices/edges into a new commit (one CAR upload to IPFS, advances your local HEAD) — it does **not** touch the chain. `push` fast-forwards the on-chain state root to your local tip: the single permissioned step.
77
76
 
78
77
  ```sh
79
78
  # Snapshot graph data into a new local commit — does NOT push
@@ -88,22 +87,44 @@ fangorn push --force # push even if it doesn't fast-forward the on-chain
88
87
 
89
88
  ```json
90
89
  {
91
- "vertices": [
92
- { "id": "t1", "tag": "track", "payload": { "title": "Locura", "artist": "Alice" } },
93
- { "id": "a1", "tag": "artist", "payload": { "name": "Alice" } }
94
- ],
95
- "edges": [
96
- { "rel": "performed_by", "from": "t1", "to": "a1" }
97
- ]
90
+ "vertices": [
91
+ {
92
+ "id": "t1",
93
+ "tag": "track",
94
+ "payload": { "title": "Locura", "artist": "Alice" }
95
+ },
96
+ { "id": "a1", "tag": "artist", "payload": { "name": "Alice" } }
97
+ ],
98
+ "edges": [{ "rel": "performed_by", "from": "t1", "to": "a1" }]
98
99
  }
99
100
  ```
100
101
 
101
- Each commit records its parent, so history is real and walkable. Deleting a vertex is just a later commit that omits it — earlier history is retained. Blocks are content-addressed, so unchanged data is reused byte-for-byte across commits.
102
-
102
+ Each commit records its parent, so history is real and walkable. By default a commit is **additive** (the staged graph joins the namespace's existing contents); pass `--replace` for snapshot semantics, where the file _is_ the namespace's new state and anything omitted is removed — earlier history is retained either way. Blocks are content-addressed, so unchanged data is reused byte-for-byte across commits and never re-uploaded.
103
103
 
104
104
  ### Graph Builders
105
105
 
106
- A graph builders are delegated to the application layer. Developers are responsible for implementing functions that take input and transform it into a set of edges and vertices. See [examples/hackmd](./examples/hackmd/) for an example.
106
+ Turning your source data into vertices and edges is application logic, but the SDK ships a small **harness** for the common "a directory of files → a graph" case, exported from the package root:
107
+
108
+ ```ts
109
+ import { buildAssetGraph, extractMarkdownLinks } from "@fangorn-network/sdk";
110
+
111
+ // One processor per file extension. Return the vertex tag/payload and the
112
+ // ids this file links to; buildAssetGraph wires the edges (rel: "links"),
113
+ // dropping self-links and links to files that don't exist.
114
+ const { vertices, edges } = buildAssetGraph("./docs", {
115
+ processors: {
116
+ ".md": (file) => ({
117
+ tag: "note",
118
+ payload: { title: file.nameNoExt, body: file.readText() },
119
+ links: extractMarkdownLinks(file.readText()), // markdown links + [[wikilinks]]
120
+ }),
121
+ },
122
+ });
123
+
124
+ await fangorn.commit({ namespace: "rusty-anchor", message: "import docs", vertices, edges });
125
+ ```
126
+
127
+ Each vertex `id` is the filename without extension. For anything that isn't "files in a folder," build the `{ vertices, edges }` arrays yourself and pass them straight to `commit` / `uploadBatch` — the harness is a convenience, not a requirement.
107
128
 
108
129
  ### Inspect
109
130
 
@@ -111,7 +132,7 @@ A graph builders are delegated to the application layer. Developers are responsi
111
132
  fangorn status # local tip vs on-chain tip
112
133
  fangorn log # walk commit history from the tip (newest first)
113
134
  fangorn log -n 5 # limit
114
- fangorn show # the tip commit + which keys it changed vs its parent
135
+ fangorn show # the tip commit + what it changed vs its parent
115
136
  fangorn show <commitCid> # a specific commit
116
137
 
117
138
  # List every vertex and edge committed under a namespace, as JSON
@@ -133,9 +154,9 @@ fangorn clone <owner> rusty-anchor --dir ./somewhere
133
154
  Watch a namespace for on-chain updates and stream the diffs — **no subgraph, no
134
155
  indexer**. A publisher owns exactly one on-chain root, so this watches that
135
156
  publisher's `StateCommitted` event (read straight from the RPC node) and, for
136
- each new root, diffs the tree against the previous one restricted to your
137
- namespace's key prefix. Only pushes that actually changed the namespace are
138
- emitted. Diffs are resolved from IPFS on demand.
157
+ each new root, diffs your namespace's link sets against the previous root.
158
+ Only pushes that actually changed the namespace are emitted. Each push's
159
+ blocks arrive as one CAR download, resolved from IPFS on demand.
139
160
 
140
161
  ```sh
141
162
  # Watch the current repo's namespace; each change is one JSON line on stdout.
@@ -152,14 +173,18 @@ Each emitted line is a namespace change:
152
173
 
153
174
  ```jsonc
154
175
  {
155
- "namespace": "rusty-anchor",
156
- "owner": "0x...",
157
- "commitCid": "bafy...", // the new on-chain tip
158
- "blockNumber": "12345678", // persist this to resume
159
- "addedVertices": [{ "cid": "bafy...", "schemaId": "track", "payload": { "title": "Locura" } }],
160
- "addedEdges": [{ "sourceCid": "bafy...", "relation": "by", "targetCid": "bafy..." }],
161
- "removedVertexCids": ["bafy..."],
162
- "removedEdges": []
176
+ "namespace": "rusty-anchor",
177
+ "owner": "0x...",
178
+ "commitCid": "bafy...", // the new on-chain tip
179
+ "blockNumber": "12345678", // persist this to resume
180
+ "addedVertices": [
181
+ { "cid": "bafy...", "schemaId": "track", "payload": { "title": "Locura" } },
182
+ ],
183
+ "addedEdges": [
184
+ { "sourceCid": "bafy...", "relation": "by", "targetCid": "bafy..." },
185
+ ],
186
+ "removedVertexCids": ["bafy..."],
187
+ "removedEdges": [],
163
188
  }
164
189
  ```
165
190
 
@@ -182,22 +207,27 @@ your initial index from `fangorn read` first, then subscribe for the deltas.
182
207
 
183
208
  ### Initialization
184
209
 
185
- `Fangorn.create` is synchronous. Pass Pinata storage for any commit/read operation.
210
+ `Fangorn.create` is synchronous. Pass Pinata storage for any commit/read operation. Supply either a `privateKey` (the SDK builds the wallet client for you) or your own viem `walletClient`.
186
211
 
187
212
  ```ts
188
213
  import { Fangorn, FangornConfig } from "@fangorn-network/sdk";
189
214
 
190
215
  const fangorn = Fangorn.create({
191
- privateKey: "0x...",
192
- storage: { pinata: { jwt: process.env.PINATA_JWT!, gateway: process.env.PINATA_GATEWAY! } },
193
- config: FangornConfig, // defaults to Arbitrum Sepolia
194
- domain: "localhost",
216
+ privateKey: "0x...",
217
+ storage: {
218
+ pinata: {
219
+ jwt: process.env.PINATA_JWT!,
220
+ gateway: process.env.PINATA_GATEWAY!,
221
+ },
222
+ },
223
+ config: FangornConfig, // defaults to Arbitrum Sepolia
224
+ domain: "localhost",
195
225
  });
196
226
 
197
227
  // Register once before committing.
198
228
  const registry = fangorn.getDataRegistry();
199
229
  if (!(await registry.isRegistered(fangorn.getAddress()))) {
200
- await registry.register();
230
+ await registry.register();
201
231
  }
202
232
  ```
203
233
 
@@ -213,13 +243,13 @@ await fangorn.initRepo("rusty-anchor");
213
243
 
214
244
  // First commit — no parent
215
245
  const c1 = await fangorn.commit({
216
- namespace: "rusty-anchor",
217
- message: "initial import",
218
- vertices: [
219
- { id: "t1", tag: "track", payload: { title: "Locura", artist: "Alice" } },
220
- { id: "a1", tag: "artist", payload: { name: "Alice" } },
221
- ],
222
- edges: [{ rel: "performed_by", from: "t1", to: "a1" }],
246
+ namespace: "rusty-anchor",
247
+ message: "initial import",
248
+ vertices: [
249
+ { id: "t1", tag: "track", payload: { title: "Locura", artist: "Alice" } },
250
+ { id: "a1", tag: "artist", payload: { name: "Alice" } },
251
+ ],
252
+ edges: [{ rel: "performed_by", from: "t1", to: "a1" }],
223
253
  });
224
254
 
225
255
  // Settle it on-chain (fast-forward from "no tip yet")
@@ -227,10 +257,12 @@ await fangorn.push(c1.commitCid);
227
257
 
228
258
  // A follow-up commit builds on the previous one
229
259
  const c2 = await fangorn.commit({
230
- namespace: "rusty-anchor",
231
- parent: c1.commitCid,
232
- message: "add another track",
233
- vertices: [{ id: "t2", tag: "track", payload: { title: "Otra", artist: "Alice" } }],
260
+ namespace: "rusty-anchor",
261
+ parent: c1.commitCid,
262
+ message: "add another track",
263
+ vertices: [
264
+ { id: "t2", tag: "track", payload: { title: "Otra", artist: "Alice" } },
265
+ ],
234
266
  });
235
267
  await fangorn.push(c2.commitCid); // refuses unless it fast-forwards the on-chain tip (pass { force: true } to override)
236
268
  ```
@@ -244,10 +276,10 @@ const tip = await fangorn.onChainTip(fangorn.getAddress());
244
276
 
245
277
  // Walk commits, newest first
246
278
  for await (const c of fangorn.log(tip!)) {
247
- console.log(c.cid, c.message);
279
+ console.log(c.cid, c.message);
248
280
  }
249
281
 
250
- // What a commit changed vs. its first parent (namespaced pail keys added/removed)
282
+ // What a commit changed vs. its first parent (namespaced vertex/edge entries added/removed)
251
283
  const diff = await fangorn.show(tip!);
252
284
 
253
285
  // Every vertex and edge currently committed under a namespace
@@ -267,9 +299,11 @@ For the common "stage and settle in one shot" case, `upload` (one vertex) and `u
267
299
  await fangorn.upload("rusty-anchor", { title: "Locura" }, "track");
268
300
 
269
301
  await fangorn.uploadBatch(
270
- "rusty-anchor",
271
- [{ id: "t1", tag: "track", payload: { title: "Locura" } }],
272
- [/* edges */],
302
+ "rusty-anchor",
303
+ [{ id: "t1", tag: "track", payload: { title: "Locura" } }],
304
+ [
305
+ /* edges */
306
+ ],
273
307
  );
274
308
  ```
275
309
 
@@ -283,14 +317,14 @@ replays from a block cursor (`fromBlock`) and then watches live until the
283
317
  const controller = new AbortController();
284
318
 
285
319
  for await (const change of fangorn.subscribe({
286
- namespace: "rusty-anchor",
287
- owner: "0x...", // defaults to your own address
288
- fromBlock: savedCursor, // omit to start live from the current tip
289
- signal: controller.signal,
320
+ namespace: "rusty-anchor",
321
+ owner: "0x...", // defaults to your own address
322
+ fromBlock: savedCursor, // omit to start live from the current tip
323
+ signal: controller.signal,
290
324
  })) {
291
- for (const v of change.addedVertices) index.upsert(v.cid, v.payload);
292
- for (const cid of change.removedVertexCids) index.remove(cid);
293
- persistCursor(change.blockNumber);
325
+ for (const v of change.addedVertices) index.upsert(v.cid, v.payload);
326
+ for (const cid of change.removedVertexCids) index.remove(cid);
327
+ persistCursor(change.blockNumber);
294
328
  }
295
329
  ```
296
330
 
@@ -300,9 +334,10 @@ two arbitrary roots without watching.
300
334
 
301
335
  ### Storage
302
336
 
303
- Fangorn operates on a 'Bring Your Own Storage' basis. Content-addressed blocks
304
- (vertices, edges, pail shards, commit objects) are pinned to IPFS via Pinata; the chain
305
- holds only the 32-byte commit pointer. Additional backends can be added behind the
337
+ Fangorn operates on a 'Bring Your Own Storage' basis. Each commit is persisted as
338
+ one CAR file (an opaque packfile of the commit's new blocks) plus one small commit
339
+ block, pinned to IPFS via Pinata; the chain holds only the 32-byte commit pointer.
340
+ The backend never needs to understand IPLD — any blob store can implement the
306
341
  `MetadataStorage` interface.
307
342
 
308
343
  ---
@@ -311,9 +346,9 @@ holds only the 32-byte commit pointer. Additional backends can be added behind t
311
346
 
312
347
  ### Arbitrum Sepolia
313
348
 
314
- | Contract | Address |
315
- | ------------- | -------------------------------------------- |
316
- | DataRegistry | `0x9a3811b365a4aeea1626eaad185b273424ae5e48` |
349
+ | Contract | Address |
350
+ | ------------ | -------------------------------------------- |
351
+ | DataRegistry | `0x9a3811b365a4aeea1626eaad185b273424ae5e48` |
317
352
 
318
353
  This is the address in `FangornConfig`; the SDK uses it by default.
319
354
 
@@ -338,11 +373,11 @@ pnpm test:e2e
338
373
 
339
374
  Required variables:
340
375
 
341
- | Variable | Description |
342
- | ----------------------- | ----------------------------------------- |
343
- | `ETH_PRIVATE_KEY` | Publisher private key (needs testnet ETH) |
344
- | `PINATA_JWT` | Pinata API JWT |
345
- | `PINATA_GATEWAY` | Pinata gateway URL |
376
+ | Variable | Description |
377
+ | ----------------- | ----------------------------------------- |
378
+ | `ETH_PRIVATE_KEY` | Publisher private key (needs testnet ETH) |
379
+ | `PINATA_JWT` | Pinata API JWT |
380
+ | `PINATA_GATEWAY` | Pinata gateway URL |
346
381
 
347
382
  The publisher must be registered (`fangorn register`, or `registry.register()`) on the target key.
348
383
 
package/lib/cli/cli.js CHANGED
@@ -4,7 +4,7 @@ import { Fangorn } from "../fangorn.js";
4
4
  import { handleCancel } from "./index.js";
5
5
  import { privateKeyToAccount } from "viem/accounts";
6
6
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
7
- import { join } from "path";
7
+ import { dirname, join } from "path";
8
8
  import { Command } from "commander";
9
9
  import { confirm, intro, outro, spinner, text } from "@clack/prompts";
10
10
  import { homedir } from "os";
@@ -33,7 +33,7 @@ function loadConfig() {
33
33
  };
34
34
  return _config;
35
35
  }
36
- {
36
+ if (privateKey || pinataJwt || pinataGateway) {
37
37
  const missing = [];
38
38
  if (!privateKey) missing.push("ETH_PRIVATE_KEY");
39
39
  if (!pinataJwt) missing.push("PINATA_JWT");
@@ -88,12 +88,12 @@ var LocalRepo = class LocalRepo {
88
88
  /** Open the repo containing `dir` (searches upward like git). Throws if none. */
89
89
  static open(dir = process.cwd()) {
90
90
  let cur = dir;
91
- while (true) {
91
+ let parent = "";
92
+ while (cur !== parent) {
92
93
  const p = LocalRepo.path(cur);
93
94
  if (existsSync(p)) return new LocalRepo(cur, JSON.parse(readFileSync(p, "utf-8")));
94
- const parent = join(cur, "..");
95
- if (parent === cur) break;
96
- cur = parent;
95
+ parent = cur;
96
+ cur = dirname(cur);
97
97
  }
98
98
  throw new Error("not a fangorn repo (no .fangorn/repo.json here or above). Run `fangorn repo init <namespace>` or `fangorn clone`.");
99
99
  }
@@ -189,7 +189,7 @@ program.command("repo").description("Repository operations").command("init").des
189
189
  const s = spinner();
190
190
  s.start(`Initializing namespace "${namespace}"...`);
191
191
  const result = await fangorn.initRepo(namespace);
192
- const head = result.alreadyInitialized ? await fangorn.onChainTip(owner) : result.commitCid ?? null;
192
+ const head = result.alreadyInitialized ? await fangorn.onChainTip(owner) : result.commitCid;
193
193
  const repo = LocalRepo.init({
194
194
  namespace,
195
195
  owner,
@@ -209,7 +209,7 @@ program.command("repo").description("Repository operations").command("init").des
209
209
  process.exit(1);
210
210
  }
211
211
  });
212
- program.command("commit").description("Snapshot a namespace's vertices/edges into a new local commit (does not push)").argument("<file>", "JSON file: {\"vertices\":[{\"id\",\"tag\",\"payload\"}],\"edges\":[{\"rel\",\"from\",\"to\"}]}").requiredOption("-m, --message <msg>", "Commit message").action(async (file, options) => {
212
+ program.command("commit").description("Snapshot a namespace's vertices/edges into a new local commit (does not push)").argument("<file>", "JSON file: {\"vertices\":[{\"id\",\"tag\",\"payload\"}],\"edges\":[{\"rel\",\"from\",\"to\"}]}").requiredOption("-m, --message <msg>", "Commit message").option("--replace", "Snapshot semantics: the file replaces the namespace's previous contents (omitted entries are removed)").action(async (file, options) => {
213
213
  try {
214
214
  if (!existsSync(file)) throw new Error(`file not found: ${file}`);
215
215
  const data = JSON.parse(readFileSync(file, "utf-8"));
@@ -224,13 +224,14 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
224
224
  vertices: data.vertices,
225
225
  edges: data.edges ?? [],
226
226
  parent,
227
- message: options.message
227
+ message: options.message,
228
+ replace: options.replace
228
229
  });
229
230
  s.stop();
230
231
  repo.setHead(result.commitCid);
231
232
  console.log(`Commit: ${result.commitCid}`);
232
233
  console.log(`Parent: ${result.parents[0] ?? "(root)"}`);
233
- console.log(`Tree: ${result.pailRoot}`);
234
+ console.log(`Tree: ${result.root}`);
234
235
  console.log(`Staged: ${data.vertices.length.toString()} vertice(s) / ${(data.edges ?? []).length.toString()} edge(s)`);
235
236
  console.log(`Message: ${options.message}`);
236
237
  console.log(`\nCommitted locally. Run \`fangorn push\` to settle it on-chain.`);
@@ -286,7 +287,7 @@ program.command("log").description("Walk commit history from the local tip").opt
286
287
  for await (const c of fangorn.log(head, options.max)) {
287
288
  console.log(`commit ${c.cid}`);
288
289
  console.log(`Date: ${new Date(c.timestamp).toISOString()}`);
289
- console.log(`Tree: ${c.pailRoot}`);
290
+ console.log(`Tree: ${c.root}`);
290
291
  console.log(`\n ${c.message}\n`);
291
292
  }
292
293
  process.exit(0);
@@ -304,7 +305,7 @@ program.command("show").description("Show a commit and what it changed vs. its p
304
305
  console.log(`commit ${target}`);
305
306
  console.log(`Date: ${new Date(diff.timestamp).toISOString()}`);
306
307
  console.log(`Parents: ${diff.parents.length ? diff.parents.join(", ") : "(root)"}`);
307
- console.log(`Tree: ${diff.pailRoot}`);
308
+ console.log(`Tree: ${diff.root}`);
308
309
  console.log(`\n ${diff.message}\n`);
309
310
  console.log(`Changes vs. parent: +${diff.added.length.toString()} / -${diff.removed.length.toString()} key(s)`);
310
311
  for (const k of diff.added) console.log(` + ${k}`);
@@ -353,7 +354,10 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
353
354
  const readCursor = () => {
354
355
  if (options.fromStart) return void 0;
355
356
  if (options.fromBlock !== void 0) return options.fromBlock;
356
- if (existsSync(cursorPath)) return BigInt(JSON.parse(readFileSync(cursorPath, "utf-8")).lastBlock) + 1n;
357
+ if (existsSync(cursorPath)) {
358
+ const numInput = JSON.parse(readFileSync(cursorPath, "utf-8")).lastBlock ?? 0;
359
+ return BigInt(numInput) + 1n;
360
+ }
357
361
  };
358
362
  const writeCursor = (block) => {
359
363
  if (!existsSync(repoDir)) mkdirSync(repoDir, { recursive: true });
@@ -365,10 +369,14 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
365
369
  };
366
370
  const bigintReplacer = (_k, v) => typeof v === "bigint" ? v.toString() : v;
367
371
  const fromBlock = readCursor();
368
- console.error(`Subscribing to "${namespace}" @ ${owner} ` + (fromBlock !== void 0 ? `from block ${fromBlock}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
372
+ console.error(`Subscribing to "${namespace}" @ ${owner} ` + (fromBlock !== void 0 ? `from block ${fromBlock.toString()}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
369
373
  const controller = new AbortController();
370
- process.on("SIGINT", () => controller.abort());
371
- process.on("SIGTERM", () => controller.abort());
374
+ process.on("SIGINT", () => {
375
+ controller.abort();
376
+ });
377
+ process.on("SIGTERM", () => {
378
+ controller.abort();
379
+ });
372
380
  for await (const change of fangorn.subscribe({
373
381
  namespace,
374
382
  owner,
@@ -402,8 +410,7 @@ program.command("read").description("List every vertex and edge committed under
402
410
  vertices: contents.vertices,
403
411
  edges: contents.edges
404
412
  };
405
- process.stdout.write(JSON.stringify(out, null, options.pretty ? 2 : 0) + "\n");
406
- process.exit(0);
413
+ process.stdout.write(JSON.stringify(out, null, options.pretty ? 2 : 0) + "\n", () => process.exit(0));
407
414
  } catch (err) {
408
415
  console.error("Failed:", err.message);
409
416
  process.exit(1);
@@ -1,5 +1,5 @@
1
1
  import "./cli.js";
2
- import * as viem105 from "viem";
2
+ import * as viem89 from "viem";
3
3
 
4
4
  //#region src/cli/index.d.ts
5
5
  declare const getChain: (chainStr: string) => {
@@ -35,17 +35,17 @@ declare const getChain: (chainStr: string) => {
35
35
  testnet: true;
36
36
  custom?: Record<string, unknown> | undefined;
37
37
  extendSchema?: Record<string, unknown> | undefined;
38
- fees?: viem105.ChainFees<undefined> | undefined;
38
+ fees?: viem89.ChainFees<undefined> | undefined;
39
39
  formatters?: undefined;
40
- prepareTransactionRequest?: ((args: viem105.PrepareTransactionRequestParameters, options: {
40
+ prepareTransactionRequest?: ((args: viem89.PrepareTransactionRequestParameters, options: {
41
41
  phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
42
- }) => Promise<viem105.PrepareTransactionRequestParameters>) | [fn: ((args: viem105.PrepareTransactionRequestParameters, options: {
42
+ }) => Promise<viem89.PrepareTransactionRequestParameters>) | [fn: ((args: viem89.PrepareTransactionRequestParameters, options: {
43
43
  phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
44
- }) => Promise<viem105.PrepareTransactionRequestParameters>) | undefined, options: {
44
+ }) => Promise<viem89.PrepareTransactionRequestParameters>) | undefined, options: {
45
45
  runAt: readonly ("beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters")[];
46
46
  }] | undefined;
47
- serializers?: viem105.ChainSerializers<undefined, viem105.TransactionSerializable> | undefined;
48
- verifyHash?: ((client: viem105.Client, parameters: viem105.VerifyHashActionParameters) => Promise<viem105.VerifyHashActionReturnType>) | undefined;
47
+ serializers?: viem89.ChainSerializers<undefined, viem89.TransactionSerializable> | undefined;
48
+ verifyHash?: ((client: viem89.Client, parameters: viem89.VerifyHashActionParameters) => Promise<viem89.VerifyHashActionReturnType>) | undefined;
49
49
  };
50
50
  declare const handleCancel: (value: unknown) => void;
51
51
  declare const selectChain: () => Promise<{
@@ -81,17 +81,17 @@ declare const selectChain: () => Promise<{
81
81
  testnet: true;
82
82
  custom?: Record<string, unknown> | undefined;
83
83
  extendSchema?: Record<string, unknown> | undefined;
84
- fees?: viem105.ChainFees<undefined> | undefined;
84
+ fees?: viem89.ChainFees<undefined> | undefined;
85
85
  formatters?: undefined;
86
- prepareTransactionRequest?: ((args: viem105.PrepareTransactionRequestParameters, options: {
86
+ prepareTransactionRequest?: ((args: viem89.PrepareTransactionRequestParameters, options: {
87
87
  phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
88
- }) => Promise<viem105.PrepareTransactionRequestParameters>) | [fn: ((args: viem105.PrepareTransactionRequestParameters, options: {
88
+ }) => Promise<viem89.PrepareTransactionRequestParameters>) | [fn: ((args: viem89.PrepareTransactionRequestParameters, options: {
89
89
  phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
90
- }) => Promise<viem105.PrepareTransactionRequestParameters>) | undefined, options: {
90
+ }) => Promise<viem89.PrepareTransactionRequestParameters>) | undefined, options: {
91
91
  runAt: readonly ("beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters")[];
92
92
  }] | undefined;
93
- serializers?: viem105.ChainSerializers<undefined, viem105.TransactionSerializable> | undefined;
94
- verifyHash?: ((client: viem105.Client, parameters: viem105.VerifyHashActionParameters) => Promise<viem105.VerifyHashActionReturnType>) | undefined;
93
+ serializers?: viem89.ChainSerializers<undefined, viem89.TransactionSerializable> | undefined;
94
+ verifyHash?: ((client: viem89.Client, parameters: viem89.VerifyHashActionParameters) => Promise<viem89.VerifyHashActionReturnType>) | undefined;
95
95
  }>;
96
96
  declare function parseGadgetArg(raw: string): {
97
97
  type: string;
package/lib/config.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as viem_chains0 from "viem/chains";
2
2
  import * as viem0 from "viem";
3
3
  import { Chain, Hex } from "viem";
4
+ import * as abitype0 from "abitype";
4
5
 
5
6
  //#region src/config.d.ts
6
7
  /**
@@ -144,7 +145,7 @@ declare const SupportedNetworks: {
144
145
  gasUsed: bigint;
145
146
  hash: `0x${string}` | null;
146
147
  logsBloom: `0x${string}` | null;
147
- miner: viem0.Address;
148
+ miner: abitype0.Address;
148
149
  mixHash: viem0.Hash;
149
150
  nonce: `0x${string}` | null;
150
151
  number: bigint | null;
@@ -170,14 +171,14 @@ declare const SupportedNetworks: {
170
171
  format: (args: viem_chains0.OpStackRpcTransaction, action?: string | undefined) => ({
171
172
  blockHash: `0x${string}` | null;
172
173
  blockNumber: bigint | null;
173
- from: viem0.Address;
174
+ from: abitype0.Address;
174
175
  gas: bigint;
175
176
  hash: viem0.Hash;
176
177
  input: viem0.Hex;
177
178
  nonce: number;
178
179
  r: viem0.Hex;
179
180
  s: viem0.Hex;
180
- to: viem0.Address | null;
181
+ to: abitype0.Address | null;
181
182
  transactionIndex: number | null;
182
183
  typeHex: viem0.Hex | null;
183
184
  v: bigint;
@@ -195,8 +196,8 @@ declare const SupportedNetworks: {
195
196
  r: viem0.Hex;
196
197
  s: viem0.Hex;
197
198
  v: bigint;
198
- to: viem0.Address | null;
199
- from: viem0.Address;
199
+ to: abitype0.Address | null;
200
+ from: abitype0.Address;
200
201
  gas: bigint;
201
202
  nonce: number;
202
203
  value: bigint;
@@ -222,14 +223,14 @@ declare const SupportedNetworks: {
222
223
  } | {
223
224
  blockHash: `0x${string}` | null;
224
225
  blockNumber: bigint | null;
225
- from: viem0.Address;
226
+ from: abitype0.Address;
226
227
  gas: bigint;
227
228
  hash: viem0.Hash;
228
229
  input: viem0.Hex;
229
230
  nonce: number;
230
231
  r: viem0.Hex;
231
232
  s: viem0.Hex;
232
- to: viem0.Address | null;
233
+ to: abitype0.Address | null;
233
234
  transactionIndex: number | null;
234
235
  typeHex: viem0.Hex | null;
235
236
  v: bigint;
@@ -250,14 +251,14 @@ declare const SupportedNetworks: {
250
251
  } | {
251
252
  blockHash: `0x${string}` | null;
252
253
  blockNumber: bigint | null;
253
- from: viem0.Address;
254
+ from: abitype0.Address;
254
255
  gas: bigint;
255
256
  hash: viem0.Hash;
256
257
  input: viem0.Hex;
257
258
  nonce: number;
258
259
  r: viem0.Hex;
259
260
  s: viem0.Hex;
260
- to: viem0.Address | null;
261
+ to: abitype0.Address | null;
261
262
  transactionIndex: number | null;
262
263
  typeHex: viem0.Hex | null;
263
264
  v: bigint;
@@ -278,14 +279,14 @@ declare const SupportedNetworks: {
278
279
  } | {
279
280
  blockHash: `0x${string}` | null;
280
281
  blockNumber: bigint | null;
281
- from: viem0.Address;
282
+ from: abitype0.Address;
282
283
  gas: bigint;
283
284
  hash: viem0.Hash;
284
285
  input: viem0.Hex;
285
286
  nonce: number;
286
287
  r: viem0.Hex;
287
288
  s: viem0.Hex;
288
- to: viem0.Address | null;
289
+ to: abitype0.Address | null;
289
290
  transactionIndex: number | null;
290
291
  typeHex: viem0.Hex | null;
291
292
  v: bigint;
@@ -306,14 +307,14 @@ declare const SupportedNetworks: {
306
307
  } | {
307
308
  blockHash: `0x${string}` | null;
308
309
  blockNumber: bigint | null;
309
- from: viem0.Address;
310
+ from: abitype0.Address;
310
311
  gas: bigint;
311
312
  hash: viem0.Hash;
312
313
  input: viem0.Hex;
313
314
  nonce: number;
314
315
  r: viem0.Hex;
315
316
  s: viem0.Hex;
316
- to: viem0.Address | null;
317
+ to: abitype0.Address | null;
317
318
  transactionIndex: number | null;
318
319
  typeHex: viem0.Hex | null;
319
320
  v: bigint;
@@ -342,16 +343,16 @@ declare const SupportedNetworks: {
342
343
  blockHash: viem0.Hash;
343
344
  blockNumber: bigint;
344
345
  blockTimestamp?: bigint | undefined;
345
- contractAddress: viem0.Address | null | undefined;
346
+ contractAddress: abitype0.Address | null | undefined;
346
347
  cumulativeGasUsed: bigint;
347
348
  effectiveGasPrice: bigint;
348
- from: viem0.Address;
349
+ from: abitype0.Address;
349
350
  gasUsed: bigint;
350
351
  logs: viem0.Log<bigint, number, false>[];
351
352
  logsBloom: viem0.Hex;
352
353
  root?: `0x${string}` | undefined;
353
354
  status: "success" | "reverted";
354
- to: viem0.Address | null;
355
+ to: abitype0.Address | null;
355
356
  transactionHash: viem0.Hash;
356
357
  transactionIndex: number;
357
358
  type: viem0.TransactionType;