@fangorn-network/sdk 2026.6.16 → 2026.7.1-2.1

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 (106) hide show
  1. package/README.md +210 -266
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +261 -167
  4. package/lib/cli/index.d.ts +13 -651
  5. package/lib/config.d.ts +137 -792
  6. package/lib/config.js +6 -22
  7. package/lib/contracts/data-registry/abi.d.ts +38 -0
  8. package/lib/contracts/data-registry/abi.js +237 -0
  9. package/lib/contracts/data-registry/index.d.ts +81 -0
  10. package/lib/contracts/data-registry/index.js +184 -0
  11. package/lib/contracts/index.d.ts +3 -0
  12. package/lib/contracts/index.js +4 -0
  13. package/lib/crypto/aes.d.ts +26 -0
  14. package/lib/crypto/aes.js +58 -0
  15. package/lib/crypto/encryption.d.ts +53 -0
  16. package/lib/crypto/encryption.js +82 -0
  17. package/lib/{modules/encryption → crypto}/rand.d.ts +1 -1
  18. package/lib/{modules/encryption → crypto}/rand.js +1 -1
  19. package/lib/{modules/encryption → crypto}/types.d.ts +1 -1
  20. package/lib/engine/blockstore.d.ts +24 -0
  21. package/lib/engine/blockstore.js +85 -0
  22. package/lib/engine/index.d.ts +180 -0
  23. package/lib/engine/index.js +367 -0
  24. package/lib/fangorn.d.ts +149 -16
  25. package/lib/fangorn.js +256 -37
  26. package/lib/harness/examples/hackmd/build-markdown-graph.js +17 -0
  27. package/lib/harness/index.d.ts +57 -0
  28. package/lib/harness/index.js +67 -0
  29. package/lib/index.d.ts +3 -2
  30. package/lib/index.js +2 -1
  31. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +218 -0
  32. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +261 -0
  33. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +156 -0
  34. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +299 -0
  35. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +532 -0
  36. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +344 -0
  37. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +137 -0
  38. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +262 -0
  39. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +150 -0
  40. package/lib/providers/storage/car.d.ts +36 -0
  41. package/lib/providers/storage/car.js +80 -0
  42. package/lib/providers/storage/pinata.d.ts +29 -1
  43. package/lib/providers/storage/pinata.js +135 -20
  44. package/lib/providers/storage/types.d.ts +25 -18
  45. package/lib/roles/repo/index.d.ts +56 -0
  46. package/lib/roles/repo/index.js +73 -0
  47. package/lib/test/car_smoke.d.ts +1 -0
  48. package/lib/test/car_smoke.js +81 -0
  49. package/lib/test/cleanup-embeddings-testdata.js +9 -38
  50. package/lib/test/setup-embeddings-testdata.d.ts +4 -6
  51. package/lib/test/setup-embeddings-testdata.js +40 -94
  52. package/lib/test/testbed.d.ts +35 -32
  53. package/lib/test/testbed.js +48 -138
  54. package/lib/types/index.d.ts +3 -19
  55. package/lib/utils/manifest.d.ts +23 -0
  56. package/lib/utils/manifest.js +77 -0
  57. package/package.json +99 -81
  58. package/lib/modules/encryption/actions.d.ts +0 -4
  59. package/lib/modules/encryption/actions.js +0 -18
  60. package/lib/modules/encryption/aes.d.ts +0 -10
  61. package/lib/modules/encryption/aes.js +0 -51
  62. package/lib/registries/datasource-registry/abi.d.ts +0 -186
  63. package/lib/registries/datasource-registry/abi.js +0 -229
  64. package/lib/registries/datasource-registry/index.d.ts +0 -39
  65. package/lib/registries/datasource-registry/index.js +0 -158
  66. package/lib/registries/index.d.ts +0 -3
  67. package/lib/registries/index.js +0 -4
  68. package/lib/registries/schema-registry/abi.d.ts +0 -218
  69. package/lib/registries/schema-registry/abi.js +0 -246
  70. package/lib/registries/schema-registry/index.d.ts +0 -34
  71. package/lib/registries/schema-registry/index.js +0 -179
  72. package/lib/registries/settlement-registry/abi.d.ts +0 -218
  73. package/lib/registries/settlement-registry/abi.js +0 -259
  74. package/lib/registries/settlement-registry/index.d.ts +0 -63
  75. package/lib/registries/settlement-registry/index.js +0 -325
  76. package/lib/registries/settlement-registry/types.d.ts +0 -54
  77. package/lib/registries/settlement-registry/types.js +0 -1
  78. package/lib/roles/consumer/index.d.ts +0 -39
  79. package/lib/roles/consumer/index.js +0 -150
  80. package/lib/roles/consumer/types.d.ts +0 -47
  81. package/lib/roles/consumer/types.js +0 -1
  82. package/lib/roles/publisher/builders/bundle.d.ts +0 -32
  83. package/lib/roles/publisher/builders/bundle.js +0 -137
  84. package/lib/roles/publisher/builders/record-set.d.ts +0 -17
  85. package/lib/roles/publisher/builders/record-set.js +0 -55
  86. package/lib/roles/publisher/builders/types.d.ts +0 -38
  87. package/lib/roles/publisher/builders/types.js +0 -1
  88. package/lib/roles/publisher/builders/utils.d.ts +0 -9
  89. package/lib/roles/publisher/builders/utils.js +0 -29
  90. package/lib/roles/publisher/encryption.d.ts +0 -18
  91. package/lib/roles/publisher/encryption.js +0 -38
  92. package/lib/roles/publisher/index.d.ts +0 -68
  93. package/lib/roles/publisher/index.js +0 -179
  94. package/lib/roles/publisher/types.d.ts +0 -114
  95. package/lib/roles/publisher/types.js +0 -1
  96. package/lib/roles/schema/index.d.ts +0 -44
  97. package/lib/roles/schema/index.js +0 -127
  98. package/lib/roles/schema/types.d.ts +0 -113
  99. package/lib/roles/schema/types.js +0 -1
  100. package/lib/roles/schema/validate.d.ts +0 -9
  101. package/lib/roles/schema/validate.js +0 -128
  102. package/lib/test/publish_mb_bundle.js +0 -296
  103. /package/lib/{modules/encryption/index.d.ts → contracts/data-registry/test.d.ts} +0 -0
  104. /package/lib/{modules/encryption/index.js → contracts/data-registry/test.js} +0 -0
  105. /package/lib/{modules/encryption → crypto}/types.js +0 -0
  106. /package/lib/{test/publish_mb_bundle.d.ts → harness/examples/hackmd/build-markdown-graph.d.ts} +0 -0
package/README.md CHANGED
@@ -1,15 +1,22 @@
1
1
  # Fangorn SDK
2
2
 
3
- commit → index → discover → prove → settle → fetch
3
+ commit → push → discover → fetch
4
4
 
5
5
  Intent-bound data for the agentic web.
6
6
 
7
- Fangorn lets you publish data under programmable access conditions. Access is enforced on-chain through settlement verification, so your content is only retrievable by those who have provably paid for it. Data is organized by schemas, enabling agent-based discovery across any number of publishers.
8
- Content is stored in your own storage backend (Cloudflare R2, IPFS, or any compatible future backend). The Fangorn protocol coordinates access without ever touching your content directly.
7
+ 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
+
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.
10
+
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.
12
+
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).
14
+
15
+ > **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.
9
16
 
10
17
  ## Supported Networks
11
18
 
12
- Arbitrum Sepolia (Base Sepolia in progress).
19
+ - Arbitrum Sepolia
13
20
 
14
21
  ---
15
22
 
@@ -32,327 +39,271 @@ fangorn init
32
39
 
33
40
  `fangorn init` prompts for:
34
41
  - Wallet private key
35
- - Pinata JWT + gateway URL (for schema/manifest storage)
36
- - Fangorn access worker URL (for content retrieval)
37
- - Default chain
42
+ - Pinata JWT + gateway URL (content + commit-object storage)
43
+ - Fangorn access worker URL (reserved for the upcoming access-control flow)
38
44
 
39
45
  Config is written to `~/.fangorn/config.json`.
40
46
 
41
- You can also configure via environment variables:
47
+ You can also configure via environment variables (these take precedence over the config file):
42
48
 
43
49
  ```sh
44
- DELEGATOR_ETH_PRIVATE_KEY=0x...
50
+ ETH_PRIVATE_KEY=0x...
45
51
  PINATA_JWT=...
46
52
  PINATA_GATEWAY=https://your-gateway.mypinata.cloud
47
- WORKER_URL=https://your-worker.workers.dev
48
53
  CHAIN_NAME=arbitrumSepolia
54
+ WORKER_URL=https://your-worker.workers.dev # optional (future access control)
49
55
  ```
50
56
 
51
- ### Register a Schema
57
+ ### Register as a publisher
58
+
59
+ Register once before committing anything. This records your wallet as a data publisher in the DataRegistry (the registration fee is currently zero).
52
60
 
53
61
  ```sh
54
- # Register a schema on-chain
55
- fangorn schema register <name>
62
+ fangorn register
63
+ ```
64
+
65
+ ### Track a namespace (git-native repo)
66
+
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).
56
68
 
57
- # Fetch a registered schema by name
58
- fangorn schema get schema.name.v1
69
+ ```sh
70
+ # Allocate a namespace on-chain (no-op if it already exists) and track it here
71
+ fangorn repo init rusty-anchor
59
72
  ```
60
73
 
61
- ### Publish Data
74
+ ### Commit → push
75
+
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.
62
77
 
63
78
  ```sh
64
- # Publish records under a schema, priced at 1 USDC unit
65
- fangorn publish upload records.json -s schema.name.v1 -p 1
79
+ # Snapshot graph data into a new local commit — does NOT push
80
+ fangorn commit graph.json -m "initial import"
66
81
 
67
- # Inspect a specific entry
68
- fangorn publish entry track1 -s schema.name.v1
82
+ # Settle the local tip on-chain (permission + fast-forward checked here)
83
+ fangorn push
84
+ fangorn push --force # push even if it doesn't fast-forward the on-chain tip
69
85
  ```
70
86
 
71
- Records are JSON files containing `PublishRecord` objects. Handle fields point to content already uploaded to your storage backend:
87
+ `graph.json` is a JSON file of vertices and (optionally) the edges between them. Edges reference vertices by their local `id`:
72
88
 
73
89
  ```json
74
90
  {
75
- "name": "track1",
76
- "fields": {
77
- "title": "Locura",
78
- "artist": "Alice",
79
- "audio": { "@type": "handle", "uri": "r2://my-dir/locura.mp3" }
80
- }
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
+ ]
81
98
  }
82
99
  ```
83
100
 
84
- > A price of `1` equals the smallest USDC unit (0.000001 USDC).
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.
85
102
 
86
- ### Consume Data
87
103
 
88
- The consumer flow is three phases: **purchase → claim → fetch**.
104
+ ### Graph Builders
89
105
 
90
- ```sh
91
- # Phase 1: pay and join the Semaphore group
92
- fangorn consume purchase <owner> <name> \
93
- -s schema.name.v1 \
94
- --burner-key 0x... \
95
- --amount 1 \
96
- --usdc 0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d
97
-
98
- # Save the identity string printed by purchase — required for claim.
99
-
100
- # Phase 2: prove membership and claim access (generates a Groth16 ZK proof)
101
- fangorn consume claim <owner> <name> \
102
- -s schema.name.v1 \
103
- --identity '<identity-string>' \
104
- --stealth <stealth-address>
105
-
106
- # Phase 3: fetch content via the access worker
107
- fangorn consume fetch <owner> <name> \
108
- -s schema.name.v1 \
109
- -f audio \
110
- --nullifier <nullifier> \
111
- --stealth-key 0x... \
112
- -o output.mp3
113
-
114
- # List a publisher's manifest
115
- fangorn consume list -s schema.name.v1 --owner <address>
116
-
117
- # Inspect a publisher's entry
118
- fangorn consume entry track1 -s schema.name.v1 --owner <address>
119
- ```
120
-
121
- ---
122
-
123
- ## SDK Usage
124
-
125
- ### Initialization
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.
126
107
 
127
- ```ts
128
- import { Fangorn, FangornConfig } from "@fangorn-network/sdk";
108
+ ### Inspect
129
109
 
130
- const fangorn = await Fangorn.create({
131
- privateKey: "0x...",
132
- workerUrl: "https://your-worker.workers.dev",
133
- config: FangornConfig.ArbitrumSepolia,
134
- domain: "localhost",
135
- });
110
+ ```sh
111
+ fangorn status # local tip vs on-chain tip
112
+ fangorn log # walk commit history from the tip (newest first)
113
+ fangorn log -n 5 # limit
114
+ fangorn show # the tip commit + which keys it changed vs its parent
115
+ fangorn show <commitCid> # a specific commit
116
+
117
+ # List every vertex and edge committed under a namespace, as JSON
118
+ fangorn read # defaults to the current repo's namespace + owner
119
+ fangorn read rusty-anchor --owner 0x... --pretty
136
120
  ```
137
121
 
138
- ### Storage
122
+ ### Clone
139
123
 
140
- Fangorn operates on a 'Bring Your Own Storage' basis.
124
+ Reconstruct tracking of a published namespace from its on-chain tip alone. History and contents are then fetched on demand from IPFS.
141
125
 
142
- - Schema definitions and schema-conformant data sets live in IPFS using Pinata.
143
- - Storage of data that should be guarded via Fangorn can live in any database desired, be it S3 or within IPFS. At present, the implementation only supports Cloudflare R2.
126
+ ```sh
127
+ fangorn clone <owner> rusty-anchor
128
+ fangorn clone <owner> rusty-anchor --dir ./somewhere
129
+ ```
144
130
 
145
- Storage is used for schemas and manifests only. Content itself lives in your storage backend (R2 etc.) and is never handled by the SDK directly.
131
+ ### Subscribe (light client)
146
132
 
147
- ### Schemas
133
+ Watch a namespace for on-chain updates and stream the diffs — **no subgraph, no
134
+ indexer**. A publisher owns exactly one on-chain root, so this watches that
135
+ 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.
148
139
 
149
- A `SchemaDefinition` is a JSON object where each field declares its type. Fields marked `@type: "handle"` point to content in an external storage backend — access is enforced by the Fangorn access worker. All other fields are stored inline in the manifest and are publicly readable.
140
+ ```sh
141
+ # Watch the current repo's namespace; each change is one JSON line on stdout.
142
+ fangorn subscribe
150
143
 
151
- ```ts
152
- const definition: SchemaDefinition = {
153
- title: { "@type": "string" },
154
- artist: { "@type": "string" },
155
- audio: { "@type": "handle" }, // content lives in R2, access-controlled by worker
156
- };
157
-
158
- // Register the schema on-chain
159
- const { schemaId, schemaCid } = await fangorn.schema.register({
160
- name: "schema.name.v1",
161
- definition,
162
- agentId: "",
163
- });
144
+ # Watch any publisher's namespace explicitly.
145
+ fangorn subscribe rusty-anchor --owner 0x...
164
146
 
165
- // Fetch a schema by name
166
- const schema = await fangorn.schema.get("schema.name.v1");
147
+ # Feed an embeddings/index builder directly.
148
+ fangorn subscribe rusty-anchor --owner 0x... | my-index-builder
167
149
  ```
168
150
 
169
- ### Publishing
151
+ Each emitted line is a namespace change:
170
152
 
171
- Fangorn supports two manifest kinds, selected by which builder you pass to `publisher.publish()`.
153
+ ```jsonc
154
+ {
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": []
163
+ }
164
+ ```
172
165
 
173
- #### Record-set
166
+ **Resumability.** The last processed block is saved to
167
+ `.fangorn/subscribe-<owner>-<namespace>.json` after each change, so restarting
168
+ replays only what you missed (via `eth_getLogs`) before going live. Override or
169
+ reset:
174
170
 
175
- Upload content to your R2 bucket out-of-band, then publish a manifest pointing at it. The SDK stores the manifest on IPFS and commits the Merkle root on-chain.
171
+ ```sh
172
+ fangorn subscribe --from-block 12000000 # replay from a specific block
173
+ fangorn subscribe --from-start # replay the namespace's full history
174
+ ```
176
175
 
177
- ```ts
178
- // Convenience wrapper — equivalent to publish({ builder: new RecordSetBuilder(), ... })
179
- await fangorn.publisher.publishRecords({
180
- schemaName: "schema.name.v1",
181
- records: [
182
- {
183
- name: "track1",
184
- fields: {
185
- title: "Locura",
186
- artist: "Alice",
187
- audio: { "@type": "handle", uri: "r2://my-dir/locura.mp3" },
188
- },
189
- },
190
- ],
191
- });
176
+ Without a saved cursor, subscribe starts **live from the current tip** — seed
177
+ your initial index from `fangorn read` first, then subscribe for the deltas.
192
178
 
193
- // Legacy alias still works
194
- await fangorn.publisher.upload({ schemaName: "schema.name.v1", records: [...] });
195
- ```
179
+ ---
196
180
 
197
- The resulting manifest has `kind: "record-set"` and `version: 2`. Plain fields (`title`, `artist`) are publicly readable from the manifest; handle fields require a valid on-chain settlement to retrieve via the access worker.
181
+ ## SDK Usage
198
182
 
199
- #### Bundle
183
+ ### Initialization
200
184
 
201
- A bundle is a small typed subgraph spanning multiple schemas. Define the shape once via a bundle schema, then publish node + edge data against it. This is the right primitive for linked data (e.g. tracks + taxonomy + edges between them).
185
+ `Fangorn.create` is synchronous. Pass Pinata storage for any commit/read operation.
202
186
 
203
187
  ```ts
204
- // 1. Register node schemas (idempotent)
205
- await fangorn.schema.register({ name: "my.track.v1", definition: trackSchema });
206
- await fangorn.schema.register({ name: "my.taxonomy.v1", definition: taxonomySchema });
207
-
208
- // 2. Register the bundle shape (idempotent)
209
- await fangorn.schema.register({
210
- kind: "bundle",
211
- name: "my.bundle.v1",
212
- bundle: {
213
- nodes: { Track: "my.track.v1", Taxonomy: "my.taxonomy.v1" },
214
- edges: [{ rel: "hasTaxonomy", from: "Track", to: "Taxonomy", min: 1, max: 1 }],
215
- },
216
- });
188
+ import { Fangorn, FangornConfig } from "@fangorn-network/sdk";
217
189
 
218
- // 3. Publish data
219
- await fangorn.publisher.publishBundle({
220
- bundleName: "my.bundle.v1",
221
- nodes: [
222
- { id: "t1", type: "Track", fields: { trackId: "t1", title: "Locura", ... } },
223
- { id: "x1", type: "Taxonomy", fields: { trackId: "t1", genres: ["electronic"] } },
224
- ],
225
- edges: [
226
- { rel: "hasTaxonomy", from: "t1", to: "x1" },
227
- ],
228
- datasetName: "my-dataset-v1",
190
+ 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",
229
195
  });
230
196
 
231
- // Legacy alias still works
232
- await fangorn.publisher.uploadBundle({ bundleName: "my.bundle.v1", nodes: [...], edges: [...] });
197
+ // Register once before committing.
198
+ const registry = fangorn.getDataRegistry();
199
+ if (!(await registry.isRegistered(fangorn.getAddress()))) {
200
+ await registry.register();
201
+ }
233
202
  ```
234
203
 
235
- The resulting manifest has `kind: "bundle"` and `version: 3`. Node chunks and the edge chunk are stored separately on IPFS and committed together under a single Merkle root.
236
-
237
- #### Custom builders
204
+ ### Namespaces & the git-native flow
238
205
 
239
- Both `RecordSetBuilder` and `BundleBuilder` implement the `ManifestBuilder` interface. You can implement your own:
206
+ `initRepo` allocates a namespace on-chain (idempotent). Then split building from settling:
207
+ `commit` writes a commit object locally (durable in IPFS, HEAD not yet on-chain), and
208
+ `push` fast-forwards the on-chain root to it.
240
209
 
241
210
  ```ts
242
- import {
243
- ManifestBuilder, BuildContext, ChunkDraft, ChunkRef,
244
- BaseManifest, ResolvedSchemaShape,
245
- } from "@fangorn-network/sdk";
246
-
247
- class MyBuilder implements ManifestBuilder<MyInput, MyManifest> {
248
- readonly kind = "my-kind";
249
- readonly version = 1;
250
- validate(schema, input) { /* ... */ }
251
- async *chunk(input, schema) { yield { name: "chunk:0", data: [...] }; }
252
- compareChunks(a, b) { return a.cid.localeCompare(b.cid); }
253
- assemble(ctx, input, schema): MyManifest { /* ... */ }
254
- }
211
+ // Allocate the namespace (no-op if it already exists)
212
+ await fangorn.initRepo("rusty-anchor");
213
+
214
+ // First commit — no parent
215
+ 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" }],
223
+ });
224
+
225
+ // Settle it on-chain (fast-forward from "no tip yet")
226
+ await fangorn.push(c1.commitCid);
255
227
 
256
- await fangorn.publisher.publish({
257
- schemaName: "my.schema.v1",
258
- builder: new MyBuilder(),
259
- input: myInput,
260
- datasetName: "my-dataset",
228
+ // A follow-up commit builds on the previous one
229
+ 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" } }],
261
234
  });
235
+ await fangorn.push(c2.commitCid); // refuses unless it fast-forwards the on-chain tip (pass { force: true } to override)
262
236
  ```
263
237
 
264
- ### Consuming
238
+ ### History, diff & read
265
239
 
266
- #### Phase 1: Purchase
240
+ Walk history from the on-chain tip (IPFS only, no indexer), and read the current namespace contents:
267
241
 
268
242
  ```ts
269
- import { Identity } from "@semaphore-protocol/identity";
243
+ const tip = await fangorn.onChainTip(fangorn.getAddress());
270
244
 
271
- const identity = new Identity();
272
-
273
- const preparedRegister = await fangorn.consumer.prepareRegister({
274
- walletClient,
275
- paymentRecipient: ownerAddress,
276
- amount: 1n,
277
- usdcAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
278
- usdcDomainName: "USD Coin",
279
- usdcDomainVersion: "2",
280
- });
245
+ // Walk commits, newest first
246
+ for await (const c of fangorn.log(tip!)) {
247
+ console.log(c.cid, c.message);
248
+ }
281
249
 
282
- const { txHash } = await fangorn.consumer.register({
283
- owner: ownerAddress,
284
- schemaId,
285
- name: "track1",
286
- identityCommitment: identity.commitment,
287
- relayerPrivateKey: "0x...",
288
- preparedRegister,
289
- });
250
+ // What a commit changed vs. its first parent (namespaced pail keys added/removed)
251
+ const diff = await fangorn.show(tip!);
290
252
 
291
- // Save identity.export() — required for Phase 2
253
+ // Every vertex and edge currently committed under a namespace
254
+ const contents = await fangorn.inspectNamespace("rusty-anchor");
255
+ // contents.vertices: { cid, schemaId, payload }[] contents.edges: { sourceCid, relation, targetCid }[]
292
256
  ```
293
257
 
294
- #### Phase 2: Claim
295
-
296
- ```ts
297
- const preparedSettle = await fangorn.consumer.prepareSettle({
298
- resourceId: DataSourceRegistry.resourceIdLocal(ownerAddress, schemaId, "track1"),
299
- identity,
300
- stealthAddress: "0x...",
301
- });
302
-
303
- const { txHash, nullifier } = await fangorn.consumer.claim({
304
- owner: ownerAddress,
305
- schemaId,
306
- name: "track1",
307
- relayerPrivateKey: "0x...",
308
- preparedSettle,
309
- });
258
+ > The fast-forward check in `push` is enforced client-side against the on-chain
259
+ > head in this release; on-chain write-authorization lands in a later slice.
310
260
 
311
- // Save nullifier — required for Phase 3
312
- ```
261
+ ### Immediate-write helpers
313
262
 
314
- #### Phase 3: Fetch
263
+ For the common "stage and settle in one shot" case, `upload` (one vertex) and `uploadBatch`
264
+ (many vertices + edges) run the whole commit-and-push atomically:
315
265
 
316
266
  ```ts
317
- import { createWalletClient, http } from "viem";
318
- import { privateKeyToAccount } from "viem/accounts";
319
- import { arbitrumSepolia } from "viem/chains";
320
-
321
- const stealthWalletClient = createWalletClient({
322
- account: privateKeyToAccount(stealthPrivateKey),
323
- chain: arbitrumSepolia,
324
- transport: http(rpcUrl),
325
- });
267
+ await fangorn.upload("rusty-anchor", { title: "Locura" }, "track");
326
268
 
327
- const { data, contentType } = await fangorn.consumer.fetchField(
328
- ownerAddress,
329
- schemaId,
330
- "track1",
331
- "audio",
332
- nullifier.toString(),
333
- stealthWalletClient,
269
+ await fangorn.uploadBatch(
270
+ "rusty-anchor",
271
+ [{ id: "t1", tag: "track", payload: { title: "Locura" } }],
272
+ [/* edges */],
334
273
  );
335
274
  ```
336
275
 
337
- The consumer signs `{ nullifier, resourceId, objectKey, timestamp }` with their stealth key. The access worker verifies the signature, checks `is_settled()` on-chain, and proxies the content bytes directly from R2. The content URL is never exposed to the client.
276
+ ### Subscribe (light client)
338
277
 
339
- ---
278
+ `subscribe` is an async generator over namespace-scoped changes. It optionally
279
+ replays from a block cursor (`fromBlock`) and then watches live until the
280
+ `AbortSignal` fires. Each change carries `blockNumber` — persist it to resume.
340
281
 
341
- ## Access Worker
342
-
343
- The Fangorn access worker is a Cloudflare Worker that gates R2 content behind on-chain settlement verification. Publishers deploy their own worker, with one worker per R2 bucket.
344
-
345
- ### How it works
282
+ ```ts
283
+ const controller = new AbortController();
284
+
285
+ 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,
290
+ })) {
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);
294
+ }
295
+ ```
346
296
 
347
- 1. Consumer signs `{ nullifier, resourceId, objectKey, timestamp }` with their stealth address private key
348
- 2. Worker recovers the stealth address from the signature
349
- 3. Worker calls `is_settled(stealthAddress, resourceId)` on the Settlement Registry
350
- 4. If settled → bytes proxied directly from R2
351
- 5. If not → 401
297
+ The pure diff primitive is also exposed on the engine —
298
+ `engine.namespaceDiff(oldRootHex, newRootHex, namespace)` — if you want to diff
299
+ two arbitrary roots without watching.
352
300
 
353
- The worker is stateless, open-source, and has no logging. Its only capability is verifying settlement and proxying bytes. The content URL is never exposed to the consumer.
301
+ ### Storage
354
302
 
355
- See the [fangorn-access-worker](https://github.com/fangorn-network/webworker) repo for deployment instructions.
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
306
+ `MetadataStorage` interface.
356
307
 
357
308
  ---
358
309
 
@@ -360,11 +311,11 @@ See the [fangorn-access-worker](https://github.com/fangorn-network/webworker) re
360
311
 
361
312
  ### Arbitrum Sepolia
362
313
 
363
- | Contract | Address |
364
- | ------------------- | -------------------------------------------- |
365
- | DataSource Registry | `0xe8a5906825680a5816a7f28f2a0fa2d9ceec3755` |
366
- | Schema Registry | `0x267084865813550d9d97d3842c4a2d33a872908f` |
367
- | Settlement Registry | `0x1d21545f536a2f026348477960ca59f9f1d7fabd` |
314
+ | Contract | Address |
315
+ | ------------- | -------------------------------------------- |
316
+ | DataRegistry | `0x9a3811b365a4aeea1626eaad185b273424ae5e48` |
317
+
318
+ This is the address in `FangornConfig`; the SDK uses it by default.
368
319
 
369
320
  ---
370
321
 
@@ -378,6 +329,8 @@ pnpm test
378
329
 
379
330
  ### E2E Tests
380
331
 
332
+ Runs the storage + on-chain anchor flow against live IPFS + the deployed contract.
333
+
381
334
  ```sh
382
335
  cp env.example .env
383
336
  pnpm test:e2e
@@ -385,34 +338,25 @@ pnpm test:e2e
385
338
 
386
339
  Required variables:
387
340
 
388
- | Variable | Description |
389
- | ------------------------------ | ----------------------------------------- |
390
- | `DELEGATOR_ETH_PRIVATE_KEY` | Publisher private key (needs testnet ETH) |
391
- | `DELEGATEE_ETH_PRIVATE_KEY` | Consumer private key |
392
- | `PINATA_JWT` | Pinata API JWT |
393
- | `PINATA_GATEWAY` | Pinata gateway URL |
394
- | `WORKER_URL` | Access worker URL (optional for Phase 3) |
395
- | `CHAIN_NAME` | `arbitrumSepolia` |
396
- | `CAIP2` | `421614` |
397
- | `RPC_URL` | RPC endpoint |
398
- | `USDC_ADDRESS` | USDC contract address |
399
- | `DATA_SOURCE_REGISTRY_ADDRESS` | DataSourceRegistry address |
400
- | `SCHEMA_REGISTRY_ADDRESS` | SchemaRegistry address |
401
- | `SETTLEMENT_REGISTRY_ADDRESS` | SettlementRegistry address |
402
-
403
- Phase 3 tests are skipped unless `WORKER_URL` is set. Run the access worker locally with `wrangler dev --local` and set `WORKER_URL=http://localhost:8787` to enable them.
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 |
346
+
347
+ The publisher must be registered (`fangorn register`, or `registry.register()`) on the target key.
404
348
 
405
349
  ---
406
350
 
407
351
  ## Limitations / Future Work
408
352
 
409
- - Schema validation is client-side only — no on-chain enforcement.
410
- - The access worker is a trusted component. Future versions will replace it with a TEE or protocol-native verification layer.
411
- - One worker per R2 bucket. Multi-bucket support is planned.
412
- - Purchase ledger is in-memory only. Persistent ledger backed by IPFS is in progress.
353
+ - Access-controlled (encrypted) fields and the purchase → claim → fetch settlement flow are being built on this registry — not available this release.
354
+ - Vertex/edge schema validation is client-side only — no on-chain enforcement.
355
+ - Push authorization is client-side in this release; on-chain write policies and non-fast-forward rejection are planned.
356
+ - Reads target one publisher's namespace at a time; cross-publisher discovery is a higher layer.
413
357
 
414
358
  ---
415
359
 
416
360
  ## License
417
361
 
418
- MITSonnet 4.6Claude is AI and can make mistakes. Please double-check responses.
362
+ MIT
package/lib/cli/cli.d.ts CHANGED
File without changes