@fangorn-network/sdk 2026.7.27 → 2026.7.29-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 +173 -8
- package/lib/cli/cli.js +83 -20
- package/lib/config.d.ts +15 -3
- package/lib/config.js +19 -2
- package/lib/contracts/data-registry/abi.d.ts +80 -2
- package/lib/contracts/data-registry/abi.js +107 -12
- package/lib/contracts/data-registry/index.d.ts +93 -19
- package/lib/contracts/data-registry/index.js +157 -24
- package/lib/contracts/index.d.ts +2 -2
- package/lib/contracts/index.js +2 -2
- package/lib/engine/index.d.ts +36 -12
- package/lib/engine/index.js +51 -19
- package/lib/engine/test-helpers.d.ts +7 -4
- package/lib/engine/test-helpers.js +9 -6
- package/lib/fangorn.d.ts +143 -12
- package/lib/fangorn.js +203 -33
- package/lib/feed.d.ts +32 -0
- package/lib/feed.js +65 -0
- package/lib/index.d.ts +8 -2
- package/lib/index.js +8 -2
- package/lib/test/testbed.d.ts +21 -3
- package/lib/test/testbed.js +35 -7
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Data is a **metagraph** — **vertices** (a JSON payload tagged by a free-form s
|
|
|
10
10
|
|
|
11
11
|
Datasets are versioned like git, down to the storage model: each update is a **commit** that points at its parent and at a single **CAR file** (a packfile) holding only the blocks that commit introduced. The registry stores only the pointer to the latest commit; full history lives in IPFS — reconstructible from the on-chain tip alone, no indexer required. `commit` builds the graph in memory and persists it as **exactly two uploads** (one CAR + one small commit block), regardless of graph size; `push` moves the on-chain pointer (the single permissioned step, fast-forward checked). Unchanged data re-derives identical CIDs and is never re-uploaded.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Fields that shouldn't be public are **sealed** under a **gadget** — a named pairing of a sealing scheme and the condition under which it opens. Two ship today: `self-hkdf-v1` (fully private, only you can re-derive the key) and `worker-usdc-v1` (settlement-gated, released by the access worker once the reader has paid). See [Encryption & gadgets](#encryption--gadgets).
|
|
14
14
|
|
|
15
15
|
## Supported Networks
|
|
16
16
|
|
|
@@ -38,8 +38,9 @@ fangorn init
|
|
|
38
38
|
`fangorn init` prompts for:
|
|
39
39
|
|
|
40
40
|
- Wallet private key
|
|
41
|
-
- Pinata JWT + gateway URL (content + commit-object storage)
|
|
42
|
-
-
|
|
41
|
+
- Pinata JWT + gateway URL (content + commit-object storage; both optional)
|
|
42
|
+
- Access-gating worker URL (optional — stores sealed ciphertext and enforces the read gate)
|
|
43
|
+
- Presigned-URL worker URL (optional — issues short-lived Pinata upload URLs so no JWT is needed)
|
|
43
44
|
|
|
44
45
|
Config is written to `~/.fangorn/config.json`.
|
|
45
46
|
|
|
@@ -50,9 +51,12 @@ ETH_PRIVATE_KEY=0x...
|
|
|
50
51
|
PINATA_JWT=...
|
|
51
52
|
PINATA_GATEWAY=https://your-gateway.mypinata.cloud
|
|
52
53
|
CHAIN_NAME=arbitrumSepolia
|
|
53
|
-
|
|
54
|
+
ACCESS_WORKER_URL=https://access-worker.your-subdomain.workers.dev # optional (sealed fields)
|
|
55
|
+
SIGNED_URL_WORKER_URL=https://pinata-url-provider.your-subdomain.workers.dev # optional
|
|
54
56
|
```
|
|
55
57
|
|
|
58
|
+
> 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.
|
|
59
|
+
|
|
56
60
|
### Register as a publisher
|
|
57
61
|
|
|
58
62
|
Register once before committing anything. This records your wallet as a data publisher in the DataRegistry (the registration fee is currently zero).
|
|
@@ -253,7 +257,7 @@ const c1 = await fangorn.commit({
|
|
|
253
257
|
});
|
|
254
258
|
|
|
255
259
|
// Settle it on-chain (fast-forward from "no tip yet")
|
|
256
|
-
await fangorn.push(c1.commitCid);
|
|
260
|
+
await fangorn.push("rusty-anchor", c1.commitCid);
|
|
257
261
|
|
|
258
262
|
// A follow-up commit builds on the previous one
|
|
259
263
|
const c2 = await fangorn.commit({
|
|
@@ -264,7 +268,7 @@ const c2 = await fangorn.commit({
|
|
|
264
268
|
{ id: "t2", tag: "track", payload: { title: "Otra", artist: "Alice" } },
|
|
265
269
|
],
|
|
266
270
|
});
|
|
267
|
-
await fangorn.push(c2.commitCid); // refuses unless it fast-forwards the on-chain tip (pass { force: true } to override)
|
|
271
|
+
await fangorn.push("rusty-anchor", c2.commitCid); // refuses unless it fast-forwards the on-chain tip (pass { force: true } to override)
|
|
268
272
|
```
|
|
269
273
|
|
|
270
274
|
### History, diff & read
|
|
@@ -272,7 +276,7 @@ await fangorn.push(c2.commitCid); // refuses unless it fast-forwards the on-chai
|
|
|
272
276
|
Walk history from the on-chain tip (IPFS only, no indexer), and read the current namespace contents:
|
|
273
277
|
|
|
274
278
|
```ts
|
|
275
|
-
const tip = await fangorn.onChainTip(fangorn.getAddress());
|
|
279
|
+
const tip = await fangorn.onChainTip(fangorn.getAddress(), "rusty-anchor");
|
|
276
280
|
|
|
277
281
|
// Walk commits, newest first
|
|
278
282
|
for await (const c of fangorn.log(tip!)) {
|
|
@@ -332,6 +336,41 @@ The pure diff primitive is also exposed on the engine —
|
|
|
332
336
|
`engine.namespaceDiff(oldRootHex, newRootHex, namespace)` — if you want to diff
|
|
333
337
|
two arbitrary roots without watching.
|
|
334
338
|
|
|
339
|
+
### Subscribe to a whole app
|
|
340
|
+
|
|
341
|
+
Namespaces are hierarchical: every commit lands under `app:publisher:namespace`,
|
|
342
|
+
and each triple is its own on-chain timeline. Two publishers — or one publisher's
|
|
343
|
+
two namespaces — never contend for the same compare-and-swap.
|
|
344
|
+
|
|
345
|
+
The registry indexes all three parts, so an app-wide feed is one topic filter
|
|
346
|
+
rather than a per-publisher fan-out. `subscribeApp` yields the same
|
|
347
|
+
`NamespaceChange` values as `subscribe`, from every publisher in the app:
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
// Everything published under this app, by anyone
|
|
351
|
+
for await (const change of fangorn.subscribeApp({ signal: controller.signal })) {
|
|
352
|
+
console.log(change.owner, change.namespace, change.addedVertices.length);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Narrow it: every publisher's "reviews" namespace, or one publisher's whole app footprint
|
|
356
|
+
fangorn.subscribeApp({ namespace: "reviews" });
|
|
357
|
+
fangorn.subscribeApp({ owner: "0x..." });
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
The app is per-client state, not part of the network config — set it when you
|
|
361
|
+
create the client, or switch at runtime:
|
|
362
|
+
|
|
363
|
+
```ts
|
|
364
|
+
const fangorn = Fangorn.create({ privateKey, storage, appId: "my-app" });
|
|
365
|
+
fangorn.setAppId("my-other-app"); // by name, or by 32-byte app id
|
|
366
|
+
fangorn.getAppId(); // 0x… — what the registry keys on
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
It must be claimed once on-chain with
|
|
370
|
+
`fangorn.getDataRegistry().registerApp()` before any publisher can commit under
|
|
371
|
+
it. From the CLI: `fangorn set-app my-app` (persists it) then `fangorn
|
|
372
|
+
register-app`.
|
|
373
|
+
|
|
335
374
|
### Storage
|
|
336
375
|
|
|
337
376
|
Fangorn operates on a 'Bring Your Own Storage' basis. Each commit is persisted as
|
|
@@ -342,6 +381,130 @@ The backend never needs to understand IPLD — any blob store can implement the
|
|
|
342
381
|
|
|
343
382
|
---
|
|
344
383
|
|
|
384
|
+
## Encryption & gadgets
|
|
385
|
+
|
|
386
|
+
Not every field belongs in public IPFS. Fangorn lets you **seal** a value and commit
|
|
387
|
+
only an opaque reference to it, keeping the graph — its shape, its edges, its
|
|
388
|
+
addressability — fully public while the payload stays closed.
|
|
389
|
+
|
|
390
|
+
A **gadget** names *how* a value is sealed and *under what condition* it opens. Two
|
|
391
|
+
ship today, both exported from the package root (`@fangorn-network/sdk`):
|
|
392
|
+
|
|
393
|
+
| Gadget | Key derivation | Who can open it |
|
|
394
|
+
| ---------------- | ------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
395
|
+
| `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. |
|
|
396
|
+
| `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. |
|
|
397
|
+
|
|
398
|
+
Every key is bound to a 32-byte **`resourceId`**, which doubles as the Settlement
|
|
399
|
+
Registry key. The same secret cannot cross-open a different resource, and changing
|
|
400
|
+
*who can read* means re-sealing under a new gadget/`resourceId` and committing a
|
|
401
|
+
vertex that points at the new bytes.
|
|
402
|
+
|
|
403
|
+
### `self-hkdf-v1` — fully private
|
|
404
|
+
|
|
405
|
+
The simplest path is entirely out of band: seal before ingestion, unseal after
|
|
406
|
+
retrieval. Fangorn never sees plaintext or a key — it commits the ciphertext like any
|
|
407
|
+
other payload. No worker, no settlement, no R2 involved.
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
import { sealSelf, unsealSelf, GADGET_SELF_HKDF_V1 } from "@fangorn-network/sdk";
|
|
411
|
+
import { keccak256, stringToBytes, hexToBytes, bytesToHex } from "viem";
|
|
412
|
+
|
|
413
|
+
const ownSecret = hexToBytes(privateKey); // your own 32 bytes
|
|
414
|
+
const resourceId = keccak256(stringToBytes("rusty-anchor:secret-msg"));
|
|
415
|
+
|
|
416
|
+
const ciphertext = sealSelf(
|
|
417
|
+
new TextEncoder().encode("the eagles are coming"),
|
|
418
|
+
ownSecret,
|
|
419
|
+
resourceId,
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
// commit the opaque bytes like anything else
|
|
423
|
+
await fangorn.upload("rusty-anchor", {
|
|
424
|
+
gadget: GADGET_SELF_HKDF_V1,
|
|
425
|
+
resourceId,
|
|
426
|
+
ciphertext: bytesToHex(ciphertext),
|
|
427
|
+
}, "secret-msg");
|
|
428
|
+
|
|
429
|
+
// later, after `read` / `inspectNamespace` hands the payload back:
|
|
430
|
+
const plaintext = unsealSelf(hexToBytes(stored.ciphertext), ownSecret, stored.resourceId);
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### `worker-usdc-v1` — settlement-gated
|
|
434
|
+
|
|
435
|
+
For paid or conditionally-readable data, seal to the **access worker's** static X25519
|
|
436
|
+
public key and hand the ciphertext to the worker, which stores the opaque bytes in R2
|
|
437
|
+
(never IPFS — a large, frequently-fetched ciphertext shouldn't burn public gateway
|
|
438
|
+
egress). `encryptAndUpload` does both and returns a **handle**:
|
|
439
|
+
|
|
440
|
+
```ts
|
|
441
|
+
import { encryptAndUpload, GADGET_WORKER_USDC_V1 } from "@fangorn-network/sdk";
|
|
442
|
+
|
|
443
|
+
const handle = await encryptAndUpload({
|
|
444
|
+
gadget: GADGET_WORKER_USDC_V1,
|
|
445
|
+
plaintext: new TextEncoder().encode("the full dataset"),
|
|
446
|
+
resourceId,
|
|
447
|
+
workerPubkey, // the access worker's static X25519 key (32 bytes)
|
|
448
|
+
storage: {
|
|
449
|
+
workerUrl: process.env.ACCESS_WORKER_URL!,
|
|
450
|
+
authToken: process.env.ACCESS_WORKER_TOKEN!,
|
|
451
|
+
contentType: "application/octet-stream",
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
The handle is what you commit in place of the plaintext value — the engine treats it
|
|
457
|
+
as an ordinary opaque object in the vertex payload:
|
|
458
|
+
|
|
459
|
+
```jsonc
|
|
460
|
+
{
|
|
461
|
+
"@type": "handle",
|
|
462
|
+
"objectKey": "…", // R2 object key
|
|
463
|
+
"workerUrl": "https://access-worker.example.workers.dev",
|
|
464
|
+
"encryption": {
|
|
465
|
+
"gadget": "worker-usdc-v1",
|
|
466
|
+
"resourceId": "0x…", // Settlement Registry key + HKDF binding
|
|
467
|
+
"ciphertextHash": "0x…", // sha256 of the sealed bytes
|
|
468
|
+
"workerPubkey": "0x…", // worker-usdc-v1 only
|
|
469
|
+
},
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
### Reading a handle
|
|
474
|
+
|
|
475
|
+
Both gadgets resolve through the worker's `POST /access`. `decryptHandle` signs the
|
|
476
|
+
request (the worker recovers the signer's address and checks the Settlement Registry
|
|
477
|
+
for `resourceId`), fetches the bytes, and returns plaintext:
|
|
478
|
+
|
|
479
|
+
```ts
|
|
480
|
+
import { decryptHandle } from "@fangorn-network/sdk";
|
|
481
|
+
|
|
482
|
+
const plaintext = await decryptHandle({
|
|
483
|
+
handle,
|
|
484
|
+
signer, // any viem LocalAccount / WalletClient — the address settlement is checked for
|
|
485
|
+
nullifier, // per-read nullifier (replay / anonymity)
|
|
486
|
+
// ownSecret, // self-hkdf-v1 only
|
|
487
|
+
});
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
- **`self-hkdf-v1`** — the resource is priced 0, so any signed request passes; the bytes
|
|
491
|
+
come back *still sealed*, are checked against `ciphertextHash`, and are unsealed
|
|
492
|
+
locally with `ownSecret`.
|
|
493
|
+
- **`worker-usdc-v1`** — the worker streams bytes only once the signer has settled,
|
|
494
|
+
having unsealed with its own key; the bytes arrive as plaintext.
|
|
495
|
+
|
|
496
|
+
`buildAccessRequest` / `accessMessageHash` are exported if you want to drive the
|
|
497
|
+
`/access` endpoint yourself, and `SettlementRegistryClient` (`isSettled`, `getPrice`)
|
|
498
|
+
reads the settlement rail directly.
|
|
499
|
+
|
|
500
|
+
**Trust model.** For `worker-usdc-v1` the access worker is the "somewhat trusted" party:
|
|
501
|
+
it holds the unsealing key and sees plaintext at release time. That is deliberate for
|
|
502
|
+
v1 — no TEE, no threshold network. Swapping in a stronger backend later is a *new
|
|
503
|
+
gadget* behind the same handle shape, so committed data doesn't change form.
|
|
504
|
+
`self-hkdf-v1` trusts nobody: the worker is dumb storage and never holds a key.
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
345
508
|
## Contracts
|
|
346
509
|
|
|
347
510
|
### Arbitrum Sepolia
|
|
@@ -385,7 +548,9 @@ The publisher must be registered (`fangorn register`, or `registry.register()`)
|
|
|
385
548
|
|
|
386
549
|
## Limitations / Future Work
|
|
387
550
|
|
|
388
|
-
-
|
|
551
|
+
- 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.
|
|
552
|
+
- The SDK reads the settlement rail (`isSettled` / `getPrice`); the pay/settle **write** path is a separate payment rail and is not modeled here.
|
|
553
|
+
- `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.
|
|
389
554
|
- Vertex/edge schema validation is client-side only — no on-chain enforcement.
|
|
390
555
|
- Push authorization is client-side in this release; on-chain write policies and non-fast-forward rejection are planned.
|
|
391
556
|
- Reads target one publisher's namespace at a time; cross-publisher discovery is a higher layer.
|
package/lib/cli/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { FangornConfig } from "../config.js";
|
|
2
|
+
import { DEFAULT_APP, FangornConfig, toAppId } from "../config.js";
|
|
3
3
|
import { Fangorn } from "../fangorn.js";
|
|
4
4
|
import { handleCancel } from "./index.js";
|
|
5
5
|
import { privateKeyToAccount } from "viem/accounts";
|
|
@@ -16,6 +16,14 @@ const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
|
16
16
|
let _config = null;
|
|
17
17
|
let _account = null;
|
|
18
18
|
let _fangorn = null;
|
|
19
|
+
function readStoredConfig() {
|
|
20
|
+
return JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
21
|
+
}
|
|
22
|
+
function writeStoredConfig(stored) {
|
|
23
|
+
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
24
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
|
|
25
|
+
chmodSync(CONFIG_PATH, 384);
|
|
26
|
+
}
|
|
19
27
|
function loadConfig() {
|
|
20
28
|
if (_config) return _config;
|
|
21
29
|
const privateKey = process.env.ETH_PRIVATE_KEY;
|
|
@@ -23,11 +31,13 @@ function loadConfig() {
|
|
|
23
31
|
const pinataGateway = process.env.PINATA_GATEWAY;
|
|
24
32
|
const accessWorkerUrl = process.env.ACCESS_WORKER_URL;
|
|
25
33
|
const signedUrlWorkerUrl = process.env.SIGNED_URL_WORKER_URL;
|
|
34
|
+
const envAppId = process.env.FANGORN_APP_ID;
|
|
26
35
|
if (existsSync(CONFIG_PATH)) {
|
|
27
|
-
const stored =
|
|
36
|
+
const stored = readStoredConfig();
|
|
28
37
|
_config = {
|
|
29
38
|
privateKey: stored.privateKey,
|
|
30
39
|
cfg: FangornConfig,
|
|
40
|
+
appId: envAppId ?? stored.appId ?? DEFAULT_APP,
|
|
31
41
|
pinataJwt: stored.pinataJwt,
|
|
32
42
|
pinataGateway: stored.pinataGateway,
|
|
33
43
|
accessWorkerUrl: stored.accessWorkerUrl ?? "",
|
|
@@ -40,6 +50,7 @@ function loadConfig() {
|
|
|
40
50
|
_config = {
|
|
41
51
|
privateKey,
|
|
42
52
|
cfg: FangornConfig,
|
|
53
|
+
appId: envAppId ?? DEFAULT_APP,
|
|
43
54
|
pinataJwt: pinataJwt ?? "",
|
|
44
55
|
pinataGateway: pinataGateway ?? "",
|
|
45
56
|
accessWorkerUrl: accessWorkerUrl ?? "",
|
|
@@ -60,12 +71,16 @@ function getFangorn() {
|
|
|
60
71
|
const storage = cfg.pinataJwt ? { pinata: {
|
|
61
72
|
jwt: cfg.pinataJwt,
|
|
62
73
|
gateway: cfg.pinataGateway
|
|
63
|
-
} } : { signedUrl: {
|
|
74
|
+
} } : { signedUrl: {
|
|
75
|
+
workerUrl: cfg.signedUrlWorkerUrl,
|
|
76
|
+
gateway: cfg.pinataGateway
|
|
77
|
+
} };
|
|
64
78
|
_fangorn = Fangorn.create({
|
|
65
79
|
privateKey: cfg.privateKey,
|
|
66
80
|
storage,
|
|
67
81
|
domain: "localhost",
|
|
68
|
-
config: cfg.cfg
|
|
82
|
+
config: cfg.cfg,
|
|
83
|
+
appId: cfg.appId
|
|
69
84
|
});
|
|
70
85
|
return _fangorn;
|
|
71
86
|
}
|
|
@@ -144,19 +159,65 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
144
159
|
placeholder: "https://pinata-url-provider.your-subdomain.workers.dev"
|
|
145
160
|
});
|
|
146
161
|
handleCancel(signedUrlWorkerUrl);
|
|
147
|
-
|
|
162
|
+
writeStoredConfig({
|
|
148
163
|
privateKey,
|
|
149
164
|
chainName: "Arbitrum Sepolia",
|
|
150
165
|
pinataJwt,
|
|
151
166
|
pinataGateway,
|
|
152
167
|
accessWorkerUrl,
|
|
153
|
-
signedUrlWorkerUrl
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
|
|
157
|
-
chmodSync(CONFIG_PATH, 384);
|
|
168
|
+
signedUrlWorkerUrl,
|
|
169
|
+
appId: existsSync(CONFIG_PATH) ? readStoredConfig().appId : void 0
|
|
170
|
+
});
|
|
158
171
|
outro(`Config saved to ${CONFIG_PATH}`);
|
|
159
172
|
});
|
|
173
|
+
program.command("set-app").description("Set the app (global namespace) this CLI publishes and reads under").argument("[app]", "App name or 32-byte app id (omit to show the current one)").action((app) => {
|
|
174
|
+
try {
|
|
175
|
+
if (!app) {
|
|
176
|
+
const current = loadConfig().appId;
|
|
177
|
+
console.log(`App: ${current}`);
|
|
178
|
+
console.log(`App id: ${toAppId(current)}`);
|
|
179
|
+
process.exit(0);
|
|
180
|
+
}
|
|
181
|
+
if (!existsSync(CONFIG_PATH)) throw new Error(`no config file at ${CONFIG_PATH} — run \`fangorn init\` first, or set FANGORN_APP_ID in the environment.`);
|
|
182
|
+
writeStoredConfig({
|
|
183
|
+
...readStoredConfig(),
|
|
184
|
+
appId: app
|
|
185
|
+
});
|
|
186
|
+
console.log(`App: ${app}`);
|
|
187
|
+
console.log(`App id: ${toAppId(app)}`);
|
|
188
|
+
if (process.env.FANGORN_APP_ID) console.log(`\nNote: FANGORN_APP_ID=${process.env.FANGORN_APP_ID} is set and overrides this.`);
|
|
189
|
+
console.log(`\nSaved to ${CONFIG_PATH}. Run \`fangorn register-app\` if nobody has claimed it yet.`);
|
|
190
|
+
process.exit(0);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
console.error("Failed:", err.message);
|
|
193
|
+
process.exit(1);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
program.command("register-app").description("Claim the configured app (global namespace) on-chain").action(async () => {
|
|
197
|
+
try {
|
|
198
|
+
const self = getAccount().address;
|
|
199
|
+
const registry = getFangorn().getDataRegistry();
|
|
200
|
+
const s = spinner();
|
|
201
|
+
s.start("Checking app ownership...");
|
|
202
|
+
const owner = await registry.getAppOwner();
|
|
203
|
+
s.stop();
|
|
204
|
+
if (owner !== "0x0000000000000000000000000000000000000000") {
|
|
205
|
+
console.log(owner.toLowerCase() === self.toLowerCase() ? `Already registered to you: ${registry.getAppId()}` : `App ${registry.getAppId()} is already owned by ${owner}. Pick another name with \`fangorn set-app\`.`);
|
|
206
|
+
process.exit(owner.toLowerCase() === self.toLowerCase() ? 0 : 1);
|
|
207
|
+
}
|
|
208
|
+
s.start("Registering app...");
|
|
209
|
+
const txHash = await registry.registerApp();
|
|
210
|
+
s.stop();
|
|
211
|
+
console.log(`App: ${loadConfig().appId}`);
|
|
212
|
+
console.log(`App id: ${registry.getAppId()}`);
|
|
213
|
+
console.log(`Owner: ${self}`);
|
|
214
|
+
console.log(`Tx: ${txHash}`);
|
|
215
|
+
process.exit(0);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
console.error("Failed:", err.message);
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
160
221
|
program.command("register").description("Register your wallet as a data publisher on-chain").action(async () => {
|
|
161
222
|
try {
|
|
162
223
|
const self = getAccount().address;
|
|
@@ -184,7 +245,7 @@ program.command("repo").description("Repository operations").command("init").des
|
|
|
184
245
|
const s = spinner();
|
|
185
246
|
s.start(`Initializing namespace "${namespace}"...`);
|
|
186
247
|
const result = await fangorn.initRepo(namespace);
|
|
187
|
-
const head = result.alreadyInitialized ? await fangorn.onChainTip(owner) : result.commitCid;
|
|
248
|
+
const head = result.alreadyInitialized ? await fangorn.onChainTip(owner, namespace) : result.commitCid;
|
|
188
249
|
const repo = LocalRepo.init({
|
|
189
250
|
namespace,
|
|
190
251
|
owner,
|
|
@@ -238,12 +299,13 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
|
|
|
238
299
|
});
|
|
239
300
|
program.command("push").description("Settle the local tip commit as the on-chain state root (the permissioned step)").option("--force", "Push even if it does not fast-forward the on-chain tip").action(async (options) => {
|
|
240
301
|
try {
|
|
241
|
-
const
|
|
302
|
+
const repo = LocalRepo.open();
|
|
303
|
+
const head = repo.head();
|
|
242
304
|
if (!head) throw new Error("nothing to push — no commits yet");
|
|
243
305
|
const fangorn = getFangorn();
|
|
244
306
|
const s = spinner();
|
|
245
307
|
s.start("Pushing...");
|
|
246
|
-
const { txHash, onChainTip } = await fangorn.push(head, { force: options.force });
|
|
308
|
+
const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head, { force: options.force });
|
|
247
309
|
s.stop();
|
|
248
310
|
console.log(`Tx: ${txHash}`);
|
|
249
311
|
console.log(`Tip: ${onChainTip}`);
|
|
@@ -258,7 +320,7 @@ program.command("status").description("Compare the local tip with the on-chain t
|
|
|
258
320
|
const repo = LocalRepo.open();
|
|
259
321
|
const fangorn = getFangorn();
|
|
260
322
|
const localHead = repo.head();
|
|
261
|
-
const onChainTip = await fangorn.onChainTip(repo.owner());
|
|
323
|
+
const onChainTip = await fangorn.onChainTip(repo.owner(), repo.namespace());
|
|
262
324
|
const state = localHead === onChainTip ? "up to date" : localHead && !onChainTip ? "local commits not yet pushed" : localHead !== onChainTip ? "local tip differs from on-chain tip (push to fast-forward)" : "no local commits";
|
|
263
325
|
console.log(`Namespace: ${repo.namespace()}`);
|
|
264
326
|
console.log(`Owner: ${repo.owner()}`);
|
|
@@ -316,7 +378,7 @@ program.command("clone").description("Track an existing on-chain namespace by re
|
|
|
316
378
|
const fangorn = getFangorn();
|
|
317
379
|
const s = spinner();
|
|
318
380
|
s.start(`Resolving on-chain tip for ${owner}...`);
|
|
319
|
-
const tip = await fangorn.onChainTip(owner);
|
|
381
|
+
const tip = await fangorn.onChainTip(owner, namespace);
|
|
320
382
|
const repo = LocalRepo.init({
|
|
321
383
|
namespace,
|
|
322
384
|
owner,
|
|
@@ -397,7 +459,7 @@ program.command("read").description("List every vertex and edge committed under
|
|
|
397
459
|
namespace = namespace ?? repo.namespace();
|
|
398
460
|
owner = owner ?? repo.owner();
|
|
399
461
|
}
|
|
400
|
-
const [head, contents] = await Promise.all([fangorn.onChainTip(owner), fangorn.engine.listNamespace(namespace, owner)]);
|
|
462
|
+
const [head, contents] = await Promise.all([fangorn.onChainTip(owner, namespace), fangorn.engine.listNamespace(namespace, owner)]);
|
|
401
463
|
const out = {
|
|
402
464
|
owner,
|
|
403
465
|
namespace,
|
|
@@ -411,15 +473,16 @@ program.command("read").description("List every vertex and edge committed under
|
|
|
411
473
|
process.exit(1);
|
|
412
474
|
}
|
|
413
475
|
});
|
|
414
|
-
program.command("reset").description("DANGER!: reset
|
|
415
|
-
const
|
|
476
|
+
program.command("reset").description("DANGER!: reset this namespace's on-chain head to zero (abandons all prior commits)").action(async () => {
|
|
477
|
+
const namespace = LocalRepo.open().namespace();
|
|
478
|
+
const confirmFirst = await confirm({ message: `Are you sure? The on-chain head for "${namespace}" will reset to 0x0000...` });
|
|
416
479
|
handleCancel(confirmFirst);
|
|
417
480
|
if (!confirmFirst) {
|
|
418
481
|
console.log("Reset aborted.");
|
|
419
482
|
process.exit(0);
|
|
420
483
|
}
|
|
421
|
-
await getFangorn().reset();
|
|
422
|
-
console.log(
|
|
484
|
+
await getFangorn().reset(namespace);
|
|
485
|
+
console.log(`On-chain head for "${namespace}" reset to zero. \`repo init\` will now start fresh.`);
|
|
423
486
|
process.exit(0);
|
|
424
487
|
});
|
|
425
488
|
program.parse();
|
package/lib/config.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import * as viem_chains0 from "viem/chains";
|
|
2
1
|
import * as viem0 from "viem";
|
|
3
2
|
import { Chain, Hex } from "viem";
|
|
3
|
+
import * as viem_chains0 from "viem/chains";
|
|
4
4
|
import * as abitype0 from "abitype";
|
|
5
5
|
|
|
6
6
|
//#region src/config.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Derive an app id from a human-readable name. Apps claim one of these on-chain
|
|
9
|
+
* with `registerApp`; it prefixes every namespace key the app's publishers write.
|
|
10
|
+
*/
|
|
11
|
+
declare function appId(name: string): Hex;
|
|
12
|
+
/** The app every client publishes under until told otherwise. */
|
|
13
|
+
declare const DEFAULT_APP = "fangorn";
|
|
14
|
+
/**
|
|
15
|
+
* Accept either form callers have on hand: a human-readable app name, or an
|
|
16
|
+
* already-derived app id (32-byte hex), which is what an app owner sees on-chain.
|
|
17
|
+
*/
|
|
18
|
+
declare function toAppId(nameOrId: string): Hex;
|
|
7
19
|
/**
|
|
8
20
|
* The networks supproted by Fangorn currently
|
|
9
21
|
*/
|
|
@@ -437,7 +449,7 @@ interface AppConfig {
|
|
|
437
449
|
ipfsGateway: string;
|
|
438
450
|
}
|
|
439
451
|
declare const FangornConfig: {
|
|
440
|
-
dataRegistryContractAddress: "
|
|
452
|
+
dataRegistryContractAddress: "0xdec430f03cdc022ab2338490e9b30ef5c63f7340";
|
|
441
453
|
chain: {
|
|
442
454
|
blockExplorers: {
|
|
443
455
|
readonly default: {
|
|
@@ -488,4 +500,4 @@ declare const FangornConfig: {
|
|
|
488
500
|
ipfsGateway: string;
|
|
489
501
|
};
|
|
490
502
|
//#endregion
|
|
491
|
-
export { AppConfig, FangornConfig, SupportedNetworks, getNetwork as default };
|
|
503
|
+
export { AppConfig, DEFAULT_APP, FangornConfig, SupportedNetworks, appId, getNetwork as default, toAppId };
|
package/lib/config.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
import { keccak256, toHex } from "viem";
|
|
1
2
|
import { arbitrumSepolia, baseSepolia } from "viem/chains";
|
|
2
3
|
|
|
3
4
|
//#region src/config.ts
|
|
4
5
|
/**
|
|
6
|
+
* Derive an app id from a human-readable name. Apps claim one of these on-chain
|
|
7
|
+
* with `registerApp`; it prefixes every namespace key the app's publishers write.
|
|
8
|
+
*/
|
|
9
|
+
function appId(name) {
|
|
10
|
+
return keccak256(toHex(name));
|
|
11
|
+
}
|
|
12
|
+
/** The app every client publishes under until told otherwise. */
|
|
13
|
+
const DEFAULT_APP = "fangorn";
|
|
14
|
+
/**
|
|
15
|
+
* Accept either form callers have on hand: a human-readable app name, or an
|
|
16
|
+
* already-derived app id (32-byte hex), which is what an app owner sees on-chain.
|
|
17
|
+
*/
|
|
18
|
+
function toAppId(nameOrId) {
|
|
19
|
+
return /^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : appId(nameOrId);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
5
22
|
* The networks supproted by Fangorn currently
|
|
6
23
|
*/
|
|
7
24
|
const SupportedNetworks = {
|
|
@@ -24,7 +41,7 @@ function getNetwork(name) {
|
|
|
24
41
|
throw new Error(`Chain ${name} is not supported`);
|
|
25
42
|
}
|
|
26
43
|
const FangornConfig = {
|
|
27
|
-
dataRegistryContractAddress: "
|
|
44
|
+
dataRegistryContractAddress: "0xdec430f03cdc022ab2338490e9b30ef5c63f7340",
|
|
28
45
|
chain: arbitrumSepolia,
|
|
29
46
|
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
30
47
|
caip2: 421614,
|
|
@@ -32,4 +49,4 @@ const FangornConfig = {
|
|
|
32
49
|
};
|
|
33
50
|
|
|
34
51
|
//#endregion
|
|
35
|
-
export { FangornConfig, SupportedNetworks, getNetwork as default };
|
|
52
|
+
export { DEFAULT_APP, FangornConfig, SupportedNetworks, appId, getNetwork as default, toAppId };
|
|
@@ -3,6 +3,14 @@ declare const DATA_REGISTRY_ABI: readonly [{
|
|
|
3
3
|
readonly inputs: readonly [];
|
|
4
4
|
readonly name: "AlreadyRegistered";
|
|
5
5
|
readonly type: "error";
|
|
6
|
+
}, {
|
|
7
|
+
readonly inputs: readonly [];
|
|
8
|
+
readonly name: "AppAlreadyRegistered";
|
|
9
|
+
readonly type: "error";
|
|
10
|
+
}, {
|
|
11
|
+
readonly inputs: readonly [];
|
|
12
|
+
readonly name: "AppNotFound";
|
|
13
|
+
readonly type: "error";
|
|
6
14
|
}, {
|
|
7
15
|
readonly inputs: readonly [];
|
|
8
16
|
readonly name: "NotRegistered";
|
|
@@ -23,6 +31,21 @@ declare const DATA_REGISTRY_ABI: readonly [{
|
|
|
23
31
|
readonly inputs: readonly [];
|
|
24
32
|
readonly name: "Unauthorized";
|
|
25
33
|
readonly type: "error";
|
|
34
|
+
}, {
|
|
35
|
+
readonly anonymous: false;
|
|
36
|
+
readonly inputs: readonly [{
|
|
37
|
+
readonly indexed: true;
|
|
38
|
+
readonly internalType: "bytes32";
|
|
39
|
+
readonly name: "app_id";
|
|
40
|
+
readonly type: "bytes32";
|
|
41
|
+
}, {
|
|
42
|
+
readonly indexed: true;
|
|
43
|
+
readonly internalType: "address";
|
|
44
|
+
readonly name: "owner";
|
|
45
|
+
readonly type: "address";
|
|
46
|
+
}];
|
|
47
|
+
readonly name: "AppRegistered";
|
|
48
|
+
readonly type: "event";
|
|
26
49
|
}, {
|
|
27
50
|
readonly anonymous: false;
|
|
28
51
|
readonly inputs: readonly [{
|
|
@@ -76,17 +99,32 @@ declare const DATA_REGISTRY_ABI: readonly [{
|
|
|
76
99
|
}, {
|
|
77
100
|
readonly anonymous: false;
|
|
78
101
|
readonly inputs: readonly [{
|
|
102
|
+
readonly indexed: true;
|
|
103
|
+
readonly internalType: "bytes32";
|
|
104
|
+
readonly name: "namespace_key";
|
|
105
|
+
readonly type: "bytes32";
|
|
106
|
+
}, {
|
|
107
|
+
readonly indexed: true;
|
|
108
|
+
readonly internalType: "bytes32";
|
|
109
|
+
readonly name: "app_id";
|
|
110
|
+
readonly type: "bytes32";
|
|
111
|
+
}, {
|
|
79
112
|
readonly indexed: true;
|
|
80
113
|
readonly internalType: "address";
|
|
81
114
|
readonly name: "publisher";
|
|
82
115
|
readonly type: "address";
|
|
83
116
|
}, {
|
|
84
|
-
readonly indexed:
|
|
117
|
+
readonly indexed: false;
|
|
118
|
+
readonly internalType: "bytes32";
|
|
119
|
+
readonly name: "subspace_id";
|
|
120
|
+
readonly type: "bytes32";
|
|
121
|
+
}, {
|
|
122
|
+
readonly indexed: false;
|
|
85
123
|
readonly internalType: "bytes32";
|
|
86
124
|
readonly name: "old_root";
|
|
87
125
|
readonly type: "bytes32";
|
|
88
126
|
}, {
|
|
89
|
-
readonly indexed:
|
|
127
|
+
readonly indexed: false;
|
|
90
128
|
readonly internalType: "bytes32";
|
|
91
129
|
readonly name: "new_root";
|
|
92
130
|
readonly type: "bytes32";
|
|
@@ -105,6 +143,14 @@ declare const DATA_REGISTRY_ABI: readonly [{
|
|
|
105
143
|
readonly type: "function";
|
|
106
144
|
}, {
|
|
107
145
|
readonly inputs: readonly [{
|
|
146
|
+
readonly internalType: "bytes32";
|
|
147
|
+
readonly name: "app_id";
|
|
148
|
+
readonly type: "bytes32";
|
|
149
|
+
}, {
|
|
150
|
+
readonly internalType: "bytes32";
|
|
151
|
+
readonly name: "subspace_id";
|
|
152
|
+
readonly type: "bytes32";
|
|
153
|
+
}, {
|
|
108
154
|
readonly internalType: "bytes32";
|
|
109
155
|
readonly name: "old_root";
|
|
110
156
|
readonly type: "bytes32";
|
|
@@ -119,9 +165,31 @@ declare const DATA_REGISTRY_ABI: readonly [{
|
|
|
119
165
|
readonly type: "function";
|
|
120
166
|
}, {
|
|
121
167
|
readonly inputs: readonly [{
|
|
168
|
+
readonly internalType: "bytes32";
|
|
169
|
+
readonly name: "app_id";
|
|
170
|
+
readonly type: "bytes32";
|
|
171
|
+
}];
|
|
172
|
+
readonly name: "getAppOwner";
|
|
173
|
+
readonly outputs: readonly [{
|
|
174
|
+
readonly internalType: "address";
|
|
175
|
+
readonly name: "";
|
|
176
|
+
readonly type: "address";
|
|
177
|
+
}];
|
|
178
|
+
readonly stateMutability: "view";
|
|
179
|
+
readonly type: "function";
|
|
180
|
+
}, {
|
|
181
|
+
readonly inputs: readonly [{
|
|
182
|
+
readonly internalType: "bytes32";
|
|
183
|
+
readonly name: "app_id";
|
|
184
|
+
readonly type: "bytes32";
|
|
185
|
+
}, {
|
|
122
186
|
readonly internalType: "address";
|
|
123
187
|
readonly name: "publisher";
|
|
124
188
|
readonly type: "address";
|
|
189
|
+
}, {
|
|
190
|
+
readonly internalType: "bytes32";
|
|
191
|
+
readonly name: "subspace_id";
|
|
192
|
+
readonly type: "bytes32";
|
|
125
193
|
}];
|
|
126
194
|
readonly name: "getNamespaceHead";
|
|
127
195
|
readonly outputs: readonly [{
|
|
@@ -175,6 +243,16 @@ declare const DATA_REGISTRY_ABI: readonly [{
|
|
|
175
243
|
readonly outputs: readonly [];
|
|
176
244
|
readonly stateMutability: "payable";
|
|
177
245
|
readonly type: "function";
|
|
246
|
+
}, {
|
|
247
|
+
readonly inputs: readonly [{
|
|
248
|
+
readonly internalType: "bytes32";
|
|
249
|
+
readonly name: "app_id";
|
|
250
|
+
readonly type: "bytes32";
|
|
251
|
+
}];
|
|
252
|
+
readonly name: "registerApp";
|
|
253
|
+
readonly outputs: readonly [];
|
|
254
|
+
readonly stateMutability: "nonpayable";
|
|
255
|
+
readonly type: "function";
|
|
178
256
|
}, {
|
|
179
257
|
readonly inputs: readonly [];
|
|
180
258
|
readonly name: "registrationFee";
|