@fangorn-network/sdk 2026.10.20-dev → 2026.10.22-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.
Files changed (48) hide show
  1. package/README.md +23 -20
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +19 -55
  4. package/lib/cli/index.d.ts +2 -2
  5. package/lib/cli/index.js +3 -3
  6. package/lib/config.d.ts +420 -83
  7. package/lib/config.js +13 -5
  8. package/lib/contracts/membership-registry/index.d.ts +1 -1
  9. package/lib/contracts/membership-registry/index.js +1 -1
  10. package/lib/engine/index.d.ts +2 -16
  11. package/lib/engine/index.js +2 -18
  12. package/lib/erc8004.d.ts +56 -0
  13. package/lib/erc8004.js +143 -0
  14. package/lib/fangorn.d.ts +22 -7
  15. package/lib/fangorn.js +69 -8
  16. package/lib/index.d.ts +2 -2
  17. package/lib/index.js +2 -2
  18. package/lib/node_modules/{@jridgewell → .pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell}/sourcemap-codec/dist/sourcemap-codec.js +1 -1
  19. package/lib/node_modules/{@vitest → .pnpm/@vitest_expect@4.0.18/node_modules/@vitest}/expect/dist/index.js +8 -8
  20. package/lib/node_modules/{@vitest → .pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest}/pretty-format/dist/index.js +2 -2
  21. package/lib/node_modules/{@vitest → .pnpm/@vitest_runner@4.0.18/node_modules/@vitest}/runner/dist/chunk-tasks.js +2 -2
  22. package/lib/node_modules/{@vitest → .pnpm/@vitest_runner@4.0.18/node_modules/@vitest}/runner/dist/index.js +4 -4
  23. package/lib/node_modules/{@vitest → .pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest}/snapshot/dist/index.js +4 -4
  24. package/lib/node_modules/{@vitest → .pnpm/@vitest_spy@4.0.18/node_modules/@vitest}/spy/dist/index.js +1 -1
  25. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/chunk-_commonjsHelpers.js +1 -1
  26. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/chunk-pathe.M-eThtNZ.js +1 -1
  27. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/diff.js +3 -3
  28. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/display.js +2 -2
  29. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/error.js +2 -2
  30. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/helpers.js +1 -1
  31. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/serialize.js +1 -1
  32. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/source-map.js +1 -1
  33. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/timers.js +1 -1
  34. package/lib/node_modules/{chai → .pnpm/chai@6.2.2/node_modules/chai}/index.js +1 -1
  35. package/lib/node_modules/{magic-string → .pnpm/magic-string@0.30.21/node_modules/magic-string}/dist/magic-string.es.js +2 -2
  36. package/lib/node_modules/{pathe → .pnpm/pathe@2.0.3/node_modules/pathe}/dist/shared/pathe.M-eThtNZ.js +1 -1
  37. package/lib/node_modules/{tinyrainbow → .pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow}/dist/index.js +1 -1
  38. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/_commonjsHelpers.D26ty3Ew.js +1 -1
  39. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/date.Bq6ZW5rf.js +1 -1
  40. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/utils.DvEY5TfP.js +2 -2
  41. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/vi.2VT5v0um.js +11 -11
  42. package/lib/providers/storage/signed-url.d.ts +4 -4
  43. package/lib/providers/storage/signed-url.js +5 -4
  44. package/lib/test/sdk-suite.js +2 -2
  45. package/lib/test/testbed.d.ts +6107 -5730
  46. package/lib/test/testbed.js +5 -1
  47. package/package.json +75 -89
  48. /package/lib/node_modules/{@vitest → .pnpm/@vitest_runner@4.0.18/node_modules/@vitest}/runner/dist/utils.js +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Fangorn SDK
2
2
 
3
- The Fangorn SDK is a lightweight "git for data" protocol: publishers version *repos* of records in IPFS and move each repo's head on-chain, and *apps* sponsor storage for the publishers they accept.
3
+ The Fangorn SDK is a decentralized "git for data" protocol. It follows an app <> publisher paradigm. An "app" is synonymous with gauranteed data availability and a 'view' of its underlying data. For publishers, it lets you cryptographically commit to to a version controlled "repo", which is data stored as a Merkle search tree in IPFS. Published data exists independently of an app, and apps emerge on top of data that they sponsor (pin).
4
4
 
5
5
  A **repo** belongs to its publisher, keyed **`publisher : repo`**. Its state is a map of **records** (`{ id, type, payload }`, content-addressed), and its head is the digest of the latest commit block. Any wallet can update its own repos; updating a head is a compare-and-swap on the parent (i.e. a git ref update), and an update names no app.
6
6
 
@@ -56,9 +56,8 @@ You can also configure via environment variables (these take precedence over the
56
56
  ETH_PRIVATE_KEY=0x...
57
57
  PINATA_JWT=...
58
58
  PINATA_GATEWAY=https://your-gateway.mypinata.cloud
59
- CHAIN_NAME=arbitrumSepolia # or baseSepolia
60
- ACCESS_WORKER_URL=https://access-worker.your-subdomain.workers.dev # optional (sealed fields)
61
- SIGNED_URL_WORKER_URL=https://pinata-url-provider.your-subdomain.workers.dev # optional
59
+ CHAIN_NAME=baseSepolia # the default; or arbitrumSepolia
60
+ SIGNED_URL_WORKER_URL=https://pinata-url-provider.your-subdomain.workers.dev # optional; defaults to the network's hosted worker
62
61
  ```
63
62
 
64
63
  > The **access worker** and the **presigned-URL worker** are two different services: the first gates reads of sealed fields, the second hands out Pinata upload URLs. Don't conflate them.
@@ -95,8 +94,8 @@ be transferred). `fangorn app claim` pays one period of the subscription fee in
95
94
  USDC (the client approves exactly the fee for you), and `fangorn app renew` pays
96
95
  the next once less than a period is left. An expired app stores and presents nothing
97
96
  until it is renewed. **Apps provide storage**: you upload relative to
98
- an app, and hosted uploads (`storage: { signedUrl: {} }`) are billed to the
99
- client's app, which must have accepted you. There is no app-less hosted upload — with no
97
+ an app, and hosted uploads (`storage: { signedUrl: {} }`, through the network's
98
+ hosted worker, `config.signedUrlWorker`) are billed to the client's app, which must have accepted you. There is no app-less hosted upload — with no
100
99
  app, bring your own Pinata (`{ pinata }`) and pin your own data. A publisher that
101
100
  pays for its own storage claims a one-member app.
102
101
 
@@ -112,6 +111,7 @@ fangorn app suspend <address> # suspend a member from THIS app only
112
111
  fangorn app reinstate <address>
113
112
  fangorn app renew # pay for the next period
114
113
  fangorn app cancel # end the subscription now, no refund
114
+ fangorn app agent --access-worker <url> # register the worker's agent card with ERC-8004 (or pass a card URL)
115
115
  fangorn app withdraw-fees [to] # join fees still owed from before joining was removed
116
116
  ```
117
117
 
@@ -274,7 +274,7 @@ const fangorn = Fangorn.create({
274
274
  gateway: process.env.PINATA_GATEWAY!,
275
275
  },
276
276
  },
277
- config: FangornConfig, // defaults to Arbitrum Sepolia
277
+ config: FangornConfig, // the default, Base Sepolia; or ArbitrumSepoliaConfig
278
278
  appId: "my-app", // optional for reads (no app: each publisher's latest head); hosted uploads need one
279
279
  });
280
280
 
@@ -590,32 +590,35 @@ gadget_ behind the same handle shape, so committed data doesn't change form.
590
590
 
591
591
  ## Contracts
592
592
 
593
- ### Arbitrum Sepolia
593
+ ### Base Sepolia (the default)
594
594
 
595
595
  | Contract | Address | What it owns |
596
596
  | -------------------- | -------------------------------------------- | --------------------------------------------------- |
597
- | DataRegistry | `0x72B5f83526F3893aF9f1eE0f32A27218EA09f8aE` | Every repo's head, and the update log |
598
- | AppRegistry | `0x55e6209ea1833ceD900989a3b3b22466934E04A5` | Apps: owner, accepted publishers, bans, storage subscription (ERC-5643, USDC); what each app excludes |
599
- | MembershipRegistry | `0xDF17030Cd65435C86eb043F31DDACa99E819E347` | Time-limited, unlinkable access to an app's paid records (USDC + Semaphore) |
597
+ | DataRegistry | `0xE9183f768865dd2Cde5f1B71F8446F0Cd798ebe0` | Every repo's head, and the update log |
598
+ | AppRegistry | `0x0D3e98399df41b558048Cdd7D71723c37A3A9D6F` | Apps: owner, accepted publishers, bans, storage subscription (ERC-5643, USDC); what each app excludes |
599
+ | MembershipRegistry | `0x0e96C012b5c53622EcDAA82F342E31C2623A04f5` | Time-limited, unlinkable access to an app's paid records (USDC + Semaphore) |
600
+
601
+ `Fangorn.create` uses it when given no `config`, and the CLI when `CHAIN_NAME` is unset.
600
602
 
601
- ### Base Sepolia
603
+ ### Arbitrum Sepolia
602
604
 
603
605
  | Contract | Address |
604
606
  | -------------------- | -------------------------------------------- |
605
- | DataRegistry | `0xE9183f768865dd2Cde5f1B71F8446F0Cd798ebe0` |
606
- | AppRegistry | `0x0D3e98399df41b558048Cdd7D71723c37A3A9D6F` |
607
- | MembershipRegistry | `0x0e96C012b5c53622EcDAA82F342E31C2623A04f5` |
607
+ | DataRegistry | `0x72B5f83526F3893aF9f1eE0f32A27218EA09f8aE` |
608
+ | AppRegistry | `0x55e6209ea1833ceD900989a3b3b22466934E04A5` |
609
+ | MembershipRegistry | `0xDF17030Cd65435C86eb043F31DDACa99E819E347` |
608
610
 
609
- Use it from the SDK with `Fangorn.create({ config: BaseSepoliaConfig, ... })`, or
610
- from the CLI with `CHAIN_NAME=baseSepolia` (or pick it in `fangorn init`).
611
+ Still runs an older version of the contracts, which this SDK's ABIs do not match.
612
+ Select it with `Fangorn.create({ config: ArbitrumSepoliaConfig, ... })`, or from the
613
+ CLI with `CHAIN_NAME=arbitrumSepolia` (or pick it in `fangorn init`).
611
614
 
612
615
  Its default RPC is `base-sepolia-rpc.publicnode.com`, not `sepolia.base.org`: the
613
616
  official endpoint caps `eth_getLogs` at 200 blocks, too narrow to scan the registry's
614
617
  history. Each config's `logWindow` is the most blocks one log query spans on its RPC
615
618
  (Base 10,000, Arbitrum 100,000); `FANGORN_LOG_WINDOW` overrides it for a private RPC.
616
619
 
617
- `FangornConfig` (Arbitrum Sepolia) and `BaseSepoliaConfig` in `src/config.ts` are the authoritative list and what the SDK
618
- uses by default — prefer it over any address copied out of a document,
620
+ `BaseSepoliaConfig` (also exported as `FangornConfig`, the default) and `ArbitrumSepoliaConfig` in `src/config.ts` are the authoritative list and what the SDK
621
+ uses — prefer it over any address copied out of a document,
619
622
  including this table. The sources are `fangorn-network/contracts`
620
623
  (`solidity/script/Deployments.sol`); regenerate the ABIs with `pnpm abis`.
621
624
 
@@ -648,7 +651,7 @@ pnpm test:e2e
648
651
  | `src/e2e/sdk.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
649
652
  | `src/e2e/apps.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
650
653
  | `src/e2e/admin.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
651
- | `src/e2e/live.e2e.test.ts` | Arbitrum Sepolia, read-only | nothing |
654
+ | `src/e2e/live.e2e.test.ts` | Base Sepolia, read-only | nothing |
652
655
 
653
656
  Without `anvil`, `forge` or the contracts checkout the anvil suites are skipped
654
657
  (in CI they fail). The deployer is the protocol admin, so the admin suite needs
package/lib/cli/cli.d.ts CHANGED
File without changes
package/lib/cli/cli.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import getNetwork, { nonBlank, toAppId } from "../config.js";
3
+ import { agentCardUrl, parseAgentId } from "../erc8004.js";
3
4
  import { PublisherStatus } from "../contracts/types.js";
4
5
  import "../contracts/index.js";
5
6
  import { Fangorn } from "../fangorn.js";
@@ -32,7 +33,6 @@ function loadConfig() {
32
33
  const privateKey = process.env.ETH_PRIVATE_KEY;
33
34
  const pinataJwt = process.env.PINATA_JWT;
34
35
  const pinataGateway = process.env.PINATA_GATEWAY;
35
- const accessWorkerUrl = process.env.ACCESS_WORKER_URL;
36
36
  const signedUrlWorkerUrl = process.env.SIGNED_URL_WORKER_URL;
37
37
  const envAppId = nonBlank(process.env.FANGORN_APP_ID);
38
38
  const envChain = nonBlank(process.env.CHAIN_NAME);
@@ -45,7 +45,6 @@ function loadConfig() {
45
45
  appId: envAppId ?? nonBlank(stored.appId),
46
46
  pinataJwt: stored.pinataJwt,
47
47
  pinataGateway: stored.pinataGateway,
48
- accessWorkerUrl: stored.accessWorkerUrl ?? "",
49
48
  signedUrlWorkerUrl: stored.signedUrlWorkerUrl ?? ""
50
49
  };
51
50
  return _config;
@@ -54,11 +53,10 @@ function loadConfig() {
54
53
  if (!privateKey) throw new Error("Incomplete environment configuration. Missing: ETH_PRIVATE_KEY\nSet it or run `fangorn init` to use a config file.");
55
54
  _config = {
56
55
  privateKey,
57
- cfg: getNetwork(envChain ?? "arbitrumSepolia"),
56
+ cfg: getNetwork(envChain ?? "baseSepolia"),
58
57
  appId: envAppId,
59
58
  pinataJwt: pinataJwt ?? "",
60
59
  pinataGateway: pinataGateway ?? "",
61
- accessWorkerUrl: accessWorkerUrl ?? "",
62
60
  signedUrlWorkerUrl: signedUrlWorkerUrl ?? ""
63
61
  };
64
62
  return _config;
@@ -172,11 +170,6 @@ program.command("init").description("Configure your Fangorn credentials").action
172
170
  placeholder: "https://your-gateway.mypinata.cloud"
173
171
  });
174
172
  handleCancel(pinataGateway);
175
- const accessWorkerUrl = await text({
176
- message: "Access-gating worker URL (optional):",
177
- placeholder: "https://access-worker.your-subdomain.workers.dev"
178
- });
179
- handleCancel(accessWorkerUrl);
180
173
  const signedUrlWorkerUrl = await text({
181
174
  message: "Presigned-URL worker URL (optional; blank uses the hosted default):",
182
175
  placeholder: "https://pinata-url-provider.your-subdomain.workers.dev"
@@ -187,7 +180,6 @@ program.command("init").description("Configure your Fangorn credentials").action
187
180
  chainName,
188
181
  pinataJwt,
189
182
  pinataGateway,
190
- accessWorkerUrl,
191
183
  signedUrlWorkerUrl,
192
184
  appId: existsSync(CONFIG_PATH) ? readStoredConfig().appId : void 0
193
185
  });
@@ -295,57 +287,29 @@ appCmd.command("claim").description("Claim the configured app on-chain (first co
295
287
  process.exit(1);
296
288
  }
297
289
  });
298
- const ERC8004_ARBITRUM_SEPOLIA = {
299
- IDENTITY: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
300
- REPUTATION: "0x8004B663056A597Dffe9eCcC1965A193B7388713"
301
- };
302
- const ERC8004_SUBGRAPH = "https://api.studio.thegraph.com/query/1742225/erc-8004-arbitrum-sepolia/version/latest";
303
- appCmd.command("agent").description("Register this app's gateway as an ERC-8004 agent and point the app at its card (owner only)").argument("[cardUrl]", "The agent card URL; defaults to the configured access worker's /.well-known/agent-card.json").option("--mcp <url>", "An MCP endpoint to index alongside the card").option("--skip-register", "Only set agent_uri on-chain — for a gateway already registered with ERC-8004").action(async (cardUrl, opts) => {
290
+ appCmd.command("agent").description("Register this app's gateway as an ERC-8004 agent and point the app at its card (owner only)").argument("[cardUrl]", "The agent card URL; or pass --access-worker to use its /.well-known/agent-card.json").option("--access-worker <url>", "The access worker serving the agent card").option("--mcp <url>", "An MCP endpoint to index alongside the card").option("--skip-register", "Only set agent_uri on-chain — for a gateway already registered with ERC-8004").option("--update <agentId>", "Update an agent already registered (e.g. 84532:10323) from the card as it is now: a new registration file, pointed to by setAgentURI; mints nothing").action(async (cardUrl, opts) => {
304
291
  try {
305
292
  const cfg = loadConfig();
306
- const url = cardUrl ?? (cfg.accessWorkerUrl ? `${cfg.accessWorkerUrl.replace(/\/$/, "")}/.well-known/agent-card.json` : void 0);
307
- if (!url) throw new Error("No card URL. Pass one, or set an access worker URL with `fangorn init`.");
293
+ const url = agentCardUrl(cardUrl, opts.accessWorker);
308
294
  const s = spinner();
309
- s.start(`Reading ${url}`);
310
- const res = await fetch(url);
311
- if (!res.ok) {
312
- s.stop();
313
- throw new Error(`card at ${url} returned ${String(res.status)}`);
314
- }
315
- const card = await res.json();
316
- s.stop(`Card: ${card.name ?? "(unnamed)"}`);
317
- if (!card.name || !card.description) throw new Error("card is missing `name` or `description`");
318
- let agentId;
319
- if (!opts.skipRegister) {
320
- if (!cfg.pinataJwt) throw new Error("ERC-8004 registration pins the registration file to IPFS — set PINATA_JWT, or pass --skip-register.");
321
- const { SDK } = await import("agent0-sdk");
322
- const agent = new SDK({
323
- chainId: cfg.cfg.caip2,
324
- rpcUrl: cfg.cfg.rpcUrl,
325
- ...cfg.cfg.caip2 === 421614 && {
326
- subgraphUrl: ERC8004_SUBGRAPH,
327
- registryOverrides: { [cfg.cfg.caip2]: ERC8004_ARBITRUM_SEPOLIA },
328
- subgraphOverrides: { [cfg.cfg.caip2]: ERC8004_SUBGRAPH }
329
- },
330
- ipfs: "pinata",
331
- pinataJwt: cfg.pinataJwt,
332
- privateKey: cfg.privateKey
333
- }).createAgent(card.name, card.description);
334
- s.start("Indexing skills and capabilities from the card");
335
- await agent.setA2A(url);
336
- if (opts.mcp) await agent.setMCP(opts.mcp);
337
- s.stop();
338
- agent.setTrust(true, false, false);
339
- agent.setX402Support(card.skills?.some((sk) => sk.tags?.includes("x402")) ?? false);
340
- agent.setActive(true);
341
- s.start("Registering with the ERC-8004 identity registry");
342
- const { result } = await (await agent.registerIPFS()).waitConfirmed();
295
+ const chainId = cfg.cfg.caip2;
296
+ const update = opts.update ? parseAgentId(opts.update, chainId) : void 0;
297
+ s.start(opts.skipRegister ? "Pointing the app at its card" : update !== void 0 ? `Updating ERC-8004 agent ${opts.update ?? ""}` : "Registering with the ERC-8004 identity registry");
298
+ let result;
299
+ try {
300
+ result = await getFangorn().registerAgent(url, {
301
+ mcp: opts.mcp,
302
+ update,
303
+ skipRegister: opts.skipRegister
304
+ });
305
+ } catch (e) {
343
306
  s.stop();
344
- agentId = String(result.agentId);
307
+ const minted = e.agentId;
308
+ throw minted !== void 0 ? /* @__PURE__ */ new Error(`${e.message.replace(/; finish it with .*/, "")}. Finish it with: fangorn app agent ${url} --update ${String(chainId)}:${String(minted)}`) : e;
345
309
  }
346
- s.start("Pointing the app at its card");
347
- const txHash = await getFangorn().getAppRegistry().setAppAgentUri(url);
348
310
  s.stop();
311
+ const agentId = result.agentId !== void 0 ? `${String(chainId)}:${String(result.agentId)}` : void 0;
312
+ const txHash = result.txHash ?? "(already bound)";
349
313
  if (agentId) console.log(`Agent ID: ${agentId}`);
350
314
  console.log(`Card: ${url}`);
351
315
  console.log(`Tx: ${txHash}`);
@@ -1,8 +1,8 @@
1
1
  import "./cli.js";
2
- import * as viem0 from "viem";
2
+ import * as viem161 from "viem";
3
3
 
4
4
  //#region src/cli/index.d.ts
5
- declare const getChain: (chainStr: string) => viem0.Chain;
5
+ declare const getChain: (chainStr: string) => viem161.Chain;
6
6
  declare const handleCancel: (value: unknown) => void;
7
7
  declare const selectChain: () => Promise<string>;
8
8
  declare function parseGadgetArg(raw: string): {
package/lib/cli/index.js CHANGED
@@ -13,11 +13,11 @@ const selectChain = async () => {
13
13
  const chainChoice = await select({
14
14
  message: "Pick your chain.",
15
15
  options: [{
16
- value: "arbitrumSepolia",
17
- label: "Arbitrum Sepolia"
18
- }, {
19
16
  value: "baseSepolia",
20
17
  label: "Base Sepolia"
18
+ }, {
19
+ value: "arbitrumSepolia",
20
+ label: "Arbitrum Sepolia"
21
21
  }]
22
22
  });
23
23
  handleCancel(chainChoice);