@fangorn-network/sdk 2026.9.22-dev → 2026.10.19-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 (89) hide show
  1. package/README.md +177 -192
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +165 -194
  4. package/lib/config.d.ts +32 -27
  5. package/lib/config.js +17 -7
  6. package/lib/contracts/app-registry/abi.d.ts +1033 -277
  7. package/lib/contracts/app-registry/abi.js +1214 -335
  8. package/lib/contracts/app-registry/index.d.ts +105 -65
  9. package/lib/contracts/app-registry/index.js +182 -175
  10. package/lib/contracts/data-registry/abi.d.ts +166 -187
  11. package/lib/contracts/data-registry/abi.js +207 -237
  12. package/lib/contracts/data-registry/index.d.ts +4 -151
  13. package/lib/contracts/data-registry/index.js +5 -279
  14. package/lib/contracts/index.d.ts +6 -7
  15. package/lib/contracts/index.js +6 -8
  16. package/lib/contracts/logs.d.ts +4 -1
  17. package/lib/contracts/logs.js +9 -2
  18. package/lib/contracts/membership-registry/abi.d.ts +1145 -0
  19. package/lib/contracts/membership-registry/abi.js +1333 -0
  20. package/lib/contracts/membership-registry/index.d.ts +79 -0
  21. package/lib/contracts/membership-registry/index.js +104 -0
  22. package/lib/contracts/types.d.ts +3 -1
  23. package/lib/contracts/types.js +3 -1
  24. package/lib/contracts/write.d.ts +34 -2
  25. package/lib/contracts/write.js +48 -1
  26. package/lib/crypto/encryption.js +4 -4
  27. package/lib/engine/car.d.ts +2 -2
  28. package/lib/engine/car.js +10 -5
  29. package/lib/engine/index.d.ts +99 -143
  30. package/lib/engine/index.js +156 -295
  31. package/lib/engine/records.d.ts +110 -0
  32. package/lib/engine/records.js +165 -0
  33. package/lib/engine/test-helpers.d.ts +7 -14
  34. package/lib/engine/test-helpers.js +7 -18
  35. package/lib/fangorn.d.ts +129 -156
  36. package/lib/fangorn.js +250 -250
  37. package/lib/feed.d.ts +7 -4
  38. package/lib/feed.js +4 -1
  39. package/lib/index.d.ts +9 -9
  40. package/lib/index.js +8 -9
  41. package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
  42. package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
  43. package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
  44. package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
  45. package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
  46. package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
  47. package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
  48. package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
  49. package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
  50. package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
  51. package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
  52. package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
  53. package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
  54. package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
  55. package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
  56. package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
  57. package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
  58. package/lib/node_modules/chai/index.js +2874 -0
  59. package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
  60. package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
  61. package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
  62. package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
  63. package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
  64. package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
  65. package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
  66. package/lib/providers/storage/signed-url.d.ts +16 -6
  67. package/lib/providers/storage/signed-url.js +20 -8
  68. package/lib/registry.d.ts +116 -0
  69. package/lib/registry.js +182 -0
  70. package/lib/test/mem-registry.d.ts +51 -0
  71. package/lib/test/mem-registry.js +107 -0
  72. package/lib/test/sdk-suite.d.ts +13 -0
  73. package/lib/test/sdk-suite.js +226 -0
  74. package/lib/test/testbed.d.ts +16411 -61
  75. package/lib/test/testbed.js +190 -84
  76. package/lib/types/index.d.ts +13 -11
  77. package/package.json +89 -73
  78. package/lib/contracts/data-registry/test.d.ts +0 -1
  79. package/lib/contracts/data-registry/test.js +0 -1
  80. package/lib/contracts/settlement-registry/abi.d.ts +0 -466
  81. package/lib/contracts/settlement-registry/abi.js +0 -535
  82. package/lib/contracts/settlement-registry/index.d.ts +0 -163
  83. package/lib/contracts/settlement-registry/index.js +0 -264
  84. package/lib/contracts/subscription-registry/abi.d.ts +0 -179
  85. package/lib/contracts/subscription-registry/abi.js +0 -195
  86. package/lib/contracts/subscription-registry/index.d.ts +0 -59
  87. package/lib/contracts/subscription-registry/index.js +0 -116
  88. package/lib/engine/graph.d.ts +0 -70
  89. 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 { FangornConfig, 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
6
  import { handleCancel } from "./index.js";
8
- import { createPublicClient, formatEther, http } from "viem";
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,13 @@ 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);
39
38
  if (existsSync(CONFIG_PATH)) {
40
39
  const stored = readStoredConfig();
41
40
  _config = {
42
41
  privateKey: stored.privateKey,
43
42
  cfg: FangornConfig,
44
- appId: envAppId ?? stored.appId ?? DEFAULT_APP,
43
+ appId: envAppId ?? nonBlank(stored.appId),
45
44
  pinataJwt: stored.pinataJwt,
46
45
  pinataGateway: stored.pinataGateway,
47
46
  accessWorkerUrl: stored.accessWorkerUrl ?? "",
@@ -54,7 +53,7 @@ function loadConfig() {
54
53
  _config = {
55
54
  privateKey,
56
55
  cfg: FangornConfig,
57
- appId: envAppId ?? DEFAULT_APP,
56
+ appId: envAppId,
58
57
  pinataJwt: pinataJwt ?? "",
59
58
  pinataGateway: pinataGateway ?? "",
60
59
  accessWorkerUrl: accessWorkerUrl ?? "",
@@ -82,17 +81,26 @@ function getFangorn() {
82
81
  _fangorn = Fangorn.create({
83
82
  privateKey: cfg.privateKey,
84
83
  storage,
85
- domain: "localhost",
86
84
  config: cfg.cfg,
87
- appId: program.opts().app ?? cfg.appId
85
+ appId: appFlag() ?? cfg.appId
88
86
  });
89
87
  return _fangorn;
90
88
  }
89
+ /** The `--app` override for this invocation; blank counts as unset. */
90
+ function appFlag() {
91
+ return nonBlank(program.opts().app);
92
+ }
91
93
  /**
92
- * The currently configured app name
94
+ * The currently configured app name. App commands need one: there is no default
95
+ * app, since publishing and reading need none.
93
96
  */
94
97
  function currentAppName() {
95
- return program.opts().app ?? loadConfig().appId;
98
+ const name = appFlag() ?? loadConfig().appId;
99
+ if (!name) throw new Error("no app chosen: run `fangorn set-app <name>` or pass --app");
100
+ return name;
101
+ }
102
+ function currentAppId() {
103
+ return toAppId(currentAppName());
96
104
  }
97
105
  var LocalRepo = class LocalRepo {
98
106
  constructor(dir, state) {
@@ -140,9 +148,7 @@ var LocalRepo = class LocalRepo {
140
148
  }
141
149
  };
142
150
  const program = new Command();
143
- const ZERO_HASH = `0x${"0".repeat(64)}`;
144
151
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
145
- const APP_TERMS_PLACEHOLDER = "0x0000000000000000000000000000000000000000000000000000000000000001";
146
152
  program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
147
153
  program.option("--app <name-or-id>", "App (global namespace) for this command — overrides the stored app (see `set-app`)");
148
154
  program.command("init").description("Configure your Fangorn credentials").action(async () => {
@@ -187,7 +193,7 @@ program.command("init").description("Configure your Fangorn credentials").action
187
193
  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
194
  try {
189
195
  if (!app) {
190
- const current = loadConfig().appId;
196
+ const current = currentAppName();
191
197
  console.log(`App: ${current}`);
192
198
  console.log(`App id: ${toAppId(current)}`);
193
199
  process.exit(0);
@@ -200,152 +206,86 @@ program.command("set-app").description("Set the app (global namespace) this CLI
200
206
  console.log(`App: ${app}`);
201
207
  console.log(`App id: ${toAppId(app)}`);
202
208
  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.`);
209
+ console.log(`\nSaved to ${CONFIG_PATH}. Run \`fangorn app info\` to see whether it is claimed and whether it has accepted you.`);
204
210
  process.exit(0);
205
211
  } catch (err) {
206
212
  console.error("Failed:", err.message);
207
213
  process.exit(1);
208
214
  }
209
215
  });
216
+ /** Fees are USDC, which has 6 decimals; the contracts count in its base units. */
217
+ const USDC_DECIMALS = 6;
218
+ function formatUsdc(amount) {
219
+ return `${formatUnits(amount, USDC_DECIMALS)} USDC`;
220
+ }
210
221
  /** 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`";
222
+ function membershipLine(status, canPublish, appSuspended, expired) {
223
+ if (appSuspended) return "the whole app is suspended by the protocol admin — nobody can publish under it";
224
+ if (expired) return "the app's subscription has expired — nobody can publish until its owner runs `fangorn app renew`";
225
+ if (canPublish) return "accepted";
226
+ if (status === PublisherStatus.SUSPENDED) return "suspended from this app by its owner";
227
+ if (status === PublisherStatus.ACTIVE) return "accepted, but suspended network-wide by the protocol admin";
228
+ return "not accepted here — ask the app's owner to run `fangorn app accept <your address>`";
217
229
  }
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 () => {
230
+ const appCmd = program.command("app").description("Claim and manage apps, and the publishers they accept");
231
+ appCmd.command("info").description("Show this app's owner, subscription, and where you stand in it").action(async () => {
220
232
  try {
221
233
  const self = getAccount().address;
222
- const fangorn = getFangorn();
223
- const apps = fangorn.getAppRegistry();
224
- const data = fangorn.getDataRegistry();
234
+ const apps = getFangorn().getAppRegistry();
225
235
  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)
236
+ s.start("Reading registry...");
237
+ const [{ canPublish, owner, expiresAt }, status, appSuspended, suspendedGlobally] = await Promise.all([
238
+ apps.access(self),
239
+ apps.status(self),
240
+ apps.isAppSuspended(),
241
+ apps.isGloballySuspended(self)
231
242
  ]);
232
243
  s.stop();
244
+ const expired = expiresAt <= BigInt(Math.floor(Date.now() / 1e3));
233
245
  console.log(`App: ${currentAppName()}`);
234
- console.log(`App id: ${apps.getAppId()}`);
246
+ console.log(`App id: ${apps.getAppId() ?? ""}`);
235
247
  if (owner === ZERO_ADDRESS) console.log(`Owner: (unclaimed — \`fangorn app claim\` takes it)`);
236
248
  else {
237
249
  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`);
250
+ console.log(expiresAt === 0n ? `Expires: cancelled — \`fangorn app renew\` starts a new period` : `Expires: ${(/* @__PURE__ */ new Date(Number(expiresAt) * 1e3)).toISOString()}${expired ? " (EXPIRED)" : ""}`);
241
251
  }
242
- if (info.appSuspended) console.log(`Status: SUSPENDED by the protocol admin`);
252
+ if (appSuspended) console.log(`Status: SUSPENDED by the protocol admin`);
243
253
  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)}`);
254
+ if (suspendedGlobally) console.log(`Network: SUSPENDED by the protocol admin — cannot claim, be accepted or publish`);
255
+ console.log(`This app: ${owner === ZERO_ADDRESS ? "n/a (unclaimed)" : membershipLine(status, canPublish, appSuspended, expired)}`);
246
256
  process.exit(0);
247
257
  } catch (err) {
248
258
  console.error("Failed:", err.message);
249
259
  process.exit(1);
250
260
  }
251
261
  });
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) => {
262
+ appCmd.command("claim").description("Claim the configured app on-chain (first come, first served)").action(async () => {
253
263
  try {
254
264
  const self = getAccount().address;
255
265
  const registry = getFangorn().getAppRegistry();
256
266
  const s = spinner();
257
267
  s.start("Checking app ownership...");
258
- const owner = await registry.getAppOwner();
268
+ const [owner, suspendedGlobally] = await Promise.all([registry.getAppOwner(), registry.isGloballySuspended(self)]);
259
269
  s.stop();
260
270
  if (owner !== ZERO_ADDRESS) {
261
271
  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\`.`);
272
+ 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
273
  process.exit(mine ? 0 : 1);
264
274
  }
265
- const termsHash = opts.termsHash ?? APP_TERMS_PLACEHOLDER;
275
+ if (suspendedGlobally) {
276
+ console.error(`${self} is suspended by the protocol admin — claiming will revert.`);
277
+ process.exit(1);
278
+ }
279
+ const subscriptionFee = await registry.subscriptionFee();
280
+ console.log(`Subscription fee: ${formatUsdc(subscriptionFee)}`);
266
281
  s.start("Claiming app...");
267
- const txHash = await registry.registerApp(termsHash, opts.termsUri, BigInt(opts.fee));
282
+ const txHash = await registry.registerApp();
268
283
  s.stop();
269
284
  console.log(`App: ${currentAppName()}`);
270
- console.log(`App id: ${registry.getAppId()}`);
285
+ console.log(`App id: ${currentAppId()}`);
271
286
  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
287
  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}`);
288
+ console.log(`\nClaiming makes you your own first publisher. Accept others with \`fangorn app accept <address>\`.`);
349
289
  process.exit(0);
350
290
  } catch (err) {
351
291
  console.error("Failed:", err.message);
@@ -410,11 +350,89 @@ appCmd.command("agent").description("Register this app's gateway as an ERC-8004
410
350
  process.exit(1);
411
351
  }
412
352
  });
413
- appCmd.command("suspend").description("Eject a publisher from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
353
+ 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) => {
354
+ try {
355
+ const registry = getFangorn().getAppRegistry();
356
+ const s = spinner();
357
+ s.start("Checking publisher standing...");
358
+ const suspended = await registry.isGloballySuspended(publisher);
359
+ s.stop();
360
+ if (suspended) {
361
+ console.error(`${publisher} is suspended by the protocol admin — accepting them will revert.`);
362
+ process.exit(1);
363
+ }
364
+ s.start("Accepting publisher...");
365
+ const txHash = await registry.acceptPublisher(publisher);
366
+ s.stop();
367
+ console.log(`Accepted: ${publisher}`);
368
+ console.log(`Tx: ${txHash}`);
369
+ console.log(`\nThey can now upload with this app's storage, and the app includes their data.`);
370
+ process.exit(0);
371
+ } catch (err) {
372
+ console.error("Failed:", err.message);
373
+ process.exit(1);
374
+ }
375
+ });
376
+ appCmd.command("renew").description("Pay for one more period of your app's subscription (owner only)").action(async () => {
377
+ try {
378
+ const registry = getFangorn().getAppRegistry();
379
+ const s = spinner();
380
+ s.start("Renewing subscription...");
381
+ const txHash = await registry.renewSubscription();
382
+ const expiresAt = await registry.expiresAt();
383
+ s.stop();
384
+ console.log(`Renewed: ${registry.getAppId() ?? ""}`);
385
+ console.log(`Expires: ${(/* @__PURE__ */ new Date(Number(expiresAt) * 1e3)).toISOString()}`);
386
+ console.log(`Tx: ${txHash}`);
387
+ process.exit(0);
388
+ } catch (err) {
389
+ console.error("Failed:", err.message);
390
+ process.exit(1);
391
+ }
392
+ });
393
+ appCmd.command("cancel").description("End your app's subscription now, without refund (owner only)").action(async () => {
394
+ try {
395
+ const registry = getFangorn().getAppRegistry();
396
+ const ok = await confirm({ message: `Cancel ${registry.getAppId() ?? ""}'s subscription? Nothing is refunded, and the app takes no commits or joins until renewed.` });
397
+ handleCancel(ok);
398
+ if (!ok) process.exit(0);
399
+ const s = spinner();
400
+ s.start("Cancelling subscription...");
401
+ const txHash = await registry.cancelSubscription();
402
+ s.stop();
403
+ console.log(`Cancelled: ${registry.getAppId() ?? ""}`);
404
+ console.log(`Tx: ${txHash}`);
405
+ process.exit(0);
406
+ } catch (err) {
407
+ console.error("Failed:", err.message);
408
+ process.exit(1);
409
+ }
410
+ });
411
+ 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) => {
412
+ try {
413
+ const registry = getFangorn().getAppRegistry();
414
+ const owed = await registry.joinFeesOwed();
415
+ if (owed === 0n) {
416
+ console.log("No join fees to withdraw.");
417
+ process.exit(0);
418
+ }
419
+ const s = spinner();
420
+ s.start(`Withdrawing ${formatUsdc(owed)}...`);
421
+ const txHash = await registry.withdrawJoinFees(to);
422
+ s.stop();
423
+ console.log(`Withdrawn: ${formatUsdc(owed)}`);
424
+ console.log(`Tx: ${txHash}`);
425
+ process.exit(0);
426
+ } catch (err) {
427
+ console.error("Failed:", err.message);
428
+ process.exit(1);
429
+ }
430
+ });
431
+ appCmd.command("suspend").description("Suspend a member from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
414
432
  try {
415
433
  const s = spinner();
416
434
  s.start("Suspending publisher...");
417
- const txHash = await getFangorn().getAppRegistry().suspendForApp(publisher);
435
+ const txHash = await getFangorn().getAppRegistry().setPublisherSuspended(publisher, true);
418
436
  s.stop();
419
437
  console.log(`Suspended: ${publisher}`);
420
438
  console.log(`Tx: ${txHash}`);
@@ -428,7 +446,7 @@ appCmd.command("reinstate").description("Reinstate a suspended publisher in your
428
446
  try {
429
447
  const s = spinner();
430
448
  s.start("Reinstating publisher...");
431
- const txHash = await getFangorn().getAppRegistry().reinstateForApp(publisher);
449
+ const txHash = await getFangorn().getAppRegistry().setPublisherSuspended(publisher, false);
432
450
  s.stop();
433
451
  console.log(`Reinstated: ${publisher}`);
434
452
  console.log(`Tx: ${txHash}`);
@@ -450,14 +468,14 @@ async function requireAdmin() {
450
468
  appAdminCmd.command("suspend").description("Suspend this entire app — nobody can publish under it (admin only)").action(async () => {
451
469
  try {
452
470
  const registry = await requireAdmin();
453
- const ok = await confirm({ message: `Suspend the whole app ${registry.getAppId()}? Every publisher, including its owner, stops being registered.` });
471
+ const ok = await confirm({ message: `Suspend the whole app ${registry.getAppId() ?? ""}? Every publisher, including its owner, stops being able to publish.` });
454
472
  handleCancel(ok);
455
473
  if (!ok) process.exit(0);
456
474
  const s = spinner();
457
475
  s.start("Suspending app...");
458
- const txHash = await registry.suspendApp();
476
+ const txHash = await registry.setAppSuspended(true);
459
477
  s.stop();
460
- console.log(`Suspended: ${registry.getAppId()}`);
478
+ console.log(`Suspended: ${currentAppId()}`);
461
479
  console.log(`Tx: ${txHash}`);
462
480
  console.log(`\nMemberships are kept — \`fangorn app admin reinstate\` restores them as they were.`);
463
481
  process.exit(0);
@@ -471,9 +489,9 @@ appAdminCmd.command("reinstate").description("Lift the suspension on this entire
471
489
  const registry = await requireAdmin();
472
490
  const s = spinner();
473
491
  s.start("Reinstating app...");
474
- const txHash = await registry.reinstateApp();
492
+ const txHash = await registry.setAppSuspended(false);
475
493
  s.stop();
476
- console.log(`Reinstated: ${registry.getAppId()}`);
494
+ console.log(`Reinstated: ${currentAppId()}`);
477
495
  console.log(`Tx: ${txHash}`);
478
496
  process.exit(0);
479
497
  } catch (err) {
@@ -489,7 +507,7 @@ appAdminCmd.command("status").description("Who the protocol admin is, and whethe
489
507
  s.start("Reading registry...");
490
508
  const [admin, suspended] = await Promise.all([registry.admin(), registry.isAppSuspended()]);
491
509
  s.stop();
492
- console.log(`App id: ${registry.getAppId()}`);
510
+ console.log(`App id: ${currentAppId()}`);
493
511
  console.log(`Admin: ${admin}${admin.toLowerCase() === self.toLowerCase() ? " (you)" : ""}`);
494
512
  console.log(`Suspended: ${suspended ? "yes — nobody can publish under this app" : "no"}`);
495
513
  process.exit(0);
@@ -498,54 +516,6 @@ appAdminCmd.command("status").description("Who the protocol admin is, and whethe
498
516
  process.exit(1);
499
517
  }
500
518
  });
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
519
  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
520
  try {
551
521
  const cfg = loadConfig();
@@ -597,20 +567,22 @@ program.command("repo").description("Repository operations").command("init").des
597
567
  process.exit(1);
598
568
  }
599
569
  });
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) => {
570
+ 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
571
  try {
602
572
  if (!existsSync(file)) throw new Error(`file not found: ${file}`);
603
573
  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`);
574
+ const records = data.records ?? [];
575
+ const deletes = data.deletes ?? [];
576
+ 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
577
  const repo = LocalRepo.open();
606
578
  const fangorn = getFangorn();
607
579
  const parent = repo.head() ?? void 0;
608
580
  const s = spinner();
609
581
  s.start(parent ? "Committing (building on local HEAD)..." : "Committing (initial)...");
610
582
  const result = await fangorn.commit({
611
- namespace: repo.namespace(),
612
- vertices: data.vertices,
613
- edges: data.edges ?? [],
583
+ repo: repo.namespace(),
584
+ records,
585
+ deletes,
614
586
  parent,
615
587
  message: options.message,
616
588
  replace: options.replace
@@ -618,9 +590,9 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
618
590
  s.stop();
619
591
  repo.setHead(result.commitCid);
620
592
  console.log(`Commit: ${result.commitCid}`);
621
- console.log(`Parent: ${result.parents[0] ?? "(root)"}`);
593
+ console.log(`Parent: ${result.parent ?? "(root)"}`);
622
594
  console.log(`Tree: ${result.root}`);
623
- console.log(`Staged: ${data.vertices.length.toString()} vertice(s) / ${(data.edges ?? []).length.toString()} edge(s)`);
595
+ console.log(`Staged: ${records.length.toString()} put(s) / ${deletes.length.toString()} delete(s)`);
624
596
  console.log(`Message: ${options.message}`);
625
597
  console.log(`\nCommitted locally. Run \`fangorn push\` to settle it on-chain.`);
626
598
  process.exit(0);
@@ -629,7 +601,7 @@ program.command("commit").description("Snapshot a namespace's vertices/edges int
629
601
  process.exit(1);
630
602
  }
631
603
  });
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) => {
604
+ program.command("push").description("Settle the local tip commit as the on-chain state root (the permissioned step)").action(async () => {
633
605
  try {
634
606
  const repo = LocalRepo.open();
635
607
  const head = repo.head();
@@ -637,7 +609,7 @@ program.command("push").description("Settle the local tip commit as the on-chain
637
609
  const fangorn = getFangorn();
638
610
  const s = spinner();
639
611
  s.start("Pushing...");
640
- const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head, { force: options.force });
612
+ const { txHash, onChainTip } = await fangorn.push(repo.namespace(), head);
641
613
  s.stop();
642
614
  console.log(`Tx: ${txHash}`);
643
615
  console.log(`Tip: ${onChainTip}`);
@@ -675,7 +647,7 @@ program.command("log").description("Walk commit history from the local tip").opt
675
647
  const fangorn = getFangorn();
676
648
  for await (const c of fangorn.log(head, options.max)) {
677
649
  console.log(`commit ${c.cid}`);
678
- console.log(`Date: ${new Date(c.timestamp).toISOString()}`);
650
+ console.log(`Epoch: ${c.epoch.toString()}`);
679
651
  console.log(`Tree: ${c.root}`);
680
652
  console.log(`\n ${c.message}\n`);
681
653
  }
@@ -692,8 +664,8 @@ program.command("show").description("Show a commit and what it changed vs. its p
692
664
  if (!target) throw new Error("no commit to show — no commits yet");
693
665
  const diff = await getFangorn().show(target);
694
666
  console.log(`commit ${target}`);
695
- console.log(`Date: ${new Date(diff.timestamp).toISOString()}`);
696
- console.log(`Parents: ${diff.parents.length ? diff.parents.join(", ") : "(root)"}`);
667
+ console.log(`Epoch: ${diff.epoch.toString()}`);
668
+ console.log(`Parent: ${diff.parent ?? "(root)"}`);
697
669
  console.log(`Tree: ${diff.root}`);
698
670
  console.log(`\n ${diff.message}\n`);
699
671
  console.log(`Changes vs. parent: +${diff.added.length.toString()} / -${diff.removed.length.toString()} key(s)`);
@@ -769,12 +741,12 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
769
741
  controller.abort();
770
742
  });
771
743
  const stream = options.all ? fangorn.subscribeApp({
772
- namespace,
744
+ repo: namespace,
773
745
  owner,
774
746
  fromBlock,
775
747
  signal: controller.signal
776
748
  }) : fangorn.subscribe({
777
- namespace: namespace ?? "",
749
+ repo: namespace ?? "",
778
750
  owner,
779
751
  fromBlock,
780
752
  signal: controller.signal
@@ -789,7 +761,7 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
789
761
  process.exit(1);
790
762
  }
791
763
  });
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) => {
764
+ 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
765
  try {
794
766
  const fangorn = getFangorn();
795
767
  let namespace = namespaceArg;
@@ -799,13 +771,12 @@ program.command("read").description("List every vertex and edge committed under
799
771
  namespace = namespace ?? repo.namespace();
800
772
  owner = owner ?? repo.owner();
801
773
  }
802
- const [head, contents] = await Promise.all([fangorn.onChainTip(owner, namespace), fangorn.engine.listNamespace(namespace, owner)]);
774
+ const [head, contents] = await Promise.all([fangorn.onChainTip(owner, namespace), fangorn.engine.listRepo(owner, namespace)]);
803
775
  const out = {
804
776
  owner,
805
777
  namespace,
806
778
  head,
807
- vertices: contents.vertices,
808
- edges: contents.edges
779
+ records: contents.records
809
780
  };
810
781
  process.stdout.write(JSON.stringify(out, null, options.pretty ? 2 : 0) + "\n", () => process.exit(0));
811
782
  } catch (err) {