@fangorn-network/sdk 2026.9.22-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 +190 -194
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +177 -201
  4. package/lib/cli/index.d.ts +3 -91
  5. package/lib/cli/index.js +5 -2
  6. package/lib/config.d.ts +358 -117
  7. package/lib/config.js +43 -23
  8. package/lib/contracts/app-registry/abi.d.ts +1033 -277
  9. package/lib/contracts/app-registry/abi.js +1214 -335
  10. package/lib/contracts/app-registry/index.d.ts +105 -65
  11. package/lib/contracts/app-registry/index.js +182 -175
  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 -151
  15. package/lib/contracts/data-registry/index.js +5 -279
  16. package/lib/contracts/index.d.ts +6 -7
  17. package/lib/contracts/index.js +6 -8
  18. package/lib/contracts/logs.d.ts +4 -1
  19. package/lib/contracts/logs.js +9 -2
  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 +129 -156
  38. package/lib/fangorn.js +250 -250
  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 +8 -9
  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 -73
  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,152 +209,86 @@ 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
- 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.`);
276
- process.exit(0);
277
- } catch (err) {
278
- console.error("Failed:", err.message);
279
- process.exit(1);
280
- }
281
- });
282
- appCmd.command("join").description("Join the configured app, accepting its current terms").action(async () => {
283
- try {
284
- const self = getAccount().address;
285
- const registry = getFangorn().getAppRegistry();
286
- 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);
297
- }
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);
301
- }
302
- if (info.appSuspended) {
303
- console.error(`App ${registry.getAppId()} has been suspended by the protocol admin — joining will revert.`);
304
- process.exit(1);
305
- }
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();
314
- s.stop();
315
- console.log(`Joined: ${registry.getAppId()}`);
316
290
  console.log(`Tx: ${txHash}`);
317
- process.exit(0);
318
- } catch (err) {
319
- console.error("Failed:", err.message);
320
- process.exit(1);
321
- }
322
- });
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) => {
324
- try {
325
- const registry = getFangorn().getAppRegistry();
326
- const ok = await confirm({ message: "New terms unregister every publisher until they re-accept (free). Continue?" });
327
- handleCancel(ok);
328
- if (!ok) process.exit(0);
329
- const s = spinner();
330
- s.start("Publishing terms...");
331
- const txHash = await registry.setAppTerms(hash, uri);
332
- s.stop();
333
- console.log(`Terms: ${hash}`);
334
- console.log(`Tx: ${txHash}`);
335
- process.exit(0);
336
- } catch (err) {
337
- console.error("Failed:", err.message);
338
- process.exit(1);
339
- }
340
- });
341
- appCmd.command("fee").description("Set what joining your app costs, in wei (owner only)").argument("<wei>", "Join fee in wei").action(async (wei) => {
342
- try {
343
- const s = spinner();
344
- s.start("Setting join fee...");
345
- const txHash = await getFangorn().getAppRegistry().setAppFee(BigInt(wei));
346
- s.stop();
347
- console.log(`Join fee: ${wei} wei`);
348
- console.log(`Tx: ${txHash}`);
291
+ console.log(`\nClaiming makes you your own first publisher. Accept others with \`fangorn app accept <address>\`.`);
349
292
  process.exit(0);
350
293
  } catch (err) {
351
294
  console.error("Failed:", err.message);
@@ -379,9 +322,11 @@ appCmd.command("agent").description("Register this app's gateway as an ERC-8004
379
322
  const agent = new SDK({
380
323
  chainId: cfg.cfg.caip2,
381
324
  rpcUrl: cfg.cfg.rpcUrl,
382
- subgraphUrl: ERC8004_SUBGRAPH,
383
- registryOverrides: { [cfg.cfg.caip2]: ERC8004_ARBITRUM_SEPOLIA },
384
- subgraphOverrides: { [cfg.cfg.caip2]: ERC8004_SUBGRAPH },
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
+ },
385
330
  ipfs: "pinata",
386
331
  pinataJwt: cfg.pinataJwt,
387
332
  privateKey: cfg.privateKey
@@ -410,11 +355,89 @@ appCmd.command("agent").description("Register this app's gateway as an ERC-8004
410
355
  process.exit(1);
411
356
  }
412
357
  });
413
- appCmd.command("suspend").description("Eject a publisher from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
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.`);
367
+ process.exit(1);
368
+ }
369
+ s.start("Accepting publisher...");
370
+ const txHash = await registry.acceptPublisher(publisher);
371
+ s.stop();
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}`);
392
+ process.exit(0);
393
+ } catch (err) {
394
+ console.error("Failed:", err.message);
395
+ process.exit(1);
396
+ }
397
+ });
398
+ appCmd.command("cancel").description("End your app's subscription now, without refund (owner only)").action(async () => {
399
+ try {
400
+ const registry = getFangorn().getAppRegistry();
401
+ const ok = await confirm({ message: `Cancel ${registry.getAppId() ?? ""}'s subscription? Nothing is refunded, and the app takes no commits or joins until renewed.` });
402
+ handleCancel(ok);
403
+ if (!ok) process.exit(0);
404
+ const s = spinner();
405
+ s.start("Cancelling subscription...");
406
+ const txHash = await registry.cancelSubscription();
407
+ s.stop();
408
+ console.log(`Cancelled: ${registry.getAppId() ?? ""}`);
409
+ console.log(`Tx: ${txHash}`);
410
+ process.exit(0);
411
+ } catch (err) {
412
+ console.error("Failed:", err.message);
413
+ process.exit(1);
414
+ }
415
+ });
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) => {
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
+ }
424
+ const s = spinner();
425
+ s.start(`Withdrawing ${formatUsdc(owed)}...`);
426
+ const txHash = await registry.withdrawJoinFees(to);
427
+ s.stop();
428
+ console.log(`Withdrawn: ${formatUsdc(owed)}`);
429
+ console.log(`Tx: ${txHash}`);
430
+ process.exit(0);
431
+ } catch (err) {
432
+ console.error("Failed:", err.message);
433
+ process.exit(1);
434
+ }
435
+ });
436
+ appCmd.command("suspend").description("Suspend a member from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
414
437
  try {
415
438
  const s = spinner();
416
439
  s.start("Suspending publisher...");
417
- const txHash = await getFangorn().getAppRegistry().suspendForApp(publisher);
440
+ const txHash = await getFangorn().getAppRegistry().setPublisherSuspended(publisher, true);
418
441
  s.stop();
419
442
  console.log(`Suspended: ${publisher}`);
420
443
  console.log(`Tx: ${txHash}`);
@@ -428,7 +451,7 @@ appCmd.command("reinstate").description("Reinstate a suspended publisher in your
428
451
  try {
429
452
  const s = spinner();
430
453
  s.start("Reinstating publisher...");
431
- const txHash = await getFangorn().getAppRegistry().reinstateForApp(publisher);
454
+ const txHash = await getFangorn().getAppRegistry().setPublisherSuspended(publisher, false);
432
455
  s.stop();
433
456
  console.log(`Reinstated: ${publisher}`);
434
457
  console.log(`Tx: ${txHash}`);
@@ -450,14 +473,14 @@ async function requireAdmin() {
450
473
  appAdminCmd.command("suspend").description("Suspend this entire app — nobody can publish under it (admin only)").action(async () => {
451
474
  try {
452
475
  const registry = await requireAdmin();
453
- 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.` });
454
477
  handleCancel(ok);
455
478
  if (!ok) process.exit(0);
456
479
  const s = spinner();
457
480
  s.start("Suspending app...");
458
- const txHash = await registry.suspendApp();
481
+ const txHash = await registry.setAppSuspended(true);
459
482
  s.stop();
460
- console.log(`Suspended: ${registry.getAppId()}`);
483
+ console.log(`Suspended: ${currentAppId()}`);
461
484
  console.log(`Tx: ${txHash}`);
462
485
  console.log(`\nMemberships are kept — \`fangorn app admin reinstate\` restores them as they were.`);
463
486
  process.exit(0);
@@ -471,9 +494,9 @@ appAdminCmd.command("reinstate").description("Lift the suspension on this entire
471
494
  const registry = await requireAdmin();
472
495
  const s = spinner();
473
496
  s.start("Reinstating app...");
474
- const txHash = await registry.reinstateApp();
497
+ const txHash = await registry.setAppSuspended(false);
475
498
  s.stop();
476
- console.log(`Reinstated: ${registry.getAppId()}`);
499
+ console.log(`Reinstated: ${currentAppId()}`);
477
500
  console.log(`Tx: ${txHash}`);
478
501
  process.exit(0);
479
502
  } catch (err) {
@@ -489,7 +512,7 @@ appAdminCmd.command("status").description("Who the protocol admin is, and whethe
489
512
  s.start("Reading registry...");
490
513
  const [admin, suspended] = await Promise.all([registry.admin(), registry.isAppSuspended()]);
491
514
  s.stop();
492
- console.log(`App id: ${registry.getAppId()}`);
515
+ console.log(`App id: ${currentAppId()}`);
493
516
  console.log(`Admin: ${admin}${admin.toLowerCase() === self.toLowerCase() ? " (you)" : ""}`);
494
517
  console.log(`Suspended: ${suspended ? "yes — nobody can publish under this app" : "no"}`);
495
518
  process.exit(0);
@@ -498,54 +521,6 @@ appAdminCmd.command("status").description("Who the protocol admin is, and whethe
498
521
  process.exit(1);
499
522
  }
500
523
  });
501
- program.command("register-app", { hidden: true }).description("Deprecated alias for `fangorn app claim`").action(() => {
502
- console.error("`register-app` is now `fangorn app claim`.");
503
- process.exit(1);
504
- });
505
- program.command("register").description("Register as a publisher: global standing, then join this app").action(async () => {
506
- try {
507
- const self = getAccount().address;
508
- const fangorn = getFangorn();
509
- const data = fangorn.getDataRegistry();
510
- const apps = fangorn.getAppRegistry();
511
- const s = spinner();
512
- s.start("Checking publisher registration...");
513
- const already = await data.isRegistered(self);
514
- s.stop();
515
- if (already) console.log(`DataRegistry: already registered`);
516
- else {
517
- s.start("Registering publisher...");
518
- const txHash = await data.register();
519
- s.stop();
520
- console.log(`DataRegistry: registered (tx ${txHash})`);
521
- }
522
- s.start("Checking app membership...");
523
- if (await apps.getAppOwner() === ZERO_ADDRESS) {
524
- s.stop();
525
- 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\`.`);
526
- process.exit(0);
527
- }
528
- const info = await apps.joinInfo(self);
529
- s.stop();
530
- if (info.registered) {
531
- console.log(`This app: already joined`);
532
- process.exit(0);
533
- }
534
- if (info.status === PublisherStatus.SUSPENDED) {
535
- console.error(`This app: suspended by the app owner — cannot join.`);
536
- process.exit(1);
537
- }
538
- s.start(needsReacceptance(info) ? "Re-accepting terms..." : "Joining app...");
539
- const joinTx = await apps.registerForApp();
540
- s.stop();
541
- console.log(`This app: joined ${apps.getAppId()} (tx ${joinTx}, fee ${info.fee.toString()} wei)`);
542
- console.log(`\nPublisher: ${self}`);
543
- process.exit(0);
544
- } catch (err) {
545
- console.error("Failed:", err.message);
546
- process.exit(1);
547
- }
548
- });
549
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) => {
550
525
  try {
551
526
  const cfg = loadConfig();
@@ -597,20 +572,22 @@ program.command("repo").description("Repository operations").command("init").des
597
572
  process.exit(1);
598
573
  }
599
574
  });
600
- 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) => {
601
576
  try {
602
577
  if (!existsSync(file)) throw new Error(`file not found: ${file}`);
603
578
  const data = JSON.parse(readFileSync(file, "utf-8"));
604
- 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`);
605
582
  const repo = LocalRepo.open();
606
583
  const fangorn = getFangorn();
607
584
  const parent = repo.head() ?? void 0;
608
585
  const s = spinner();
609
586
  s.start(parent ? "Committing (building on local HEAD)..." : "Committing (initial)...");
610
587
  const result = await fangorn.commit({
611
- namespace: repo.namespace(),
612
- vertices: data.vertices,
613
- edges: data.edges ?? [],
588
+ repo: repo.namespace(),
589
+ records,
590
+ deletes,
614
591
  parent,
615
592
  message: options.message,
616
593
  replace: options.replace
@@ -618,9 +595,9 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
618
595
  s.stop();
619
596
  repo.setHead(result.commitCid);
620
597
  console.log(`Commit: ${result.commitCid}`);
621
- console.log(`Parent: ${result.parents[0] ?? "(root)"}`);
598
+ console.log(`Parent: ${result.parent ?? "(root)"}`);
622
599
  console.log(`Tree: ${result.root}`);
623
- 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)`);
624
601
  console.log(`Message: ${options.message}`);
625
602
  console.log(`\nCommitted locally. Run \`fangorn push\` to settle it on-chain.`);
626
603
  process.exit(0);
@@ -629,7 +606,7 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
629
606
  process.exit(1);
630
607
  }
631
608
  });
632
- 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 () => {
633
610
  try {
634
611
  const repo = LocalRepo.open();
635
612
  const head = repo.head();
@@ -637,7 +614,7 @@ program.command("push").description("Settle the local tip commit as the on-chain
637
614
  const fangorn = getFangorn();
638
615
  const s = spinner();
639
616
  s.start("Pushing...");
640
- const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head, { force: options.force });
617
+ const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head);
641
618
  s.stop();
642
619
  console.log(`Tx: ${txHash}`);
643
620
  console.log(`Tip: ${onChainTip}`);
@@ -675,7 +652,7 @@ program.command("log").description("Walk commit history from the local tip").opt
675
652
  const fangorn = getFangorn();
676
653
  for await (const c of fangorn.log(head, options.max)) {
677
654
  console.log(`commit ${c.cid}`);
678
- console.log(`Date: ${new Date(c.timestamp).toISOString()}`);
655
+ console.log(`Epoch: ${c.epoch.toString()}`);
679
656
  console.log(`Tree: ${c.root}`);
680
657
  console.log(`\n ${c.message}\n`);
681
658
  }
@@ -692,8 +669,8 @@ program.command("show").description("Show a commit and what it changed vs. its p
692
669
  if (!target) throw new Error("no commit to show — no commits yet");
693
670
  const diff = await getFangorn().show(target);
694
671
  console.log(`commit ${target}`);
695
- console.log(`Date: ${new Date(diff.timestamp).toISOString()}`);
696
- console.log(`Parents: ${diff.parents.length ? diff.parents.join(", ") : "(root)"}`);
672
+ console.log(`Epoch: ${diff.epoch.toString()}`);
673
+ console.log(`Parent: ${diff.parent ?? "(root)"}`);
697
674
  console.log(`Tree: ${diff.root}`);
698
675
  console.log(`\n ${diff.message}\n`);
699
676
  console.log(`Changes vs. parent: +${diff.added.length.toString()} / -${diff.removed.length.toString()} key(s)`);
@@ -769,12 +746,12 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
769
746
  controller.abort();
770
747
  });
771
748
  const stream = options.all ? fangorn.subscribeApp({
772
- namespace,
749
+ repo: namespace,
773
750
  owner,
774
751
  fromBlock,
775
752
  signal: controller.signal
776
753
  }) : fangorn.subscribe({
777
- namespace: namespace ?? "",
754
+ repo: namespace ?? "",
778
755
  owner,
779
756
  fromBlock,
780
757
  signal: controller.signal
@@ -789,7 +766,7 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
789
766
  process.exit(1);
790
767
  }
791
768
  });
792
- 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) => {
793
770
  try {
794
771
  const fangorn = getFangorn();
795
772
  let namespace = namespaceArg;
@@ -799,13 +776,12 @@ program.command("read").description("List every vertex and edge committed under
799
776
  namespace = namespace ?? repo.namespace();
800
777
  owner = owner ?? repo.owner();
801
778
  }
802
- 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)]);
803
780
  const out = {
804
781
  owner,
805
782
  namespace,
806
783
  head,
807
- vertices: contents.vertices,
808
- edges: contents.edges
784
+ records: contents.records
809
785
  };
810
786
  process.stdout.write(JSON.stringify(out, null, options.pretty ? 2 : 0) + "\n", () => process.exit(0));
811
787
  } catch (err) {