@fangorn-network/sdk 2026.7.24 → 2026.7.28
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 +163 -8
- package/lib/cli/cli.js +43 -43
- package/lib/config.d.ts +10 -3
- package/lib/config.js +11 -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 +91 -19
- package/lib/contracts/data-registry/index.js +153 -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 +83 -13
- package/lib/fangorn.js +129 -39
- package/lib/index.d.ts +10 -3
- package/lib/index.js +9 -3
- package/lib/providers/storage/index.d.ts +2 -1
- package/lib/providers/storage/index.js +2 -1
- package/lib/providers/storage/pinata.js +1 -19
- package/lib/providers/storage/signed-url.d.ts +52 -0
- package/lib/providers/storage/signed-url.js +119 -0
- package/lib/providers/storage/utils.d.ts +19 -1
- package/lib/providers/storage/utils.js +55 -1
- package/lib/test/testbed.d.ts +21 -3
- package/lib/test/testbed.js +38 -7
- package/lib/types/index.d.ts +5 -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,31 @@ 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 id comes from config (`appId("my-app")`), and must be claimed once
|
|
361
|
+
on-chain with `fangorn.getDataRegistry().registerApp()` before any publisher can
|
|
362
|
+
commit under it.
|
|
363
|
+
|
|
335
364
|
### Storage
|
|
336
365
|
|
|
337
366
|
Fangorn operates on a 'Bring Your Own Storage' basis. Each commit is persisted as
|
|
@@ -342,6 +371,130 @@ The backend never needs to understand IPLD — any blob store can implement the
|
|
|
342
371
|
|
|
343
372
|
---
|
|
344
373
|
|
|
374
|
+
## Encryption & gadgets
|
|
375
|
+
|
|
376
|
+
Not every field belongs in public IPFS. Fangorn lets you **seal** a value and commit
|
|
377
|
+
only an opaque reference to it, keeping the graph — its shape, its edges, its
|
|
378
|
+
addressability — fully public while the payload stays closed.
|
|
379
|
+
|
|
380
|
+
A **gadget** names *how* a value is sealed and *under what condition* it opens. Two
|
|
381
|
+
ship today, both exported from the package root (`@fangorn-network/sdk`):
|
|
382
|
+
|
|
383
|
+
| Gadget | Key derivation | Who can open it |
|
|
384
|
+
| ---------------- | ------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
385
|
+
| `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. |
|
|
386
|
+
| `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. |
|
|
387
|
+
|
|
388
|
+
Every key is bound to a 32-byte **`resourceId`**, which doubles as the Settlement
|
|
389
|
+
Registry key. The same secret cannot cross-open a different resource, and changing
|
|
390
|
+
*who can read* means re-sealing under a new gadget/`resourceId` and committing a
|
|
391
|
+
vertex that points at the new bytes.
|
|
392
|
+
|
|
393
|
+
### `self-hkdf-v1` — fully private
|
|
394
|
+
|
|
395
|
+
The simplest path is entirely out of band: seal before ingestion, unseal after
|
|
396
|
+
retrieval. Fangorn never sees plaintext or a key — it commits the ciphertext like any
|
|
397
|
+
other payload. No worker, no settlement, no R2 involved.
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
import { sealSelf, unsealSelf, GADGET_SELF_HKDF_V1 } from "@fangorn-network/sdk";
|
|
401
|
+
import { keccak256, stringToBytes, hexToBytes, bytesToHex } from "viem";
|
|
402
|
+
|
|
403
|
+
const ownSecret = hexToBytes(privateKey); // your own 32 bytes
|
|
404
|
+
const resourceId = keccak256(stringToBytes("rusty-anchor:secret-msg"));
|
|
405
|
+
|
|
406
|
+
const ciphertext = sealSelf(
|
|
407
|
+
new TextEncoder().encode("the eagles are coming"),
|
|
408
|
+
ownSecret,
|
|
409
|
+
resourceId,
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
// commit the opaque bytes like anything else
|
|
413
|
+
await fangorn.upload("rusty-anchor", {
|
|
414
|
+
gadget: GADGET_SELF_HKDF_V1,
|
|
415
|
+
resourceId,
|
|
416
|
+
ciphertext: bytesToHex(ciphertext),
|
|
417
|
+
}, "secret-msg");
|
|
418
|
+
|
|
419
|
+
// later, after `read` / `inspectNamespace` hands the payload back:
|
|
420
|
+
const plaintext = unsealSelf(hexToBytes(stored.ciphertext), ownSecret, stored.resourceId);
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### `worker-usdc-v1` — settlement-gated
|
|
424
|
+
|
|
425
|
+
For paid or conditionally-readable data, seal to the **access worker's** static X25519
|
|
426
|
+
public key and hand the ciphertext to the worker, which stores the opaque bytes in R2
|
|
427
|
+
(never IPFS — a large, frequently-fetched ciphertext shouldn't burn public gateway
|
|
428
|
+
egress). `encryptAndUpload` does both and returns a **handle**:
|
|
429
|
+
|
|
430
|
+
```ts
|
|
431
|
+
import { encryptAndUpload, GADGET_WORKER_USDC_V1 } from "@fangorn-network/sdk";
|
|
432
|
+
|
|
433
|
+
const handle = await encryptAndUpload({
|
|
434
|
+
gadget: GADGET_WORKER_USDC_V1,
|
|
435
|
+
plaintext: new TextEncoder().encode("the full dataset"),
|
|
436
|
+
resourceId,
|
|
437
|
+
workerPubkey, // the access worker's static X25519 key (32 bytes)
|
|
438
|
+
storage: {
|
|
439
|
+
workerUrl: process.env.ACCESS_WORKER_URL!,
|
|
440
|
+
authToken: process.env.ACCESS_WORKER_TOKEN!,
|
|
441
|
+
contentType: "application/octet-stream",
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
The handle is what you commit in place of the plaintext value — the engine treats it
|
|
447
|
+
as an ordinary opaque object in the vertex payload:
|
|
448
|
+
|
|
449
|
+
```jsonc
|
|
450
|
+
{
|
|
451
|
+
"@type": "handle",
|
|
452
|
+
"objectKey": "…", // R2 object key
|
|
453
|
+
"workerUrl": "https://access-worker.example.workers.dev",
|
|
454
|
+
"encryption": {
|
|
455
|
+
"gadget": "worker-usdc-v1",
|
|
456
|
+
"resourceId": "0x…", // Settlement Registry key + HKDF binding
|
|
457
|
+
"ciphertextHash": "0x…", // sha256 of the sealed bytes
|
|
458
|
+
"workerPubkey": "0x…", // worker-usdc-v1 only
|
|
459
|
+
},
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Reading a handle
|
|
464
|
+
|
|
465
|
+
Both gadgets resolve through the worker's `POST /access`. `decryptHandle` signs the
|
|
466
|
+
request (the worker recovers the signer's address and checks the Settlement Registry
|
|
467
|
+
for `resourceId`), fetches the bytes, and returns plaintext:
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
import { decryptHandle } from "@fangorn-network/sdk";
|
|
471
|
+
|
|
472
|
+
const plaintext = await decryptHandle({
|
|
473
|
+
handle,
|
|
474
|
+
signer, // any viem LocalAccount / WalletClient — the address settlement is checked for
|
|
475
|
+
nullifier, // per-read nullifier (replay / anonymity)
|
|
476
|
+
// ownSecret, // self-hkdf-v1 only
|
|
477
|
+
});
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
- **`self-hkdf-v1`** — the resource is priced 0, so any signed request passes; the bytes
|
|
481
|
+
come back *still sealed*, are checked against `ciphertextHash`, and are unsealed
|
|
482
|
+
locally with `ownSecret`.
|
|
483
|
+
- **`worker-usdc-v1`** — the worker streams bytes only once the signer has settled,
|
|
484
|
+
having unsealed with its own key; the bytes arrive as plaintext.
|
|
485
|
+
|
|
486
|
+
`buildAccessRequest` / `accessMessageHash` are exported if you want to drive the
|
|
487
|
+
`/access` endpoint yourself, and `SettlementRegistryClient` (`isSettled`, `getPrice`)
|
|
488
|
+
reads the settlement rail directly.
|
|
489
|
+
|
|
490
|
+
**Trust model.** For `worker-usdc-v1` the access worker is the "somewhat trusted" party:
|
|
491
|
+
it holds the unsealing key and sees plaintext at release time. That is deliberate for
|
|
492
|
+
v1 — no TEE, no threshold network. Swapping in a stronger backend later is a *new
|
|
493
|
+
gadget* behind the same handle shape, so committed data doesn't change form.
|
|
494
|
+
`self-hkdf-v1` trusts nobody: the worker is dumb storage and never holds a key.
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
345
498
|
## Contracts
|
|
346
499
|
|
|
347
500
|
### Arbitrum Sepolia
|
|
@@ -385,7 +538,9 @@ The publisher must be registered (`fangorn register`, or `registry.register()`)
|
|
|
385
538
|
|
|
386
539
|
## Limitations / Future Work
|
|
387
540
|
|
|
388
|
-
-
|
|
541
|
+
- 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.
|
|
542
|
+
- The SDK reads the settlement rail (`isSettled` / `getPrice`); the pay/settle **write** path is a separate payment rail and is not modeled here.
|
|
543
|
+
- `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
544
|
- Vertex/edge schema validation is client-side only — no on-chain enforcement.
|
|
390
545
|
- Push authorization is client-side in this release; on-chain write policies and non-fast-forward rejection are planned.
|
|
391
546
|
- Reads target one publisher's namespace at a time; cross-publisher discovery is a higher layer.
|
package/lib/cli/cli.js
CHANGED
|
@@ -21,7 +21,8 @@ function loadConfig() {
|
|
|
21
21
|
const privateKey = process.env.ETH_PRIVATE_KEY;
|
|
22
22
|
const pinataJwt = process.env.PINATA_JWT;
|
|
23
23
|
const pinataGateway = process.env.PINATA_GATEWAY;
|
|
24
|
-
const
|
|
24
|
+
const accessWorkerUrl = process.env.ACCESS_WORKER_URL;
|
|
25
|
+
const signedUrlWorkerUrl = process.env.SIGNED_URL_WORKER_URL;
|
|
25
26
|
if (existsSync(CONFIG_PATH)) {
|
|
26
27
|
const stored = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
27
28
|
_config = {
|
|
@@ -29,26 +30,24 @@ function loadConfig() {
|
|
|
29
30
|
cfg: FangornConfig,
|
|
30
31
|
pinataJwt: stored.pinataJwt,
|
|
31
32
|
pinataGateway: stored.pinataGateway,
|
|
32
|
-
|
|
33
|
+
accessWorkerUrl: stored.accessWorkerUrl ?? "",
|
|
34
|
+
signedUrlWorkerUrl: stored.signedUrlWorkerUrl ?? ""
|
|
33
35
|
};
|
|
34
36
|
return _config;
|
|
35
37
|
}
|
|
36
|
-
if (privateKey || pinataJwt || pinataGateway) {
|
|
37
|
-
|
|
38
|
-
if (!privateKey) missing.push("ETH_PRIVATE_KEY");
|
|
39
|
-
if (!pinataJwt) missing.push("PINATA_JWT");
|
|
40
|
-
if (!pinataGateway) missing.push("PINATA_GATEWAY");
|
|
41
|
-
if (missing.length > 0) throw new Error(`Incomplete environment configuration. Missing: ${missing.join(", ")}\nSet all required env vars or run \`fangorn init\` to use a config file.`);
|
|
38
|
+
if (privateKey || pinataJwt || pinataGateway || signedUrlWorkerUrl) {
|
|
39
|
+
if (!privateKey) throw new Error("Incomplete environment configuration. Missing: ETH_PRIVATE_KEY\nSet it or run `fangorn init` to use a config file.");
|
|
42
40
|
_config = {
|
|
43
41
|
privateKey,
|
|
44
42
|
cfg: FangornConfig,
|
|
45
43
|
pinataJwt: pinataJwt ?? "",
|
|
46
44
|
pinataGateway: pinataGateway ?? "",
|
|
47
|
-
|
|
45
|
+
accessWorkerUrl: accessWorkerUrl ?? "",
|
|
46
|
+
signedUrlWorkerUrl: signedUrlWorkerUrl ?? ""
|
|
48
47
|
};
|
|
49
48
|
return _config;
|
|
50
49
|
}
|
|
51
|
-
throw new Error("No configuration found. Run `fangorn init` or set
|
|
50
|
+
throw new Error("No configuration found. Run `fangorn init` or set ETH_PRIVATE_KEY\n(with no config, uploads go to Fangorn's shared Pinata account — a best-effort testnet convenience; files may be unpinned without notice. Set PINATA_JWT + PINATA_GATEWAY to use your own storage).");
|
|
52
51
|
}
|
|
53
52
|
function getAccount() {
|
|
54
53
|
if (_account) return _account;
|
|
@@ -58,12 +57,16 @@ function getAccount() {
|
|
|
58
57
|
function getFangorn() {
|
|
59
58
|
if (_fangorn) return _fangorn;
|
|
60
59
|
const cfg = loadConfig();
|
|
60
|
+
const storage = cfg.pinataJwt ? { pinata: {
|
|
61
|
+
jwt: cfg.pinataJwt,
|
|
62
|
+
gateway: cfg.pinataGateway
|
|
63
|
+
} } : { signedUrl: {
|
|
64
|
+
workerUrl: cfg.signedUrlWorkerUrl,
|
|
65
|
+
gateway: cfg.pinataGateway
|
|
66
|
+
} };
|
|
61
67
|
_fangorn = Fangorn.create({
|
|
62
68
|
privateKey: cfg.privateKey,
|
|
63
|
-
storage
|
|
64
|
-
jwt: cfg.pinataJwt,
|
|
65
|
-
gateway: cfg.pinataGateway
|
|
66
|
-
} },
|
|
69
|
+
storage,
|
|
67
70
|
domain: "localhost",
|
|
68
71
|
config: cfg.cfg
|
|
69
72
|
});
|
|
@@ -127,35 +130,30 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
127
130
|
}
|
|
128
131
|
});
|
|
129
132
|
handleCancel(privateKey);
|
|
130
|
-
const pinataJwt = await text({
|
|
131
|
-
message: "Pinata JWT:",
|
|
132
|
-
validate: (v) => {
|
|
133
|
-
if (!v) return "Required";
|
|
134
|
-
}
|
|
135
|
-
});
|
|
133
|
+
const pinataJwt = await text({ message: "Pinata JWT — leave blank to use Fangorn's shared Pinata account (testnet convenience; files may be unpinned without notice):" });
|
|
136
134
|
handleCancel(pinataJwt);
|
|
137
135
|
const pinataGateway = await text({
|
|
138
|
-
message: "Pinata Gateway URL:",
|
|
139
|
-
placeholder: "https://your-gateway.mypinata.cloud"
|
|
140
|
-
validate: (v) => {
|
|
141
|
-
if (!v) return "Required";
|
|
142
|
-
}
|
|
136
|
+
message: "Pinata Gateway URL (optional; blank uses a public IPFS gateway):",
|
|
137
|
+
placeholder: "https://your-gateway.mypinata.cloud"
|
|
143
138
|
});
|
|
144
139
|
handleCancel(pinataGateway);
|
|
145
|
-
const
|
|
146
|
-
message: "
|
|
147
|
-
placeholder: "https://
|
|
148
|
-
validate: (v) => {
|
|
149
|
-
if (!v) return "Required";
|
|
150
|
-
}
|
|
140
|
+
const accessWorkerUrl = await text({
|
|
141
|
+
message: "Access-gating worker URL (optional):",
|
|
142
|
+
placeholder: "https://access-worker.your-subdomain.workers.dev"
|
|
151
143
|
});
|
|
152
|
-
handleCancel(
|
|
144
|
+
handleCancel(accessWorkerUrl);
|
|
145
|
+
const signedUrlWorkerUrl = await text({
|
|
146
|
+
message: "Presigned-URL worker URL (optional; blank uses the hosted default):",
|
|
147
|
+
placeholder: "https://pinata-url-provider.your-subdomain.workers.dev"
|
|
148
|
+
});
|
|
149
|
+
handleCancel(signedUrlWorkerUrl);
|
|
153
150
|
const stored = {
|
|
154
151
|
privateKey,
|
|
155
152
|
chainName: "Arbitrum Sepolia",
|
|
156
153
|
pinataJwt,
|
|
157
154
|
pinataGateway,
|
|
158
|
-
|
|
155
|
+
accessWorkerUrl,
|
|
156
|
+
signedUrlWorkerUrl
|
|
159
157
|
};
|
|
160
158
|
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
161
159
|
writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
|
|
@@ -189,7 +187,7 @@ program.command("repo").description("Repository operations").command("init").des
|
|
|
189
187
|
const s = spinner();
|
|
190
188
|
s.start(`Initializing namespace "${namespace}"...`);
|
|
191
189
|
const result = await fangorn.initRepo(namespace);
|
|
192
|
-
const head = result.alreadyInitialized ? await fangorn.onChainTip(owner) : result.commitCid;
|
|
190
|
+
const head = result.alreadyInitialized ? await fangorn.onChainTip(owner, namespace) : result.commitCid;
|
|
193
191
|
const repo = LocalRepo.init({
|
|
194
192
|
namespace,
|
|
195
193
|
owner,
|
|
@@ -243,12 +241,13 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
|
|
|
243
241
|
});
|
|
244
242
|
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) => {
|
|
245
243
|
try {
|
|
246
|
-
const
|
|
244
|
+
const repo = LocalRepo.open();
|
|
245
|
+
const head = repo.head();
|
|
247
246
|
if (!head) throw new Error("nothing to push — no commits yet");
|
|
248
247
|
const fangorn = getFangorn();
|
|
249
248
|
const s = spinner();
|
|
250
249
|
s.start("Pushing...");
|
|
251
|
-
const { txHash, onChainTip } = await fangorn.push(head, { force: options.force });
|
|
250
|
+
const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head, { force: options.force });
|
|
252
251
|
s.stop();
|
|
253
252
|
console.log(`Tx: ${txHash}`);
|
|
254
253
|
console.log(`Tip: ${onChainTip}`);
|
|
@@ -263,7 +262,7 @@ program.command("status").description("Compare the local tip with the on-chain t
|
|
|
263
262
|
const repo = LocalRepo.open();
|
|
264
263
|
const fangorn = getFangorn();
|
|
265
264
|
const localHead = repo.head();
|
|
266
|
-
const onChainTip = await fangorn.onChainTip(repo.owner());
|
|
265
|
+
const onChainTip = await fangorn.onChainTip(repo.owner(), repo.namespace());
|
|
267
266
|
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";
|
|
268
267
|
console.log(`Namespace: ${repo.namespace()}`);
|
|
269
268
|
console.log(`Owner: ${repo.owner()}`);
|
|
@@ -321,7 +320,7 @@ program.command("clone").description("Track an existing on-chain namespace by re
|
|
|
321
320
|
const fangorn = getFangorn();
|
|
322
321
|
const s = spinner();
|
|
323
322
|
s.start(`Resolving on-chain tip for ${owner}...`);
|
|
324
|
-
const tip = await fangorn.onChainTip(owner);
|
|
323
|
+
const tip = await fangorn.onChainTip(owner, namespace);
|
|
325
324
|
const repo = LocalRepo.init({
|
|
326
325
|
namespace,
|
|
327
326
|
owner,
|
|
@@ -402,7 +401,7 @@ program.command("read").description("List every vertex and edge committed under
|
|
|
402
401
|
namespace = namespace ?? repo.namespace();
|
|
403
402
|
owner = owner ?? repo.owner();
|
|
404
403
|
}
|
|
405
|
-
const [head, contents] = await Promise.all([fangorn.onChainTip(owner), fangorn.engine.listNamespace(namespace, owner)]);
|
|
404
|
+
const [head, contents] = await Promise.all([fangorn.onChainTip(owner, namespace), fangorn.engine.listNamespace(namespace, owner)]);
|
|
406
405
|
const out = {
|
|
407
406
|
owner,
|
|
408
407
|
namespace,
|
|
@@ -416,15 +415,16 @@ program.command("read").description("List every vertex and edge committed under
|
|
|
416
415
|
process.exit(1);
|
|
417
416
|
}
|
|
418
417
|
});
|
|
419
|
-
program.command("reset").description("DANGER!: reset
|
|
420
|
-
const
|
|
418
|
+
program.command("reset").description("DANGER!: reset this namespace's on-chain head to zero (abandons all prior commits)").action(async () => {
|
|
419
|
+
const namespace = LocalRepo.open().namespace();
|
|
420
|
+
const confirmFirst = await confirm({ message: `Are you sure? The on-chain head for "${namespace}" will reset to 0x0000...` });
|
|
421
421
|
handleCancel(confirmFirst);
|
|
422
422
|
if (!confirmFirst) {
|
|
423
423
|
console.log("Reset aborted.");
|
|
424
424
|
process.exit(0);
|
|
425
425
|
}
|
|
426
|
-
await getFangorn().reset();
|
|
427
|
-
console.log(
|
|
426
|
+
await getFangorn().reset(namespace);
|
|
427
|
+
console.log(`On-chain head for "${namespace}" reset to zero. \`repo init\` will now start fresh.`);
|
|
428
428
|
process.exit(0);
|
|
429
429
|
});
|
|
430
430
|
program.parse();
|
package/lib/config.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import * as viem_chains0 from "viem/chains";
|
|
2
1
|
import * as viem19 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;
|
|
7
12
|
/**
|
|
8
13
|
* The networks supproted by Fangorn currently
|
|
9
14
|
*/
|
|
@@ -431,13 +436,15 @@ declare function getNetwork(name: string): {
|
|
|
431
436
|
};
|
|
432
437
|
interface AppConfig {
|
|
433
438
|
dataRegistryContractAddress: Hex;
|
|
439
|
+
appId: Hex;
|
|
434
440
|
chain: Chain;
|
|
435
441
|
rpcUrl: string;
|
|
436
442
|
caip2: number;
|
|
437
443
|
ipfsGateway: string;
|
|
438
444
|
}
|
|
439
445
|
declare const FangornConfig: {
|
|
440
|
-
dataRegistryContractAddress: "
|
|
446
|
+
dataRegistryContractAddress: "0xdec430f03cdc022ab2338490e9b30ef5c63f7340";
|
|
447
|
+
appId: `0x${string}`;
|
|
441
448
|
chain: {
|
|
442
449
|
blockExplorers: {
|
|
443
450
|
readonly default: {
|
|
@@ -488,4 +495,4 @@ declare const FangornConfig: {
|
|
|
488
495
|
ipfsGateway: string;
|
|
489
496
|
};
|
|
490
497
|
//#endregion
|
|
491
|
-
export { AppConfig, FangornConfig, SupportedNetworks, getNetwork as default };
|
|
498
|
+
export { AppConfig, FangornConfig, SupportedNetworks, appId, getNetwork as default };
|
package/lib/config.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
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
|
+
/**
|
|
5
13
|
* The networks supproted by Fangorn currently
|
|
6
14
|
*/
|
|
7
15
|
const SupportedNetworks = {
|
|
@@ -24,7 +32,8 @@ function getNetwork(name) {
|
|
|
24
32
|
throw new Error(`Chain ${name} is not supported`);
|
|
25
33
|
}
|
|
26
34
|
const FangornConfig = {
|
|
27
|
-
dataRegistryContractAddress: "
|
|
35
|
+
dataRegistryContractAddress: "0xdec430f03cdc022ab2338490e9b30ef5c63f7340",
|
|
36
|
+
appId: appId("fangorn"),
|
|
28
37
|
chain: arbitrumSepolia,
|
|
29
38
|
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
30
39
|
caip2: 421614,
|
|
@@ -32,4 +41,4 @@ const FangornConfig = {
|
|
|
32
41
|
};
|
|
33
42
|
|
|
34
43
|
//#endregion
|
|
35
|
-
export { FangornConfig, SupportedNetworks, getNetwork as default };
|
|
44
|
+
export { FangornConfig, SupportedNetworks, appId, getNetwork as default };
|
|
@@ -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";
|