@fangorn-network/sdk 2026.10.27-dev → 2026.11.3-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 +36 -642
- package/lib/cli/cli.js +47 -322
- package/lib/cli/index.d.ts +1 -4
- package/lib/cli/index.js +2 -20
- package/lib/config.d.ts +15 -78
- package/lib/config.js +8 -35
- package/lib/contracts/data-registry/abi.d.ts +195 -19
- package/lib/contracts/data-registry/abi.js +223 -20
- package/lib/contracts/data-registry/index.d.ts +126 -2
- package/lib/contracts/data-registry/index.js +174 -1
- package/lib/contracts/index.d.ts +5 -8
- package/lib/contracts/index.js +4 -7
- package/lib/contracts/logs.d.ts +1 -1
- package/lib/contracts/logs.js +1 -1
- package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +288 -637
- package/lib/contracts/{membership-registry → settlement-registry}/abi.js +326 -712
- package/lib/contracts/settlement-registry/index.d.ts +141 -0
- package/lib/contracts/settlement-registry/index.js +209 -0
- package/lib/crypto/aes.d.ts +2 -2
- package/lib/crypto/aes.js +4 -4
- package/lib/crypto/encryption.d.ts +8 -109
- package/lib/crypto/encryption.js +16 -114
- package/lib/crypto/paid.d.ts +104 -0
- package/lib/crypto/paid.js +147 -0
- package/lib/engine/index.d.ts +23 -12
- package/lib/engine/index.js +68 -29
- package/lib/engine/records.d.ts +4 -7
- package/lib/engine/records.js +6 -6
- package/lib/engine/test-helpers.d.ts +2 -3
- package/lib/engine/test-helpers.js +7 -5
- package/lib/erc8004.js +1 -4
- package/lib/fangorn.d.ts +64 -85
- package/lib/fangorn.js +106 -148
- package/lib/feed.d.ts +7 -8
- package/lib/feed.js +7 -8
- package/lib/index.d.ts +10 -14
- package/lib/index.js +9 -13
- package/lib/providers/storage/signed-url.d.ts +2 -10
- package/lib/providers/storage/signed-url.js +4 -14
- package/lib/providers/storage/types.d.ts +1 -1
- package/lib/providers/storage/utils.js +5 -3
- package/lib/test/key-server.d.ts +12 -0
- package/lib/test/key-server.js +30 -0
- package/lib/test/mem-registry.d.ts +14 -19
- package/lib/test/mem-registry.js +44 -37
- package/lib/test/sdk-suite.d.ts +1 -4
- package/lib/test/sdk-suite.js +16 -87
- package/lib/test/testbed.d.ts +5216 -5226
- package/lib/test/testbed.js +29 -56
- package/lib/types/index.d.ts +6 -11
- package/package.json +1 -4
- package/lib/contracts/app-registry/abi.d.ts +0 -1317
- package/lib/contracts/app-registry/abi.js +0 -1510
- package/lib/contracts/app-registry/index.d.ts +0 -173
- package/lib/contracts/app-registry/index.js +0 -294
- package/lib/contracts/membership-registry/index.d.ts +0 -79
- package/lib/contracts/membership-registry/index.js +0 -104
- package/lib/contracts/types.d.ts +0 -10
- package/lib/contracts/types.js +0 -12
- package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
- package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
- package/lib/harness/index.d.ts +0 -58
- package/lib/harness/index.js +0 -73
- package/lib/registry.d.ts +0 -118
- package/lib/registry.js +0 -184
package/README.md
CHANGED
|
@@ -1,678 +1,72 @@
|
|
|
1
1
|
# Fangorn SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
**Version Control**
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
**Storage**
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
#### What it is not
|
|
23
|
-
|
|
24
|
-
This is not a graph database. There is no query langauge here and there is no native indexer.
|
|
25
|
-
|
|
26
|
-
## Supported Networks
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
3
|
+
Fangorn is git for published data. You publish **repos** of records, and you can make any field paid. Each repo's head is anchored on chain and its history lives in IPFS. Anyone can read, verify, diff, subscribe to, or buy from your repos without asking you, an indexer, or a platform.
|
|
30
4
|
|
|
31
5
|
```sh
|
|
32
6
|
npm i @fangorn-network/sdk
|
|
33
7
|
```
|
|
34
8
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## CLI Quickstart
|
|
38
|
-
|
|
39
|
-
```sh
|
|
40
|
-
npm i -g @fangorn-network/sdk
|
|
41
|
-
fangorn init
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
`fangorn init` prompts for:
|
|
45
|
-
|
|
46
|
-
- Wallet private key
|
|
47
|
-
- Pinata JWT + gateway URL (content + commit-object storage; both optional)
|
|
48
|
-
- Access-gating worker URL (optional — stores sealed ciphertext and enforces the read gate)
|
|
49
|
-
- Presigned-URL worker URL (optional — issues short-lived Pinata upload URLs so no JWT is needed)
|
|
50
|
-
|
|
51
|
-
Config is written to `~/.fangorn/config.json`.
|
|
52
|
-
|
|
53
|
-
You can also configure via environment variables (these take precedence over the config file):
|
|
54
|
-
|
|
55
|
-
```sh
|
|
56
|
-
ETH_PRIVATE_KEY=0x...
|
|
57
|
-
PINATA_JWT=...
|
|
58
|
-
PINATA_GATEWAY=https://your-gateway.mypinata.cloud
|
|
59
|
-
CHAIN_NAME=baseSepolia # the default; or arbitrumSepolia
|
|
60
|
-
SIGNED_URL_WORKER_URL=https://pinata-url-provider.your-subdomain.workers.dev # optional; defaults to the network's hosted worker
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
> The **access worker** and the **presigned-URL worker** are two different services: the first gates reads of sealed fields, the second hands out Pinata upload URLs. Don't conflate them.
|
|
64
|
-
|
|
65
|
-
### Check your wallet
|
|
66
|
-
|
|
67
|
-
```sh
|
|
68
|
-
fangorn wallet show # address, public key, balance, network, current app
|
|
69
|
-
fangorn wallet show --reveal # also prints the PRIVATE key — it grants full control
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
The private key is never printed without `--reveal`: terminal scrollback, shell
|
|
73
|
-
logs and screen shares all outlive the command.
|
|
74
|
-
|
|
75
|
-
### Pick an app
|
|
76
|
-
|
|
77
|
-
Publishing needs no app: any wallet updates its own repos, and an update names
|
|
78
|
-
no app. **An app is sponsored storage for the publishers it accepts**: its owner
|
|
79
|
-
accepts a publisher, the app pays for that publisher's uploads, and it includes
|
|
80
|
-
their repos at their latest heads, less what the owner withdraws
|
|
81
|
-
(`registry.exclude`).
|
|
82
|
-
|
|
83
|
-
```sh
|
|
84
|
-
fangorn set-app my-app # persists the app; --app <name-or-id> overrides per command
|
|
85
|
-
fangorn app info # owner, subscription, and where you stand in it
|
|
86
|
-
fangorn app claim # claim it, if nobody owns it yet (irreversible; pays the subscription)
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
The protocol admin can ban a wallet network-wide: it can't claim an app or be
|
|
90
|
-
accepted into one, and no app stores or presents it.
|
|
91
|
-
|
|
92
|
-
**An app is a storage subscription** (ERC-5643; the app is a token that cannot
|
|
93
|
-
be transferred). `fangorn app claim` pays one period of the subscription fee in
|
|
94
|
-
USDC (the client approves exactly the fee for you), and `fangorn app renew` pays
|
|
95
|
-
the next once less than a period is left. An expired app stores and presents nothing
|
|
96
|
-
until it is renewed. **Apps provide storage**: you upload relative to
|
|
97
|
-
an app, and hosted uploads (`storage: { signedUrl: {} }`, through the network's
|
|
98
|
-
hosted worker, `config.signedUrlWorker`) are billed to the client's app, which must have accepted you. There is no app-less hosted upload — with no
|
|
99
|
-
app, bring your own Pinata (`{ pinata }`) and pin your own data. A publisher that
|
|
100
|
-
pays for its own storage claims a one-member app.
|
|
101
|
-
|
|
102
|
-
**The owner accepts publishers.** `fangorn app accept <address>` is the whole
|
|
103
|
-
membership: no invitation, terms or join fee. The owner is their own first
|
|
104
|
-
publisher.
|
|
105
|
-
|
|
106
|
-
Owning an app comes with its own commands:
|
|
107
|
-
|
|
108
|
-
```sh
|
|
109
|
-
fangorn app accept <address> # accept a publisher: the app stores and includes its data
|
|
110
|
-
fangorn app suspend <address> # suspend a member from THIS app only
|
|
111
|
-
fangorn app reinstate <address>
|
|
112
|
-
fangorn app renew # pay for the next period
|
|
113
|
-
fangorn app cancel # end the subscription now, no refund
|
|
114
|
-
fangorn app agent --access-worker <url> # register the worker's agent card with ERC-8004 (or pass a card URL)
|
|
115
|
-
fangorn app withdraw-fees [to] # join fees still owed from before joining was removed
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Track a repo
|
|
9
|
+
## The model
|
|
119
10
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
11
|
+
- **Publisher.** A wallet address. Publishers own their repos, and nobody admits or approves them.
|
|
12
|
+
- **Repo.** Keyed `publisher : repo`. Its state is a map of **records** `{ id, type, payload }`, stored as a content-addressed Merkle search tree.
|
|
13
|
+
- **Commit.** Each commit points at its parent and at one CAR file holding the blocks it introduced. History can be walked and diffed from the head alone.
|
|
14
|
+
- **Push.** Moves the on-chain head with a compare-and-swap on the parent, like a git ref update. The registry stores only heads.
|
|
15
|
+
- **Paid fields.** A publisher seals a field and signs a price for it in the record. Buyers pay through the SettlementRegistry, and a key server releases the key.
|
|
16
|
+
- **Apps are just repos.** An app is a publisher's repo of records that **cite** other publishers' records at named heads. It selects and arranges data, but it never holds or gates that data. When a citation leads to a sale, the app's publisher address receives the referral share.
|
|
126
17
|
|
|
127
|
-
|
|
18
|
+
What Fangorn is not: it is not a database. It has no query language and no indexer. You build those on top with `subscribe` (see [westmarch](https://github.com/fangorn-network/westmarch)).
|
|
128
19
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
```sh
|
|
132
|
-
# Stage records into a new local commit — does NOT push
|
|
133
|
-
fangorn commit records.json -m "initial import"
|
|
134
|
-
|
|
135
|
-
# Settle the local tip on-chain (permission + fast-forward checked here)
|
|
136
|
-
fangorn push
|
|
137
|
-
fangorn push --force # push even if it doesn't fast-forward the on-chain tip
|
|
138
|
-
```
|
|
139
|
-
|
|
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:
|
|
141
|
-
|
|
142
|
-
```json
|
|
143
|
-
{
|
|
144
|
-
"records": [
|
|
145
|
-
{ "id": "t1", "type": "track", "payload": { "title": "Locura", "artist": "Alice" } },
|
|
146
|
-
{ "id": "a1", "type": "artist", "payload": { "name": "Alice" } }
|
|
147
|
-
],
|
|
148
|
-
"deletes": ["t0"]
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
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.
|
|
153
|
-
|
|
154
|
-
### Builders
|
|
155
|
-
|
|
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:
|
|
20
|
+
## Quickstart (SDK)
|
|
157
21
|
|
|
158
22
|
```ts
|
|
159
|
-
import {
|
|
160
|
-
|
|
161
|
-
// One processor per file extension. Return the vertex tag/payload and the
|
|
162
|
-
// ids this file links to; buildAssetGraph wires the edges (rel: "links"),
|
|
163
|
-
// dropping self-links and links to files that don't exist.
|
|
164
|
-
const { vertices } = buildAssetGraph("./docs", {
|
|
165
|
-
processors: {
|
|
166
|
-
".md": (file) => ({
|
|
167
|
-
tag: "note",
|
|
168
|
-
payload: { title: file.nameNoExt, body: file.readText() },
|
|
169
|
-
links: extractMarkdownLinks(file.readText()), // markdown links + [[wikilinks]]
|
|
170
|
-
}),
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
await fangorn.commit({
|
|
175
|
-
repo: "rusty-anchor",
|
|
176
|
-
message: "import docs",
|
|
177
|
-
records: vertices.map((v) => ({ id: v.id, type: v.tag, payload: v.payload })),
|
|
178
|
-
});
|
|
179
|
-
```
|
|
180
|
-
|
|
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.
|
|
182
|
-
|
|
183
|
-
### Inspect
|
|
184
|
-
|
|
185
|
-
```sh
|
|
186
|
-
fangorn status # local tip vs on-chain tip
|
|
187
|
-
fangorn log # walk commit history from the tip (newest first)
|
|
188
|
-
fangorn log -n 5 # limit
|
|
189
|
-
fangorn show # the tip commit + what it changed vs its parent
|
|
190
|
-
fangorn show <commitCid> # a specific commit
|
|
191
|
-
|
|
192
|
-
# List every record in a repo, as JSON
|
|
193
|
-
fangorn read # defaults to the current repo + owner
|
|
194
|
-
fangorn read rusty-anchor --owner 0x... --pretty
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### Clone
|
|
198
|
-
|
|
199
|
-
Reconstruct tracking of a published repo from its on-chain head alone. History and contents are then fetched on demand from IPFS.
|
|
200
|
-
|
|
201
|
-
```sh
|
|
202
|
-
fangorn clone <owner> rusty-anchor
|
|
203
|
-
fangorn clone <owner> rusty-anchor --dir ./somewhere
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### Subscribe (light client)
|
|
207
|
-
|
|
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
|
|
213
|
-
blocks arrive as one CAR download, resolved from IPFS on demand.
|
|
214
|
-
|
|
215
|
-
```sh
|
|
216
|
-
# Watch the current repo; each change is one JSON line on stdout.
|
|
217
|
-
fangorn subscribe
|
|
218
|
-
|
|
219
|
-
# Watch any publisher's repo explicitly.
|
|
220
|
-
fangorn subscribe rusty-anchor --owner 0x...
|
|
221
|
-
|
|
222
|
-
# Feed an embeddings/index builder directly.
|
|
223
|
-
fangorn subscribe rusty-anchor --owner 0x... | my-index-builder
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
Each emitted line is a repo change:
|
|
227
|
-
|
|
228
|
-
```jsonc
|
|
229
|
-
{
|
|
230
|
-
"repo": "rusty-anchor",
|
|
231
|
-
"owner": "0x...",
|
|
232
|
-
"commitCid": "bafy...", // the new on-chain head
|
|
233
|
-
"oldRoot": "0x...",
|
|
234
|
-
"newRoot": "0x...",
|
|
235
|
-
"blockNumber": "12345678", // persist this to resume
|
|
236
|
-
"puts": [
|
|
237
|
-
{ "id": "t1", "cid": "bafy...", "type": "track", "payload": { "title": "Locura" } },
|
|
238
|
-
],
|
|
239
|
-
"deletes": ["t0"],
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
`fangorn subscribe --all` watches the whole app instead (every presented publisher and repo); a repo name or `--owner` narrows it.
|
|
244
|
-
|
|
245
|
-
**Resumability.** The last processed block is saved to
|
|
246
|
-
`.fangorn/subscribe-<owner>-<repo>.json` after each change, so restarting
|
|
247
|
-
replays only what you missed (via `eth_getLogs`) before going live. Override or
|
|
248
|
-
reset:
|
|
249
|
-
|
|
250
|
-
```sh
|
|
251
|
-
fangorn subscribe --from-block 12000000 # replay from a specific block
|
|
252
|
-
fangorn subscribe --from-start # replay the repo's full history
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
Without a saved cursor, subscribe starts **live from the current tip** — seed
|
|
256
|
-
your initial index from `fangorn read` first, then subscribe for the deltas.
|
|
257
|
-
|
|
258
|
-
---
|
|
259
|
-
|
|
260
|
-
## SDK Usage
|
|
261
|
-
|
|
262
|
-
### Initialization
|
|
263
|
-
|
|
264
|
-
`Fangorn.create` is synchronous. Pass Pinata storage for any commit/read operation. Supply either a `privateKey` (the SDK builds the wallet client for you) or your own viem `walletClient`.
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
import { Fangorn, FangornConfig } from "@fangorn-network/sdk";
|
|
23
|
+
import { Fangorn } from "@fangorn-network/sdk";
|
|
268
24
|
|
|
269
25
|
const fangorn = Fangorn.create({
|
|
270
26
|
privateKey: "0x...",
|
|
271
|
-
storage: {
|
|
272
|
-
pinata: {
|
|
273
|
-
jwt: process.env.PINATA_JWT!,
|
|
274
|
-
gateway: process.env.PINATA_GATEWAY!,
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
config: FangornConfig, // the default, Base Sepolia; or ArbitrumSepoliaConfig
|
|
278
|
-
appId: "my-app", // optional for reads (no app: each publisher's latest head); hosted uploads need one
|
|
27
|
+
storage: { signedUrl: {} }, // hosted uploads on Base Sepolia; or { pinata: { jwt, gateway } }
|
|
279
28
|
});
|
|
280
29
|
|
|
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.
|
|
284
|
-
const apps = fangorn.getAppRegistry();
|
|
285
|
-
await apps.canPublish(fangorn.getAddress());
|
|
286
|
-
```
|
|
287
|
-
|
|
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.
|
|
294
|
-
|
|
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.
|
|
298
|
-
|
|
299
|
-
### Repos & the git-native flow
|
|
300
|
-
|
|
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.
|
|
304
|
-
|
|
305
|
-
```ts
|
|
306
|
-
// Create the repo (no-op if it already exists)
|
|
307
30
|
await fangorn.initRepo("rusty-anchor");
|
|
308
|
-
|
|
31
|
+
await fangorn.uploadBatch("rusty-anchor", [
|
|
32
|
+
{ id: "t1", type: "track", payload: { title: "Locura", artist: "Alice" } },
|
|
33
|
+
]);
|
|
309
34
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
parent: tip!,
|
|
313
|
-
message: "initial import",
|
|
314
|
-
records: [
|
|
315
|
-
{ id: "t1", type: "track", payload: { title: "Locura", artist: "Alice" } },
|
|
316
|
-
{ id: "a1", type: "artist", payload: { name: "Alice" } },
|
|
317
|
-
],
|
|
318
|
-
});
|
|
319
|
-
await fangorn.push("rusty-anchor", c1.commitCid);
|
|
320
|
-
|
|
321
|
-
// A follow-up commit builds on the previous one
|
|
322
|
-
const c2 = await fangorn.commit({
|
|
323
|
-
repo: "rusty-anchor",
|
|
324
|
-
parent: c1.commitCid,
|
|
325
|
-
message: "add a track, drop the artist",
|
|
326
|
-
records: [{ id: "t2", type: "track", payload: { title: "Otra", artist: "Alice" } }],
|
|
327
|
-
deletes: ["a1"],
|
|
328
|
-
});
|
|
329
|
-
await fangorn.push("rusty-anchor", c2.commitCid); // the chain rejects it unless the parent is the current head
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
### History, diff & read
|
|
333
|
-
|
|
334
|
-
Walk history from the on-chain tip (IPFS only, no indexer), and read the current contents:
|
|
335
|
-
|
|
336
|
-
```ts
|
|
337
|
-
const tip = await fangorn.onChainTip(fangorn.getAddress(), "rusty-anchor");
|
|
338
|
-
|
|
339
|
-
// Walk commits, newest first
|
|
340
|
-
for await (const c of fangorn.log(tip!)) {
|
|
341
|
-
console.log(c.cid, c.message);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// What a commit changed vs. its parent ({ puts, deletes })
|
|
345
|
-
const diff = await fangorn.show(tip!);
|
|
346
|
-
|
|
347
|
-
// Every record currently in one of your repos
|
|
348
|
-
const { records } = await fangorn.inspectRepo("rusty-anchor"); // { id, cid, type, payload }[]
|
|
349
|
-
|
|
350
|
-
// Someone else's repo, as this client's app presents it
|
|
351
|
-
const { tip: head, contents } = await fangorn.readRepo("0x...", "rusty-anchor");
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
### Immediate-write helpers
|
|
355
|
-
|
|
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:
|
|
358
|
-
|
|
359
|
-
```ts
|
|
360
|
-
await fangorn.upload("rusty-anchor", { title: "Locura" }, "track");
|
|
361
|
-
|
|
362
|
-
await fangorn.uploadBatch(
|
|
363
|
-
"rusty-anchor",
|
|
364
|
-
[{ id: "t1", type: "track", payload: { title: "Locura" } }],
|
|
365
|
-
["t0"], // ids to delete
|
|
366
|
-
);
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### Subscribe (light client)
|
|
370
|
-
|
|
371
|
-
`subscribe` is an async generator over one repo's changes. It optionally
|
|
372
|
-
replays from a block cursor (`fromBlock`) and then watches live until the
|
|
373
|
-
`AbortSignal` fires. Each change carries `blockNumber` — persist it to resume.
|
|
374
|
-
|
|
375
|
-
```ts
|
|
376
|
-
const controller = new AbortController();
|
|
377
|
-
|
|
378
|
-
for await (const change of fangorn.subscribe({
|
|
379
|
-
repo: "rusty-anchor",
|
|
380
|
-
owner: "0x...", // defaults to your own address
|
|
381
|
-
fromBlock: savedCursor, // omit to start live from the current tip
|
|
382
|
-
signal: controller.signal,
|
|
383
|
-
})) {
|
|
384
|
-
for (const r of change.puts) index.upsert(r.id, r.payload);
|
|
385
|
-
for (const id of change.deletes) index.remove(id);
|
|
386
|
-
persistCursor(change.blockNumber);
|
|
387
|
-
}
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
The pure diff primitive is also exposed on the engine —
|
|
391
|
-
`engine.repoDiff(oldRootHex, newRootHex)` — if you want to diff
|
|
392
|
-
two arbitrary roots without watching.
|
|
393
|
-
|
|
394
|
-
### Subscribe to a whole app
|
|
395
|
-
|
|
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.
|
|
399
|
-
|
|
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:
|
|
403
|
-
|
|
404
|
-
```ts
|
|
405
|
-
// Everything the app presents
|
|
406
|
-
for await (const change of fangorn.subscribeApp({
|
|
407
|
-
signal: controller.signal,
|
|
408
|
-
})) {
|
|
409
|
-
console.log(change.owner, change.repo, change.puts.length);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// Narrow it: every publisher's "reviews" repo, or one publisher's whole footprint
|
|
413
|
-
fangorn.subscribeApp({ repo: "reviews" });
|
|
414
|
-
fangorn.subscribeApp({ owner: "0x..." });
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
The app is per-client state, not part of the network config — set it when you
|
|
418
|
-
create the client, or switch at runtime:
|
|
419
|
-
|
|
420
|
-
```ts
|
|
421
|
-
const fangorn = Fangorn.create({ privateKey, storage, appId: "my-app" });
|
|
422
|
-
fangorn.setAppId("my-other-app"); // by name, or by 32-byte app id
|
|
423
|
-
fangorn.getAppId(); // 0x… — what the registry keys on
|
|
424
|
-
```
|
|
425
|
-
|
|
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.
|
|
429
|
-
|
|
430
|
-
Apps live in the AppRegistry, and membership of one is what gets your storage
|
|
431
|
-
paid for and your repos presented:
|
|
432
|
-
|
|
433
|
-
```ts
|
|
434
|
-
const apps = fangorn.getAppRegistry();
|
|
435
|
-
|
|
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
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
See the [CLI quickstart](#pick-an-app) for the same flow from the
|
|
443
|
-
command line.
|
|
444
|
-
|
|
445
|
-
### Storage
|
|
446
|
-
|
|
447
|
-
Fangorn operates on a 'Bring Your Own Storage' basis. Each commit is persisted as
|
|
448
|
-
one CAR file (an opaque packfile of the commit's new blocks) plus one small commit
|
|
449
|
-
block, pinned to IPFS via Pinata; the chain holds only the 32-byte commit pointer.
|
|
450
|
-
The backend never needs to understand IPLD — any blob store can implement the
|
|
451
|
-
`MetadataStorage` interface.
|
|
452
|
-
|
|
453
|
-
---
|
|
454
|
-
|
|
455
|
-
## Encryption & gadgets
|
|
35
|
+
// Anyone, from the head alone:
|
|
36
|
+
const { contents } = await fangorn.readRepo(fangorn.getAddress(), "rusty-anchor");
|
|
456
37
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
addressability — fully public while the payload stays closed.
|
|
460
|
-
|
|
461
|
-
A **gadget** names _how_ a value is sealed and _under what condition_ it opens. Two
|
|
462
|
-
ship today, both exported from the package root (`@fangorn-network/sdk`):
|
|
463
|
-
|
|
464
|
-
| Gadget | Key derivation | Who can open it |
|
|
465
|
-
| ---------------- | --------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
466
|
-
| `self-hkdf-v1` | HKDF from your own 32-byte secret | Only you. No ECDH, no recipient, no gate — nobody else can re-derive the key. |
|
|
467
|
-
| `worker-usdc-v1` | X25519 ECDH to the access worker's static key | Anyone who has settled for the resource; the worker checks the Settlement Registry. |
|
|
468
|
-
|
|
469
|
-
Every key is bound to a 32-byte **`resourceId`**, which doubles as the Settlement
|
|
470
|
-
Registry key. The same secret cannot cross-open a different resource, and changing
|
|
471
|
-
_who can read_ means re-sealing under a new gadget/`resourceId` and committing a
|
|
472
|
-
record that points at the new bytes.
|
|
473
|
-
|
|
474
|
-
### `self-hkdf-v1` — fully private
|
|
475
|
-
|
|
476
|
-
The simplest path is entirely out of band: seal before ingestion, unseal after
|
|
477
|
-
retrieval. Fangorn never sees plaintext or a key — it commits the ciphertext like any
|
|
478
|
-
other payload. No worker, no settlement, no R2 involved.
|
|
479
|
-
|
|
480
|
-
```ts
|
|
481
|
-
import {
|
|
482
|
-
sealSelf,
|
|
483
|
-
unsealSelf,
|
|
484
|
-
GADGET_SELF_HKDF_V1,
|
|
485
|
-
} from "@fangorn-network/sdk";
|
|
486
|
-
import { keccak256, stringToBytes, hexToBytes, bytesToHex } from "viem";
|
|
487
|
-
|
|
488
|
-
const ownSecret = hexToBytes(privateKey); // your own 32 bytes
|
|
489
|
-
const resourceId = keccak256(stringToBytes("rusty-anchor:secret-msg"));
|
|
490
|
-
|
|
491
|
-
const ciphertext = sealSelf(
|
|
492
|
-
new TextEncoder().encode("the eagles are coming"),
|
|
493
|
-
ownSecret,
|
|
494
|
-
resourceId,
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
// commit the opaque bytes like anything else
|
|
498
|
-
await fangorn.upload(
|
|
499
|
-
"rusty-anchor",
|
|
500
|
-
{
|
|
501
|
-
gadget: GADGET_SELF_HKDF_V1,
|
|
502
|
-
resourceId,
|
|
503
|
-
ciphertext: bytesToHex(ciphertext),
|
|
504
|
-
},
|
|
505
|
-
"secret-msg",
|
|
506
|
-
);
|
|
507
|
-
|
|
508
|
-
// later, after `read` / `inspectRepo` hands the payload back:
|
|
509
|
-
const plaintext = unsealSelf(
|
|
510
|
-
hexToBytes(stored.ciphertext),
|
|
511
|
-
ownSecret,
|
|
512
|
-
stored.resourceId,
|
|
513
|
-
);
|
|
514
|
-
```
|
|
515
|
-
|
|
516
|
-
### `worker-usdc-v1` — settlement-gated
|
|
517
|
-
|
|
518
|
-
For paid or conditionally-readable data, seal to the **access worker's** static X25519
|
|
519
|
-
public key and hand the ciphertext to the worker, which stores the opaque bytes in R2
|
|
520
|
-
(never IPFS — a large, frequently-fetched ciphertext shouldn't burn public gateway
|
|
521
|
-
egress). `encryptAndUpload` does both and returns a **handle**:
|
|
522
|
-
|
|
523
|
-
```ts
|
|
524
|
-
import { encryptAndUpload, GADGET_WORKER_USDC_V1 } from "@fangorn-network/sdk";
|
|
525
|
-
|
|
526
|
-
const handle = await encryptAndUpload({
|
|
527
|
-
gadget: GADGET_WORKER_USDC_V1,
|
|
528
|
-
plaintext: new TextEncoder().encode("the full dataset"),
|
|
529
|
-
resourceId,
|
|
530
|
-
workerPubkey, // the access worker's static X25519 key (32 bytes)
|
|
531
|
-
storage: {
|
|
532
|
-
workerUrl: process.env.ACCESS_WORKER_URL!,
|
|
533
|
-
authToken: process.env.ACCESS_WORKER_TOKEN!,
|
|
534
|
-
contentType: "application/octet-stream",
|
|
535
|
-
},
|
|
536
|
-
});
|
|
537
|
-
```
|
|
538
|
-
|
|
539
|
-
The handle is what you commit in place of the plaintext value — the engine treats it
|
|
540
|
-
as an ordinary opaque object in the record payload:
|
|
541
|
-
|
|
542
|
-
```jsonc
|
|
543
|
-
{
|
|
544
|
-
"@type": "handle",
|
|
545
|
-
"objectKey": "…", // R2 object key
|
|
546
|
-
"workerUrl": "https://access-worker.example.workers.dev",
|
|
547
|
-
"encryption": {
|
|
548
|
-
"gadget": "worker-usdc-v1",
|
|
549
|
-
"resourceId": "0x…", // Settlement Registry key + HKDF binding
|
|
550
|
-
"ciphertextHash": "0x…", // sha256 of the sealed bytes
|
|
551
|
-
"workerPubkey": "0x…", // worker-usdc-v1 only
|
|
552
|
-
},
|
|
38
|
+
for await (const change of fangorn.subscribe({ repo: "rusty-anchor", owner: fangorn.getAddress() })) {
|
|
39
|
+
console.log(change.puts, change.deletes);
|
|
553
40
|
}
|
|
554
41
|
```
|
|
555
42
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
Both gadgets resolve through the worker's `POST /access`. `decryptHandle` signs the
|
|
559
|
-
request (the worker recovers the signer's address and checks the Settlement Registry
|
|
560
|
-
for `resourceId`), fetches the bytes, and returns plaintext:
|
|
561
|
-
|
|
562
|
-
```ts
|
|
563
|
-
import { decryptHandle } from "@fangorn-network/sdk";
|
|
43
|
+
## Quickstart (CLI)
|
|
564
44
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
45
|
+
```sh
|
|
46
|
+
npm i -g @fangorn-network/sdk
|
|
47
|
+
fangorn init # wallet key, storage → ~/.fangorn/config.json
|
|
48
|
+
fangorn repo init rusty-anchor # create on chain, track in ./.fangorn
|
|
49
|
+
fangorn commit records.json # local commit (IPFS only)
|
|
50
|
+
fangorn push # move the on-chain head
|
|
51
|
+
fangorn subscribe --owner 0x... rusty-anchor # stream diffs as JSON lines
|
|
571
52
|
```
|
|
572
53
|
|
|
573
|
-
|
|
574
|
-
come back _still sealed_, are checked against `ciphertextHash`, and are unsealed
|
|
575
|
-
locally with `ownSecret`.
|
|
576
|
-
- **`worker-usdc-v1`** — the worker streams bytes only once the signer has settled,
|
|
577
|
-
having unsealed with its own key; the bytes arrive as plaintext.
|
|
578
|
-
|
|
579
|
-
`buildAccessRequest` / `accessMessageHash` are exported if you want to drive the
|
|
580
|
-
`/access` endpoint yourself, and `MembershipRegistryClient` (`canRead`, `planOf`)
|
|
581
|
-
reads the membership rail directly.
|
|
582
|
-
|
|
583
|
-
**Trust model.** For `worker-usdc-v1` the access worker is the "somewhat trusted" party:
|
|
584
|
-
it holds the unsealing key and sees plaintext at release time. That is deliberate for
|
|
585
|
-
v1 — no TEE, no threshold network. Swapping in a stronger backend later is a _new
|
|
586
|
-
gadget_ behind the same handle shape, so committed data doesn't change form.
|
|
587
|
-
`self-hkdf-v1` trusts nobody: the worker is dumb storage and never holds a key.
|
|
588
|
-
|
|
589
|
-
---
|
|
590
|
-
|
|
591
|
-
## Contracts
|
|
592
|
-
|
|
593
|
-
### Base Sepolia (the default)
|
|
594
|
-
|
|
595
|
-
| Contract | Address | What it owns |
|
|
596
|
-
| -------------------- | -------------------------------------------- | --------------------------------------------------- |
|
|
597
|
-
| DataRegistry | `0xE9183f768865dd2Cde5f1B71F8446F0Cd798ebe0` | Every repo's head, and the update log |
|
|
598
|
-
| AppRegistry | `0x0D3e98399df41b558048Cdd7D71723c37A3A9D6F` | Apps: owner, accepted publishers, bans, storage subscription (ERC-5643, USDC); what each app excludes |
|
|
599
|
-
| MembershipRegistry | `0x0e96C012b5c53622EcDAA82F342E31C2623A04f5` | Time-limited, unlinkable access to an app's paid records (USDC + Semaphore) |
|
|
600
|
-
|
|
601
|
-
`Fangorn.create` uses it when given no `config`, and the CLI when `CHAIN_NAME` is unset.
|
|
602
|
-
|
|
603
|
-
### Arbitrum Sepolia
|
|
604
|
-
|
|
605
|
-
| Contract | Address |
|
|
606
|
-
| -------------------- | -------------------------------------------- |
|
|
607
|
-
| DataRegistry | `0x72B5f83526F3893aF9f1eE0f32A27218EA09f8aE` |
|
|
608
|
-
| AppRegistry | `0x55e6209ea1833ceD900989a3b3b22466934E04A5` |
|
|
609
|
-
| MembershipRegistry | `0xDF17030Cd65435C86eb043F31DDACa99E819E347` |
|
|
610
|
-
|
|
611
|
-
Still runs an older version of the contracts, which this SDK's ABIs do not match.
|
|
612
|
-
Select it with `Fangorn.create({ config: ArbitrumSepoliaConfig, ... })`, or from the
|
|
613
|
-
CLI with `CHAIN_NAME=arbitrumSepolia` (or pick it in `fangorn init`).
|
|
614
|
-
|
|
615
|
-
Its default RPC is `base-sepolia-rpc.publicnode.com`, not `sepolia.base.org`: the
|
|
616
|
-
official endpoint caps `eth_getLogs` at 200 blocks, too narrow to scan the registry's
|
|
617
|
-
history. Each config's `logWindow` is the most blocks one log query spans on its RPC
|
|
618
|
-
(Base 10,000, Arbitrum 100,000); `FANGORN_LOG_WINDOW` overrides it for a private RPC.
|
|
619
|
-
|
|
620
|
-
`BaseSepoliaConfig` (also exported as `FangornConfig`, the default) and `ArbitrumSepoliaConfig` in `src/config.ts` are the authoritative list and what the SDK
|
|
621
|
-
uses — prefer it over any address copied out of a document,
|
|
622
|
-
including this table. The sources are `fangorn-network/contracts`
|
|
623
|
-
(`solidity/script/Deployments.sol`); regenerate the ABIs with `pnpm abis`.
|
|
54
|
+
The [Guide](docs/GUIDE.md) covers the full flow: commit vs push, epochs, history, subscribing, agent cards, storage, and sealed and paid fields.
|
|
624
55
|
|
|
625
|
-
|
|
626
|
-
its members (`canPublish`).
|
|
56
|
+
## Network
|
|
627
57
|
|
|
628
|
-
|
|
58
|
+
Fangorn runs on **Base Sepolia**. The DataRegistry, SettlementRegistry, and hosted upload worker are all deployed there. Addresses are in [`src/config.ts`](src/config.ts) (`BaseSepoliaConfig`). To use a local anvil or a private deployment, pass your own `NetworkConfig` to `Fangorn.create`, or set the `FANGORN_*` overrides for the CLI (see the [Guide](docs/GUIDE.md#configure)). Contract sources are in [fangorn-network/contracts](https://github.com/fangorn-network/contracts).
|
|
629
59
|
|
|
630
|
-
##
|
|
631
|
-
|
|
632
|
-
### Unit Tests
|
|
633
|
-
|
|
634
|
-
```sh
|
|
635
|
-
pnpm test
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
### E2E Tests
|
|
639
|
-
|
|
640
|
-
The SDK suite (`src/test/sdk-suite.ts`) runs twice: in memory with the unit
|
|
641
|
-
tests, and against the contracts, built from source in a sibling checkout of
|
|
642
|
-
`fangorn-network/contracts` (`FANGORN_CONTRACTS_DIR` to point elsewhere) and
|
|
643
|
-
deployed to a fresh `anvil`. Nothing touches a real chain.
|
|
60
|
+
## Development
|
|
644
61
|
|
|
645
62
|
```sh
|
|
646
|
-
pnpm
|
|
63
|
+
pnpm i
|
|
64
|
+
pnpm test # unit tests + the SDK suite in memory
|
|
65
|
+
pnpm test:e2e # the same suite against the contracts on a fresh anvil
|
|
66
|
+
pnpm abis # regenerate ABIs from the contracts repo
|
|
647
67
|
```
|
|
648
68
|
|
|
649
|
-
|
|
650
|
-
| ------------------------------ | ---------------------------- | ------------------------ |
|
|
651
|
-
| `src/e2e/sdk.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
|
|
652
|
-
| `src/e2e/apps.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
|
|
653
|
-
| `src/e2e/admin.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
|
|
654
|
-
| `src/e2e/live.e2e.test.ts` | Base Sepolia, read-only | nothing |
|
|
655
|
-
|
|
656
|
-
Without `anvil`, `forge` or the contracts checkout the anvil suites are skipped
|
|
657
|
-
(in CI they fail). The deployer is the protocol admin, so the admin suite needs
|
|
658
|
-
no real key. Storage is in memory; `E2E_STORAGE=pinata` runs the same suites
|
|
659
|
-
against Pinata (`PINATA_JWT`, `PINATA_GATEWAY`).
|
|
660
|
-
|
|
661
|
-
**The live suite** only reads: that the registries point at each other, and that
|
|
662
|
-
the config's start block is the AppRegistry's deployment.
|
|
663
|
-
|
|
664
|
-
---
|
|
665
|
-
|
|
666
|
-
## Limitations / Future Work
|
|
667
|
-
|
|
668
|
-
- 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.
|
|
669
|
-
- 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.
|
|
670
|
-
- `fangorn subscribe` is the event stream, not the storage paywall — that is `fangorn app claim` / `fangorn app renew`.
|
|
671
|
-
- `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.
|
|
672
|
-
- Record schema validation is client-side only — no on-chain enforcement.
|
|
673
|
-
- An app presents each accepted publisher's latest head; the data itself is unverified, so accept publishers you trust.
|
|
674
|
-
|
|
675
|
-
---
|
|
69
|
+
The e2e tests need `anvil`, `forge`, and a sibling checkout of `fangorn-network/contracts` (set `FANGORN_CONTRACTS_DIR` to use another location). Without them, the tests are skipped locally and fail in CI. `E2E_STORAGE=pinata` runs the tests against Pinata (`PINATA_JWT`, `PINATA_GATEWAY`). `pnpm test:live` runs read-only checks against Base Sepolia.
|
|
676
70
|
|
|
677
71
|
## License
|
|
678
72
|
|