@fangorn-network/sdk 2026.8.18-dev → 2026.10.1-9.0-dev

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 (91) hide show
  1. package/README.md +191 -195
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +198 -164
  4. package/lib/cli/index.d.ts +3 -91
  5. package/lib/cli/index.js +5 -2
  6. package/lib/config.d.ts +349 -433
  7. package/lib/config.js +41 -28
  8. package/lib/contracts/app-registry/abi.d.ts +1064 -265
  9. package/lib/contracts/app-registry/abi.js +1233 -308
  10. package/lib/contracts/app-registry/index.d.ts +123 -102
  11. package/lib/contracts/app-registry/index.js +200 -198
  12. package/lib/contracts/data-registry/abi.d.ts +166 -187
  13. package/lib/contracts/data-registry/abi.js +207 -237
  14. package/lib/contracts/data-registry/index.d.ts +4 -160
  15. package/lib/contracts/data-registry/index.js +5 -294
  16. package/lib/contracts/index.d.ts +6 -7
  17. package/lib/contracts/index.js +6 -8
  18. package/lib/contracts/logs.d.ts +21 -0
  19. package/lib/contracts/logs.js +32 -0
  20. package/lib/contracts/membership-registry/abi.d.ts +1145 -0
  21. package/lib/contracts/membership-registry/abi.js +1333 -0
  22. package/lib/contracts/membership-registry/index.d.ts +79 -0
  23. package/lib/contracts/membership-registry/index.js +104 -0
  24. package/lib/contracts/types.d.ts +3 -1
  25. package/lib/contracts/types.js +3 -1
  26. package/lib/contracts/write.d.ts +34 -2
  27. package/lib/contracts/write.js +48 -1
  28. package/lib/crypto/encryption.js +4 -4
  29. package/lib/engine/car.d.ts +2 -2
  30. package/lib/engine/car.js +10 -5
  31. package/lib/engine/index.d.ts +99 -143
  32. package/lib/engine/index.js +156 -295
  33. package/lib/engine/records.d.ts +110 -0
  34. package/lib/engine/records.js +165 -0
  35. package/lib/engine/test-helpers.d.ts +7 -14
  36. package/lib/engine/test-helpers.js +7 -18
  37. package/lib/fangorn.d.ts +163 -155
  38. package/lib/fangorn.js +284 -248
  39. package/lib/feed.d.ts +7 -4
  40. package/lib/feed.js +4 -1
  41. package/lib/index.d.ts +9 -9
  42. package/lib/index.js +9 -10
  43. package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
  44. package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
  45. package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
  46. package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
  47. package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
  48. package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
  49. package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
  50. package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
  51. package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
  52. package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
  53. package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
  54. package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
  55. package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
  56. package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
  57. package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
  58. package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
  59. package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
  60. package/lib/node_modules/chai/index.js +2874 -0
  61. package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
  62. package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
  63. package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
  64. package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
  65. package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
  66. package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
  67. package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
  68. package/lib/providers/storage/signed-url.d.ts +16 -6
  69. package/lib/providers/storage/signed-url.js +20 -8
  70. package/lib/registry.d.ts +116 -0
  71. package/lib/registry.js +182 -0
  72. package/lib/test/mem-registry.d.ts +51 -0
  73. package/lib/test/mem-registry.js +107 -0
  74. package/lib/test/sdk-suite.d.ts +13 -0
  75. package/lib/test/sdk-suite.js +226 -0
  76. package/lib/test/testbed.d.ts +16411 -61
  77. package/lib/test/testbed.js +190 -84
  78. package/lib/types/index.d.ts +13 -11
  79. package/package.json +89 -72
  80. package/lib/contracts/data-registry/test.d.ts +0 -1
  81. package/lib/contracts/data-registry/test.js +0 -1
  82. package/lib/contracts/settlement-registry/abi.d.ts +0 -466
  83. package/lib/contracts/settlement-registry/abi.js +0 -535
  84. package/lib/contracts/settlement-registry/index.d.ts +0 -163
  85. package/lib/contracts/settlement-registry/index.js +0 -264
  86. package/lib/contracts/subscription-registry/abi.d.ts +0 -179
  87. package/lib/contracts/subscription-registry/abi.js +0 -195
  88. package/lib/contracts/subscription-registry/index.d.ts +0 -59
  89. package/lib/contracts/subscription-registry/index.js +0 -116
  90. package/lib/engine/graph.d.ts +0 -70
  91. package/lib/engine/graph.js +0 -73
package/README.md CHANGED
@@ -1,33 +1,29 @@
1
1
  # Fangorn SDK
2
2
 
3
- The Fangorn SDK is git for graphs, enabling version control and distribution of *metagraphs* organized into applications and namespaces.
3
+ The Fangorn SDK is a lightweight "git for data" protocol: publishers version *repos* of records in IPFS and move each repo's head on-chain, and *apps* sponsor storage for the publishers they accept.
4
4
 
5
- It lets you treat IPFS as a hierarchical data store for your app-level storage with enforced terms, conditions, and validation logic for publishers. Data is published under a *namespace* in a *registered application*, **`app : publisher : namespace`**. Each namespace has its own on-chain state root (the digest of a commit block wrapping a native IPLD DAG) owned by the *publisher* who passed the app's validation logic. Updating a namespace root is a compare-and-swap operation (i.e. a git ref update).
5
+ A **repo** belongs to its publisher, keyed **`publisher : repo`**. Its state is a map of **records** (`{ id, type, payload }`, content-addressed), and its head is the digest of the latest commit block. Any wallet can update its own repos; updating a head is a compare-and-swap on the parent (i.e. a git ref update), and an update names no app.
6
6
 
7
- Each namespace's state is represented by a **metagraph**, $G = (V, E, L)$ where $V$=**vertices** (a JSON payload tagged by a free-form schema id) and $E$=**edges** (a labeled relation between two vertices, as native IPLD links), $L$=**labels** (the allowed labels in any edge).
7
+ An **app** is sponsored storage. Its owner accepts publishers; an accepted publisher uploads with the app's storage, and the app presents that publisher's repos at their latest heads.
8
8
 
9
9
  **Version Control**
10
10
 
11
- Datasets are versioned like git. Each update is a **commit** that points at its parent (previous graph state) and at a single **CAR file** (a packfile) holding only the blocks that were introduced in the commit. The onchain data registry stores the root of the latest commit, with full history living in IPFS. Full history is reconstructible from the onchain root (head) of a namespace without an indexer required.
11
+ Repos are versioned like git. Each update is a **commit** that points at its parent (previous state) and at a single **CAR file** (a packfile) holding only the blocks that were introduced in the commit. The on-chain data registry stores the head of each repo, with full history living in IPFS. Full history is reconstructible from the on-chain head without an indexer.
12
12
 
13
- - `commit` (local) builds the graph in memory and persists it in two uploads, one CAR (the graph data) + one small commit block.
14
- - `push` (remote) updates the onchain root to the latest staged commit
13
+ - `commit` (local) builds the new state in memory and persists it in two uploads, one CAR (the data) + one small commit block.
14
+ - `push` (remote) moves the on-chain head to the latest staged commit
15
15
 
16
- > Since the metagraph edges are native IPLD links, the DAG (directed acyclic graph) is easily 'diffable' and verifiable from the root stored onchain, though it is not easily queryable (see: [quickbeam](https://github.com/fangorn-network/quickbeam))
16
+ > Since commits and records are native IPLD links, the DAG (directed acyclic graph) is easily 'diffable' and verifiable from the head stored on-chain, though it is not easily queryable (see: [quickbeam](https://github.com/fangorn-network/quickbeam))
17
17
 
18
18
  **Storage**
19
19
 
20
- Metagraphs are stored in IPFS. The SDK currently expects Pinata to be used to ensure data availability, which will be relaxed in the future.
20
+ Repos are stored in IPFS. The SDK currently expects Pinata to be used to ensure data availability, which will be relaxed in the future.
21
21
 
22
22
  #### What it is not
23
23
 
24
- This is not a graph database, there is no query langauge here, and there is no native indexer.
25
-
24
+ This is not a graph database. There is no query langauge here and there is no native indexer.
26
25
 
27
26
  ## Supported Networks
28
-
29
- - Arbitrum Sepolia
30
-
31
27
  ---
32
28
 
33
29
  ## Installation
@@ -60,7 +56,7 @@ You can also configure via environment variables (these take precedence over the
60
56
  ETH_PRIVATE_KEY=0x...
61
57
  PINATA_JWT=...
62
58
  PINATA_GATEWAY=https://your-gateway.mypinata.cloud
63
- CHAIN_NAME=arbitrumSepolia
59
+ CHAIN_NAME=arbitrumSepolia # or baseSepolia
64
60
  ACCESS_WORKER_URL=https://access-worker.your-subdomain.workers.dev # optional (sealed fields)
65
61
  SIGNED_URL_WORKER_URL=https://pinata-url-provider.your-subdomain.workers.dev # optional
66
62
  ```
@@ -77,77 +73,87 @@ fangorn wallet show --reveal # also prints the PRIVATE key — it grants full
77
73
  The private key is never printed without `--reveal`: terminal scrollback, shell
78
74
  logs and screen shares all outlive the command.
79
75
 
80
- ### Pick an app, then register
76
+ ### Pick an app
81
77
 
82
- Publishing takes standing in **two** registries, and skipping the second is the
83
- usual first failure: `commitStateRoot` cross-calls `isRegisteredForApp`, so a
84
- wallet registered globally but not joined to the app gets `NotRegisteredForApp`
85
- at push time — far from the cause.
78
+ Publishing needs no app: any wallet updates its own repos, and an update names
79
+ no app. **An app is sponsored storage for the publishers it accepts**: its owner
80
+ accepts a publisher, the app pays for that publisher's uploads, and it includes
81
+ their repos at their latest heads, less what the owner withdraws
82
+ (`registry.exclude`).
86
83
 
87
84
  ```sh
88
85
  fangorn set-app my-app # persists the app; --app <name-or-id> overrides per command
89
- fangorn app info # owner, terms, join fee, and where you stand in both registries
90
- fangorn app claim # claim it, if nobody owns it yet (irreversible)
91
- fangorn register # global standing in the DataRegistry, then join the app
86
+ fangorn app info # owner, subscription, and where you stand in it
87
+ fangorn app claim # claim it, if nobody owns it yet (irreversible; pays the subscription)
92
88
  ```
93
89
 
94
- `fangorn register` is idempotent and does both halves, reporting each. It is the
95
- only registration command you normally need; `fangorn app join` exists for
96
- joining an app you don't own, and for re-accepting terms after the owner moves
97
- them (free).
90
+ The protocol admin can ban a wallet network-wide: it can't claim an app or be
91
+ accepted into one, and no app stores or presents it.
92
+
93
+ **An app is a storage subscription** (ERC-5643; the app is a token that cannot
94
+ be transferred). `fangorn app claim` pays one period of the subscription fee in
95
+ USDC (the client approves exactly the fee for you), and `fangorn app renew` pays
96
+ the next once less than a period is left. An expired app stores and presents nothing
97
+ until it is renewed. **Apps provide storage**: you upload relative to
98
+ an app, and hosted uploads (`storage: { signedUrl: {} }`) are billed to the
99
+ client's app, which must have accepted you. There is no app-less hosted upload — with no
100
+ app, bring your own Pinata (`{ pinata }`) and pin your own data. A publisher that
101
+ pays for its own storage claims a one-member app.
102
+
103
+ **The owner accepts publishers.** `fangorn app accept <address>` is the whole
104
+ membership: no invitation, terms or join fee. The owner is their own first
105
+ publisher.
98
106
 
99
107
  Owning an app comes with its own commands:
100
108
 
101
109
  ```sh
102
- fangorn app terms <hash> [uri] # publish new terms — everyone must re-accept
103
- fangorn app fee <wei> # what joining costs
104
- fangorn app suspend <address> # eject a publisher from THIS app only
110
+ fangorn app accept <address> # accept a publisher: the app stores and includes its data
111
+ fangorn app suspend <address> # suspend a member from THIS app only
105
112
  fangorn app reinstate <address>
113
+ fangorn app renew # pay for the next period
114
+ fangorn app cancel # end the subscription now, no refund
115
+ fangorn app withdraw-fees [to] # join fees still owed from before joining was removed
106
116
  ```
107
117
 
108
- ### Track a namespace (git-native repo)
118
+ ### Track a repo
109
119
 
110
- 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).
120
+ `repo init` creates the repo with an empty first commit, pushes 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).
111
121
 
112
122
  ```sh
113
- # Allocate a namespace on-chain (no-op if it already exists) and track it here
123
+ # Create the repo on-chain (no-op if it already exists) and track it here
114
124
  fangorn repo init rusty-anchor
115
125
  ```
116
126
 
117
127
  ### Commit → push
118
128
 
119
- `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.
129
+ `commit` puts and deletes a repo's records in a new commit (one CAR upload to IPFS, advances your local HEAD) — it does **not** touch the chain. `push` fast-forwards the on-chain head to your local tip.
120
130
 
121
131
  ```sh
122
- # Snapshot graph data into a new local commit — does NOT push
123
- fangorn commit graph.json -m "initial import"
132
+ # Stage records into a new local commit — does NOT push
133
+ fangorn commit records.json -m "initial import"
124
134
 
125
135
  # Settle the local tip on-chain (permission + fast-forward checked here)
126
136
  fangorn push
127
137
  fangorn push --force # push even if it doesn't fast-forward the on-chain tip
128
138
  ```
129
139
 
130
- `graph.json` is a JSON file of vertices and (optionally) the edges between them. Edges reference vertices by their local `id`:
140
+ `records.json` lists the records to put (an `id` is generated when omitted, and an existing `id` is overwritten) and the ids to delete:
131
141
 
132
142
  ```json
133
143
  {
134
- "vertices": [
135
- {
136
- "id": "t1",
137
- "tag": "track",
138
- "payload": { "title": "Locura", "artist": "Alice" }
139
- },
140
- { "id": "a1", "tag": "artist", "payload": { "name": "Alice" } }
144
+ "records": [
145
+ { "id": "t1", "type": "track", "payload": { "title": "Locura", "artist": "Alice" } },
146
+ { "id": "a1", "type": "artist", "payload": { "name": "Alice" } }
141
147
  ],
142
- "edges": [{ "rel": "performed_by", "from": "t1", "to": "a1" }]
148
+ "deletes": ["t0"]
143
149
  }
144
150
  ```
145
151
 
146
- 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.
152
+ Each commit records its parent, so history is real and walkable. By default a commit is **additive** (the staged records join the repo's existing contents); pass `--replace` for snapshot semantics, where the file _is_ the repo's new state and anything omitted is removed — earlier history is retained either way. Blocks are content-addressed, so unchanged records are reused byte-for-byte across commits and never re-uploaded.
147
153
 
148
- ### Graph Builders
154
+ ### Builders
149
155
 
150
- 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:
156
+ Turning your source data into records is application logic, but the SDK ships a small **harness** for the common "a directory of files → records" case, exported from the package root:
151
157
 
152
158
  ```ts
153
159
  import { buildAssetGraph, extractMarkdownLinks } from "@fangorn-network/sdk";
@@ -155,7 +161,7 @@ import { buildAssetGraph, extractMarkdownLinks } from "@fangorn-network/sdk";
155
161
  // One processor per file extension. Return the vertex tag/payload and the
156
162
  // ids this file links to; buildAssetGraph wires the edges (rel: "links"),
157
163
  // dropping self-links and links to files that don't exist.
158
- const { vertices, edges } = buildAssetGraph("./docs", {
164
+ const { vertices } = buildAssetGraph("./docs", {
159
165
  processors: {
160
166
  ".md": (file) => ({
161
167
  tag: "note",
@@ -166,14 +172,13 @@ const { vertices, edges } = buildAssetGraph("./docs", {
166
172
  });
167
173
 
168
174
  await fangorn.commit({
169
- namespace: "rusty-anchor",
175
+ repo: "rusty-anchor",
170
176
  message: "import docs",
171
- vertices,
172
- edges,
177
+ records: vertices.map((v) => ({ id: v.id, type: v.tag, payload: v.payload })),
173
178
  });
174
179
  ```
175
180
 
176
- 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.
181
+ Each `id` is the filename without extension. The harness also returns the links between files as `edges`; records have no edges, so keep links you need in the payload. For anything that isn't "files in a folder," build the records yourself and pass them straight to `commit` / `uploadBatch` — the harness is a convenience, not a requirement.
177
182
 
178
183
  ### Inspect
179
184
 
@@ -184,14 +189,14 @@ fangorn log -n 5 # limit
184
189
  fangorn show # the tip commit + what it changed vs its parent
185
190
  fangorn show <commitCid> # a specific commit
186
191
 
187
- # List every vertex and edge committed under a namespace, as JSON
188
- fangorn read # defaults to the current repo's namespace + owner
192
+ # List every record in a repo, as JSON
193
+ fangorn read # defaults to the current repo + owner
189
194
  fangorn read rusty-anchor --owner 0x... --pretty
190
195
  ```
191
196
 
192
197
  ### Clone
193
198
 
194
- Reconstruct tracking of a published namespace from its on-chain tip alone. History and contents are then fetched on demand from IPFS.
199
+ Reconstruct tracking of a published repo from its on-chain head alone. History and contents are then fetched on demand from IPFS.
195
200
 
196
201
  ```sh
197
202
  fangorn clone <owner> rusty-anchor
@@ -200,52 +205,51 @@ fangorn clone <owner> rusty-anchor --dir ./somewhere
200
205
 
201
206
  ### Subscribe (light client)
202
207
 
203
- Watch a namespace for on-chain updates and stream the diffs — **no subgraph, no
204
- indexer**. Each `app:publisher:namespace` triple is its own timeline, and the
205
- registry indexes all three parts, so this watches exactly that timeline's
206
- `StateCommitted` event (read straight from the RPC node) and, for each new root,
207
- diffs the namespace's link sets against the previous root.
208
- Only pushes that actually changed the namespace are emitted. Each push's
208
+ Watch a repo for on-chain updates and stream the diffs — **no subgraph, no
209
+ indexer**. Each `publisher:repo` pair is its own timeline, and the registry's
210
+ `Updated` event indexes both, so this reads exactly that timeline straight from
211
+ the RPC node and, for each new head, diffs the repo's records against the
212
+ previous one. Under an app, only what the app presents is emitted. Each push's
209
213
  blocks arrive as one CAR download, resolved from IPFS on demand.
210
214
 
211
215
  ```sh
212
- # Watch the current repo's namespace; each change is one JSON line on stdout.
216
+ # Watch the current repo; each change is one JSON line on stdout.
213
217
  fangorn subscribe
214
218
 
215
- # Watch any publisher's namespace explicitly.
219
+ # Watch any publisher's repo explicitly.
216
220
  fangorn subscribe rusty-anchor --owner 0x...
217
221
 
218
222
  # Feed an embeddings/index builder directly.
219
223
  fangorn subscribe rusty-anchor --owner 0x... | my-index-builder
220
224
  ```
221
225
 
222
- Each emitted line is a namespace change:
226
+ Each emitted line is a repo change:
223
227
 
224
228
  ```jsonc
225
229
  {
226
- "namespace": "rusty-anchor",
230
+ "repo": "rusty-anchor",
227
231
  "owner": "0x...",
228
- "commitCid": "bafy...", // the new on-chain tip
232
+ "commitCid": "bafy...", // the new on-chain head
233
+ "oldRoot": "0x...",
234
+ "newRoot": "0x...",
229
235
  "blockNumber": "12345678", // persist this to resume
230
- "addedVertices": [
231
- { "cid": "bafy...", "schemaId": "track", "payload": { "title": "Locura" } },
236
+ "puts": [
237
+ { "id": "t1", "cid": "bafy...", "type": "track", "payload": { "title": "Locura" } },
232
238
  ],
233
- "addedEdges": [
234
- { "sourceCid": "bafy...", "relation": "by", "targetCid": "bafy..." },
235
- ],
236
- "removedVertexCids": ["bafy..."],
237
- "removedEdges": [],
239
+ "deletes": ["t0"],
238
240
  }
239
241
  ```
240
242
 
243
+ `fangorn subscribe --all` watches the whole app instead (every presented publisher and repo); a repo name or `--owner` narrows it.
244
+
241
245
  **Resumability.** The last processed block is saved to
242
- `.fangorn/subscribe-<owner>-<namespace>.json` after each change, so restarting
246
+ `.fangorn/subscribe-<owner>-<repo>.json` after each change, so restarting
243
247
  replays only what you missed (via `eth_getLogs`) before going live. Override or
244
248
  reset:
245
249
 
246
250
  ```sh
247
251
  fangorn subscribe --from-block 12000000 # replay from a specific block
248
- fangorn subscribe --from-start # replay the namespace's full history
252
+ fangorn subscribe --from-start # replay the repo's full history
249
253
  ```
250
254
 
251
255
  Without a saved cursor, subscribe starts **live from the current tip** — seed
@@ -271,76 +275,63 @@ const fangorn = Fangorn.create({
271
275
  },
272
276
  },
273
277
  config: FangornConfig, // defaults to Arbitrum Sepolia
274
- appId: "my-app", // defaults to "fangorn"
275
- domain: "localhost",
278
+ appId: "my-app", // optional for reads (no app: each publisher's latest head); hosted uploads need one
276
279
  });
277
280
 
278
- // Register once before committing — BOTH registries. The second is the one
279
- // `commitStateRoot` cross-calls, so skipping it surfaces as a revert at push
280
- // time rather than here.
281
- const self = fangorn.getAddress();
282
- const data = fangorn.getDataRegistry();
281
+ // The app stores and presents your repos once its owner accepts this wallet
282
+ // (`apps.acceptPublisher`). A non-member's update still lands; the app just
283
+ // presents nothing of it.
283
284
  const apps = fangorn.getAppRegistry();
284
-
285
- if (!(await data.isRegistered(self))) await data.register();
286
- if (!(await apps.isRegisteredForApp(self))) await apps.registerForApp();
285
+ await apps.canPublish(fangorn.getAddress());
287
286
  ```
288
287
 
289
- `joinInfo` is what a join screen needs, and it separates two failures a bare
290
- "not registered" conflates — never joined, versus joined before the owner moved
291
- the terms:
292
-
293
- ```ts
294
- import { needsReacceptance } from "@fangorn-network/sdk";
295
-
296
- const info = await apps.joinInfo(self);
297
- if (needsReacceptance(info)) await apps.registerForApp(); // free re-accept
298
- ```
288
+ The storage paywall lives on the same client, because an app is its
289
+ subscription: `apps.subscriptionFee()`, `apps.expiresAt()`,
290
+ `apps.renewSubscription()`, `apps.cancelSubscription()`, and
291
+ `apps.access(publisher)` — the `{ canPublish, owner, expiresAt }` the upload gate
292
+ reads. The contract enforces the expiry itself: `canPublish` is false once it
293
+ has passed.
299
294
 
300
- The other two clients hang off the same object: `fangorn.getSubscriptionRegistry()`
301
- (publisher storage paywall) and `fangorn.getSettlementRegistry()` (consumer
302
- pay-then-read). Neither is app-scoped — a subscription is per wallet and a
303
- resource is per owner — so `setAppId` deliberately leaves both alone.
295
+ `fangorn.getMembershipRegistry()` (consumer access to an app's paid records)
296
+ hangs off the same object. It takes the app id per call, so `setAppId`
297
+ deliberately leaves it alone.
304
298
 
305
- ### Namespaces & the git-native flow
299
+ ### Repos & the git-native flow
306
300
 
307
- `initRepo` allocates a namespace on-chain (idempotent). Then split building from settling:
308
- `commit` writes a commit object locally (durable in IPFS, HEAD not yet on-chain), and
309
- `push` fast-forwards the on-chain root to it.
301
+ `initRepo` creates a repo with an empty first commit (idempotent). Then split building from settling:
302
+ `commit` writes a commit object (durable in IPFS, HEAD not yet on-chain), and
303
+ `push` fast-forwards the on-chain head to it.
310
304
 
311
305
  ```ts
312
- // Allocate the namespace (no-op if it already exists)
306
+ // Create the repo (no-op if it already exists)
313
307
  await fangorn.initRepo("rusty-anchor");
308
+ let tip = await fangorn.onChainTip(fangorn.getAddress(), "rusty-anchor");
314
309
 
315
- // First commit — no parent
316
310
  const c1 = await fangorn.commit({
317
- namespace: "rusty-anchor",
311
+ repo: "rusty-anchor",
312
+ parent: tip!,
318
313
  message: "initial import",
319
- vertices: [
320
- { id: "t1", tag: "track", payload: { title: "Locura", artist: "Alice" } },
321
- { id: "a1", tag: "artist", payload: { name: "Alice" } },
314
+ records: [
315
+ { id: "t1", type: "track", payload: { title: "Locura", artist: "Alice" } },
316
+ { id: "a1", type: "artist", payload: { name: "Alice" } },
322
317
  ],
323
- edges: [{ rel: "performed_by", from: "t1", to: "a1" }],
324
318
  });
325
-
326
- // Settle it on-chain (fast-forward from "no tip yet")
327
319
  await fangorn.push("rusty-anchor", c1.commitCid);
328
320
 
329
321
  // A follow-up commit builds on the previous one
330
322
  const c2 = await fangorn.commit({
331
- namespace: "rusty-anchor",
323
+ repo: "rusty-anchor",
332
324
  parent: c1.commitCid,
333
- message: "add another track",
334
- vertices: [
335
- { id: "t2", tag: "track", payload: { title: "Otra", artist: "Alice" } },
336
- ],
325
+ message: "add a track, drop the artist",
326
+ records: [{ id: "t2", type: "track", payload: { title: "Otra", artist: "Alice" } }],
327
+ deletes: ["a1"],
337
328
  });
338
- await fangorn.push("rusty-anchor", c2.commitCid); // refuses unless it fast-forwards the on-chain tip (pass { force: true } to override)
329
+ await fangorn.push("rusty-anchor", c2.commitCid); // the chain rejects it unless the parent is the current head
339
330
  ```
340
331
 
341
332
  ### History, diff & read
342
333
 
343
- Walk history from the on-chain tip (IPFS only, no indexer), and read the current namespace contents:
334
+ Walk history from the on-chain tip (IPFS only, no indexer), and read the current contents:
344
335
 
345
336
  ```ts
346
337
  const tip = await fangorn.onChainTip(fangorn.getAddress(), "rusty-anchor");
@@ -350,37 +341,34 @@ for await (const c of fangorn.log(tip!)) {
350
341
  console.log(c.cid, c.message);
351
342
  }
352
343
 
353
- // What a commit changed vs. its first parent (namespaced vertex/edge entries added/removed)
344
+ // What a commit changed vs. its parent ({ puts, deletes })
354
345
  const diff = await fangorn.show(tip!);
355
346
 
356
- // Every vertex and edge currently committed under a namespace
357
- const contents = await fangorn.inspectNamespace("rusty-anchor");
358
- // contents.vertices: { cid, schemaId, payload }[] contents.edges: { sourceCid, relation, targetCid }[]
359
- ```
347
+ // Every record currently in one of your repos
348
+ const { records } = await fangorn.inspectRepo("rusty-anchor"); // { id, cid, type, payload }[]
360
349
 
361
- > The fast-forward check in `push` is enforced client-side against the on-chain
362
- > head in this release; on-chain write-authorization lands in a later slice.
350
+ // Someone else's repo, as this client's app presents it
351
+ const { tip: head, contents } = await fangorn.readRepo("0x...", "rusty-anchor");
352
+ ```
363
353
 
364
354
  ### Immediate-write helpers
365
355
 
366
- For the common "stage and settle in one shot" case, `upload` (one vertex) and `uploadBatch`
367
- (many vertices + edges) run the whole commit-and-push atomically:
356
+ For the common "stage and settle in one shot" case, `upload` (one record) and `uploadBatch`
357
+ (many records, plus deletes) run the whole commit-and-push atomically:
368
358
 
369
359
  ```ts
370
360
  await fangorn.upload("rusty-anchor", { title: "Locura" }, "track");
371
361
 
372
362
  await fangorn.uploadBatch(
373
363
  "rusty-anchor",
374
- [{ id: "t1", tag: "track", payload: { title: "Locura" } }],
375
- [
376
- /* edges */
377
- ],
364
+ [{ id: "t1", type: "track", payload: { title: "Locura" } }],
365
+ ["t0"], // ids to delete
378
366
  );
379
367
  ```
380
368
 
381
369
  ### Subscribe (light client)
382
370
 
383
- `subscribe` is an async generator over namespace-scoped changes. It optionally
371
+ `subscribe` is an async generator over one repo's changes. It optionally
384
372
  replays from a block cursor (`fromBlock`) and then watches live until the
385
373
  `AbortSignal` fires. Each change carries `blockNumber` — persist it to resume.
386
374
 
@@ -388,41 +376,41 @@ replays from a block cursor (`fromBlock`) and then watches live until the
388
376
  const controller = new AbortController();
389
377
 
390
378
  for await (const change of fangorn.subscribe({
391
- namespace: "rusty-anchor",
379
+ repo: "rusty-anchor",
392
380
  owner: "0x...", // defaults to your own address
393
381
  fromBlock: savedCursor, // omit to start live from the current tip
394
382
  signal: controller.signal,
395
383
  })) {
396
- for (const v of change.addedVertices) index.upsert(v.cid, v.payload);
397
- for (const cid of change.removedVertexCids) index.remove(cid);
384
+ for (const r of change.puts) index.upsert(r.id, r.payload);
385
+ for (const id of change.deletes) index.remove(id);
398
386
  persistCursor(change.blockNumber);
399
387
  }
400
388
  ```
401
389
 
402
390
  The pure diff primitive is also exposed on the engine —
403
- `engine.namespaceDiff(oldRootHex, newRootHex, namespace)` — if you want to diff
391
+ `engine.repoDiff(oldRootHex, newRootHex)` — if you want to diff
404
392
  two arbitrary roots without watching.
405
393
 
406
394
  ### Subscribe to a whole app
407
395
 
408
- Namespaces are hierarchical: every commit lands under `app:publisher:namespace`,
409
- and each triple is its own on-chain timeline. Two publishers — or one publisher's
410
- two namespaces — never contend for the same compare-and-swap.
396
+ Every update lands under `publisher:repo`, and each pair is its own on-chain
397
+ timeline. Two publishers — or one publisher's two repos — never contend for the
398
+ same compare-and-swap.
411
399
 
412
- The registry indexes all three parts, so an app-wide feed is one topic filter
413
- rather than a per-publisher fan-out. `subscribeApp` yields the same
414
- `NamespaceChange` values as `subscribe`, from every publisher in the app:
400
+ `subscribeApp` yields the same `RepoChange` values as `subscribe`, from every
401
+ publisher the app presents, less its exclusions. With no app it is every update
402
+ by anyone:
415
403
 
416
404
  ```ts
417
- // Everything published under this app, by anyone
405
+ // Everything the app presents
418
406
  for await (const change of fangorn.subscribeApp({
419
407
  signal: controller.signal,
420
408
  })) {
421
- console.log(change.owner, change.namespace, change.addedVertices.length);
409
+ console.log(change.owner, change.repo, change.puts.length);
422
410
  }
423
411
 
424
- // Narrow it: every publisher's "reviews" namespace, or one publisher's whole app footprint
425
- fangorn.subscribeApp({ namespace: "reviews" });
412
+ // Narrow it: every publisher's "reviews" repo, or one publisher's whole footprint
413
+ fangorn.subscribeApp({ repo: "reviews" });
426
414
  fangorn.subscribeApp({ owner: "0x..." });
427
415
  ```
428
416
 
@@ -435,28 +423,23 @@ fangorn.setAppId("my-other-app"); // by name, or by 32-byte app id
435
423
  fangorn.getAppId(); // 0x… — what the registry keys on
436
424
  ```
437
425
 
438
- `setAppId` re-scopes the DataRegistry and AppRegistry clients **together**. They
439
- must never disagree: a DataRegistry pointed at one app while the AppRegistry
440
- answers for another checks membership against the wrong market, and it surfaces
441
- as a revert at commit time, far from the mistake.
426
+ Under an app, reads (`readRepo`, `appRepos`, `subscribe`) are what the app
427
+ presents: its members' latest heads (`canPublish`), less its exclusions. With
428
+ no app they are each publisher's latest heads.
442
429
 
443
- Apps live in the AppRegistry, and membership of one is a precondition for
444
- publishing under it:
430
+ Apps live in the AppRegistry, and membership of one is what gets your storage
431
+ paid for and your repos presented:
445
432
 
446
433
  ```ts
447
434
  const apps = fangorn.getAppRegistry();
448
435
 
449
- await apps.registerApp(termsHash, termsUri, joinFee); // claim it (first come, first served)
450
- await apps.registerForApp(); // join it, accepting the current terms
436
+ await apps.registerApp(); // claim it — pays the subscription fee (USDC); you are its first publisher
437
+ await apps.acceptPublisher(publisher); // owner: accept a publisher
438
+ await apps.setPublisherSuspended(publisher, true); // owner: suspend them from this app
439
+ await apps.renewSubscription(); // owner: pay for the next period
451
440
  ```
452
441
 
453
- Joining reads the terms hash immediately before sending and passes it as an
454
- argument, so the contract reverts `TermsMismatch` if the owner moved the terms
455
- in between. A race is a revert, never silent agreement to a document the
456
- publisher never saw. The join fee is read from the chain for the same reason a
457
- caller never supplies it: a caller can supply the wrong one.
458
-
459
- See the [CLI quickstart](#pick-an-app-then-register) for the same flow from the
442
+ See the [CLI quickstart](#pick-an-app) for the same flow from the
460
443
  command line.
461
444
 
462
445
  ### Storage
@@ -472,7 +455,7 @@ The backend never needs to understand IPLD — any blob store can implement the
472
455
  ## Encryption & gadgets
473
456
 
474
457
  Not every field belongs in public IPFS. Fangorn lets you **seal** a value and commit
475
- only an opaque reference to it, keeping the graph — its shape, its edges, its
458
+ only an opaque reference to it, keeping the repo — its records, their ids and types, their
476
459
  addressability — fully public while the payload stays closed.
477
460
 
478
461
  A **gadget** names _how_ a value is sealed and _under what condition_ it opens. Two
@@ -486,7 +469,7 @@ ship today, both exported from the package root (`@fangorn-network/sdk`):
486
469
  Every key is bound to a 32-byte **`resourceId`**, which doubles as the Settlement
487
470
  Registry key. The same secret cannot cross-open a different resource, and changing
488
471
  _who can read_ means re-sealing under a new gadget/`resourceId` and committing a
489
- vertex that points at the new bytes.
472
+ record that points at the new bytes.
490
473
 
491
474
  ### `self-hkdf-v1` — fully private
492
475
 
@@ -522,7 +505,7 @@ await fangorn.upload(
522
505
  "secret-msg",
523
506
  );
524
507
 
525
- // later, after `read` / `inspectNamespace` hands the payload back:
508
+ // later, after `read` / `inspectRepo` hands the payload back:
526
509
  const plaintext = unsealSelf(
527
510
  hexToBytes(stored.ciphertext),
528
511
  ownSecret,
@@ -554,7 +537,7 @@ const handle = await encryptAndUpload({
554
537
  ```
555
538
 
556
539
  The handle is what you commit in place of the plaintext value — the engine treats it
557
- as an ordinary opaque object in the vertex payload:
540
+ as an ordinary opaque object in the record payload:
558
541
 
559
542
  ```jsonc
560
543
  {
@@ -594,8 +577,8 @@ const plaintext = await decryptHandle({
594
577
  having unsealed with its own key; the bytes arrive as plaintext.
595
578
 
596
579
  `buildAccessRequest` / `accessMessageHash` are exported if you want to drive the
597
- `/access` endpoint yourself, and `SettlementRegistryClient` (`isSettled`, `getPrice`)
598
- reads the settlement rail directly.
580
+ `/access` endpoint yourself, and `MembershipRegistryClient` (`canRead`, `planOf`)
581
+ reads the membership rail directly.
599
582
 
600
583
  **Trust model.** For `worker-usdc-v1` the access worker is the "somewhat trusted" party:
601
584
  it holds the unsealing key and sees plaintext at release time. That is deliberate for
@@ -611,18 +594,28 @@ gadget_ behind the same handle shape, so committed data doesn't change form.
611
594
 
612
595
  | Contract | Address | What it owns |
613
596
  | -------------------- | -------------------------------------------- | --------------------------------------------------- |
614
- | DataRegistry | `0x3b0cf19bef492500401e4d74e6fa29a56d0cc67b` | Namespace state roots; global publisher standing |
615
- | AppRegistry | `0xcc92f3d827df33be7323eef28e67a509034f5a59` | Apps: owner, terms, join fee, per-app membership |
616
- | SubscriptionRegistry | `0xe82192be4c20d3dc93fbc63e3ecd7e13c3889726` | Publisher-side storage paywall (USDC) |
617
- | SettlementRegistry | `0x47a2a0d7e7fc8a044f6d6f1d878c4178952ea779` | Consumer-side pay-then-read rail (USDC + Semaphore) |
597
+ | DataRegistry | `0x72B5f83526F3893aF9f1eE0f32A27218EA09f8aE` | Every repo's head, and the update log |
598
+ | AppRegistry | `0x55e6209ea1833ceD900989a3b3b22466934E04A5` | Apps: owner, accepted publishers, bans, storage subscription (ERC-5643, USDC); what each app excludes |
599
+ | MembershipRegistry | `0xDF17030Cd65435C86eb043F31DDACa99E819E347` | Time-limited, unlinkable access to an app's paid records (USDC + Semaphore) |
600
+
601
+ ### Base Sepolia
602
+
603
+ | Contract | Address |
604
+ | -------------------- | -------------------------------------------- |
605
+ | DataRegistry | `0xE9183f768865dd2Cde5f1B71F8446F0Cd798ebe0` |
606
+ | AppRegistry | `0x0D3e98399df41b558048Cdd7D71723c37A3A9D6F` |
607
+ | MembershipRegistry | `0x0e96C012b5c53622EcDAA82F342E31C2623A04f5` |
608
+
609
+ Use it from the SDK with `Fangorn.create({ config: BaseSepoliaConfig, ... })`, or
610
+ from the CLI with `CHAIN_NAME=baseSepolia` (or pick it in `fangorn init`).
618
611
 
619
- `FangornConfig` in `src/config.ts` is the authoritative list and what the SDK
620
- uses by default — these contracts have been redeployed more than once, so prefer
621
- the config over any address copied out of a document, including this table.
612
+ `FangornConfig` (Arbitrum Sepolia) and `BaseSepoliaConfig` in `src/config.ts` are the authoritative list and what the SDK
613
+ uses by default — prefer it over any address copied out of a document,
614
+ including this table. The sources are `fangorn-network/contracts`
615
+ (`solidity/script/Deployments.sol`); regenerate the ABIs with `pnpm abis`.
622
616
 
623
- The dependency runs one way: `DataRegistry.commitStateRoot` cross-calls
624
- `AppRegistry.isRegisteredForApp`, and `SubscriptionRegistry` cross-calls
625
- `DataRegistry.isRegistered`. Nothing calls back the other way.
617
+ Neither contract calls the other: an update names no app, and an app presents
618
+ its members (`canPublish`).
626
619
 
627
620
  ---
628
621
 
@@ -636,37 +629,40 @@ pnpm test
636
629
 
637
630
  ### E2E Tests
638
631
 
639
- Runs the storage + on-chain anchor flow against live IPFS + the deployed contract.
632
+ The SDK suite (`src/test/sdk-suite.ts`) runs twice: in memory with the unit
633
+ tests, and against the contracts, built from source in a sibling checkout of
634
+ `fangorn-network/contracts` (`FANGORN_CONTRACTS_DIR` to point elsewhere) and
635
+ deployed to a fresh `anvil`. Nothing touches a real chain.
640
636
 
641
637
  ```sh
642
- cp env.example .env
643
638
  pnpm test:e2e
644
639
  ```
645
640
 
646
- Required variables:
641
+ | File | Runs against | Needs |
642
+ | ------------------------------ | ---------------------------- | ------------------------ |
643
+ | `src/e2e/sdk.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
644
+ | `src/e2e/apps.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
645
+ | `src/e2e/admin.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
646
+ | `src/e2e/live.e2e.test.ts` | Arbitrum Sepolia, read-only | nothing |
647
647
 
648
- | Variable | Description |
649
- | ----------------- | ----------------------------------------- |
650
- | `ETH_PRIVATE_KEY` | Publisher private key (needs testnet ETH) |
651
- | `PINATA_JWT` | Pinata API JWT |
652
- | `PINATA_GATEWAY` | Pinata gateway URL |
648
+ Without `anvil`, `forge` or the contracts checkout the anvil suites are skipped
649
+ (in CI they fail). The deployer is the protocol admin, so the admin suite needs
650
+ no real key. Storage is in memory; `E2E_STORAGE=pinata` runs the same suites
651
+ against Pinata (`PINATA_JWT`, `PINATA_GATEWAY`).
653
652
 
654
- The publisher must be registered on the target key — `fangorn register` does
655
- both halves (DataRegistry standing, then joining the app). The suite's own
656
- `TestBed.registerApp` / `TestBed.register` do the same thing programmatically,
657
- claiming the app first if nobody owns it.
653
+ **The live suite** only reads: that the registries point at each other, and that
654
+ the config's start block is the AppRegistry's deployment.
658
655
 
659
656
  ---
660
657
 
661
658
  ## Limitations / Future Work
662
659
 
663
660
  - Sealed fields are live (`self-hkdf-v1`, `worker-usdc-v1`), but which fields to seal is expressed per-call at stage time — there is no schema-level `sealedFields` hint yet, and no CLI command for sealing.
664
- - The SDK covers the **publisher** half of the settlement rail (`createResource`, `updatePrice`, `setDisabled`, plus the reads). The **buyer** half — Semaphore identity, the EIP-3009 authorization, membership proofs — lives in [`@fangorn-network/fetch`](https://github.com/fangorn-network/x402f), which relays both writes through a facilitator so the buyer needs no gas. This package deliberately carries no proving dependency.
665
- - The SubscriptionRegistry (publisher storage paywall) has a client but no CLI command yet; `fangorn subscribe` is the event stream, not the paywall.
661
+ - The SDK covers the **app owner** half of the membership rail (`setPlan`, plus the reads and the relayed `join`/`claim`). The **buyer** half — Semaphore identity, the ERC-3009 authorization, membership proofs — lives in [`@fangorn-network/fetch`](https://github.com/fangorn-network/x402f), which relays both writes through a facilitator so the buyer needs no gas. This package deliberately carries no proving dependency.
662
+ - `fangorn subscribe` is the event stream, not the storage paywall — that is `fangorn app claim` / `fangorn app renew`.
666
663
  - `worker-usdc-v1` trusts the access worker with the unsealing key. A TEE- or threshold-backed replacement would ship as a new gadget, and the on-chain gadget registry (`gadget → resolver`) is still future work.
667
- - Vertex/edge schema validation is client-side only — no on-chain enforcement.
668
- - Push authorization is client-side in this release; on-chain write policies and non-fast-forward rejection are planned.
669
- - Reads target one publisher's namespace at a time; cross-publisher discovery is a higher layer.
664
+ - Record schema validation is client-side only — no on-chain enforcement.
665
+ - An app presents each accepted publisher's latest head; the data itself is unverified, so accept publishers you trust.
670
666
 
671
667
  ---
672
668