@fangorn-network/sdk 2026.10.26-dev → 2026.10.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 CHANGED
@@ -112,9 +112,20 @@ fangorn app reinstate <address>
112
112
  fangorn app renew # pay for the next period
113
113
  fangorn app cancel # end the subscription now, no refund
114
114
  fangorn app agent --access-worker <url> # register the worker's agent card with ERC-8004 (or pass a card URL)
115
- fangorn app withdraw-fees [to] # join fees still owed from before joining was removed
115
+ fangorn app rename <name> # give the app a new name; the old ones keep working
116
116
  ```
117
117
 
118
+ **Renaming moves nothing.** `fangorn app rename` (SDK: `fangorn.renameApp(name)`)
119
+ makes the new name's id an alias of the id the app was claimed under, its
120
+ *canonical* id. Publishers, exclusions, the subscription and the token carry on,
121
+ and every name the app has gone by still resolves to it and stays the owner's:
122
+ nobody can claim one, and clients still using an old name keep working. The token
123
+ id, the app listings and the contract's events keep the canonical id;
124
+ `getAppRegistry().canonicalAppId()` and `.currentAppId()` translate between them,
125
+ and `fangorn app info` shows both when they differ. The CLI saves the new name to
126
+ its config file, unless the app came from `--app` or `FANGORN_APP_ID`, which you
127
+ update yourself.
128
+
118
129
  ### Track a repo
119
130
 
120
131
  `repo init` creates the repo with an empty first commit, pushes it, and starts tracking it in a local `.fangorn/` pointer file (just a HEAD ref — there is no local object store; commit objects and their CARs live in IPFS).
@@ -617,6 +628,10 @@ official endpoint caps `eth_getLogs` at 200 blocks, too narrow to scan the regis
617
628
  history. Each config's `logWindow` is the most blocks one log query spans on its RPC
618
629
  (Base 10,000, Arbitrum 100,000); `FANGORN_LOG_WINDOW` overrides it for a private RPC.
619
630
 
631
+ The CLI takes the chosen network's RPC and contracts from the environment when set:
632
+ `FANGORN_RPC_URL`, `FANGORN_APP_REGISTRY` and `FANGORN_DATA_REGISTRY`, for a private
633
+ RPC or a local `anvil` with the contracts deployed.
634
+
620
635
  `BaseSepoliaConfig` (also exported as `FangornConfig`, the default) and `ArbitrumSepoliaConfig` in `src/config.ts` are the authoritative list and what the SDK
621
636
  uses — prefer it over any address copied out of a document,
622
637
  including this table. The sources are `fangorn-network/contracts`
@@ -651,6 +666,7 @@ pnpm test:e2e
651
666
  | `src/e2e/sdk.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
652
667
  | `src/e2e/apps.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
653
668
  | `src/e2e/admin.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
669
+ | `src/e2e/cli.e2e.test.ts` | the CLI, on anvil | `anvil`, `forge` |
654
670
  | `src/e2e/live.e2e.test.ts` | Base Sepolia, read-only | nothing |
655
671
 
656
672
  Without `anvil`, `forge` or the contracts checkout the anvil suites are skipped
package/lib/cli/cli.js CHANGED
@@ -5,7 +5,7 @@ import { PublisherStatus } from "../contracts/types.js";
5
5
  import "../contracts/index.js";
6
6
  import { Fangorn } from "../fangorn.js";
7
7
  import { handleCancel, selectChain } from "./index.js";
8
- import { createPublicClient, formatEther, formatUnits, http } from "viem";
8
+ import { createPublicClient, formatEther, formatUnits, http, isAddress } from "viem";
9
9
  import { privateKeyToAccount } from "viem/accounts";
10
10
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
11
11
  import { dirname, join } from "path";
@@ -41,7 +41,7 @@ function loadConfig() {
41
41
  const storedChain = stored.chainName === "Arbitrum Sepolia" ? "arbitrumSepolia" : stored.chainName;
42
42
  _config = {
43
43
  privateKey: stored.privateKey,
44
- cfg: getNetwork(envChain ?? storedChain),
44
+ cfg: network(envChain ?? storedChain),
45
45
  appId: envAppId ?? nonBlank(stored.appId),
46
46
  pinataJwt: stored.pinataJwt,
47
47
  pinataGateway: stored.pinataGateway,
@@ -53,7 +53,7 @@ function loadConfig() {
53
53
  if (!privateKey) throw new Error("Incomplete environment configuration. Missing: ETH_PRIVATE_KEY\nSet it or run `fangorn init` to use a config file.");
54
54
  _config = {
55
55
  privateKey,
56
- cfg: getNetwork(envChain ?? "baseSepolia"),
56
+ cfg: network(envChain ?? "baseSepolia"),
57
57
  appId: envAppId,
58
58
  pinataJwt: pinataJwt ?? "",
59
59
  pinataGateway: pinataGateway ?? "",
@@ -63,6 +63,25 @@ function loadConfig() {
63
63
  }
64
64
  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; files may be unpinned without notice. Set PINATA_JWT + PINATA_GATEWAY to use your own storage).");
65
65
  }
66
+ /**
67
+ * The named network, with its RPC and contracts overridable from the environment:
68
+ * FANGORN_RPC_URL, FANGORN_APP_REGISTRY and FANGORN_DATA_REGISTRY, for a local
69
+ * chain (an anvil with the contracts deployed) or a private RPC. Blank counts as unset.
70
+ */
71
+ function network(name) {
72
+ const cfg = getNetwork(name);
73
+ const address = (variable) => {
74
+ const value = nonBlank(process.env[variable]);
75
+ if (value !== void 0 && !isAddress(value)) throw new Error(`${variable} is not an address: "${value}"`);
76
+ return value;
77
+ };
78
+ return {
79
+ ...cfg,
80
+ rpcUrl: nonBlank(process.env.FANGORN_RPC_URL) ?? cfg.rpcUrl,
81
+ appRegistryContractAddress: address("FANGORN_APP_REGISTRY") ?? cfg.appRegistryContractAddress,
82
+ dataRegistryContractAddress: address("FANGORN_DATA_REGISTRY") ?? cfg.dataRegistryContractAddress
83
+ };
84
+ }
66
85
  function getAccount() {
67
86
  if (_account) return _account;
68
87
  _account = privateKeyToAccount(loadConfig().privateKey);
@@ -229,16 +248,21 @@ appCmd.command("info").description("Show this app's owner, subscription, and whe
229
248
  const apps = getFangorn().getAppRegistry();
230
249
  const s = spinner();
231
250
  s.start("Reading registry...");
232
- const [{ canPublish, owner, expiresAt }, status, appSuspended, suspendedGlobally] = await Promise.all([
251
+ const [{ canPublish, owner, expiresAt }, status, appSuspended, suspendedGlobally, canonical, current] = await Promise.all([
233
252
  apps.access(self),
234
253
  apps.status(self),
235
254
  apps.isAppSuspended(),
236
- apps.isGloballySuspended(self)
255
+ apps.isGloballySuspended(self),
256
+ apps.canonicalAppId(),
257
+ apps.currentAppId()
237
258
  ]);
238
259
  s.stop();
239
260
  const expired = expiresAt <= BigInt(Math.floor(Date.now() / 1e3));
240
261
  console.log(`App: ${currentAppName()}`);
241
262
  console.log(`App id: ${apps.getAppId() ?? ""}`);
263
+ const id = apps.getAppId()?.toLowerCase();
264
+ if (canonical.toLowerCase() !== id) console.log(`Claimed as: ${canonical}`);
265
+ if (current.toLowerCase() !== id) console.log(`Renamed to: ${current} (this name still works; \`fangorn set-app <new name>\` follows it)`);
242
266
  if (owner === ZERO_ADDRESS) console.log(`Owner: (unclaimed — \`fangorn app claim\` takes it)`);
243
267
  else {
244
268
  console.log(`Owner: ${owner}${owner.toLowerCase() === self.toLowerCase() ? " (you)" : ""}`);
@@ -287,6 +311,53 @@ appCmd.command("claim").description("Claim the configured app on-chain (first co
287
311
  process.exit(1);
288
312
  }
289
313
  });
314
+ appCmd.command("rename").description("Give your app a new name (owner only); its old names keep working").argument("<name>", "The new app name, or a 32-byte app id").action(async (name) => {
315
+ try {
316
+ const self = getAccount().address;
317
+ const fangorn = getFangorn();
318
+ const registry = fangorn.getAppRegistry();
319
+ const newId = toAppId(name);
320
+ const s = spinner();
321
+ s.start("Checking app ownership...");
322
+ const [owner, canonical, holder, holderOwner] = await Promise.all([
323
+ registry.getAppOwner(),
324
+ registry.canonicalAppId(),
325
+ registry.canonicalAppId(newId),
326
+ registry.getAppOwner(newId)
327
+ ]);
328
+ s.stop();
329
+ if (owner === ZERO_ADDRESS) {
330
+ console.error(`App ${registry.getAppId() ?? ""} is unclaimed — \`fangorn app claim\` takes it.`);
331
+ process.exit(1);
332
+ }
333
+ if (owner.toLowerCase() !== self.toLowerCase()) {
334
+ console.error(`App ${registry.getAppId() ?? ""} is owned by ${owner}; only its owner can rename it.`);
335
+ process.exit(1);
336
+ }
337
+ if (holderOwner !== ZERO_ADDRESS && holder !== canonical) {
338
+ console.error(`"${name}" (${newId}) is already another app's, owned by ${holderOwner}. Pick another name.`);
339
+ process.exit(1);
340
+ }
341
+ s.start("Renaming app...");
342
+ const txHash = await fangorn.renameApp(name);
343
+ s.stop();
344
+ const source = appFlag() ? "--app" : nonBlank(process.env.FANGORN_APP_ID) ? "FANGORN_APP_ID" : void 0;
345
+ if (!source) writeStoredConfig({
346
+ ...readStoredConfig(),
347
+ appId: name
348
+ });
349
+ console.log(`App: ${name}`);
350
+ console.log(`App id: ${newId}`);
351
+ console.log(`Claimed as: ${canonical}`);
352
+ console.log(`Tx: ${txHash}`);
353
+ console.log(source ? `\nThe app came from ${source}: update it to "${name}". The old name keeps working meanwhile.` : `\nSaved to ${CONFIG_PATH}.`);
354
+ console.log(`Every name the app went by still resolves to it, and stays yours: nobody else can claim one.`);
355
+ process.exit(0);
356
+ } catch (err) {
357
+ console.error("Failed:", err.message);
358
+ process.exit(1);
359
+ }
360
+ });
290
361
  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) => {
291
362
  try {
292
363
  const cfg = loadConfig();
@@ -377,26 +448,6 @@ appCmd.command("cancel").description("End your app's subscription now, without r
377
448
  process.exit(1);
378
449
  }
379
450
  });
380
- appCmd.command("withdraw-fees").description("Withdraw the join fees your apps collected before joining was removed (owner only)").argument("[to]", "Where to send them; defaults to this wallet").action(async (to) => {
381
- try {
382
- const registry = getFangorn().getAppRegistry();
383
- const owed = await registry.joinFeesOwed();
384
- if (owed === 0n) {
385
- console.log("No join fees to withdraw.");
386
- process.exit(0);
387
- }
388
- const s = spinner();
389
- s.start(`Withdrawing ${formatUsdc(owed)}...`);
390
- const txHash = await registry.withdrawJoinFees(to);
391
- s.stop();
392
- console.log(`Withdrawn: ${formatUsdc(owed)}`);
393
- console.log(`Tx: ${txHash}`);
394
- process.exit(0);
395
- } catch (err) {
396
- console.error("Failed:", err.message);
397
- process.exit(1);
398
- }
399
- });
400
451
  appCmd.command("suspend").description("Suspend a member from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
401
452
  try {
402
453
  const s = spinner();
@@ -1,8 +1,8 @@
1
1
  import "./cli.js";
2
- import * as viem5957 from "viem";
2
+ import * as viem0 from "viem";
3
3
 
4
4
  //#region src/cli/index.d.ts
5
- declare const getChain: (chainStr: string) => viem5957.Chain;
5
+ declare const getChain: (chainStr: string) => viem0.Chain;
6
6
  declare const handleCancel: (value: unknown) => void;
7
7
  declare const selectChain: () => Promise<string>;
8
8
  declare function parseGadgetArg(raw: string): {