@fangorn-network/sdk 2026.8.12-dev → 2026.9.22-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 (40) hide show
  1. package/README.md +175 -62
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +348 -17
  4. package/lib/cli/index.d.ts +13 -13
  5. package/lib/config.d.ts +28 -352
  6. package/lib/config.js +11 -20
  7. package/lib/contracts/app-registry/abi.d.ts +509 -0
  8. package/lib/contracts/app-registry/abi.js +575 -0
  9. package/lib/contracts/app-registry/index.d.ts +120 -0
  10. package/lib/contracts/app-registry/index.js +266 -0
  11. package/lib/contracts/data-registry/abi.d.ts +124 -125
  12. package/lib/contracts/data-registry/abi.js +145 -142
  13. package/lib/contracts/data-registry/index.d.ts +20 -27
  14. package/lib/contracts/data-registry/index.js +32 -78
  15. package/lib/contracts/index.d.ts +8 -3
  16. package/lib/contracts/index.js +8 -3
  17. package/lib/contracts/logs.d.ts +18 -0
  18. package/lib/contracts/logs.js +25 -0
  19. package/lib/contracts/settlement-registry/abi.d.ts +430 -11
  20. package/lib/contracts/settlement-registry/abi.js +528 -41
  21. package/lib/contracts/settlement-registry/index.d.ts +148 -10
  22. package/lib/contracts/settlement-registry/index.js +233 -9
  23. package/lib/contracts/subscription-registry/abi.d.ts +179 -0
  24. package/lib/contracts/subscription-registry/abi.js +195 -0
  25. package/lib/contracts/subscription-registry/index.d.ts +59 -0
  26. package/lib/contracts/subscription-registry/index.js +116 -0
  27. package/lib/contracts/types.d.ts +8 -0
  28. package/lib/contracts/types.js +10 -0
  29. package/lib/contracts/write.d.ts +27 -0
  30. package/lib/contracts/write.js +55 -0
  31. package/lib/crypto/encryption.js +4 -4
  32. package/lib/engine/index.d.ts +14 -12
  33. package/lib/engine/index.js +13 -7
  34. package/lib/fangorn.d.ts +71 -6
  35. package/lib/fangorn.js +86 -7
  36. package/lib/index.d.ts +9 -4
  37. package/lib/index.js +9 -4
  38. package/lib/test/testbed.js +9 -3
  39. package/lib/types/index.d.ts +6 -0
  40. package/package.json +73 -85
@@ -0,0 +1,575 @@
1
+ //#region src/contracts/app-registry/abi.ts
2
+ const APP_REGISTRY_ABI = [
3
+ {
4
+ "inputs": [],
5
+ "name": "AlreadyRegistered",
6
+ "type": "error"
7
+ },
8
+ {
9
+ "inputs": [],
10
+ "name": "AppAlreadyRegistered",
11
+ "type": "error"
12
+ },
13
+ {
14
+ "inputs": [],
15
+ "name": "AppNotFound",
16
+ "type": "error"
17
+ },
18
+ {
19
+ "inputs": [],
20
+ "name": "AppSuspendedErr",
21
+ "type": "error"
22
+ },
23
+ {
24
+ "inputs": [],
25
+ "name": "JoinFeeRequired",
26
+ "type": "error"
27
+ },
28
+ {
29
+ "inputs": [],
30
+ "name": "NotRegistered",
31
+ "type": "error"
32
+ },
33
+ {
34
+ "inputs": [],
35
+ "name": "PublisherSuspendedErr",
36
+ "type": "error"
37
+ },
38
+ {
39
+ "inputs": [],
40
+ "name": "TermsMismatch",
41
+ "type": "error"
42
+ },
43
+ {
44
+ "inputs": [],
45
+ "name": "TermsNotSet",
46
+ "type": "error"
47
+ },
48
+ {
49
+ "inputs": [],
50
+ "name": "TransferFailed",
51
+ "type": "error"
52
+ },
53
+ {
54
+ "inputs": [],
55
+ "name": "Unauthorized",
56
+ "type": "error"
57
+ },
58
+ {
59
+ "inputs": [{
60
+ "internalType": "bytes32",
61
+ "name": "app_id",
62
+ "type": "bytes32"
63
+ }, {
64
+ "internalType": "address",
65
+ "name": "publisher",
66
+ "type": "address"
67
+ }],
68
+ "name": "acceptedTerms",
69
+ "outputs": [{
70
+ "internalType": "bytes32",
71
+ "name": "",
72
+ "type": "bytes32"
73
+ }],
74
+ "stateMutability": "view",
75
+ "type": "function"
76
+ },
77
+ {
78
+ "inputs": [],
79
+ "name": "admin",
80
+ "outputs": [{
81
+ "internalType": "address",
82
+ "name": "",
83
+ "type": "address"
84
+ }],
85
+ "stateMutability": "view",
86
+ "type": "function"
87
+ },
88
+ {
89
+ "inputs": [{
90
+ "internalType": "bytes32",
91
+ "name": "app_id",
92
+ "type": "bytes32"
93
+ }],
94
+ "name": "appFee",
95
+ "outputs": [{
96
+ "internalType": "uint256",
97
+ "name": "",
98
+ "type": "uint256"
99
+ }],
100
+ "stateMutability": "view",
101
+ "type": "function"
102
+ },
103
+ {
104
+ "inputs": [{
105
+ "internalType": "bytes32",
106
+ "name": "app_id",
107
+ "type": "bytes32"
108
+ }],
109
+ "name": "appTerms",
110
+ "outputs": [{
111
+ "internalType": "bytes32",
112
+ "name": "",
113
+ "type": "bytes32"
114
+ }],
115
+ "stateMutability": "view",
116
+ "type": "function"
117
+ },
118
+ {
119
+ "inputs": [{
120
+ "internalType": "bytes32",
121
+ "name": "app_id",
122
+ "type": "bytes32"
123
+ }],
124
+ "name": "appAgentUri",
125
+ "outputs": [{
126
+ "internalType": "string",
127
+ "name": "",
128
+ "type": "string"
129
+ }],
130
+ "stateMutability": "view",
131
+ "type": "function"
132
+ },
133
+ {
134
+ "inputs": [{
135
+ "internalType": "bytes32",
136
+ "name": "app_id",
137
+ "type": "bytes32"
138
+ }],
139
+ "name": "appTermsUri",
140
+ "outputs": [{
141
+ "internalType": "string",
142
+ "name": "",
143
+ "type": "string"
144
+ }],
145
+ "stateMutability": "view",
146
+ "type": "function"
147
+ },
148
+ {
149
+ "inputs": [{
150
+ "internalType": "bytes32",
151
+ "name": "app_id",
152
+ "type": "bytes32"
153
+ }],
154
+ "name": "getAppOwner",
155
+ "outputs": [{
156
+ "internalType": "address",
157
+ "name": "",
158
+ "type": "address"
159
+ }],
160
+ "stateMutability": "view",
161
+ "type": "function"
162
+ },
163
+ {
164
+ "inputs": [{
165
+ "internalType": "bytes32",
166
+ "name": "app_id",
167
+ "type": "bytes32"
168
+ }],
169
+ "name": "isAppSuspended",
170
+ "outputs": [{
171
+ "internalType": "bool",
172
+ "name": "",
173
+ "type": "bool"
174
+ }],
175
+ "stateMutability": "view",
176
+ "type": "function"
177
+ },
178
+ {
179
+ "inputs": [{
180
+ "internalType": "bytes32",
181
+ "name": "app_id",
182
+ "type": "bytes32"
183
+ }, {
184
+ "internalType": "address",
185
+ "name": "publisher",
186
+ "type": "address"
187
+ }],
188
+ "name": "isRegisteredForApp",
189
+ "outputs": [{
190
+ "internalType": "bool",
191
+ "name": "",
192
+ "type": "bool"
193
+ }],
194
+ "stateMutability": "view",
195
+ "type": "function"
196
+ },
197
+ {
198
+ "inputs": [{
199
+ "internalType": "bytes32",
200
+ "name": "app_id",
201
+ "type": "bytes32"
202
+ }, {
203
+ "internalType": "address",
204
+ "name": "publisher",
205
+ "type": "address"
206
+ }],
207
+ "name": "joinInfo",
208
+ "outputs": [
209
+ {
210
+ "internalType": "bytes32",
211
+ "name": "",
212
+ "type": "bytes32"
213
+ },
214
+ {
215
+ "internalType": "string",
216
+ "name": "",
217
+ "type": "string"
218
+ },
219
+ {
220
+ "internalType": "uint256",
221
+ "name": "",
222
+ "type": "uint256"
223
+ },
224
+ {
225
+ "internalType": "uint8",
226
+ "name": "",
227
+ "type": "uint8"
228
+ },
229
+ {
230
+ "internalType": "bool",
231
+ "name": "",
232
+ "type": "bool"
233
+ }
234
+ ],
235
+ "stateMutability": "view",
236
+ "type": "function"
237
+ },
238
+ {
239
+ "inputs": [
240
+ {
241
+ "internalType": "bytes32",
242
+ "name": "app_id",
243
+ "type": "bytes32"
244
+ },
245
+ {
246
+ "internalType": "bytes32",
247
+ "name": "terms_hash",
248
+ "type": "bytes32"
249
+ },
250
+ {
251
+ "internalType": "string",
252
+ "name": "terms_uri",
253
+ "type": "string"
254
+ },
255
+ {
256
+ "internalType": "uint256",
257
+ "name": "fee",
258
+ "type": "uint256"
259
+ }
260
+ ],
261
+ "name": "registerApp",
262
+ "outputs": [],
263
+ "stateMutability": "nonpayable",
264
+ "type": "function"
265
+ },
266
+ {
267
+ "inputs": [{
268
+ "internalType": "bytes32",
269
+ "name": "app_id",
270
+ "type": "bytes32"
271
+ }, {
272
+ "internalType": "bytes32",
273
+ "name": "terms_hash",
274
+ "type": "bytes32"
275
+ }],
276
+ "name": "registerForApp",
277
+ "outputs": [],
278
+ "stateMutability": "payable",
279
+ "type": "function"
280
+ },
281
+ {
282
+ "inputs": [{
283
+ "internalType": "bytes32",
284
+ "name": "app_id",
285
+ "type": "bytes32"
286
+ }, {
287
+ "internalType": "address",
288
+ "name": "publisher",
289
+ "type": "address"
290
+ }],
291
+ "name": "reinstateForApp",
292
+ "outputs": [],
293
+ "stateMutability": "nonpayable",
294
+ "type": "function"
295
+ },
296
+ {
297
+ "inputs": [{
298
+ "internalType": "bytes32",
299
+ "name": "app_id",
300
+ "type": "bytes32"
301
+ }],
302
+ "name": "reinstateApp",
303
+ "outputs": [],
304
+ "stateMutability": "nonpayable",
305
+ "type": "function"
306
+ },
307
+ {
308
+ "inputs": [{
309
+ "internalType": "bytes32",
310
+ "name": "app_id",
311
+ "type": "bytes32"
312
+ }],
313
+ "name": "suspendApp",
314
+ "outputs": [],
315
+ "stateMutability": "nonpayable",
316
+ "type": "function"
317
+ },
318
+ {
319
+ "inputs": [{
320
+ "internalType": "bytes32",
321
+ "name": "app_id",
322
+ "type": "bytes32"
323
+ }, {
324
+ "internalType": "uint256",
325
+ "name": "fee",
326
+ "type": "uint256"
327
+ }],
328
+ "name": "setAppFee",
329
+ "outputs": [],
330
+ "stateMutability": "nonpayable",
331
+ "type": "function"
332
+ },
333
+ {
334
+ "inputs": [{
335
+ "internalType": "bytes32",
336
+ "name": "app_id",
337
+ "type": "bytes32"
338
+ }, {
339
+ "internalType": "string",
340
+ "name": "agent_uri",
341
+ "type": "string"
342
+ }],
343
+ "name": "setAppAgentUri",
344
+ "outputs": [],
345
+ "stateMutability": "nonpayable",
346
+ "type": "function"
347
+ },
348
+ {
349
+ "inputs": [
350
+ {
351
+ "internalType": "bytes32",
352
+ "name": "app_id",
353
+ "type": "bytes32"
354
+ },
355
+ {
356
+ "internalType": "bytes32",
357
+ "name": "terms_hash",
358
+ "type": "bytes32"
359
+ },
360
+ {
361
+ "internalType": "string",
362
+ "name": "terms_uri",
363
+ "type": "string"
364
+ }
365
+ ],
366
+ "name": "setAppTerms",
367
+ "outputs": [],
368
+ "stateMutability": "nonpayable",
369
+ "type": "function"
370
+ },
371
+ {
372
+ "inputs": [{
373
+ "internalType": "bytes32",
374
+ "name": "app_id",
375
+ "type": "bytes32"
376
+ }, {
377
+ "internalType": "address",
378
+ "name": "publisher",
379
+ "type": "address"
380
+ }],
381
+ "name": "statusForApp",
382
+ "outputs": [{
383
+ "internalType": "uint8",
384
+ "name": "",
385
+ "type": "uint8"
386
+ }],
387
+ "stateMutability": "view",
388
+ "type": "function"
389
+ },
390
+ {
391
+ "inputs": [{
392
+ "internalType": "bytes32",
393
+ "name": "app_id",
394
+ "type": "bytes32"
395
+ }, {
396
+ "internalType": "address",
397
+ "name": "publisher",
398
+ "type": "address"
399
+ }],
400
+ "name": "suspendForApp",
401
+ "outputs": [],
402
+ "stateMutability": "nonpayable",
403
+ "type": "function"
404
+ },
405
+ {
406
+ "inputs": [{
407
+ "internalType": "address",
408
+ "name": "to",
409
+ "type": "address"
410
+ }, {
411
+ "internalType": "uint256",
412
+ "name": "amount",
413
+ "type": "uint256"
414
+ }],
415
+ "name": "withdrawEth",
416
+ "outputs": [],
417
+ "stateMutability": "nonpayable",
418
+ "type": "function"
419
+ },
420
+ {
421
+ "anonymous": false,
422
+ "inputs": [{
423
+ "indexed": true,
424
+ "internalType": "bytes32",
425
+ "name": "app_id",
426
+ "type": "bytes32"
427
+ }, {
428
+ "indexed": true,
429
+ "internalType": "address",
430
+ "name": "owner",
431
+ "type": "address"
432
+ }],
433
+ "name": "AppRegistered",
434
+ "type": "event"
435
+ },
436
+ {
437
+ "anonymous": false,
438
+ "inputs": [
439
+ {
440
+ "indexed": true,
441
+ "internalType": "bytes32",
442
+ "name": "app_id",
443
+ "type": "bytes32"
444
+ },
445
+ {
446
+ "indexed": false,
447
+ "internalType": "bytes32",
448
+ "name": "terms_hash",
449
+ "type": "bytes32"
450
+ },
451
+ {
452
+ "indexed": false,
453
+ "internalType": "string",
454
+ "name": "terms_uri",
455
+ "type": "string"
456
+ }
457
+ ],
458
+ "name": "AppTermsChanged",
459
+ "type": "event"
460
+ },
461
+ {
462
+ "anonymous": false,
463
+ "inputs": [{
464
+ "indexed": true,
465
+ "internalType": "bytes32",
466
+ "name": "app_id",
467
+ "type": "bytes32"
468
+ }, {
469
+ "indexed": false,
470
+ "internalType": "uint256",
471
+ "name": "fee",
472
+ "type": "uint256"
473
+ }],
474
+ "name": "AppFeeChanged",
475
+ "type": "event"
476
+ },
477
+ {
478
+ "anonymous": false,
479
+ "inputs": [{
480
+ "indexed": true,
481
+ "internalType": "bytes32",
482
+ "name": "app_id",
483
+ "type": "bytes32"
484
+ }, {
485
+ "indexed": false,
486
+ "internalType": "string",
487
+ "name": "agent_uri",
488
+ "type": "string"
489
+ }],
490
+ "name": "AppAgentChanged",
491
+ "type": "event"
492
+ },
493
+ {
494
+ "anonymous": false,
495
+ "inputs": [
496
+ {
497
+ "indexed": true,
498
+ "internalType": "bytes32",
499
+ "name": "app_id",
500
+ "type": "bytes32"
501
+ },
502
+ {
503
+ "indexed": true,
504
+ "internalType": "address",
505
+ "name": "publisher",
506
+ "type": "address"
507
+ },
508
+ {
509
+ "indexed": false,
510
+ "internalType": "bytes32",
511
+ "name": "terms_hash",
512
+ "type": "bytes32"
513
+ },
514
+ {
515
+ "indexed": false,
516
+ "internalType": "uint256",
517
+ "name": "fee",
518
+ "type": "uint256"
519
+ }
520
+ ],
521
+ "name": "PublisherJoined",
522
+ "type": "event"
523
+ },
524
+ {
525
+ "anonymous": false,
526
+ "inputs": [{
527
+ "indexed": true,
528
+ "internalType": "bytes32",
529
+ "name": "app_id",
530
+ "type": "bytes32"
531
+ }, {
532
+ "indexed": true,
533
+ "internalType": "address",
534
+ "name": "publisher",
535
+ "type": "address"
536
+ }],
537
+ "name": "PublisherSuspendedForApp",
538
+ "type": "event"
539
+ },
540
+ {
541
+ "anonymous": false,
542
+ "inputs": [{
543
+ "indexed": true,
544
+ "internalType": "bytes32",
545
+ "name": "app_id",
546
+ "type": "bytes32"
547
+ }, {
548
+ "indexed": true,
549
+ "internalType": "address",
550
+ "name": "publisher",
551
+ "type": "address"
552
+ }],
553
+ "name": "PublisherReinstatedForApp",
554
+ "type": "event"
555
+ },
556
+ {
557
+ "anonymous": false,
558
+ "inputs": [{
559
+ "indexed": true,
560
+ "internalType": "bytes32",
561
+ "name": "app_id",
562
+ "type": "bytes32"
563
+ }, {
564
+ "indexed": false,
565
+ "internalType": "bool",
566
+ "name": "suspended",
567
+ "type": "bool"
568
+ }],
569
+ "name": "AppSuspensionChanged",
570
+ "type": "event"
571
+ }
572
+ ];
573
+
574
+ //#endregion
575
+ export { APP_REGISTRY_ABI };
@@ -0,0 +1,120 @@
1
+ import { PublisherStatus } from "../types.js";
2
+ import { PreparedTx } from "../data-registry/index.js";
3
+ import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
4
+
5
+ //#region src/contracts/app-registry/index.d.ts
6
+
7
+ /**
8
+ * The information required of a publisher in order to join an app
9
+ */
10
+ interface AppJoinInfo {
11
+ /** The app's terms hash (zero means no terms); e.g. an IPFS cid */
12
+ termsHash: Hex;
13
+ /** A uri pointing to the terms: e.g. an IPFS gateway+CID */
14
+ termsUri: string;
15
+ /** publisher defined joiners fee */
16
+ fee: bigint;
17
+ /** app publisher status (active, unregistered, suspended) */
18
+ status: PublisherStatus;
19
+ /** Active AND up-to-date with term agreements */
20
+ registered: boolean;
21
+ /** The terms hash this publisher actually accepted, or zero. */
22
+ acceptedTerms: Hex;
23
+ /** The protocol admin has taken the whole app down — nobody is registered. */
24
+ appSuspended: boolean;
25
+ }
26
+ /** One `AppAgentChanged` event: an app owner pointed their app at a card. */
27
+ interface AppAgentLog {
28
+ appId: Hex;
29
+ agentUri: string;
30
+ blockNumber: bigint;
31
+ transactionHash: Hash;
32
+ }
33
+ /** True when the publisher joined but the app's terms have since changed. */
34
+ declare function needsReacceptance(info: AppJoinInfo): boolean;
35
+ /**
36
+ * Client for the AppRegistry
37
+ */
38
+ declare class AppRegistryClient {
39
+ private contractAddress;
40
+ private appId;
41
+ private publicClient;
42
+ private walletClient;
43
+ constructor(contractAddress: Address, appId: Hex, publicClient: PublicClient, walletClient: WalletClient);
44
+ getAppId(): Hex;
45
+ setAppId(appId: Hex): void;
46
+ getAddress(): Address;
47
+ private executeWrite;
48
+ /**
49
+ * try to register an app (if it has not been claimed)
50
+ */
51
+ registerApp(termsHash: Hex, termsUri: string, fee?: bigint): Promise<Hash>;
52
+ /**
53
+ * Publish new terms for this app.
54
+ *
55
+ * Every registered must accept the new terms in order to publish again
56
+ */
57
+ setAppTerms(termsHash: Hex, termsUri: string): Promise<Hash>;
58
+ /**
59
+ * Point this app at its ERC-8004 agent card.
60
+ *
61
+ * Safe to call whenever the card moves. It is a separate field from the terms
62
+ * URI for one reason: publishers are bound to `termsHash`, so anything sharing
63
+ * that slot unregisters every publisher in the app the moment it changes (see
64
+ * `needsReacceptance`). A card holds endpoints and pubkeys, which rotate.
65
+ */
66
+ setAppAgentUri(agentUri: string): Promise<Hash>;
67
+ setAppFee(fee: bigint): Promise<Hash>;
68
+ /**
69
+ * Suspend a publisher from this app
70
+ * only callable by the app owner
71
+ */
72
+ suspendForApp(publisher: Address): Promise<Hash>;
73
+ reinstateForApp(publisher: Address): Promise<Hash>;
74
+ /**
75
+ * Suspend an app and all publish capabilities
76
+ */
77
+ suspendApp(): Promise<Hash>;
78
+ reinstateApp(): Promise<Hash>;
79
+ admin(): Promise<Address>;
80
+ /**
81
+ * Register as a publisher within an app
82
+ * Registration = accepting its current terms
83
+ */
84
+ registerForApp(): Promise<Hash>;
85
+ /**
86
+ * prepare the tx to register as a publisher for an app
87
+ */
88
+ prepareRegisterForApp(publisher: Address): Promise<PreparedTx & {
89
+ value: Hex;
90
+ }>;
91
+ getAppOwner(): Promise<Address>;
92
+ isRegisteredForApp(publisher: Address): Promise<boolean>;
93
+ isAppSuspended(): Promise<boolean>;
94
+ appTerms(): Promise<Hex>;
95
+ appTermsUri(): Promise<string>;
96
+ /** The agent card URI of this app, or of `appId`. Empty if none is set. */
97
+ appAgentUri(appId?: Hex): Promise<string>;
98
+ /**
99
+ * `AppAgentChanged` events, oldest first. The last one for an app is its
100
+ * current card; an empty `agentUri` means the owner unset it.
101
+ *
102
+ * Leave `appId` out to list every app that has ever set a card. The chain is
103
+ * the directory: one windowed log scan, no indexer and no registry namespace.
104
+ * `fromBlock` is required because scanning from genesis on an L2 costs
105
+ * hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
106
+ * a block you know to be before the app's registration.
107
+ */
108
+ getAppAgentLogs(opts: {
109
+ appId?: Hex;
110
+ fromBlock: bigint;
111
+ toBlock?: bigint;
112
+ }): Promise<AppAgentLog[]>;
113
+ appFee(): Promise<bigint>;
114
+ acceptedTerms(publisher: Address): Promise<Hex>;
115
+ joinInfo(publisher: Address): Promise<AppJoinInfo>;
116
+ private readJoinInfoTuple;
117
+ private senderAddress;
118
+ }
119
+ //#endregion
120
+ export { AppAgentLog, AppJoinInfo, AppRegistryClient, needsReacceptance };