@fangorn-network/sdk 2026.7.29 → 2026.8.18-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.
- package/README.md +175 -62
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +313 -31
- package/lib/config.d.ts +9 -8
- package/lib/config.js +6 -8
- package/lib/contracts/app-registry/abi.d.ts +466 -0
- package/lib/contracts/app-registry/abi.js +529 -0
- package/lib/contracts/app-registry/index.d.ts +139 -0
- package/lib/contracts/app-registry/index.js +271 -0
- package/lib/contracts/data-registry/abi.d.ts +124 -125
- package/lib/contracts/data-registry/abi.js +145 -142
- package/lib/contracts/data-registry/index.d.ts +22 -14
- package/lib/contracts/data-registry/index.js +40 -58
- package/lib/contracts/index.d.ts +8 -3
- package/lib/contracts/index.js +8 -3
- package/lib/contracts/settlement-registry/abi.d.ts +430 -11
- package/lib/contracts/settlement-registry/abi.js +528 -41
- package/lib/contracts/settlement-registry/index.d.ts +148 -10
- package/lib/contracts/settlement-registry/index.js +233 -9
- package/lib/contracts/subscription-registry/abi.d.ts +179 -0
- package/lib/contracts/subscription-registry/abi.js +195 -0
- package/lib/contracts/subscription-registry/index.d.ts +59 -0
- package/lib/contracts/subscription-registry/index.js +116 -0
- package/lib/contracts/types.d.ts +8 -0
- package/lib/contracts/types.js +10 -0
- package/lib/contracts/write.d.ts +27 -0
- package/lib/contracts/write.js +55 -0
- package/lib/crypto/encryption.js +4 -4
- package/lib/engine/index.d.ts +15 -13
- package/lib/engine/index.js +14 -8
- package/lib/fangorn.d.ts +45 -8
- package/lib/fangorn.js +59 -8
- package/lib/index.d.ts +8 -3
- package/lib/index.js +8 -3
- package/lib/test/testbed.js +9 -3
- package/lib/types/index.d.ts +6 -0
- package/package.json +72 -96
package/lib/cli/cli.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { DEFAULT_APP, FangornConfig, toAppId } from "../config.js";
|
|
3
|
+
import { PublisherStatus } from "../contracts/types.js";
|
|
4
|
+
import { needsReacceptance } from "../contracts/app-registry/index.js";
|
|
5
|
+
import "../contracts/index.js";
|
|
3
6
|
import { Fangorn } from "../fangorn.js";
|
|
4
7
|
import { handleCancel } from "./index.js";
|
|
8
|
+
import { createPublicClient, formatEther, http } from "viem";
|
|
5
9
|
import { privateKeyToAccount } from "viem/accounts";
|
|
6
10
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
7
11
|
import { dirname, join } from "path";
|
|
@@ -58,7 +62,7 @@ function loadConfig() {
|
|
|
58
62
|
};
|
|
59
63
|
return _config;
|
|
60
64
|
}
|
|
61
|
-
throw new Error("No configuration found. Run `fangorn init` or set ETH_PRIVATE_KEY\n(with no config, uploads go to Fangorn's shared Pinata account
|
|
65
|
+
throw new Error("No configuration found. Run `fangorn init` or set ETH_PRIVATE_KEY\n(with no config, uploads go to Fangorn's shared Pinata account; files may be unpinned without notice. Set PINATA_JWT + PINATA_GATEWAY to use your own storage).");
|
|
62
66
|
}
|
|
63
67
|
function getAccount() {
|
|
64
68
|
if (_account) return _account;
|
|
@@ -80,10 +84,16 @@ function getFangorn() {
|
|
|
80
84
|
storage,
|
|
81
85
|
domain: "localhost",
|
|
82
86
|
config: cfg.cfg,
|
|
83
|
-
appId: cfg.appId
|
|
87
|
+
appId: program.opts().app ?? cfg.appId
|
|
84
88
|
});
|
|
85
89
|
return _fangorn;
|
|
86
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* The currently configured app name
|
|
93
|
+
*/
|
|
94
|
+
function currentAppName() {
|
|
95
|
+
return program.opts().app ?? loadConfig().appId;
|
|
96
|
+
}
|
|
87
97
|
var LocalRepo = class LocalRepo {
|
|
88
98
|
constructor(dir, state) {
|
|
89
99
|
this.dir = dir;
|
|
@@ -130,7 +140,11 @@ var LocalRepo = class LocalRepo {
|
|
|
130
140
|
}
|
|
131
141
|
};
|
|
132
142
|
const program = new Command();
|
|
143
|
+
const ZERO_HASH = `0x${"0".repeat(64)}`;
|
|
144
|
+
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
145
|
+
const APP_TERMS_PLACEHOLDER = "0x0000000000000000000000000000000000000000000000000000000000000001";
|
|
133
146
|
program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
|
|
147
|
+
program.option("--app <name-or-id>", "App (global namespace) for this command — overrides the stored app (see `set-app`)");
|
|
134
148
|
program.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
135
149
|
intro("Fangorn Setup");
|
|
136
150
|
const privateKey = await text({
|
|
@@ -186,52 +200,312 @@ program.command("set-app").description("Set the app (global namespace) this CLI
|
|
|
186
200
|
console.log(`App: ${app}`);
|
|
187
201
|
console.log(`App id: ${toAppId(app)}`);
|
|
188
202
|
if (process.env.FANGORN_APP_ID) console.log(`\nNote: FANGORN_APP_ID=${process.env.FANGORN_APP_ID} is set and overrides this.`);
|
|
189
|
-
console.log(`\nSaved to ${CONFIG_PATH}. Run \`fangorn
|
|
203
|
+
console.log(`\nSaved to ${CONFIG_PATH}. Run \`fangorn app info\` to see whether it is claimed and whether you have joined it.`);
|
|
204
|
+
process.exit(0);
|
|
205
|
+
} catch (err) {
|
|
206
|
+
console.error("Failed:", err.message);
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
/** 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`";
|
|
217
|
+
}
|
|
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 () => {
|
|
220
|
+
try {
|
|
221
|
+
const self = getAccount().address;
|
|
222
|
+
const fangorn = getFangorn();
|
|
223
|
+
const apps = fangorn.getAppRegistry();
|
|
224
|
+
const data = fangorn.getDataRegistry();
|
|
225
|
+
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)
|
|
231
|
+
]);
|
|
232
|
+
s.stop();
|
|
233
|
+
console.log(`App: ${currentAppName()}`);
|
|
234
|
+
console.log(`App id: ${apps.getAppId()}`);
|
|
235
|
+
if (owner === ZERO_ADDRESS) console.log(`Owner: (unclaimed — \`fangorn app claim\` takes it)`);
|
|
236
|
+
else {
|
|
237
|
+
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`);
|
|
241
|
+
}
|
|
242
|
+
if (info.appSuspended) console.log(`Status: SUSPENDED by the protocol admin`);
|
|
243
|
+
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)}`);
|
|
190
246
|
process.exit(0);
|
|
191
247
|
} catch (err) {
|
|
192
248
|
console.error("Failed:", err.message);
|
|
193
249
|
process.exit(1);
|
|
194
250
|
}
|
|
195
251
|
});
|
|
196
|
-
|
|
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) => {
|
|
197
253
|
try {
|
|
198
254
|
const self = getAccount().address;
|
|
199
|
-
const registry = getFangorn().
|
|
255
|
+
const registry = getFangorn().getAppRegistry();
|
|
200
256
|
const s = spinner();
|
|
201
257
|
s.start("Checking app ownership...");
|
|
202
258
|
const owner = await registry.getAppOwner();
|
|
203
259
|
s.stop();
|
|
204
|
-
if (owner !==
|
|
205
|
-
|
|
206
|
-
|
|
260
|
+
if (owner !== ZERO_ADDRESS) {
|
|
261
|
+
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\`.`);
|
|
263
|
+
process.exit(mine ? 0 : 1);
|
|
207
264
|
}
|
|
208
|
-
|
|
209
|
-
|
|
265
|
+
const termsHash = opts.termsHash ?? APP_TERMS_PLACEHOLDER;
|
|
266
|
+
s.start("Claiming app...");
|
|
267
|
+
const txHash = await registry.registerApp(termsHash, opts.termsUri, BigInt(opts.fee));
|
|
210
268
|
s.stop();
|
|
211
|
-
console.log(`App: ${
|
|
269
|
+
console.log(`App: ${currentAppName()}`);
|
|
212
270
|
console.log(`App id: ${registry.getAppId()}`);
|
|
213
271
|
console.log(`Owner: ${self}`);
|
|
272
|
+
console.log(`Terms: ${termsHash}`);
|
|
214
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.`);
|
|
215
276
|
process.exit(0);
|
|
216
277
|
} catch (err) {
|
|
217
278
|
console.error("Failed:", err.message);
|
|
218
279
|
process.exit(1);
|
|
219
280
|
}
|
|
220
281
|
});
|
|
221
|
-
|
|
282
|
+
appCmd.command("join").description("Join the configured app, accepting its current terms").action(async () => {
|
|
222
283
|
try {
|
|
223
284
|
const self = getAccount().address;
|
|
224
|
-
const registry = getFangorn().
|
|
285
|
+
const registry = getFangorn().getAppRegistry();
|
|
225
286
|
const s = spinner();
|
|
226
|
-
|
|
227
|
-
|
|
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}`);
|
|
228
292
|
process.exit(0);
|
|
229
293
|
}
|
|
230
|
-
|
|
231
|
-
|
|
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
|
+
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}`);
|
|
349
|
+
process.exit(0);
|
|
350
|
+
} catch (err) {
|
|
351
|
+
console.error("Failed:", err.message);
|
|
352
|
+
process.exit(1);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
appCmd.command("suspend").description("Eject a publisher from your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
|
|
356
|
+
try {
|
|
357
|
+
const s = spinner();
|
|
358
|
+
s.start("Suspending publisher...");
|
|
359
|
+
const txHash = await getFangorn().getAppRegistry().suspendForApp(publisher);
|
|
360
|
+
s.stop();
|
|
361
|
+
console.log(`Suspended: ${publisher}`);
|
|
362
|
+
console.log(`Tx: ${txHash}`);
|
|
363
|
+
process.exit(0);
|
|
364
|
+
} catch (err) {
|
|
365
|
+
console.error("Failed:", err.message);
|
|
366
|
+
process.exit(1);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
appCmd.command("reinstate").description("Reinstate a suspended publisher in your app (owner only)").argument("<publisher>", "Publisher address").action(async (publisher) => {
|
|
370
|
+
try {
|
|
371
|
+
const s = spinner();
|
|
372
|
+
s.start("Reinstating publisher...");
|
|
373
|
+
const txHash = await getFangorn().getAppRegistry().reinstateForApp(publisher);
|
|
374
|
+
s.stop();
|
|
375
|
+
console.log(`Reinstated: ${publisher}`);
|
|
376
|
+
console.log(`Tx: ${txHash}`);
|
|
377
|
+
process.exit(0);
|
|
378
|
+
} catch (err) {
|
|
379
|
+
console.error("Failed:", err.message);
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
const appAdminCmd = appCmd.command("admin").description("Protocol-admin takedowns for the whole app (admin only)");
|
|
384
|
+
/** The AppRegistry client, refusing early if this wallet is not the protocol admin. */
|
|
385
|
+
async function requireAdmin() {
|
|
386
|
+
const registry = getFangorn().getAppRegistry();
|
|
387
|
+
const self = getAccount().address;
|
|
388
|
+
const admin = await registry.admin();
|
|
389
|
+
if (admin.toLowerCase() !== self.toLowerCase()) throw new Error(`Not the protocol admin: this registry's admin is ${admin}, you are ${self}.`);
|
|
390
|
+
return registry;
|
|
391
|
+
}
|
|
392
|
+
appAdminCmd.command("suspend").description("Suspend this entire app — nobody can publish under it (admin only)").action(async () => {
|
|
393
|
+
try {
|
|
394
|
+
const registry = await requireAdmin();
|
|
395
|
+
const ok = await confirm({ message: `Suspend the whole app ${registry.getAppId()}? Every publisher, including its owner, stops being registered.` });
|
|
396
|
+
handleCancel(ok);
|
|
397
|
+
if (!ok) process.exit(0);
|
|
398
|
+
const s = spinner();
|
|
399
|
+
s.start("Suspending app...");
|
|
400
|
+
const txHash = await registry.suspendApp();
|
|
232
401
|
s.stop();
|
|
233
|
-
console.log(`
|
|
402
|
+
console.log(`Suspended: ${registry.getAppId()}`);
|
|
234
403
|
console.log(`Tx: ${txHash}`);
|
|
404
|
+
console.log(`\nMemberships are kept — \`fangorn app admin reinstate\` restores them as they were.`);
|
|
405
|
+
process.exit(0);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
console.error("Failed:", err.message);
|
|
408
|
+
process.exit(1);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
appAdminCmd.command("reinstate").description("Lift the suspension on this entire app (admin only)").action(async () => {
|
|
412
|
+
try {
|
|
413
|
+
const registry = await requireAdmin();
|
|
414
|
+
const s = spinner();
|
|
415
|
+
s.start("Reinstating app...");
|
|
416
|
+
const txHash = await registry.reinstateApp();
|
|
417
|
+
s.stop();
|
|
418
|
+
console.log(`Reinstated: ${registry.getAppId()}`);
|
|
419
|
+
console.log(`Tx: ${txHash}`);
|
|
420
|
+
process.exit(0);
|
|
421
|
+
} catch (err) {
|
|
422
|
+
console.error("Failed:", err.message);
|
|
423
|
+
process.exit(1);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
appAdminCmd.command("status").description("Who the protocol admin is, and whether this app is suspended").action(async () => {
|
|
427
|
+
try {
|
|
428
|
+
const registry = getFangorn().getAppRegistry();
|
|
429
|
+
const self = getAccount().address;
|
|
430
|
+
const s = spinner();
|
|
431
|
+
s.start("Reading registry...");
|
|
432
|
+
const [admin, suspended] = await Promise.all([registry.admin(), registry.isAppSuspended()]);
|
|
433
|
+
s.stop();
|
|
434
|
+
console.log(`App id: ${registry.getAppId()}`);
|
|
435
|
+
console.log(`Admin: ${admin}${admin.toLowerCase() === self.toLowerCase() ? " (you)" : ""}`);
|
|
436
|
+
console.log(`Suspended: ${suspended ? "yes — nobody can publish under this app" : "no"}`);
|
|
437
|
+
process.exit(0);
|
|
438
|
+
} catch (err) {
|
|
439
|
+
console.error("Failed:", err.message);
|
|
440
|
+
process.exit(1);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
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
|
+
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
|
+
try {
|
|
493
|
+
const cfg = loadConfig();
|
|
494
|
+
const account = getAccount();
|
|
495
|
+
const s = spinner();
|
|
496
|
+
s.start("Reading balance...");
|
|
497
|
+
const balance = await createPublicClient({ transport: http(cfg.cfg.rpcUrl) }).getBalance({ address: account.address });
|
|
498
|
+
s.stop();
|
|
499
|
+
console.log(`Address: ${account.address}`);
|
|
500
|
+
console.log(`Public key: ${account.publicKey}`);
|
|
501
|
+
console.log(`Balance: ${formatEther(balance)} ETH`);
|
|
502
|
+
console.log(`Network: ${cfg.cfg.chain.name} (${cfg.cfg.caip2.toString()})`);
|
|
503
|
+
console.log(`App: ${currentAppName()}`);
|
|
504
|
+
console.log(`Config: ${existsSync(CONFIG_PATH) ? CONFIG_PATH : "(from environment)"}`);
|
|
505
|
+
if (opts.reveal) {
|
|
506
|
+
console.log(`\nPrivate key: ${cfg.privateKey}`);
|
|
507
|
+
console.log(`Anyone with that key controls this wallet. Do not share it.`);
|
|
508
|
+
} else console.log(`\nPrivate key: hidden — pass --reveal to print it`);
|
|
235
509
|
process.exit(0);
|
|
236
510
|
} catch (err) {
|
|
237
511
|
console.error("Failed:", err.message);
|
|
@@ -394,22 +668,24 @@ program.command("clone").description("Track an existing on-chain namespace by re
|
|
|
394
668
|
process.exit(1);
|
|
395
669
|
}
|
|
396
670
|
});
|
|
397
|
-
program.command("subscribe").description("Watch on-chain pushes to a namespace and stream JSON diffs (light client — no indexer)").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner, else self)").option("--from-block <n>", "Replay from this block (overrides the saved cursor)", (v) => BigInt(v)).option("--from-start", "Replay this namespace's full history (ignore the saved cursor)").option("--pretty", "Pretty-print each change").action(async (namespaceArg, options) => {
|
|
671
|
+
program.command("subscribe").description("Watch on-chain pushes to a namespace and stream JSON diffs (light client — no indexer)").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner, else self)").option("--from-block <n>", "Replay from this block (overrides the saved cursor)", (v) => BigInt(v)).option("--from-start", "Replay this namespace's full history (ignore the saved cursor)").option("--pretty", "Pretty-print each change").option("--all", "Watch the whole app (every publisher, every namespace); --owner/namespace narrow it").action(async (namespaceArg, options) => {
|
|
398
672
|
try {
|
|
399
673
|
const fangorn = getFangorn();
|
|
400
674
|
let namespace = namespaceArg;
|
|
401
675
|
let owner = options.owner;
|
|
402
|
-
if (!
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
676
|
+
if (!options.all) {
|
|
677
|
+
if (!namespace || !owner) try {
|
|
678
|
+
const repo = LocalRepo.open();
|
|
679
|
+
namespace = namespace ?? repo.namespace();
|
|
680
|
+
owner = owner ?? repo.owner();
|
|
681
|
+
} catch {}
|
|
682
|
+
if (!namespace) throw new Error("namespace required (pass it as an argument, run inside a repo, or use --all)");
|
|
683
|
+
owner = owner ?? fangorn.getAddress();
|
|
684
|
+
}
|
|
409
685
|
const repoDir = join(process.cwd(), ".fangorn");
|
|
410
|
-
const cursorPath = join(repoDir, `subscribe-${owner}-${namespace}.json`);
|
|
686
|
+
const cursorPath = join(repoDir, `subscribe-${owner ?? "app"}-${namespace ?? "all"}.json`);
|
|
411
687
|
const readCursor = () => {
|
|
412
|
-
if (options.fromStart) return
|
|
688
|
+
if (options.fromStart) return 0n;
|
|
413
689
|
if (options.fromBlock !== void 0) return options.fromBlock;
|
|
414
690
|
if (existsSync(cursorPath)) {
|
|
415
691
|
const numInput = JSON.parse(readFileSync(cursorPath, "utf-8")).lastBlock ?? 0;
|
|
@@ -426,7 +702,7 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
|
|
|
426
702
|
};
|
|
427
703
|
const bigintReplacer = (_k, v) => typeof v === "bigint" ? v.toString() : v;
|
|
428
704
|
const fromBlock = readCursor();
|
|
429
|
-
console.error(`Subscribing to "${namespace}" @ ${owner} ` + (fromBlock !== void 0 ? `from block ${fromBlock.toString()}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
|
|
705
|
+
console.error(`Subscribing to "${namespace ?? "*"}" @ ${owner ?? "* (whole app)"} ` + (fromBlock !== void 0 ? `from block ${fromBlock.toString()}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
|
|
430
706
|
const controller = new AbortController();
|
|
431
707
|
process.on("SIGINT", () => {
|
|
432
708
|
controller.abort();
|
|
@@ -434,12 +710,18 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
|
|
|
434
710
|
process.on("SIGTERM", () => {
|
|
435
711
|
controller.abort();
|
|
436
712
|
});
|
|
437
|
-
|
|
713
|
+
const stream = options.all ? fangorn.subscribeApp({
|
|
438
714
|
namespace,
|
|
439
715
|
owner,
|
|
440
716
|
fromBlock,
|
|
441
717
|
signal: controller.signal
|
|
442
|
-
})
|
|
718
|
+
}) : fangorn.subscribe({
|
|
719
|
+
namespace: namespace ?? "",
|
|
720
|
+
owner,
|
|
721
|
+
fromBlock,
|
|
722
|
+
signal: controller.signal
|
|
723
|
+
});
|
|
724
|
+
for await (const change of stream) {
|
|
443
725
|
process.stdout.write(JSON.stringify(change, bigintReplacer, options.pretty ? 2 : 0) + "\n");
|
|
444
726
|
writeCursor(change.blockNumber);
|
|
445
727
|
}
|
package/lib/config.d.ts
CHANGED
|
@@ -5,16 +5,11 @@ import * as abitype0 from "abitype";
|
|
|
5
5
|
|
|
6
6
|
//#region src/config.d.ts
|
|
7
7
|
/**
|
|
8
|
-
* Derive an app id from a human-readable name.
|
|
9
|
-
*
|
|
8
|
+
* Derive an app id from a human-readable name (keccak256(hex(name)).
|
|
9
|
+
* Apps are claim one of these on-chain with `AppRegistry.registerApp`
|
|
10
10
|
*/
|
|
11
11
|
declare function appId(name: string): Hex;
|
|
12
|
-
/** The app every client publishes under until told otherwise. */
|
|
13
12
|
declare const DEFAULT_APP = "fangorn";
|
|
14
|
-
/**
|
|
15
|
-
* Accept either form callers have on hand: a human-readable app name, or an
|
|
16
|
-
* already-derived app id (32-byte hex), which is what an app owner sees on-chain.
|
|
17
|
-
*/
|
|
18
13
|
declare function toAppId(nameOrId: string): Hex;
|
|
19
14
|
/**
|
|
20
15
|
* The networks supproted by Fangorn currently
|
|
@@ -443,13 +438,19 @@ declare function getNetwork(name: string): {
|
|
|
443
438
|
};
|
|
444
439
|
interface AppConfig {
|
|
445
440
|
dataRegistryContractAddress: Hex;
|
|
441
|
+
appRegistryContractAddress: Hex;
|
|
442
|
+
subscriptionRegistryContractAddress: Hex;
|
|
443
|
+
settlementRegistryContractAddress: Hex;
|
|
446
444
|
chain: Chain;
|
|
447
445
|
rpcUrl: string;
|
|
448
446
|
caip2: number;
|
|
449
447
|
ipfsGateway: string;
|
|
450
448
|
}
|
|
451
449
|
declare const FangornConfig: {
|
|
452
|
-
dataRegistryContractAddress: "
|
|
450
|
+
dataRegistryContractAddress: "0x97d63259bd91e386322c12fa7e923e5e1c0ddf91";
|
|
451
|
+
appRegistryContractAddress: "0xeb1309d4607ffbe2051d296de72d3ca4d2795731";
|
|
452
|
+
subscriptionRegistryContractAddress: "0x81681e4f89a24cb46112480f63404fdc35ee4cec";
|
|
453
|
+
settlementRegistryContractAddress: "0x480d54411d77820701fd80f42b81fb6e20176d12";
|
|
453
454
|
chain: {
|
|
454
455
|
blockExplorers: {
|
|
455
456
|
readonly default: {
|
package/lib/config.js
CHANGED
|
@@ -3,18 +3,13 @@ import { arbitrumSepolia, baseSepolia } from "viem/chains";
|
|
|
3
3
|
|
|
4
4
|
//#region src/config.ts
|
|
5
5
|
/**
|
|
6
|
-
* Derive an app id from a human-readable name.
|
|
7
|
-
*
|
|
6
|
+
* Derive an app id from a human-readable name (keccak256(hex(name)).
|
|
7
|
+
* Apps are claim one of these on-chain with `AppRegistry.registerApp`
|
|
8
8
|
*/
|
|
9
9
|
function appId(name) {
|
|
10
10
|
return keccak256(toHex(name));
|
|
11
11
|
}
|
|
12
|
-
/** The app every client publishes under until told otherwise. */
|
|
13
12
|
const DEFAULT_APP = "fangorn";
|
|
14
|
-
/**
|
|
15
|
-
* Accept either form callers have on hand: a human-readable app name, or an
|
|
16
|
-
* already-derived app id (32-byte hex), which is what an app owner sees on-chain.
|
|
17
|
-
*/
|
|
18
13
|
function toAppId(nameOrId) {
|
|
19
14
|
return /^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : appId(nameOrId);
|
|
20
15
|
}
|
|
@@ -41,7 +36,10 @@ function getNetwork(name) {
|
|
|
41
36
|
throw new Error(`Chain ${name} is not supported`);
|
|
42
37
|
}
|
|
43
38
|
const FangornConfig = {
|
|
44
|
-
dataRegistryContractAddress: "
|
|
39
|
+
dataRegistryContractAddress: "0x97d63259bd91e386322c12fa7e923e5e1c0ddf91",
|
|
40
|
+
appRegistryContractAddress: "0xeb1309d4607ffbe2051d296de72d3ca4d2795731",
|
|
41
|
+
subscriptionRegistryContractAddress: "0x81681e4f89a24cb46112480f63404fdc35ee4cec",
|
|
42
|
+
settlementRegistryContractAddress: "0x480d54411d77820701fd80f42b81fb6e20176d12",
|
|
45
43
|
chain: arbitrumSepolia,
|
|
46
44
|
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
47
45
|
caip2: 421614,
|