@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.
- package/README.md +191 -195
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +198 -164
- package/lib/cli/index.d.ts +3 -91
- package/lib/cli/index.js +5 -2
- package/lib/config.d.ts +349 -433
- package/lib/config.js +41 -28
- package/lib/contracts/app-registry/abi.d.ts +1064 -265
- package/lib/contracts/app-registry/abi.js +1233 -308
- package/lib/contracts/app-registry/index.d.ts +123 -102
- package/lib/contracts/app-registry/index.js +200 -198
- package/lib/contracts/data-registry/abi.d.ts +166 -187
- package/lib/contracts/data-registry/abi.js +207 -237
- package/lib/contracts/data-registry/index.d.ts +4 -160
- package/lib/contracts/data-registry/index.js +5 -294
- package/lib/contracts/index.d.ts +6 -7
- package/lib/contracts/index.js +6 -8
- package/lib/contracts/logs.d.ts +21 -0
- package/lib/contracts/logs.js +32 -0
- package/lib/contracts/membership-registry/abi.d.ts +1145 -0
- package/lib/contracts/membership-registry/abi.js +1333 -0
- package/lib/contracts/membership-registry/index.d.ts +79 -0
- package/lib/contracts/membership-registry/index.js +104 -0
- package/lib/contracts/types.d.ts +3 -1
- package/lib/contracts/types.js +3 -1
- package/lib/contracts/write.d.ts +34 -2
- package/lib/contracts/write.js +48 -1
- package/lib/crypto/encryption.js +4 -4
- package/lib/engine/car.d.ts +2 -2
- package/lib/engine/car.js +10 -5
- package/lib/engine/index.d.ts +99 -143
- package/lib/engine/index.js +156 -295
- package/lib/engine/records.d.ts +110 -0
- package/lib/engine/records.js +165 -0
- package/lib/engine/test-helpers.d.ts +7 -14
- package/lib/engine/test-helpers.js +7 -18
- package/lib/fangorn.d.ts +163 -155
- package/lib/fangorn.js +284 -248
- package/lib/feed.d.ts +7 -4
- package/lib/feed.js +4 -1
- package/lib/index.d.ts +9 -9
- package/lib/index.js +9 -10
- package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
- package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
- package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
- package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
- package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
- package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
- package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
- package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
- package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
- package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
- package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
- package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
- package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
- package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
- package/lib/node_modules/chai/index.js +2874 -0
- package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
- package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
- package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
- package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
- package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
- package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
- package/lib/providers/storage/signed-url.d.ts +16 -6
- package/lib/providers/storage/signed-url.js +20 -8
- package/lib/registry.d.ts +116 -0
- package/lib/registry.js +182 -0
- package/lib/test/mem-registry.d.ts +51 -0
- package/lib/test/mem-registry.js +107 -0
- package/lib/test/sdk-suite.d.ts +13 -0
- package/lib/test/sdk-suite.js +226 -0
- package/lib/test/testbed.d.ts +16411 -61
- package/lib/test/testbed.js +190 -84
- package/lib/types/index.d.ts +13 -11
- package/package.json +89 -72
- package/lib/contracts/data-registry/test.d.ts +0 -1
- package/lib/contracts/data-registry/test.js +0 -1
- package/lib/contracts/settlement-registry/abi.d.ts +0 -466
- package/lib/contracts/settlement-registry/abi.js +0 -535
- package/lib/contracts/settlement-registry/index.d.ts +0 -163
- package/lib/contracts/settlement-registry/index.js +0 -264
- package/lib/contracts/subscription-registry/abi.d.ts +0 -179
- package/lib/contracts/subscription-registry/abi.js +0 -195
- package/lib/contracts/subscription-registry/index.d.ts +0 -59
- package/lib/contracts/subscription-registry/index.js +0 -116
- package/lib/engine/graph.d.ts +0 -70
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
14
|
-
- `push` (remote)
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
76
|
+
### Pick an app
|
|
81
77
|
|
|
82
|
-
Publishing
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
at
|
|
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,
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
103
|
-
fangorn app
|
|
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
|
|
118
|
+
### Track a repo
|
|
109
119
|
|
|
110
|
-
|
|
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
|
-
#
|
|
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`
|
|
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
|
-
#
|
|
123
|
-
fangorn commit
|
|
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
|
-
`
|
|
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
|
-
"
|
|
135
|
-
{
|
|
136
|
-
|
|
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
|
-
"
|
|
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
|
|
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
|
-
###
|
|
154
|
+
### Builders
|
|
149
155
|
|
|
150
|
-
Turning your source data into
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
188
|
-
fangorn read # defaults to the current repo
|
|
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
|
|
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
|
|
204
|
-
indexer**. Each `
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
|
216
|
+
# Watch the current repo; each change is one JSON line on stdout.
|
|
213
217
|
fangorn subscribe
|
|
214
218
|
|
|
215
|
-
# Watch any publisher's
|
|
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
|
|
226
|
+
Each emitted line is a repo change:
|
|
223
227
|
|
|
224
228
|
```jsonc
|
|
225
229
|
{
|
|
226
|
-
"
|
|
230
|
+
"repo": "rusty-anchor",
|
|
227
231
|
"owner": "0x...",
|
|
228
|
-
"commitCid": "bafy...", // the new on-chain
|
|
232
|
+
"commitCid": "bafy...", // the new on-chain head
|
|
233
|
+
"oldRoot": "0x...",
|
|
234
|
+
"newRoot": "0x...",
|
|
229
235
|
"blockNumber": "12345678", // persist this to resume
|
|
230
|
-
"
|
|
231
|
-
{ "cid": "bafy...", "
|
|
236
|
+
"puts": [
|
|
237
|
+
{ "id": "t1", "cid": "bafy...", "type": "track", "payload": { "title": "Locura" } },
|
|
232
238
|
],
|
|
233
|
-
"
|
|
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>-<
|
|
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
|
|
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", //
|
|
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
|
-
//
|
|
279
|
-
// `
|
|
280
|
-
//
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
###
|
|
299
|
+
### Repos & the git-native flow
|
|
306
300
|
|
|
307
|
-
`initRepo`
|
|
308
|
-
`commit` writes a commit object
|
|
309
|
-
`push` fast-forwards the on-chain
|
|
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
|
-
//
|
|
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
|
-
|
|
311
|
+
repo: "rusty-anchor",
|
|
312
|
+
parent: tip!,
|
|
318
313
|
message: "initial import",
|
|
319
|
-
|
|
320
|
-
{ id: "t1",
|
|
321
|
-
{ id: "a1",
|
|
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
|
-
|
|
323
|
+
repo: "rusty-anchor",
|
|
332
324
|
parent: c1.commitCid,
|
|
333
|
-
message: "add
|
|
334
|
-
|
|
335
|
-
|
|
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); //
|
|
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
|
|
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
|
|
344
|
+
// What a commit changed vs. its parent ({ puts, deletes })
|
|
354
345
|
const diff = await fangorn.show(tip!);
|
|
355
346
|
|
|
356
|
-
// Every
|
|
357
|
-
const
|
|
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
|
-
|
|
362
|
-
|
|
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
|
|
367
|
-
(many
|
|
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",
|
|
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
|
|
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
|
-
|
|
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
|
|
397
|
-
for (const
|
|
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.
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
|
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.
|
|
409
|
+
console.log(change.owner, change.repo, change.puts.length);
|
|
422
410
|
}
|
|
423
411
|
|
|
424
|
-
// Narrow it: every publisher's "reviews"
|
|
425
|
-
fangorn.subscribeApp({
|
|
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
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
|
444
|
-
|
|
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(
|
|
450
|
-
await apps.
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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` / `
|
|
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
|
|
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 `
|
|
598
|
-
reads the
|
|
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 | `
|
|
615
|
-
| AppRegistry | `
|
|
616
|
-
|
|
|
617
|
-
|
|
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`
|
|
620
|
-
uses by default —
|
|
621
|
-
|
|
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
|
-
|
|
624
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
|
655
|
-
|
|
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 **
|
|
665
|
-
-
|
|
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
|
-
-
|
|
668
|
-
-
|
|
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
|
|