@fangorn-network/sdk 2026.8.12-dev → 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.
Files changed (37) hide show
  1. package/README.md +175 -62
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +290 -17
  4. package/lib/config.d.ts +9 -8
  5. package/lib/config.js +6 -8
  6. package/lib/contracts/app-registry/abi.d.ts +466 -0
  7. package/lib/contracts/app-registry/abi.js +529 -0
  8. package/lib/contracts/app-registry/index.d.ts +139 -0
  9. package/lib/contracts/app-registry/index.js +271 -0
  10. package/lib/contracts/data-registry/abi.d.ts +124 -125
  11. package/lib/contracts/data-registry/abi.js +145 -142
  12. package/lib/contracts/data-registry/index.d.ts +16 -14
  13. package/lib/contracts/data-registry/index.js +19 -50
  14. package/lib/contracts/index.d.ts +8 -3
  15. package/lib/contracts/index.js +8 -3
  16. package/lib/contracts/settlement-registry/abi.d.ts +430 -11
  17. package/lib/contracts/settlement-registry/abi.js +528 -41
  18. package/lib/contracts/settlement-registry/index.d.ts +148 -10
  19. package/lib/contracts/settlement-registry/index.js +233 -9
  20. package/lib/contracts/subscription-registry/abi.d.ts +179 -0
  21. package/lib/contracts/subscription-registry/abi.js +195 -0
  22. package/lib/contracts/subscription-registry/index.d.ts +59 -0
  23. package/lib/contracts/subscription-registry/index.js +116 -0
  24. package/lib/contracts/types.d.ts +8 -0
  25. package/lib/contracts/types.js +10 -0
  26. package/lib/contracts/write.d.ts +27 -0
  27. package/lib/contracts/write.js +55 -0
  28. package/lib/crypto/encryption.js +4 -4
  29. package/lib/engine/index.d.ts +14 -12
  30. package/lib/engine/index.js +13 -7
  31. package/lib/fangorn.d.ts +35 -5
  32. package/lib/fangorn.js +49 -6
  33. package/lib/index.d.ts +8 -3
  34. package/lib/index.js +8 -3
  35. package/lib/test/testbed.js +9 -3
  36. package/lib/types/index.d.ts +6 -0
  37. package/package.json +72 -85
@@ -0,0 +1,529 @@
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": "appTermsUri",
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": "getAppOwner",
140
+ "outputs": [{
141
+ "internalType": "address",
142
+ "name": "",
143
+ "type": "address"
144
+ }],
145
+ "stateMutability": "view",
146
+ "type": "function"
147
+ },
148
+ {
149
+ "inputs": [{
150
+ "internalType": "bytes32",
151
+ "name": "app_id",
152
+ "type": "bytes32"
153
+ }],
154
+ "name": "isAppSuspended",
155
+ "outputs": [{
156
+ "internalType": "bool",
157
+ "name": "",
158
+ "type": "bool"
159
+ }],
160
+ "stateMutability": "view",
161
+ "type": "function"
162
+ },
163
+ {
164
+ "inputs": [{
165
+ "internalType": "bytes32",
166
+ "name": "app_id",
167
+ "type": "bytes32"
168
+ }, {
169
+ "internalType": "address",
170
+ "name": "publisher",
171
+ "type": "address"
172
+ }],
173
+ "name": "isRegisteredForApp",
174
+ "outputs": [{
175
+ "internalType": "bool",
176
+ "name": "",
177
+ "type": "bool"
178
+ }],
179
+ "stateMutability": "view",
180
+ "type": "function"
181
+ },
182
+ {
183
+ "inputs": [{
184
+ "internalType": "bytes32",
185
+ "name": "app_id",
186
+ "type": "bytes32"
187
+ }, {
188
+ "internalType": "address",
189
+ "name": "publisher",
190
+ "type": "address"
191
+ }],
192
+ "name": "joinInfo",
193
+ "outputs": [
194
+ {
195
+ "internalType": "bytes32",
196
+ "name": "",
197
+ "type": "bytes32"
198
+ },
199
+ {
200
+ "internalType": "string",
201
+ "name": "",
202
+ "type": "string"
203
+ },
204
+ {
205
+ "internalType": "uint256",
206
+ "name": "",
207
+ "type": "uint256"
208
+ },
209
+ {
210
+ "internalType": "uint8",
211
+ "name": "",
212
+ "type": "uint8"
213
+ },
214
+ {
215
+ "internalType": "bool",
216
+ "name": "",
217
+ "type": "bool"
218
+ }
219
+ ],
220
+ "stateMutability": "view",
221
+ "type": "function"
222
+ },
223
+ {
224
+ "inputs": [
225
+ {
226
+ "internalType": "bytes32",
227
+ "name": "app_id",
228
+ "type": "bytes32"
229
+ },
230
+ {
231
+ "internalType": "bytes32",
232
+ "name": "terms_hash",
233
+ "type": "bytes32"
234
+ },
235
+ {
236
+ "internalType": "string",
237
+ "name": "terms_uri",
238
+ "type": "string"
239
+ },
240
+ {
241
+ "internalType": "uint256",
242
+ "name": "fee",
243
+ "type": "uint256"
244
+ }
245
+ ],
246
+ "name": "registerApp",
247
+ "outputs": [],
248
+ "stateMutability": "nonpayable",
249
+ "type": "function"
250
+ },
251
+ {
252
+ "inputs": [{
253
+ "internalType": "bytes32",
254
+ "name": "app_id",
255
+ "type": "bytes32"
256
+ }, {
257
+ "internalType": "bytes32",
258
+ "name": "terms_hash",
259
+ "type": "bytes32"
260
+ }],
261
+ "name": "registerForApp",
262
+ "outputs": [],
263
+ "stateMutability": "payable",
264
+ "type": "function"
265
+ },
266
+ {
267
+ "inputs": [{
268
+ "internalType": "bytes32",
269
+ "name": "app_id",
270
+ "type": "bytes32"
271
+ }, {
272
+ "internalType": "address",
273
+ "name": "publisher",
274
+ "type": "address"
275
+ }],
276
+ "name": "reinstateForApp",
277
+ "outputs": [],
278
+ "stateMutability": "nonpayable",
279
+ "type": "function"
280
+ },
281
+ {
282
+ "inputs": [{
283
+ "internalType": "bytes32",
284
+ "name": "app_id",
285
+ "type": "bytes32"
286
+ }],
287
+ "name": "reinstateApp",
288
+ "outputs": [],
289
+ "stateMutability": "nonpayable",
290
+ "type": "function"
291
+ },
292
+ {
293
+ "inputs": [{
294
+ "internalType": "bytes32",
295
+ "name": "app_id",
296
+ "type": "bytes32"
297
+ }],
298
+ "name": "suspendApp",
299
+ "outputs": [],
300
+ "stateMutability": "nonpayable",
301
+ "type": "function"
302
+ },
303
+ {
304
+ "inputs": [{
305
+ "internalType": "bytes32",
306
+ "name": "app_id",
307
+ "type": "bytes32"
308
+ }, {
309
+ "internalType": "uint256",
310
+ "name": "fee",
311
+ "type": "uint256"
312
+ }],
313
+ "name": "setAppFee",
314
+ "outputs": [],
315
+ "stateMutability": "nonpayable",
316
+ "type": "function"
317
+ },
318
+ {
319
+ "inputs": [
320
+ {
321
+ "internalType": "bytes32",
322
+ "name": "app_id",
323
+ "type": "bytes32"
324
+ },
325
+ {
326
+ "internalType": "bytes32",
327
+ "name": "terms_hash",
328
+ "type": "bytes32"
329
+ },
330
+ {
331
+ "internalType": "string",
332
+ "name": "terms_uri",
333
+ "type": "string"
334
+ }
335
+ ],
336
+ "name": "setAppTerms",
337
+ "outputs": [],
338
+ "stateMutability": "nonpayable",
339
+ "type": "function"
340
+ },
341
+ {
342
+ "inputs": [{
343
+ "internalType": "bytes32",
344
+ "name": "app_id",
345
+ "type": "bytes32"
346
+ }, {
347
+ "internalType": "address",
348
+ "name": "publisher",
349
+ "type": "address"
350
+ }],
351
+ "name": "statusForApp",
352
+ "outputs": [{
353
+ "internalType": "uint8",
354
+ "name": "",
355
+ "type": "uint8"
356
+ }],
357
+ "stateMutability": "view",
358
+ "type": "function"
359
+ },
360
+ {
361
+ "inputs": [{
362
+ "internalType": "bytes32",
363
+ "name": "app_id",
364
+ "type": "bytes32"
365
+ }, {
366
+ "internalType": "address",
367
+ "name": "publisher",
368
+ "type": "address"
369
+ }],
370
+ "name": "suspendForApp",
371
+ "outputs": [],
372
+ "stateMutability": "nonpayable",
373
+ "type": "function"
374
+ },
375
+ {
376
+ "inputs": [{
377
+ "internalType": "address",
378
+ "name": "to",
379
+ "type": "address"
380
+ }, {
381
+ "internalType": "uint256",
382
+ "name": "amount",
383
+ "type": "uint256"
384
+ }],
385
+ "name": "withdrawEth",
386
+ "outputs": [],
387
+ "stateMutability": "nonpayable",
388
+ "type": "function"
389
+ },
390
+ {
391
+ "anonymous": false,
392
+ "inputs": [{
393
+ "indexed": true,
394
+ "internalType": "bytes32",
395
+ "name": "app_id",
396
+ "type": "bytes32"
397
+ }, {
398
+ "indexed": true,
399
+ "internalType": "address",
400
+ "name": "owner",
401
+ "type": "address"
402
+ }],
403
+ "name": "AppRegistered",
404
+ "type": "event"
405
+ },
406
+ {
407
+ "anonymous": false,
408
+ "inputs": [
409
+ {
410
+ "indexed": true,
411
+ "internalType": "bytes32",
412
+ "name": "app_id",
413
+ "type": "bytes32"
414
+ },
415
+ {
416
+ "indexed": false,
417
+ "internalType": "bytes32",
418
+ "name": "terms_hash",
419
+ "type": "bytes32"
420
+ },
421
+ {
422
+ "indexed": false,
423
+ "internalType": "string",
424
+ "name": "terms_uri",
425
+ "type": "string"
426
+ }
427
+ ],
428
+ "name": "AppTermsChanged",
429
+ "type": "event"
430
+ },
431
+ {
432
+ "anonymous": false,
433
+ "inputs": [{
434
+ "indexed": true,
435
+ "internalType": "bytes32",
436
+ "name": "app_id",
437
+ "type": "bytes32"
438
+ }, {
439
+ "indexed": false,
440
+ "internalType": "uint256",
441
+ "name": "fee",
442
+ "type": "uint256"
443
+ }],
444
+ "name": "AppFeeChanged",
445
+ "type": "event"
446
+ },
447
+ {
448
+ "anonymous": false,
449
+ "inputs": [
450
+ {
451
+ "indexed": true,
452
+ "internalType": "bytes32",
453
+ "name": "app_id",
454
+ "type": "bytes32"
455
+ },
456
+ {
457
+ "indexed": true,
458
+ "internalType": "address",
459
+ "name": "publisher",
460
+ "type": "address"
461
+ },
462
+ {
463
+ "indexed": false,
464
+ "internalType": "bytes32",
465
+ "name": "terms_hash",
466
+ "type": "bytes32"
467
+ },
468
+ {
469
+ "indexed": false,
470
+ "internalType": "uint256",
471
+ "name": "fee",
472
+ "type": "uint256"
473
+ }
474
+ ],
475
+ "name": "PublisherJoined",
476
+ "type": "event"
477
+ },
478
+ {
479
+ "anonymous": false,
480
+ "inputs": [{
481
+ "indexed": true,
482
+ "internalType": "bytes32",
483
+ "name": "app_id",
484
+ "type": "bytes32"
485
+ }, {
486
+ "indexed": true,
487
+ "internalType": "address",
488
+ "name": "publisher",
489
+ "type": "address"
490
+ }],
491
+ "name": "PublisherSuspendedForApp",
492
+ "type": "event"
493
+ },
494
+ {
495
+ "anonymous": false,
496
+ "inputs": [{
497
+ "indexed": true,
498
+ "internalType": "bytes32",
499
+ "name": "app_id",
500
+ "type": "bytes32"
501
+ }, {
502
+ "indexed": true,
503
+ "internalType": "address",
504
+ "name": "publisher",
505
+ "type": "address"
506
+ }],
507
+ "name": "PublisherReinstatedForApp",
508
+ "type": "event"
509
+ },
510
+ {
511
+ "anonymous": false,
512
+ "inputs": [{
513
+ "indexed": true,
514
+ "internalType": "bytes32",
515
+ "name": "app_id",
516
+ "type": "bytes32"
517
+ }, {
518
+ "indexed": false,
519
+ "internalType": "bool",
520
+ "name": "suspended",
521
+ "type": "bool"
522
+ }],
523
+ "name": "AppSuspensionChanged",
524
+ "type": "event"
525
+ }
526
+ ];
527
+
528
+ //#endregion
529
+ export { APP_REGISTRY_ABI };
@@ -0,0 +1,139 @@
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
+ /** True when the publisher joined but the app's terms have since changed. */
27
+ declare function needsReacceptance(info: AppJoinInfo): boolean;
28
+ /**
29
+ * Client for the AppRegistry — app ids, per-app publisher terms, per-app join
30
+ * fees, and per-app membership.
31
+ *
32
+ * This contract owns what an "app" is. `registerApp` and `getAppOwner` used to
33
+ * live on the DataRegistry, which meant two contracts held partial opinions about
34
+ * apps and neither could enforce membership. The dependency now runs one way:
35
+ * `DataRegistry.commitStateRoot` cross-calls `isRegisteredForApp` here, so a
36
+ * publisher must join an app *before* they can write under it.
37
+ *
38
+ * Scoped to one `appId`, like `DataRegistryClient` — the app is an identity the
39
+ * client carries, not an argument every call repeats.
40
+ */
41
+ declare class AppRegistryClient {
42
+ private contractAddress;
43
+ private appId;
44
+ private publicClient;
45
+ private walletClient;
46
+ constructor(contractAddress: Address, appId: Hex, publicClient: PublicClient, walletClient: WalletClient);
47
+ /** The app every call on this client is scoped to. */
48
+ getAppId(): Hex;
49
+ /** Re-scope every subsequent call to a different app. */
50
+ setAppId(appId: Hex): void;
51
+ /** The deployed AppRegistry this client talks to. */
52
+ getAddress(): Address;
53
+ /** Same gas buffer and fee styling as DataRegistryClient.executeWrite. */
54
+ private executeWrite;
55
+ /**
56
+ * Claim this client's `appId` and open it in one transaction — owner, terms
57
+ * and join fee together. First come, first served, and irreversible: there is
58
+ * no transfer and no release.
59
+ *
60
+ * `termsHash` must be real. An app whose terms hash is zero cannot be joined
61
+ * by anyone, so claiming an id without them creates a market nobody can enter.
62
+ */
63
+ registerApp(termsHash: Hex, termsUri: string, fee?: bigint): Promise<Hash>;
64
+ /**
65
+ * Publish new terms for this app.
66
+ *
67
+ * This drops every publisher back to "must accept again" — `isRegisteredForApp`
68
+ * is false for anyone whose accepted hash no longer matches — so it is a real
69
+ * act with a real consequence, not a copy edit. Re-accepting is free for them.
70
+ */
71
+ setAppTerms(termsHash: Hex, termsUri: string): Promise<Hash>;
72
+ /** Set what joining this app costs, in wei. Paid to the app owner. */
73
+ setAppFee(fee: bigint): Promise<Hash>;
74
+ /**
75
+ * Eject a publisher from THIS app. Their global DataRegistry standing and
76
+ * their membership of every other app are untouched.
77
+ */
78
+ suspendForApp(publisher: Address): Promise<Hash>;
79
+ reinstateForApp(publisher: Address): Promise<Hash>;
80
+ /**
81
+ * Take this whole app down. Protocol-admin only, and a level above
82
+ * `suspendForApp`: every publisher of the app — its owner included — reads as
83
+ * unregistered, so nothing commits under it until it is reinstated. The
84
+ * memberships underneath are left intact, so reinstating restores them exactly.
85
+ */
86
+ suspendApp(): Promise<Hash>;
87
+ /** Lift an admin takedown, restoring every membership as it was. */
88
+ reinstateApp(): Promise<Hash>;
89
+ /** The protocol admin of this AppRegistry — the only caller `suspendApp` accepts. */
90
+ admin(): Promise<Address>;
91
+ /**
92
+ * Join this app, accepting its current terms by the act of doing so.
93
+ *
94
+ * The hash is read immediately before sending and passed as an argument, and
95
+ * the contract reverts `TermsMismatch` if it no longer matches. That is the
96
+ * point: the transaction is only valid against the exact version that was in
97
+ * front of the caller, so terms cannot change under a pending registration and
98
+ * land as agreement to something else. A race here is a revert, not a
99
+ * surprise obligation.
100
+ *
101
+ * The join fee is read from the chain rather than passed in, for the same
102
+ * reason `DataRegistryClient.register()` reads the registration fee: a caller
103
+ * who supplies it can supply the wrong one.
104
+ */
105
+ registerForApp(): Promise<Hash>;
106
+ /**
107
+ * The same join, as an unsigned transaction for a wallet that signs elsewhere
108
+ * (the sond3r relay never holds a key). Mirrors `prepareCommitStateRoot`.
109
+ */
110
+ prepareRegisterForApp(publisher: Address): Promise<PreparedTx & {
111
+ value: Hex;
112
+ }>;
113
+ /** Owner of this client's app id, or the zero address if unclaimed. */
114
+ getAppOwner(): Promise<Address>;
115
+ /**
116
+ * May this publisher commit under this app? This is the exact question
117
+ * `DataRegistry.commitStateRoot` asks on-chain, so a false here means a
118
+ * publish would revert.
119
+ */
120
+ isRegisteredForApp(publisher: Address): Promise<boolean>;
121
+ /** Has the protocol admin taken this app down? */
122
+ isAppSuspended(): Promise<boolean>;
123
+ /** This app's current terms hash, or the zero hash if it has published none. */
124
+ appTerms(): Promise<Hex>;
125
+ appTermsUri(): Promise<string>;
126
+ appFee(): Promise<bigint>;
127
+ /** The terms hash this publisher accepted, or the zero hash. */
128
+ acceptedTerms(publisher: Address): Promise<Hex>;
129
+ /**
130
+ * Everything a join screen needs. Two reads rather than one, because the
131
+ * accepted hash is what turns "not registered" into the far more useful "the
132
+ * terms changed since you joined".
133
+ */
134
+ joinInfo(publisher: Address): Promise<AppJoinInfo>;
135
+ private readJoinInfoTuple;
136
+ private senderAddress;
137
+ }
138
+ //#endregion
139
+ export { AppJoinInfo, AppRegistryClient, needsReacceptance };