@fangorn-network/sdk 2026.8.18-dev → 2026.10.1-9.0-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 (91) hide show
  1. package/README.md +191 -195
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +198 -164
  4. package/lib/cli/index.d.ts +3 -91
  5. package/lib/cli/index.js +5 -2
  6. package/lib/config.d.ts +349 -433
  7. package/lib/config.js +41 -28
  8. package/lib/contracts/app-registry/abi.d.ts +1064 -265
  9. package/lib/contracts/app-registry/abi.js +1233 -308
  10. package/lib/contracts/app-registry/index.d.ts +123 -102
  11. package/lib/contracts/app-registry/index.js +200 -198
  12. package/lib/contracts/data-registry/abi.d.ts +166 -187
  13. package/lib/contracts/data-registry/abi.js +207 -237
  14. package/lib/contracts/data-registry/index.d.ts +4 -160
  15. package/lib/contracts/data-registry/index.js +5 -294
  16. package/lib/contracts/index.d.ts +6 -7
  17. package/lib/contracts/index.js +6 -8
  18. package/lib/contracts/logs.d.ts +21 -0
  19. package/lib/contracts/logs.js +32 -0
  20. package/lib/contracts/membership-registry/abi.d.ts +1145 -0
  21. package/lib/contracts/membership-registry/abi.js +1333 -0
  22. package/lib/contracts/membership-registry/index.d.ts +79 -0
  23. package/lib/contracts/membership-registry/index.js +104 -0
  24. package/lib/contracts/types.d.ts +3 -1
  25. package/lib/contracts/types.js +3 -1
  26. package/lib/contracts/write.d.ts +34 -2
  27. package/lib/contracts/write.js +48 -1
  28. package/lib/crypto/encryption.js +4 -4
  29. package/lib/engine/car.d.ts +2 -2
  30. package/lib/engine/car.js +10 -5
  31. package/lib/engine/index.d.ts +99 -143
  32. package/lib/engine/index.js +156 -295
  33. package/lib/engine/records.d.ts +110 -0
  34. package/lib/engine/records.js +165 -0
  35. package/lib/engine/test-helpers.d.ts +7 -14
  36. package/lib/engine/test-helpers.js +7 -18
  37. package/lib/fangorn.d.ts +163 -155
  38. package/lib/fangorn.js +284 -248
  39. package/lib/feed.d.ts +7 -4
  40. package/lib/feed.js +4 -1
  41. package/lib/index.d.ts +9 -9
  42. package/lib/index.js +9 -10
  43. package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
  44. package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
  45. package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
  46. package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
  47. package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
  48. package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
  49. package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
  50. package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
  51. package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
  52. package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
  53. package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
  54. package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
  55. package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
  56. package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
  57. package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
  58. package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
  59. package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
  60. package/lib/node_modules/chai/index.js +2874 -0
  61. package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
  62. package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
  63. package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
  64. package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
  65. package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
  66. package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
  67. package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
  68. package/lib/providers/storage/signed-url.d.ts +16 -6
  69. package/lib/providers/storage/signed-url.js +20 -8
  70. package/lib/registry.d.ts +116 -0
  71. package/lib/registry.js +182 -0
  72. package/lib/test/mem-registry.d.ts +51 -0
  73. package/lib/test/mem-registry.js +107 -0
  74. package/lib/test/sdk-suite.d.ts +13 -0
  75. package/lib/test/sdk-suite.js +226 -0
  76. package/lib/test/testbed.d.ts +16411 -61
  77. package/lib/test/testbed.js +190 -84
  78. package/lib/types/index.d.ts +13 -11
  79. package/package.json +89 -72
  80. package/lib/contracts/data-registry/test.d.ts +0 -1
  81. package/lib/contracts/data-registry/test.js +0 -1
  82. package/lib/contracts/settlement-registry/abi.d.ts +0 -466
  83. package/lib/contracts/settlement-registry/abi.js +0 -535
  84. package/lib/contracts/settlement-registry/index.d.ts +0 -163
  85. package/lib/contracts/settlement-registry/index.js +0 -264
  86. package/lib/contracts/subscription-registry/abi.d.ts +0 -179
  87. package/lib/contracts/subscription-registry/abi.js +0 -195
  88. package/lib/contracts/subscription-registry/index.d.ts +0 -59
  89. package/lib/contracts/subscription-registry/index.js +0 -116
  90. package/lib/engine/graph.d.ts +0 -70
  91. package/lib/engine/graph.js +0 -73
package/lib/cli/cli.d.ts CHANGED
File without changes
package/lib/cli/cli.js CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { DEFAULT_APP, FangornConfig, toAppId } from "../config.js";
2
+ import getNetwork, { nonBlank, toAppId } from "../config.js";
3
3
  import { PublisherStatus } from "../contracts/types.js";
4
- import { needsReacceptance } from "../contracts/app-registry/index.js";
5
4
  import "../contracts/index.js";
6
5
  import { Fangorn } from "../fangorn.js";
7
- import { handleCancel } from "./index.js";
8
- import { createPublicClient, formatEther, http } from "viem";
6
+ import { handleCancel, selectChain } from "./index.js";
7
+ import { createPublicClient, formatEther, formatUnits, http } from "viem";
9
8
  import { privateKeyToAccount } from "viem/accounts";
10
9
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
11
10
  import { dirname, join } from "path";
@@ -35,13 +34,15 @@ function loadConfig() {
35
34
  const pinataGateway = process.env.PINATA_GATEWAY;
36
35
  const accessWorkerUrl = process.env.ACCESS_WORKER_URL;
37
36
  const signedUrlWorkerUrl = process.env.SIGNED_URL_WORKER_URL;
38
- const envAppId = process.env.FANGORN_APP_ID;
37
+ const envAppId = nonBlank(process.env.FANGORN_APP_ID);
38
+ const envChain = nonBlank(process.env.CHAIN_NAME);
39
39
  if (existsSync(CONFIG_PATH)) {
40
40
  const stored = readStoredConfig();
41
+ const storedChain = stored.chainName === "Arbitrum Sepolia" ? "arbitrumSepolia" : stored.chainName;
41
42
  _config = {
42
43
  privateKey: stored.privateKey,
43
- cfg: FangornConfig,
44
- appId: envAppId ?? stored.appId ?? DEFAULT_APP,
44
+ cfg: getNetwork(envChain ?? storedChain),
45
+ appId: envAppId ?? nonBlank(stored.appId),
45
46
  pinataJwt: stored.pinataJwt,
46
47
  pinataGateway: stored.pinataGateway,
47
48
  accessWorkerUrl: stored.accessWorkerUrl ?? "",
@@ -53,8 +54,8 @@ function loadConfig() {
53
54
  if (!privateKey) throw new Error("Incomplete environment configuration. Missing: ETH_PRIVATE_KEY\nSet it or run `fangorn init` to use a config file.");
54
55
  _config = {
55
56
  privateKey,
56
- cfg: FangornConfig,
57
- appId: envAppId ?? DEFAULT_APP,
57
+ cfg: getNetwork(envChain ?? "arbitrumSepolia"),
58
+ appId: envAppId,
58
59
  pinataJwt: pinataJwt ?? "",
59
60
  pinataGateway: pinataGateway ?? "",
60
61
  accessWorkerUrl: accessWorkerUrl ?? "",
@@ -82,17 +83,26 @@ function getFangorn() {
82
83
  _fangorn = Fangorn.create({
83
84
  privateKey: cfg.privateKey,
84
85
  storage,
85
- domain: "localhost",
86
86
  config: cfg.cfg,
87
- appId: program.opts().app ?? cfg.appId
87
+ appId: appFlag() ?? cfg.appId
88
88
  });
89
89
  return _fangorn;
90
90
  }
91
+ /** The `--app` override for this invocation; blank counts as unset. */
92
+ function appFlag() {
93
+ return nonBlank(program.opts().app);
94
+ }
91
95
  /**
92
- * The currently configured app name
96
+ * The currently configured app name. App commands need one: there is no default
97
+ * app, since publishing and reading need none.
93
98
  */
94
99
  function currentAppName() {
95
- return program.opts().app ?? loadConfig().appId;
100
+ const name = appFlag() ?? loadConfig().appId;
101
+ if (!name) throw new Error("no app chosen: run `fangorn set-app <name>` or pass --app");
102
+ return name;
103
+ }
104
+ function currentAppId() {
105
+ return toAppId(currentAppName());
96
106
  }
97
107
  var LocalRepo = class LocalRepo {
98
108
  constructor(dir, state) {
@@ -140,13 +150,12 @@ var LocalRepo = class LocalRepo {
140
150
  }
141
151
  };
142
152
  const program = new Command();
143
- const ZERO_HASH = `0x${"0".repeat(64)}`;
144
153
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
145
- const APP_TERMS_PLACEHOLDER = "0x0000000000000000000000000000000000000000000000000000000000000001";
146
154
  program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
147
155
  program.option("--app <name-or-id>", "App (global namespace) for this command — overrides the stored app (see `set-app`)");
148
156
  program.command("init").description("Configure your Fangorn credentials").action(async () => {
149
157
  intro("Fangorn Setup");
158
+ const chainName = await selectChain();
150
159
  const privateKey = await text({
151
160
  message: "Wallet private key (stored locally, never transmitted):",
152
161
  placeholder: "0x...",
@@ -175,7 +184,7 @@ program.command("init").description("Configure your Fangorn credentials").action
175
184
  handleCancel(signedUrlWorkerUrl);
176
185
  writeStoredConfig({
177
186
  privateKey,
178
- chainName: "Arbitrum Sepolia",
187
+ chainName,
179
188
  pinataJwt,
180
189
  pinataGateway,
181
190
  accessWorkerUrl,
@@ -187,7 +196,7 @@ program.command("init").description("Configure your Fangorn credentials").action
187
196
  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) => {
188
197
  try {
189
198
  if (!app) {
190
- const current = loadConfig().appId;
199
+ const current = currentAppName();
191
200
  console.log(`App: ${current}`);
192
201
  console.log(`App id: ${toAppId(current)}`);
193
202
  process.exit(0);
@@ -200,163 +209,235 @@ program.command("set-app").description("Set the app (global namespace) this CLI
200
209
  console.log(`App: ${app}`);
201
210
  console.log(`App id: ${toAppId(app)}`);
202
211
  if (process.env.FANGORN_APP_ID) console.log(`\nNote: FANGORN_APP_ID=${process.env.FANGORN_APP_ID} is set and overrides this.`);
203
- console.log(`\nSaved to ${CONFIG_PATH}. Run \`fangorn app info\` to see whether it is claimed and whether you have joined it.`);
212
+ console.log(`\nSaved to ${CONFIG_PATH}. Run \`fangorn app info\` to see whether it is claimed and whether it has accepted you.`);
204
213
  process.exit(0);
205
214
  } catch (err) {
206
215
  console.error("Failed:", err.message);
207
216
  process.exit(1);
208
217
  }
209
218
  });
219
+ /** Fees are USDC, which has 6 decimals; the contracts count in its base units. */
220
+ const USDC_DECIMALS = 6;
221
+ function formatUsdc(amount) {
222
+ return `${formatUnits(amount, USDC_DECIMALS)} USDC`;
223
+ }
210
224
  /** The status word for a publisher in one app, and whether they can publish. */
211
- function membershipLine(info) {
212
- if (info.appSuspended) return "the whole app is suspended by the protocol admin — nobody can publish under it";
213
- if (info.registered) return "joined";
214
- if (needsReacceptance(info)) return "terms changed since you joined — run `fangorn app join` to re-accept (free)";
215
- if (info.status === PublisherStatus.SUSPENDED) return "suspended from this app by its owner";
216
- return "not joined — run `fangorn app join`";
225
+ function membershipLine(status, canPublish, appSuspended, expired) {
226
+ if (appSuspended) return "the whole app is suspended by the protocol admin — nobody can publish under it";
227
+ if (expired) return "the app's subscription has expired — nobody can publish until its owner runs `fangorn app renew`";
228
+ if (canPublish) return "accepted";
229
+ if (status === PublisherStatus.SUSPENDED) return "suspended from this app by its owner";
230
+ if (status === PublisherStatus.ACTIVE) return "accepted, but suspended network-wide by the protocol admin";
231
+ return "not accepted here — ask the app's owner to run `fangorn app accept <your address>`";
217
232
  }
218
- const appCmd = program.command("app").description("Claim, join and manage apps (global namespaces)");
219
- appCmd.command("info").description("Show this app's terms, fee, owner, and where you stand in it").action(async () => {
233
+ const appCmd = program.command("app").description("Claim and manage apps, and the publishers they accept");
234
+ appCmd.command("info").description("Show this app's owner, subscription, and where you stand in it").action(async () => {
220
235
  try {
221
236
  const self = getAccount().address;
222
- const fangorn = getFangorn();
223
- const apps = fangorn.getAppRegistry();
224
- const data = fangorn.getDataRegistry();
237
+ const apps = getFangorn().getAppRegistry();
225
238
  const s = spinner();
226
- s.start("Reading registries...");
227
- const [owner, info, registeredGlobally] = await Promise.all([
228
- apps.getAppOwner(),
229
- apps.joinInfo(self),
230
- data.isRegistered(self)
239
+ s.start("Reading registry...");
240
+ const [{ canPublish, owner, expiresAt }, status, appSuspended, suspendedGlobally] = await Promise.all([
241
+ apps.access(self),
242
+ apps.status(self),
243
+ apps.isAppSuspended(),
244
+ apps.isGloballySuspended(self)
231
245
  ]);
232
246
  s.stop();
247
+ const expired = expiresAt <= BigInt(Math.floor(Date.now() / 1e3));
233
248
  console.log(`App: ${currentAppName()}`);
234
- console.log(`App id: ${apps.getAppId()}`);
249
+ console.log(`App id: ${apps.getAppId() ?? ""}`);
235
250
  if (owner === ZERO_ADDRESS) console.log(`Owner: (unclaimed — \`fangorn app claim\` takes it)`);
236
251
  else {
237
252
  console.log(`Owner: ${owner}${owner.toLowerCase() === self.toLowerCase() ? " (you)" : ""}`);
238
- console.log(`Terms: ${info.termsHash}`);
239
- if (info.termsUri) console.log(`Terms uri: ${info.termsUri}`);
240
- console.log(`Join fee: ${info.fee.toString()} wei`);
253
+ console.log(expiresAt === 0n ? `Expires: cancelled — \`fangorn app renew\` starts a new period` : `Expires: ${(/* @__PURE__ */ new Date(Number(expiresAt) * 1e3)).toISOString()}${expired ? " (EXPIRED)" : ""}`);
241
254
  }
242
- if (info.appSuspended) console.log(`Status: SUSPENDED by the protocol admin`);
255
+ if (appSuspended) console.log(`Status: SUSPENDED by the protocol admin`);
243
256
  console.log(`\nWallet: ${self}`);
244
- console.log(`DataRegistry: ${registeredGlobally ? "registered" : "not registered — run `fangorn register`"}`);
245
- console.log(`This app: ${owner === ZERO_ADDRESS ? "n/a (unclaimed)" : membershipLine(info)}`);
257
+ if (suspendedGlobally) console.log(`Network: SUSPENDED by the protocol admin — cannot claim, be accepted or publish`);
258
+ console.log(`This app: ${owner === ZERO_ADDRESS ? "n/a (unclaimed)" : membershipLine(status, canPublish, appSuspended, expired)}`);
246
259
  process.exit(0);
247
260
  } catch (err) {
248
261
  console.error("Failed:", err.message);
249
262
  process.exit(1);
250
263
  }
251
264
  });
252
- appCmd.command("claim").description("Claim the configured app on-chain (first come, first served)").option("--terms-hash <hash>", "32-byte hash of your terms document (default: a placeholder you should replace)").option("--terms-uri <uri>", "Where the terms document lives", "").option("--fee <wei>", "What joining this app costs, in wei", "0").action(async (opts) => {
265
+ appCmd.command("claim").description("Claim the configured app on-chain (first come, first served)").action(async () => {
253
266
  try {
254
267
  const self = getAccount().address;
255
268
  const registry = getFangorn().getAppRegistry();
256
269
  const s = spinner();
257
270
  s.start("Checking app ownership...");
258
- const owner = await registry.getAppOwner();
271
+ const [owner, suspendedGlobally] = await Promise.all([registry.getAppOwner(), registry.isGloballySuspended(self)]);
259
272
  s.stop();
260
273
  if (owner !== ZERO_ADDRESS) {
261
274
  const mine = owner.toLowerCase() === self.toLowerCase();
262
- console.log(mine ? `Already claimed by you: ${registry.getAppId()}` : `App ${registry.getAppId()} is already owned by ${owner}. Pick another name with \`fangorn set-app\`, or join this one with \`fangorn app join\`.`);
275
+ console.log(mine ? `Already claimed by you: ${registry.getAppId() ?? ""}` : `App ${registry.getAppId() ?? ""} is already owned by ${owner}. Pick another name with \`fangorn set-app\`, or ask its owner to accept you.`);
263
276
  process.exit(mine ? 0 : 1);
264
277
  }
265
- const termsHash = opts.termsHash ?? APP_TERMS_PLACEHOLDER;
278
+ if (suspendedGlobally) {
279
+ console.error(`${self} is suspended by the protocol admin — claiming will revert.`);
280
+ process.exit(1);
281
+ }
282
+ const subscriptionFee = await registry.subscriptionFee();
283
+ console.log(`Subscription fee: ${formatUsdc(subscriptionFee)}`);
266
284
  s.start("Claiming app...");
267
- const txHash = await registry.registerApp(termsHash, opts.termsUri, BigInt(opts.fee));
285
+ const txHash = await registry.registerApp();
268
286
  s.stop();
269
287
  console.log(`App: ${currentAppName()}`);
270
- console.log(`App id: ${registry.getAppId()}`);
288
+ console.log(`App id: ${currentAppId()}`);
271
289
  console.log(`Owner: ${self}`);
272
- console.log(`Terms: ${termsHash}`);
273
290
  console.log(`Tx: ${txHash}`);
274
- if (!opts.termsHash) console.log("\nThose are placeholder terms. Publish real ones with `fangorn app terms <hash> <uri>` —\nanyone who joined against the placeholder must then re-accept.");
275
- console.log(`\nClaiming makes you your own first publisher; run \`fangorn register\` for global standing.`);
291
+ console.log(`\nClaiming makes you your own first publisher. Accept others with \`fangorn app accept <address>\`.`);
276
292
  process.exit(0);
277
293
  } catch (err) {
278
294
  console.error("Failed:", err.message);
279
295
  process.exit(1);
280
296
  }
281
297
  });
282
- appCmd.command("join").description("Join the configured app, accepting its current terms").action(async () => {
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) => {
283
304
  try {
284
- const self = getAccount().address;
285
- const registry = getFangorn().getAppRegistry();
305
+ 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`.");
286
308
  const s = spinner();
287
- s.start("Reading terms...");
288
- const info = await registry.joinInfo(self);
289
- s.stop();
290
- if (info.registered) {
291
- console.log(`Already joined ${registry.getAppId()} as ${self}`);
292
- process.exit(0);
293
- }
294
- if (info.termsHash === ZERO_HASH) {
295
- console.error(`App ${registry.getAppId()} has published no terms — it cannot be joined.\nIf it is unclaimed, \`fangorn app claim\` takes it; otherwise its owner must set terms.`);
296
- process.exit(1);
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)}`);
297
314
  }
298
- if (info.status === PublisherStatus.SUSPENDED) {
299
- console.error(`Suspended from this app by its owner — joining again will revert. Ask them to reinstate you.`);
300
- process.exit(1);
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();
343
+ s.stop();
344
+ agentId = String(result.agentId);
301
345
  }
302
- if (info.appSuspended) {
303
- console.error(`App ${registry.getAppId()} has been suspended by the protocol admin — joining will revert.`);
346
+ s.start("Pointing the app at its card");
347
+ const txHash = await getFangorn().getAppRegistry().setAppAgentUri(url);
348
+ s.stop();
349
+ if (agentId) console.log(`Agent ID: ${agentId}`);
350
+ console.log(`Card: ${url}`);
351
+ console.log(`Tx: ${txHash}`);
352
+ process.exit(0);
353
+ } catch (err) {
354
+ console.error("Failed:", err.message);
355
+ process.exit(1);
356
+ }
357
+ });
358
+ appCmd.command("accept").description("Accept a publisher into your app (owner only): the app stores and includes its data").argument("<publisher>", "Publisher address").action(async (publisher) => {
359
+ try {
360
+ const registry = getFangorn().getAppRegistry();
361
+ const s = spinner();
362
+ s.start("Checking publisher standing...");
363
+ const suspended = await registry.isGloballySuspended(publisher);
364
+ s.stop();
365
+ if (suspended) {
366
+ console.error(`${publisher} is suspended by the protocol admin — accepting them will revert.`);
304
367
  process.exit(1);
305
368
  }
306
- console.log(`Terms: ${info.termsHash}`);
307
- if (info.termsUri) console.log(`Terms uri: ${info.termsUri}`);
308
- console.log(`Join fee: ${info.fee.toString()} wei`);
309
- const ok = await confirm({ message: needsReacceptance(info) ? "The terms changed since you joined. Accept the new ones?" : "Accept these terms and join?" });
310
- handleCancel(ok);
311
- if (!ok) process.exit(0);
312
- s.start("Joining app...");
313
- const txHash = await registry.registerForApp();
369
+ s.start("Accepting publisher...");
370
+ const txHash = await registry.acceptPublisher(publisher);
314
371
  s.stop();
315
- console.log(`Joined: ${registry.getAppId()}`);
316
- console.log(`Tx: ${txHash}`);
372
+ console.log(`Accepted: ${publisher}`);
373
+ console.log(`Tx: ${txHash}`);
374
+ console.log(`\nThey can now upload with this app's storage, and the app includes their data.`);
375
+ process.exit(0);
376
+ } catch (err) {
377
+ console.error("Failed:", err.message);
378
+ process.exit(1);
379
+ }
380
+ });
381
+ appCmd.command("renew").description("Pay for one more period of your app's subscription (owner only)").action(async () => {
382
+ try {
383
+ const registry = getFangorn().getAppRegistry();
384
+ const s = spinner();
385
+ s.start("Renewing subscription...");
386
+ const txHash = await registry.renewSubscription();
387
+ const expiresAt = await registry.expiresAt();
388
+ s.stop();
389
+ console.log(`Renewed: ${registry.getAppId() ?? ""}`);
390
+ console.log(`Expires: ${(/* @__PURE__ */ new Date(Number(expiresAt) * 1e3)).toISOString()}`);
391
+ console.log(`Tx: ${txHash}`);
317
392
  process.exit(0);
318
393
  } catch (err) {
319
394
  console.error("Failed:", err.message);
320
395
  process.exit(1);
321
396
  }
322
397
  });
323
- appCmd.command("terms").description("Publish new terms for your app (owner only)").argument("<hash>", "32-byte hash of the terms document").argument("[uri]", "Where the document lives", "").action(async (hash, uri) => {
398
+ appCmd.command("cancel").description("End your app's subscription now, without refund (owner only)").action(async () => {
324
399
  try {
325
400
  const registry = getFangorn().getAppRegistry();
326
- const ok = await confirm({ message: "New terms unregister every publisher until they re-accept (free). Continue?" });
401
+ const ok = await confirm({ message: `Cancel ${registry.getAppId() ?? ""}'s subscription? Nothing is refunded, and the app takes no commits or joins until renewed.` });
327
402
  handleCancel(ok);
328
403
  if (!ok) process.exit(0);
329
404
  const s = spinner();
330
- s.start("Publishing terms...");
331
- const txHash = await registry.setAppTerms(hash, uri);
405
+ s.start("Cancelling subscription...");
406
+ const txHash = await registry.cancelSubscription();
332
407
  s.stop();
333
- console.log(`Terms: ${hash}`);
334
- console.log(`Tx: ${txHash}`);
408
+ console.log(`Cancelled: ${registry.getAppId() ?? ""}`);
409
+ console.log(`Tx: ${txHash}`);
335
410
  process.exit(0);
336
411
  } catch (err) {
337
412
  console.error("Failed:", err.message);
338
413
  process.exit(1);
339
414
  }
340
415
  });
341
- appCmd.command("fee").description("Set what joining your app costs, in wei (owner only)").argument("<wei>", "Join fee in wei").action(async (wei) => {
416
+ 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) => {
342
417
  try {
418
+ const registry = getFangorn().getAppRegistry();
419
+ const owed = await registry.joinFeesOwed();
420
+ if (owed === 0n) {
421
+ console.log("No join fees to withdraw.");
422
+ process.exit(0);
423
+ }
343
424
  const s = spinner();
344
- s.start("Setting join fee...");
345
- const txHash = await getFangorn().getAppRegistry().setAppFee(BigInt(wei));
425
+ s.start(`Withdrawing ${formatUsdc(owed)}...`);
426
+ const txHash = await registry.withdrawJoinFees(to);
346
427
  s.stop();
347
- console.log(`Join fee: ${wei} wei`);
348
- console.log(`Tx: ${txHash}`);
428
+ console.log(`Withdrawn: ${formatUsdc(owed)}`);
429
+ console.log(`Tx: ${txHash}`);
349
430
  process.exit(0);
350
431
  } catch (err) {
351
432
  console.error("Failed:", err.message);
352
433
  process.exit(1);
353
434
  }
354
435
  });
355
- appCmd.command("suspend").description("Eject a publisher from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
436
+ appCmd.command("suspend").description("Suspend a member from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
356
437
  try {
357
438
  const s = spinner();
358
439
  s.start("Suspending publisher...");
359
- const txHash = await getFangorn().getAppRegistry().suspendForApp(publisher);
440
+ const txHash = await getFangorn().getAppRegistry().setPublisherSuspended(publisher, true);
360
441
  s.stop();
361
442
  console.log(`Suspended: ${publisher}`);
362
443
  console.log(`Tx: ${txHash}`);
@@ -370,7 +451,7 @@ appCmd.command("reinstate").description("Reinstate a suspended publisher in your
370
451
  try {
371
452
  const s = spinner();
372
453
  s.start("Reinstating publisher...");
373
- const txHash = await getFangorn().getAppRegistry().reinstateForApp(publisher);
454
+ const txHash = await getFangorn().getAppRegistry().setPublisherSuspended(publisher, false);
374
455
  s.stop();
375
456
  console.log(`Reinstated: ${publisher}`);
376
457
  console.log(`Tx: ${txHash}`);
@@ -392,14 +473,14 @@ async function requireAdmin() {
392
473
  appAdminCmd.command("suspend").description("Suspend this entire app — nobody can publish under it (admin only)").action(async () => {
393
474
  try {
394
475
  const registry = await requireAdmin();
395
- const ok = await confirm({ message: `Suspend the whole app ${registry.getAppId()}? Every publisher, including its owner, stops being registered.` });
476
+ const ok = await confirm({ message: `Suspend the whole app ${registry.getAppId() ?? ""}? Every publisher, including its owner, stops being able to publish.` });
396
477
  handleCancel(ok);
397
478
  if (!ok) process.exit(0);
398
479
  const s = spinner();
399
480
  s.start("Suspending app...");
400
- const txHash = await registry.suspendApp();
481
+ const txHash = await registry.setAppSuspended(true);
401
482
  s.stop();
402
- console.log(`Suspended: ${registry.getAppId()}`);
483
+ console.log(`Suspended: ${currentAppId()}`);
403
484
  console.log(`Tx: ${txHash}`);
404
485
  console.log(`\nMemberships are kept — \`fangorn app admin reinstate\` restores them as they were.`);
405
486
  process.exit(0);
@@ -413,9 +494,9 @@ appAdminCmd.command("reinstate").description("Lift the suspension on this entire
413
494
  const registry = await requireAdmin();
414
495
  const s = spinner();
415
496
  s.start("Reinstating app...");
416
- const txHash = await registry.reinstateApp();
497
+ const txHash = await registry.setAppSuspended(false);
417
498
  s.stop();
418
- console.log(`Reinstated: ${registry.getAppId()}`);
499
+ console.log(`Reinstated: ${currentAppId()}`);
419
500
  console.log(`Tx: ${txHash}`);
420
501
  process.exit(0);
421
502
  } catch (err) {
@@ -431,7 +512,7 @@ appAdminCmd.command("status").description("Who the protocol admin is, and whethe
431
512
  s.start("Reading registry...");
432
513
  const [admin, suspended] = await Promise.all([registry.admin(), registry.isAppSuspended()]);
433
514
  s.stop();
434
- console.log(`App id: ${registry.getAppId()}`);
515
+ console.log(`App id: ${currentAppId()}`);
435
516
  console.log(`Admin: ${admin}${admin.toLowerCase() === self.toLowerCase() ? " (you)" : ""}`);
436
517
  console.log(`Suspended: ${suspended ? "yes — nobody can publish under this app" : "no"}`);
437
518
  process.exit(0);
@@ -440,54 +521,6 @@ appAdminCmd.command("status").description("Who the protocol admin is, and whethe
440
521
  process.exit(1);
441
522
  }
442
523
  });
443
- program.command("register-app", { hidden: true }).description("Deprecated alias for `fangorn app claim`").action(() => {
444
- console.error("`register-app` is now `fangorn app claim`.");
445
- process.exit(1);
446
- });
447
- program.command("register").description("Register as a publisher: global standing, then join this app").action(async () => {
448
- try {
449
- const self = getAccount().address;
450
- const fangorn = getFangorn();
451
- const data = fangorn.getDataRegistry();
452
- const apps = fangorn.getAppRegistry();
453
- const s = spinner();
454
- s.start("Checking publisher registration...");
455
- const already = await data.isRegistered(self);
456
- s.stop();
457
- if (already) console.log(`DataRegistry: already registered`);
458
- else {
459
- s.start("Registering publisher...");
460
- const txHash = await data.register();
461
- s.stop();
462
- console.log(`DataRegistry: registered (tx ${txHash})`);
463
- }
464
- s.start("Checking app membership...");
465
- if (await apps.getAppOwner() === ZERO_ADDRESS) {
466
- s.stop();
467
- console.log(`This app: ${apps.getAppId()} is unclaimed — nothing to join yet.\n Claim it with \`fangorn app claim\`, or point elsewhere with \`fangorn set-app\`.`);
468
- process.exit(0);
469
- }
470
- const info = await apps.joinInfo(self);
471
- s.stop();
472
- if (info.registered) {
473
- console.log(`This app: already joined`);
474
- process.exit(0);
475
- }
476
- if (info.status === PublisherStatus.SUSPENDED) {
477
- console.error(`This app: suspended by the app owner — cannot join.`);
478
- process.exit(1);
479
- }
480
- s.start(needsReacceptance(info) ? "Re-accepting terms..." : "Joining app...");
481
- const joinTx = await apps.registerForApp();
482
- s.stop();
483
- console.log(`This app: joined ${apps.getAppId()} (tx ${joinTx}, fee ${info.fee.toString()} wei)`);
484
- console.log(`\nPublisher: ${self}`);
485
- process.exit(0);
486
- } catch (err) {
487
- console.error("Failed:", err.message);
488
- process.exit(1);
489
- }
490
- });
491
524
  program.command("wallet").description("Show the wallet this CLI signs with").argument("[action]", "show", "show").option("--reveal", "Also print the PRIVATE key — it grants full control of this wallet").action(async (_action, opts) => {
492
525
  try {
493
526
  const cfg = loadConfig();
@@ -539,20 +572,22 @@ program.command("repo").description("Repository operations").command("init").des
539
572
  process.exit(1);
540
573
  }
541
574
  });
542
- program.command("commit").description("Snapshot a namespace's vertices/edges into a new local commit (does not push)").argument("<file>", "JSON file: {\"vertices\":[{\"id\",\"tag\",\"payload\"}],\"edges\":[{\"rel\",\"from\",\"to\"}]}").requiredOption("-m, --message <msg>", "Commit message").option("--replace", "Snapshot semantics: the file replaces the namespace's previous contents (omitted entries are removed)").action(async (file, options) => {
575
+ program.command("commit").description("Put/delete a namespace's records in a new local commit (does not push)").argument("<file>", "JSON file: {\"records\":[{\"id\",\"type\",\"payload\"}],\"deletes\":[\"id\"]}").requiredOption("-m, --message <msg>", "Commit message").option("--replace", "Snapshot semantics: the file replaces the namespace's previous contents (omitted entries are removed)").action(async (file, options) => {
543
576
  try {
544
577
  if (!existsSync(file)) throw new Error(`file not found: ${file}`);
545
578
  const data = JSON.parse(readFileSync(file, "utf-8"));
546
- if (!Array.isArray(data.vertices) || data.vertices.length === 0) throw new Error(`${file} must contain a non-empty "vertices" array`);
579
+ const records = data.records ?? [];
580
+ const deletes = data.deletes ?? [];
581
+ if (!Array.isArray(records) || !Array.isArray(deletes) || records.length + deletes.length === 0) throw new Error(`${file} must contain a non-empty "records" or "deletes" array`);
547
582
  const repo = LocalRepo.open();
548
583
  const fangorn = getFangorn();
549
584
  const parent = repo.head() ?? void 0;
550
585
  const s = spinner();
551
586
  s.start(parent ? "Committing (building on local HEAD)..." : "Committing (initial)...");
552
587
  const result = await fangorn.commit({
553
- namespace: repo.namespace(),
554
- vertices: data.vertices,
555
- edges: data.edges ?? [],
588
+ repo: repo.namespace(),
589
+ records,
590
+ deletes,
556
591
  parent,
557
592
  message: options.message,
558
593
  replace: options.replace
@@ -560,9 +595,9 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
560
595
  s.stop();
561
596
  repo.setHead(result.commitCid);
562
597
  console.log(`Commit: ${result.commitCid}`);
563
- console.log(`Parent: ${result.parents[0] ?? "(root)"}`);
598
+ console.log(`Parent: ${result.parent ?? "(root)"}`);
564
599
  console.log(`Tree: ${result.root}`);
565
- console.log(`Staged: ${data.vertices.length.toString()} vertice(s) / ${(data.edges ?? []).length.toString()} edge(s)`);
600
+ console.log(`Staged: ${records.length.toString()} put(s) / ${deletes.length.toString()} delete(s)`);
566
601
  console.log(`Message: ${options.message}`);
567
602
  console.log(`\nCommitted locally. Run \`fangorn push\` to settle it on-chain.`);
568
603
  process.exit(0);
@@ -571,7 +606,7 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
571
606
  process.exit(1);
572
607
  }
573
608
  });
574
- 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) => {
609
+ program.command("push").description("Settle the local tip commit as the on-chain state root (the permissioned step)").action(async () => {
575
610
  try {
576
611
  const repo = LocalRepo.open();
577
612
  const head = repo.head();
@@ -579,7 +614,7 @@ program.command("push").description("Settle the local tip commit as the on-chain
579
614
  const fangorn = getFangorn();
580
615
  const s = spinner();
581
616
  s.start("Pushing...");
582
- const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head, { force: options.force });
617
+ const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head);
583
618
  s.stop();
584
619
  console.log(`Tx: ${txHash}`);
585
620
  console.log(`Tip: ${onChainTip}`);
@@ -617,7 +652,7 @@ program.command("log").description("Walk commit history from the local tip").opt
617
652
  const fangorn = getFangorn();
618
653
  for await (const c of fangorn.log(head, options.max)) {
619
654
  console.log(`commit ${c.cid}`);
620
- console.log(`Date: ${new Date(c.timestamp).toISOString()}`);
655
+ console.log(`Epoch: ${c.epoch.toString()}`);
621
656
  console.log(`Tree: ${c.root}`);
622
657
  console.log(`\n ${c.message}\n`);
623
658
  }
@@ -634,8 +669,8 @@ program.command("show").description("Show a commit and what it changed vs. its p
634
669
  if (!target) throw new Error("no commit to show — no commits yet");
635
670
  const diff = await getFangorn().show(target);
636
671
  console.log(`commit ${target}`);
637
- console.log(`Date: ${new Date(diff.timestamp).toISOString()}`);
638
- console.log(`Parents: ${diff.parents.length ? diff.parents.join(", ") : "(root)"}`);
672
+ console.log(`Epoch: ${diff.epoch.toString()}`);
673
+ console.log(`Parent: ${diff.parent ?? "(root)"}`);
639
674
  console.log(`Tree: ${diff.root}`);
640
675
  console.log(`\n ${diff.message}\n`);
641
676
  console.log(`Changes vs. parent: +${diff.added.length.toString()} / -${diff.removed.length.toString()} key(s)`);
@@ -711,12 +746,12 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
711
746
  controller.abort();
712
747
  });
713
748
  const stream = options.all ? fangorn.subscribeApp({
714
- namespace,
749
+ repo: namespace,
715
750
  owner,
716
751
  fromBlock,
717
752
  signal: controller.signal
718
753
  }) : fangorn.subscribe({
719
- namespace: namespace ?? "",
754
+ repo: namespace ?? "",
720
755
  owner,
721
756
  fromBlock,
722
757
  signal: controller.signal
@@ -731,7 +766,7 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
731
766
  process.exit(1);
732
767
  }
733
768
  });
734
- program.command("read").description("List every vertex and edge committed under a namespace, as JSON").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner)").option("--pretty", "Pretty-print the JSON output").action(async (namespaceArg, options) => {
769
+ program.command("read").description("List every record committed under a namespace, as JSON").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner)").option("--pretty", "Pretty-print the JSON output").action(async (namespaceArg, options) => {
735
770
  try {
736
771
  const fangorn = getFangorn();
737
772
  let namespace = namespaceArg;
@@ -741,13 +776,12 @@ program.command("read").description("List every vertex and edge committed under
741
776
  namespace = namespace ?? repo.namespace();
742
777
  owner = owner ?? repo.owner();
743
778
  }
744
- const [head, contents] = await Promise.all([fangorn.onChainTip(owner, namespace), fangorn.engine.listNamespace(namespace, owner)]);
779
+ const [head, contents] = await Promise.all([fangorn.onChainTip(owner, namespace), fangorn.engine.listRepo(owner, namespace)]);
745
780
  const out = {
746
781
  owner,
747
782
  namespace,
748
783
  head,
749
- vertices: contents.vertices,
750
- edges: contents.edges
784
+ records: contents.records
751
785
  };
752
786
  process.stdout.write(JSON.stringify(out, null, options.pretty ? 2 : 0) + "\n", () => process.exit(0));
753
787
  } catch (err) {