@fangorn-network/sdk 2026.6.16 → 2026.7.1-2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +210 -266
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +261 -167
- package/lib/cli/index.d.ts +13 -651
- package/lib/config.d.ts +137 -792
- package/lib/config.js +6 -22
- package/lib/contracts/data-registry/abi.d.ts +38 -0
- package/lib/contracts/data-registry/abi.js +237 -0
- package/lib/contracts/data-registry/index.d.ts +81 -0
- package/lib/contracts/data-registry/index.js +184 -0
- package/lib/contracts/index.d.ts +3 -0
- package/lib/contracts/index.js +4 -0
- package/lib/crypto/aes.d.ts +26 -0
- package/lib/crypto/aes.js +58 -0
- package/lib/crypto/encryption.d.ts +53 -0
- package/lib/crypto/encryption.js +82 -0
- package/lib/{modules/encryption → crypto}/rand.d.ts +1 -1
- package/lib/{modules/encryption → crypto}/rand.js +1 -1
- package/lib/{modules/encryption → crypto}/types.d.ts +1 -1
- package/lib/engine/blockstore.d.ts +24 -0
- package/lib/engine/blockstore.js +85 -0
- package/lib/engine/index.d.ts +180 -0
- package/lib/engine/index.js +367 -0
- package/lib/fangorn.d.ts +149 -16
- package/lib/fangorn.js +256 -37
- package/lib/harness/examples/hackmd/build-markdown-graph.js +17 -0
- package/lib/harness/index.d.ts +57 -0
- package/lib/harness/index.js +67 -0
- package/lib/index.d.ts +2 -2
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +218 -0
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +261 -0
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +156 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +299 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +532 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +344 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +137 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +262 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +150 -0
- package/lib/providers/storage/car.d.ts +36 -0
- package/lib/providers/storage/car.js +80 -0
- package/lib/providers/storage/pinata.d.ts +29 -1
- package/lib/providers/storage/pinata.js +135 -20
- package/lib/providers/storage/types.d.ts +25 -18
- package/lib/roles/repo/index.d.ts +56 -0
- package/lib/roles/repo/index.js +73 -0
- package/lib/test/car_smoke.d.ts +1 -0
- package/lib/test/car_smoke.js +81 -0
- package/lib/test/cleanup-embeddings-testdata.js +9 -38
- package/lib/test/setup-embeddings-testdata.d.ts +4 -6
- package/lib/test/setup-embeddings-testdata.js +40 -94
- package/lib/test/testbed.d.ts +35 -32
- package/lib/test/testbed.js +48 -138
- package/lib/types/index.d.ts +3 -19
- package/lib/utils/manifest.d.ts +23 -0
- package/lib/utils/manifest.js +77 -0
- package/package.json +99 -81
- package/lib/modules/encryption/actions.d.ts +0 -4
- package/lib/modules/encryption/actions.js +0 -18
- package/lib/modules/encryption/aes.d.ts +0 -10
- package/lib/modules/encryption/aes.js +0 -51
- package/lib/registries/datasource-registry/abi.d.ts +0 -186
- package/lib/registries/datasource-registry/abi.js +0 -229
- package/lib/registries/datasource-registry/index.d.ts +0 -39
- package/lib/registries/datasource-registry/index.js +0 -158
- package/lib/registries/index.d.ts +0 -3
- package/lib/registries/index.js +0 -4
- package/lib/registries/schema-registry/abi.d.ts +0 -218
- package/lib/registries/schema-registry/abi.js +0 -246
- package/lib/registries/schema-registry/index.d.ts +0 -34
- package/lib/registries/schema-registry/index.js +0 -179
- package/lib/registries/settlement-registry/abi.d.ts +0 -218
- package/lib/registries/settlement-registry/abi.js +0 -259
- package/lib/registries/settlement-registry/index.d.ts +0 -63
- package/lib/registries/settlement-registry/index.js +0 -325
- package/lib/registries/settlement-registry/types.d.ts +0 -54
- package/lib/registries/settlement-registry/types.js +0 -1
- package/lib/roles/consumer/index.d.ts +0 -39
- package/lib/roles/consumer/index.js +0 -150
- package/lib/roles/consumer/types.d.ts +0 -47
- package/lib/roles/consumer/types.js +0 -1
- package/lib/roles/publisher/builders/bundle.d.ts +0 -32
- package/lib/roles/publisher/builders/bundle.js +0 -137
- package/lib/roles/publisher/builders/record-set.d.ts +0 -17
- package/lib/roles/publisher/builders/record-set.js +0 -55
- package/lib/roles/publisher/builders/types.d.ts +0 -38
- package/lib/roles/publisher/builders/types.js +0 -1
- package/lib/roles/publisher/builders/utils.d.ts +0 -9
- package/lib/roles/publisher/builders/utils.js +0 -29
- package/lib/roles/publisher/encryption.d.ts +0 -18
- package/lib/roles/publisher/encryption.js +0 -38
- package/lib/roles/publisher/index.d.ts +0 -68
- package/lib/roles/publisher/index.js +0 -179
- package/lib/roles/publisher/types.d.ts +0 -114
- package/lib/roles/publisher/types.js +0 -1
- package/lib/roles/schema/index.d.ts +0 -44
- package/lib/roles/schema/index.js +0 -127
- package/lib/roles/schema/types.d.ts +0 -113
- package/lib/roles/schema/types.js +0 -1
- package/lib/roles/schema/validate.d.ts +0 -9
- package/lib/roles/schema/validate.js +0 -128
- package/lib/test/publish_mb_bundle.js +0 -296
- /package/lib/{modules/encryption/index.d.ts → contracts/data-registry/test.d.ts} +0 -0
- /package/lib/{modules/encryption/index.js → contracts/data-registry/test.js} +0 -0
- /package/lib/{modules/encryption → crypto}/types.js +0 -0
- /package/lib/{test/publish_mb_bundle.d.ts → harness/examples/hackmd/build-markdown-graph.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
# Fangorn SDK
|
|
2
2
|
|
|
3
|
-
commit →
|
|
3
|
+
commit → push → discover → fetch
|
|
4
4
|
|
|
5
5
|
Intent-bound data for the agentic web.
|
|
6
6
|
|
|
7
|
-
Fangorn lets you publish data
|
|
8
|
-
|
|
7
|
+
Fangorn lets you publish content-addressed graph data, organized into namespaces, so that agents can discover and verify it across any number of publishers. Content is stored in your own storage backend (IPFS via Pinata today); the on-chain **DataRegistry** holds only a single cryptographic pointer per publisher. The protocol coordinates commitment and discovery without ever touching your content directly.
|
|
8
|
+
|
|
9
|
+
Each publisher owns exactly **one on-chain state root** — the root of a content-addressed Pail tree (`@web3-storage/pail`), wrapped in a commit. Everything you publish lives as key-prefixed **namespaces** inside that one tree. Advancing the root is a compare-and-swap: it *is* a git ref update.
|
|
10
|
+
|
|
11
|
+
Data is a **metagraph** — **vertices** (a JSON payload tagged by a free-form schema id) and **edges** (a labeled relation between two vertex CIDs) — committed under a namespace.
|
|
12
|
+
|
|
13
|
+
Datasets are versioned like git: each update is a **commit** that points at its parent, the registry stores only the pointer to the latest commit, and full history lives in IPFS — reconstructible from the on-chain tip alone, no indexer required. `commit` builds locally (permissionless); `push` moves the on-chain pointer (the single permissioned step, fast-forward checked).
|
|
14
|
+
|
|
15
|
+
> **Note:** access-controlled (encrypted) fields and the purchase → claim → fetch settlement flow are being built on top of this registry and are **not available in the current release**. Registration, namespaces, and the git-native commit / push / log / clone rail are live.
|
|
9
16
|
|
|
10
17
|
## Supported Networks
|
|
11
18
|
|
|
12
|
-
Arbitrum Sepolia
|
|
19
|
+
- Arbitrum Sepolia
|
|
13
20
|
|
|
14
21
|
---
|
|
15
22
|
|
|
@@ -32,327 +39,271 @@ fangorn init
|
|
|
32
39
|
|
|
33
40
|
`fangorn init` prompts for:
|
|
34
41
|
- Wallet private key
|
|
35
|
-
- Pinata JWT + gateway URL (
|
|
36
|
-
- Fangorn access worker URL (for
|
|
37
|
-
- Default chain
|
|
42
|
+
- Pinata JWT + gateway URL (content + commit-object storage)
|
|
43
|
+
- Fangorn access worker URL (reserved for the upcoming access-control flow)
|
|
38
44
|
|
|
39
45
|
Config is written to `~/.fangorn/config.json`.
|
|
40
46
|
|
|
41
|
-
You can also configure via environment variables:
|
|
47
|
+
You can also configure via environment variables (these take precedence over the config file):
|
|
42
48
|
|
|
43
49
|
```sh
|
|
44
|
-
|
|
50
|
+
ETH_PRIVATE_KEY=0x...
|
|
45
51
|
PINATA_JWT=...
|
|
46
52
|
PINATA_GATEWAY=https://your-gateway.mypinata.cloud
|
|
47
|
-
WORKER_URL=https://your-worker.workers.dev
|
|
48
53
|
CHAIN_NAME=arbitrumSepolia
|
|
54
|
+
WORKER_URL=https://your-worker.workers.dev # optional (future access control)
|
|
49
55
|
```
|
|
50
56
|
|
|
51
|
-
### Register a
|
|
57
|
+
### Register as a publisher
|
|
58
|
+
|
|
59
|
+
Register once before committing anything. This records your wallet as a data publisher in the DataRegistry (the registration fee is currently zero).
|
|
52
60
|
|
|
53
61
|
```sh
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
fangorn register
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Track a namespace (git-native repo)
|
|
66
|
+
|
|
67
|
+
A **namespace** is a key prefix inside your on-chain tree. `repo init` allocates it and starts tracking it in a local `.fangorn/` pointer file (just a HEAD ref — there is no local object store; commit objects live in IPFS).
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
```sh
|
|
70
|
+
# Allocate a namespace on-chain (no-op if it already exists) and track it here
|
|
71
|
+
fangorn repo init rusty-anchor
|
|
59
72
|
```
|
|
60
73
|
|
|
61
|
-
###
|
|
74
|
+
### Commit → push
|
|
75
|
+
|
|
76
|
+
`commit` snapshots a namespace's vertices/edges into a new commit **locally** (pins the blocks to IPFS, advances your local HEAD) — it does **not** touch the chain. `push` fast-forwards the on-chain state root to your local tip: the single permissioned step.
|
|
62
77
|
|
|
63
78
|
```sh
|
|
64
|
-
#
|
|
65
|
-
fangorn
|
|
79
|
+
# Snapshot graph data into a new local commit — does NOT push
|
|
80
|
+
fangorn commit graph.json -m "initial import"
|
|
66
81
|
|
|
67
|
-
#
|
|
68
|
-
fangorn
|
|
82
|
+
# Settle the local tip on-chain (permission + fast-forward checked here)
|
|
83
|
+
fangorn push
|
|
84
|
+
fangorn push --force # push even if it doesn't fast-forward the on-chain tip
|
|
69
85
|
```
|
|
70
86
|
|
|
71
|
-
|
|
87
|
+
`graph.json` is a JSON file of vertices and (optionally) the edges between them. Edges reference vertices by their local `id`:
|
|
72
88
|
|
|
73
89
|
```json
|
|
74
90
|
{
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
"vertices": [
|
|
92
|
+
{ "id": "t1", "tag": "track", "payload": { "title": "Locura", "artist": "Alice" } },
|
|
93
|
+
{ "id": "a1", "tag": "artist", "payload": { "name": "Alice" } }
|
|
94
|
+
],
|
|
95
|
+
"edges": [
|
|
96
|
+
{ "rel": "performed_by", "from": "t1", "to": "a1" }
|
|
97
|
+
]
|
|
81
98
|
}
|
|
82
99
|
```
|
|
83
100
|
|
|
84
|
-
|
|
101
|
+
Each commit records its parent, so history is real and walkable. Deleting a vertex is just a later commit that omits it — earlier history is retained. Blocks are content-addressed, so unchanged data is reused byte-for-byte across commits.
|
|
85
102
|
|
|
86
|
-
### Consume Data
|
|
87
103
|
|
|
88
|
-
|
|
104
|
+
### Graph Builders
|
|
89
105
|
|
|
90
|
-
|
|
91
|
-
# Phase 1: pay and join the Semaphore group
|
|
92
|
-
fangorn consume purchase <owner> <name> \
|
|
93
|
-
-s schema.name.v1 \
|
|
94
|
-
--burner-key 0x... \
|
|
95
|
-
--amount 1 \
|
|
96
|
-
--usdc 0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d
|
|
97
|
-
|
|
98
|
-
# Save the identity string printed by purchase — required for claim.
|
|
99
|
-
|
|
100
|
-
# Phase 2: prove membership and claim access (generates a Groth16 ZK proof)
|
|
101
|
-
fangorn consume claim <owner> <name> \
|
|
102
|
-
-s schema.name.v1 \
|
|
103
|
-
--identity '<identity-string>' \
|
|
104
|
-
--stealth <stealth-address>
|
|
105
|
-
|
|
106
|
-
# Phase 3: fetch content via the access worker
|
|
107
|
-
fangorn consume fetch <owner> <name> \
|
|
108
|
-
-s schema.name.v1 \
|
|
109
|
-
-f audio \
|
|
110
|
-
--nullifier <nullifier> \
|
|
111
|
-
--stealth-key 0x... \
|
|
112
|
-
-o output.mp3
|
|
113
|
-
|
|
114
|
-
# List a publisher's manifest
|
|
115
|
-
fangorn consume list -s schema.name.v1 --owner <address>
|
|
116
|
-
|
|
117
|
-
# Inspect a publisher's entry
|
|
118
|
-
fangorn consume entry track1 -s schema.name.v1 --owner <address>
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
---
|
|
122
|
-
|
|
123
|
-
## SDK Usage
|
|
124
|
-
|
|
125
|
-
### Initialization
|
|
106
|
+
A graph builders are delegated to the application layer. Developers are responsible for implementing functions that take input and transform it into a set of edges and vertices. See [examples/hackmd](./examples/hackmd/) for an example.
|
|
126
107
|
|
|
127
|
-
|
|
128
|
-
import { Fangorn, FangornConfig } from "@fangorn-network/sdk";
|
|
108
|
+
### Inspect
|
|
129
109
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
110
|
+
```sh
|
|
111
|
+
fangorn status # local tip vs on-chain tip
|
|
112
|
+
fangorn log # walk commit history from the tip (newest first)
|
|
113
|
+
fangorn log -n 5 # limit
|
|
114
|
+
fangorn show # the tip commit + which keys it changed vs its parent
|
|
115
|
+
fangorn show <commitCid> # a specific commit
|
|
116
|
+
|
|
117
|
+
# List every vertex and edge committed under a namespace, as JSON
|
|
118
|
+
fangorn read # defaults to the current repo's namespace + owner
|
|
119
|
+
fangorn read rusty-anchor --owner 0x... --pretty
|
|
136
120
|
```
|
|
137
121
|
|
|
138
|
-
###
|
|
122
|
+
### Clone
|
|
139
123
|
|
|
140
|
-
|
|
124
|
+
Reconstruct tracking of a published namespace from its on-chain tip alone. History and contents are then fetched on demand from IPFS.
|
|
141
125
|
|
|
142
|
-
|
|
143
|
-
|
|
126
|
+
```sh
|
|
127
|
+
fangorn clone <owner> rusty-anchor
|
|
128
|
+
fangorn clone <owner> rusty-anchor --dir ./somewhere
|
|
129
|
+
```
|
|
144
130
|
|
|
145
|
-
|
|
131
|
+
### Subscribe (light client)
|
|
146
132
|
|
|
147
|
-
|
|
133
|
+
Watch a namespace for on-chain updates and stream the diffs — **no subgraph, no
|
|
134
|
+
indexer**. A publisher owns exactly one on-chain root, so this watches that
|
|
135
|
+
publisher's `StateCommitted` event (read straight from the RPC node) and, for
|
|
136
|
+
each new root, diffs the tree against the previous one restricted to your
|
|
137
|
+
namespace's key prefix. Only pushes that actually changed the namespace are
|
|
138
|
+
emitted. Diffs are resolved from IPFS on demand.
|
|
148
139
|
|
|
149
|
-
|
|
140
|
+
```sh
|
|
141
|
+
# Watch the current repo's namespace; each change is one JSON line on stdout.
|
|
142
|
+
fangorn subscribe
|
|
150
143
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
title: { "@type": "string" },
|
|
154
|
-
artist: { "@type": "string" },
|
|
155
|
-
audio: { "@type": "handle" }, // content lives in R2, access-controlled by worker
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
// Register the schema on-chain
|
|
159
|
-
const { schemaId, schemaCid } = await fangorn.schema.register({
|
|
160
|
-
name: "schema.name.v1",
|
|
161
|
-
definition,
|
|
162
|
-
agentId: "",
|
|
163
|
-
});
|
|
144
|
+
# Watch any publisher's namespace explicitly.
|
|
145
|
+
fangorn subscribe rusty-anchor --owner 0x...
|
|
164
146
|
|
|
165
|
-
|
|
166
|
-
|
|
147
|
+
# Feed an embeddings/index builder directly.
|
|
148
|
+
fangorn subscribe rusty-anchor --owner 0x... | my-index-builder
|
|
167
149
|
```
|
|
168
150
|
|
|
169
|
-
|
|
151
|
+
Each emitted line is a namespace change:
|
|
170
152
|
|
|
171
|
-
|
|
153
|
+
```jsonc
|
|
154
|
+
{
|
|
155
|
+
"namespace": "rusty-anchor",
|
|
156
|
+
"owner": "0x...",
|
|
157
|
+
"commitCid": "bafy...", // the new on-chain tip
|
|
158
|
+
"blockNumber": "12345678", // persist this to resume
|
|
159
|
+
"addedVertices": [{ "cid": "bafy...", "schemaId": "track", "payload": { "title": "Locura" } }],
|
|
160
|
+
"addedEdges": [{ "sourceCid": "bafy...", "relation": "by", "targetCid": "bafy..." }],
|
|
161
|
+
"removedVertexCids": ["bafy..."],
|
|
162
|
+
"removedEdges": []
|
|
163
|
+
}
|
|
164
|
+
```
|
|
172
165
|
|
|
173
|
-
|
|
166
|
+
**Resumability.** The last processed block is saved to
|
|
167
|
+
`.fangorn/subscribe-<owner>-<namespace>.json` after each change, so restarting
|
|
168
|
+
replays only what you missed (via `eth_getLogs`) before going live. Override or
|
|
169
|
+
reset:
|
|
174
170
|
|
|
175
|
-
|
|
171
|
+
```sh
|
|
172
|
+
fangorn subscribe --from-block 12000000 # replay from a specific block
|
|
173
|
+
fangorn subscribe --from-start # replay the namespace's full history
|
|
174
|
+
```
|
|
176
175
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
await fangorn.publisher.publishRecords({
|
|
180
|
-
schemaName: "schema.name.v1",
|
|
181
|
-
records: [
|
|
182
|
-
{
|
|
183
|
-
name: "track1",
|
|
184
|
-
fields: {
|
|
185
|
-
title: "Locura",
|
|
186
|
-
artist: "Alice",
|
|
187
|
-
audio: { "@type": "handle", uri: "r2://my-dir/locura.mp3" },
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
});
|
|
176
|
+
Without a saved cursor, subscribe starts **live from the current tip** — seed
|
|
177
|
+
your initial index from `fangorn read` first, then subscribe for the deltas.
|
|
192
178
|
|
|
193
|
-
|
|
194
|
-
await fangorn.publisher.upload({ schemaName: "schema.name.v1", records: [...] });
|
|
195
|
-
```
|
|
179
|
+
---
|
|
196
180
|
|
|
197
|
-
|
|
181
|
+
## SDK Usage
|
|
198
182
|
|
|
199
|
-
|
|
183
|
+
### Initialization
|
|
200
184
|
|
|
201
|
-
|
|
185
|
+
`Fangorn.create` is synchronous. Pass Pinata storage for any commit/read operation.
|
|
202
186
|
|
|
203
187
|
```ts
|
|
204
|
-
|
|
205
|
-
await fangorn.schema.register({ name: "my.track.v1", definition: trackSchema });
|
|
206
|
-
await fangorn.schema.register({ name: "my.taxonomy.v1", definition: taxonomySchema });
|
|
207
|
-
|
|
208
|
-
// 2. Register the bundle shape (idempotent)
|
|
209
|
-
await fangorn.schema.register({
|
|
210
|
-
kind: "bundle",
|
|
211
|
-
name: "my.bundle.v1",
|
|
212
|
-
bundle: {
|
|
213
|
-
nodes: { Track: "my.track.v1", Taxonomy: "my.taxonomy.v1" },
|
|
214
|
-
edges: [{ rel: "hasTaxonomy", from: "Track", to: "Taxonomy", min: 1, max: 1 }],
|
|
215
|
-
},
|
|
216
|
-
});
|
|
188
|
+
import { Fangorn, FangornConfig } from "@fangorn-network/sdk";
|
|
217
189
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
{ id: "x1", type: "Taxonomy", fields: { trackId: "t1", genres: ["electronic"] } },
|
|
224
|
-
],
|
|
225
|
-
edges: [
|
|
226
|
-
{ rel: "hasTaxonomy", from: "t1", to: "x1" },
|
|
227
|
-
],
|
|
228
|
-
datasetName: "my-dataset-v1",
|
|
190
|
+
const fangorn = Fangorn.create({
|
|
191
|
+
privateKey: "0x...",
|
|
192
|
+
storage: { pinata: { jwt: process.env.PINATA_JWT!, gateway: process.env.PINATA_GATEWAY! } },
|
|
193
|
+
config: FangornConfig, // defaults to Arbitrum Sepolia
|
|
194
|
+
domain: "localhost",
|
|
229
195
|
});
|
|
230
196
|
|
|
231
|
-
//
|
|
232
|
-
|
|
197
|
+
// Register once before committing.
|
|
198
|
+
const registry = fangorn.getDataRegistry();
|
|
199
|
+
if (!(await registry.isRegistered(fangorn.getAddress()))) {
|
|
200
|
+
await registry.register();
|
|
201
|
+
}
|
|
233
202
|
```
|
|
234
203
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
#### Custom builders
|
|
204
|
+
### Namespaces & the git-native flow
|
|
238
205
|
|
|
239
|
-
|
|
206
|
+
`initRepo` allocates a namespace on-chain (idempotent). Then split building from settling:
|
|
207
|
+
`commit` writes a commit object locally (durable in IPFS, HEAD not yet on-chain), and
|
|
208
|
+
`push` fast-forwards the on-chain root to it.
|
|
240
209
|
|
|
241
210
|
```ts
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
211
|
+
// Allocate the namespace (no-op if it already exists)
|
|
212
|
+
await fangorn.initRepo("rusty-anchor");
|
|
213
|
+
|
|
214
|
+
// First commit — no parent
|
|
215
|
+
const c1 = await fangorn.commit({
|
|
216
|
+
namespace: "rusty-anchor",
|
|
217
|
+
message: "initial import",
|
|
218
|
+
vertices: [
|
|
219
|
+
{ id: "t1", tag: "track", payload: { title: "Locura", artist: "Alice" } },
|
|
220
|
+
{ id: "a1", tag: "artist", payload: { name: "Alice" } },
|
|
221
|
+
],
|
|
222
|
+
edges: [{ rel: "performed_by", from: "t1", to: "a1" }],
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Settle it on-chain (fast-forward from "no tip yet")
|
|
226
|
+
await fangorn.push(c1.commitCid);
|
|
255
227
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
228
|
+
// A follow-up commit builds on the previous one
|
|
229
|
+
const c2 = await fangorn.commit({
|
|
230
|
+
namespace: "rusty-anchor",
|
|
231
|
+
parent: c1.commitCid,
|
|
232
|
+
message: "add another track",
|
|
233
|
+
vertices: [{ id: "t2", tag: "track", payload: { title: "Otra", artist: "Alice" } }],
|
|
261
234
|
});
|
|
235
|
+
await fangorn.push(c2.commitCid); // refuses unless it fast-forwards the on-chain tip (pass { force: true } to override)
|
|
262
236
|
```
|
|
263
237
|
|
|
264
|
-
###
|
|
238
|
+
### History, diff & read
|
|
265
239
|
|
|
266
|
-
|
|
240
|
+
Walk history from the on-chain tip (IPFS only, no indexer), and read the current namespace contents:
|
|
267
241
|
|
|
268
242
|
```ts
|
|
269
|
-
|
|
243
|
+
const tip = await fangorn.onChainTip(fangorn.getAddress());
|
|
270
244
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
paymentRecipient: ownerAddress,
|
|
276
|
-
amount: 1n,
|
|
277
|
-
usdcAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
|
|
278
|
-
usdcDomainName: "USD Coin",
|
|
279
|
-
usdcDomainVersion: "2",
|
|
280
|
-
});
|
|
245
|
+
// Walk commits, newest first
|
|
246
|
+
for await (const c of fangorn.log(tip!)) {
|
|
247
|
+
console.log(c.cid, c.message);
|
|
248
|
+
}
|
|
281
249
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
schemaId,
|
|
285
|
-
name: "track1",
|
|
286
|
-
identityCommitment: identity.commitment,
|
|
287
|
-
relayerPrivateKey: "0x...",
|
|
288
|
-
preparedRegister,
|
|
289
|
-
});
|
|
250
|
+
// What a commit changed vs. its first parent (namespaced pail keys added/removed)
|
|
251
|
+
const diff = await fangorn.show(tip!);
|
|
290
252
|
|
|
291
|
-
//
|
|
253
|
+
// Every vertex and edge currently committed under a namespace
|
|
254
|
+
const contents = await fangorn.inspectNamespace("rusty-anchor");
|
|
255
|
+
// contents.vertices: { cid, schemaId, payload }[] contents.edges: { sourceCid, relation, targetCid }[]
|
|
292
256
|
```
|
|
293
257
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
```ts
|
|
297
|
-
const preparedSettle = await fangorn.consumer.prepareSettle({
|
|
298
|
-
resourceId: DataSourceRegistry.resourceIdLocal(ownerAddress, schemaId, "track1"),
|
|
299
|
-
identity,
|
|
300
|
-
stealthAddress: "0x...",
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
const { txHash, nullifier } = await fangorn.consumer.claim({
|
|
304
|
-
owner: ownerAddress,
|
|
305
|
-
schemaId,
|
|
306
|
-
name: "track1",
|
|
307
|
-
relayerPrivateKey: "0x...",
|
|
308
|
-
preparedSettle,
|
|
309
|
-
});
|
|
258
|
+
> The fast-forward check in `push` is enforced client-side against the on-chain
|
|
259
|
+
> head in this release; on-chain write-authorization lands in a later slice.
|
|
310
260
|
|
|
311
|
-
|
|
312
|
-
```
|
|
261
|
+
### Immediate-write helpers
|
|
313
262
|
|
|
314
|
-
|
|
263
|
+
For the common "stage and settle in one shot" case, `upload` (one vertex) and `uploadBatch`
|
|
264
|
+
(many vertices + edges) run the whole commit-and-push atomically:
|
|
315
265
|
|
|
316
266
|
```ts
|
|
317
|
-
|
|
318
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
319
|
-
import { arbitrumSepolia } from "viem/chains";
|
|
320
|
-
|
|
321
|
-
const stealthWalletClient = createWalletClient({
|
|
322
|
-
account: privateKeyToAccount(stealthPrivateKey),
|
|
323
|
-
chain: arbitrumSepolia,
|
|
324
|
-
transport: http(rpcUrl),
|
|
325
|
-
});
|
|
267
|
+
await fangorn.upload("rusty-anchor", { title: "Locura" }, "track");
|
|
326
268
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
"audio",
|
|
332
|
-
nullifier.toString(),
|
|
333
|
-
stealthWalletClient,
|
|
269
|
+
await fangorn.uploadBatch(
|
|
270
|
+
"rusty-anchor",
|
|
271
|
+
[{ id: "t1", tag: "track", payload: { title: "Locura" } }],
|
|
272
|
+
[/* edges */],
|
|
334
273
|
);
|
|
335
274
|
```
|
|
336
275
|
|
|
337
|
-
|
|
276
|
+
### Subscribe (light client)
|
|
338
277
|
|
|
339
|
-
|
|
278
|
+
`subscribe` is an async generator over namespace-scoped changes. It optionally
|
|
279
|
+
replays from a block cursor (`fromBlock`) and then watches live until the
|
|
280
|
+
`AbortSignal` fires. Each change carries `blockNumber` — persist it to resume.
|
|
340
281
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
282
|
+
```ts
|
|
283
|
+
const controller = new AbortController();
|
|
284
|
+
|
|
285
|
+
for await (const change of fangorn.subscribe({
|
|
286
|
+
namespace: "rusty-anchor",
|
|
287
|
+
owner: "0x...", // defaults to your own address
|
|
288
|
+
fromBlock: savedCursor, // omit to start live from the current tip
|
|
289
|
+
signal: controller.signal,
|
|
290
|
+
})) {
|
|
291
|
+
for (const v of change.addedVertices) index.upsert(v.cid, v.payload);
|
|
292
|
+
for (const cid of change.removedVertexCids) index.remove(cid);
|
|
293
|
+
persistCursor(change.blockNumber);
|
|
294
|
+
}
|
|
295
|
+
```
|
|
346
296
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
4. If settled → bytes proxied directly from R2
|
|
351
|
-
5. If not → 401
|
|
297
|
+
The pure diff primitive is also exposed on the engine —
|
|
298
|
+
`engine.namespaceDiff(oldRootHex, newRootHex, namespace)` — if you want to diff
|
|
299
|
+
two arbitrary roots without watching.
|
|
352
300
|
|
|
353
|
-
|
|
301
|
+
### Storage
|
|
354
302
|
|
|
355
|
-
|
|
303
|
+
Fangorn operates on a 'Bring Your Own Storage' basis. Content-addressed blocks
|
|
304
|
+
(vertices, edges, pail shards, commit objects) are pinned to IPFS via Pinata; the chain
|
|
305
|
+
holds only the 32-byte commit pointer. Additional backends can be added behind the
|
|
306
|
+
`MetadataStorage` interface.
|
|
356
307
|
|
|
357
308
|
---
|
|
358
309
|
|
|
@@ -360,11 +311,11 @@ See the [fangorn-access-worker](https://github.com/fangorn-network/webworker) re
|
|
|
360
311
|
|
|
361
312
|
### Arbitrum Sepolia
|
|
362
313
|
|
|
363
|
-
| Contract
|
|
364
|
-
|
|
|
365
|
-
|
|
|
366
|
-
|
|
367
|
-
|
|
314
|
+
| Contract | Address |
|
|
315
|
+
| ------------- | -------------------------------------------- |
|
|
316
|
+
| DataRegistry | `0x9a3811b365a4aeea1626eaad185b273424ae5e48` |
|
|
317
|
+
|
|
318
|
+
This is the address in `FangornConfig`; the SDK uses it by default.
|
|
368
319
|
|
|
369
320
|
---
|
|
370
321
|
|
|
@@ -378,6 +329,8 @@ pnpm test
|
|
|
378
329
|
|
|
379
330
|
### E2E Tests
|
|
380
331
|
|
|
332
|
+
Runs the storage + on-chain anchor flow against live IPFS + the deployed contract.
|
|
333
|
+
|
|
381
334
|
```sh
|
|
382
335
|
cp env.example .env
|
|
383
336
|
pnpm test:e2e
|
|
@@ -385,34 +338,25 @@ pnpm test:e2e
|
|
|
385
338
|
|
|
386
339
|
Required variables:
|
|
387
340
|
|
|
388
|
-
| Variable
|
|
389
|
-
|
|
|
390
|
-
| `
|
|
391
|
-
| `
|
|
392
|
-
| `
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
| `CHAIN_NAME` | `arbitrumSepolia` |
|
|
396
|
-
| `CAIP2` | `421614` |
|
|
397
|
-
| `RPC_URL` | RPC endpoint |
|
|
398
|
-
| `USDC_ADDRESS` | USDC contract address |
|
|
399
|
-
| `DATA_SOURCE_REGISTRY_ADDRESS` | DataSourceRegistry address |
|
|
400
|
-
| `SCHEMA_REGISTRY_ADDRESS` | SchemaRegistry address |
|
|
401
|
-
| `SETTLEMENT_REGISTRY_ADDRESS` | SettlementRegistry address |
|
|
402
|
-
|
|
403
|
-
Phase 3 tests are skipped unless `WORKER_URL` is set. Run the access worker locally with `wrangler dev --local` and set `WORKER_URL=http://localhost:8787` to enable them.
|
|
341
|
+
| Variable | Description |
|
|
342
|
+
| ----------------------- | ----------------------------------------- |
|
|
343
|
+
| `ETH_PRIVATE_KEY` | Publisher private key (needs testnet ETH) |
|
|
344
|
+
| `PINATA_JWT` | Pinata API JWT |
|
|
345
|
+
| `PINATA_GATEWAY` | Pinata gateway URL |
|
|
346
|
+
|
|
347
|
+
The publisher must be registered (`fangorn register`, or `registry.register()`) on the target key.
|
|
404
348
|
|
|
405
349
|
---
|
|
406
350
|
|
|
407
351
|
## Limitations / Future Work
|
|
408
352
|
|
|
409
|
-
-
|
|
410
|
-
-
|
|
411
|
-
-
|
|
412
|
-
-
|
|
353
|
+
- Access-controlled (encrypted) fields and the purchase → claim → fetch settlement flow are being built on this registry — not available this release.
|
|
354
|
+
- Vertex/edge schema validation is client-side only — no on-chain enforcement.
|
|
355
|
+
- Push authorization is client-side in this release; on-chain write policies and non-fast-forward rejection are planned.
|
|
356
|
+
- Reads target one publisher's namespace at a time; cross-publisher discovery is a higher layer.
|
|
413
357
|
|
|
414
358
|
---
|
|
415
359
|
|
|
416
360
|
## License
|
|
417
361
|
|
|
418
|
-
|
|
362
|
+
MIT
|
package/lib/cli/cli.d.ts
CHANGED
|
File without changes
|