@fangorn-network/sdk 2026.8.18-dev → 2026.10.1-9.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +191 -195
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +198 -164
  4. package/lib/cli/index.d.ts +3 -91
  5. package/lib/cli/index.js +5 -2
  6. package/lib/config.d.ts +349 -433
  7. package/lib/config.js +41 -28
  8. package/lib/contracts/app-registry/abi.d.ts +1064 -265
  9. package/lib/contracts/app-registry/abi.js +1233 -308
  10. package/lib/contracts/app-registry/index.d.ts +123 -102
  11. package/lib/contracts/app-registry/index.js +200 -198
  12. package/lib/contracts/data-registry/abi.d.ts +166 -187
  13. package/lib/contracts/data-registry/abi.js +207 -237
  14. package/lib/contracts/data-registry/index.d.ts +4 -160
  15. package/lib/contracts/data-registry/index.js +5 -294
  16. package/lib/contracts/index.d.ts +6 -7
  17. package/lib/contracts/index.js +6 -8
  18. package/lib/contracts/logs.d.ts +21 -0
  19. package/lib/contracts/logs.js +32 -0
  20. package/lib/contracts/membership-registry/abi.d.ts +1145 -0
  21. package/lib/contracts/membership-registry/abi.js +1333 -0
  22. package/lib/contracts/membership-registry/index.d.ts +79 -0
  23. package/lib/contracts/membership-registry/index.js +104 -0
  24. package/lib/contracts/types.d.ts +3 -1
  25. package/lib/contracts/types.js +3 -1
  26. package/lib/contracts/write.d.ts +34 -2
  27. package/lib/contracts/write.js +48 -1
  28. package/lib/crypto/encryption.js +4 -4
  29. package/lib/engine/car.d.ts +2 -2
  30. package/lib/engine/car.js +10 -5
  31. package/lib/engine/index.d.ts +99 -143
  32. package/lib/engine/index.js +156 -295
  33. package/lib/engine/records.d.ts +110 -0
  34. package/lib/engine/records.js +165 -0
  35. package/lib/engine/test-helpers.d.ts +7 -14
  36. package/lib/engine/test-helpers.js +7 -18
  37. package/lib/fangorn.d.ts +163 -155
  38. package/lib/fangorn.js +284 -248
  39. package/lib/feed.d.ts +7 -4
  40. package/lib/feed.js +4 -1
  41. package/lib/index.d.ts +9 -9
  42. package/lib/index.js +9 -10
  43. package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
  44. package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
  45. package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
  46. package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
  47. package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
  48. package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
  49. package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
  50. package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
  51. package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
  52. package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
  53. package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
  54. package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
  55. package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
  56. package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
  57. package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
  58. package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
  59. package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
  60. package/lib/node_modules/chai/index.js +2874 -0
  61. package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
  62. package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
  63. package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
  64. package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
  65. package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
  66. package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
  67. package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
  68. package/lib/providers/storage/signed-url.d.ts +16 -6
  69. package/lib/providers/storage/signed-url.js +20 -8
  70. package/lib/registry.d.ts +116 -0
  71. package/lib/registry.js +182 -0
  72. package/lib/test/mem-registry.d.ts +51 -0
  73. package/lib/test/mem-registry.js +107 -0
  74. package/lib/test/sdk-suite.d.ts +13 -0
  75. package/lib/test/sdk-suite.js +226 -0
  76. package/lib/test/testbed.d.ts +16411 -61
  77. package/lib/test/testbed.js +190 -84
  78. package/lib/types/index.d.ts +13 -11
  79. package/package.json +89 -72
  80. package/lib/contracts/data-registry/test.d.ts +0 -1
  81. package/lib/contracts/data-registry/test.js +0 -1
  82. package/lib/contracts/settlement-registry/abi.d.ts +0 -466
  83. package/lib/contracts/settlement-registry/abi.js +0 -535
  84. package/lib/contracts/settlement-registry/index.d.ts +0 -163
  85. package/lib/contracts/settlement-registry/index.js +0 -264
  86. package/lib/contracts/subscription-registry/abi.d.ts +0 -179
  87. package/lib/contracts/subscription-registry/abi.js +0 -195
  88. package/lib/contracts/subscription-registry/index.d.ts +0 -59
  89. package/lib/contracts/subscription-registry/index.js +0 -116
  90. package/lib/engine/graph.d.ts +0 -70
  91. package/lib/engine/graph.js +0 -73
@@ -1,139 +1,160 @@
1
1
  import { PublisherStatus } from "../types.js";
2
- import { PreparedTx } from "../data-registry/index.js";
2
+ import { PreparedTx } from "../write.js";
3
3
  import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
4
4
 
5
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;
6
+ /** What the upload gate needs to decide whether to serve a publisher under an app. */
7
+ interface AppAccess {
8
+ /** May publish to the app now (see `canPublish`). */
9
+ canPublish: boolean;
10
+ /** The app's owner, or the zero address for an unclaimed app. */
11
+ owner: Address;
12
+ /** Unix seconds the app's subscription expires at; 0 if unclaimed or cancelled. */
13
+ expiresAt: bigint;
14
+ }
15
+ /** One `AppAgentChanged` event: an app owner pointed their app at a card. */
16
+ interface AppAgentLog {
17
+ appId: Hex;
18
+ agentUri: string;
19
+ blockNumber: bigint;
20
+ transactionHash: Hash;
25
21
  }
26
- /** True when the publisher joined but the app's terms have since changed. */
27
- declare function needsReacceptance(info: AppJoinInfo): boolean;
28
22
  /**
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.
23
+ * Client for the AppRegistry's app management: apps and their ERC-5643
24
+ * subscriptions, the publishers each app accepts, the agent card, and the
25
+ * protocol admin's powers. What an app presents — its members, less exclusions — is
26
+ * read through the registry (`ChainRegistry`), not this client.
37
27
  *
38
- * Scoped to one `appId`, like `DataRegistryClient` — the app is an identity the
39
- * client carries, not an argument every call repeats.
28
+ * Scoped to one app, which may be unset: then only the calls that take no app work.
40
29
  */
41
30
  declare class AppRegistryClient {
42
31
  private contractAddress;
43
32
  private appId;
44
33
  private publicClient;
45
34
  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. */
35
+ constructor(contractAddress: Address, appId: Hex | undefined, publicClient: PublicClient, walletClient: WalletClient);
36
+ getAppId(): Hex | undefined;
37
+ setAppId(appId: Hex | undefined): void;
52
38
  getAddress(): Address;
53
- /** Same gas buffer and fee styling as DataRegistryClient.executeWrite. */
39
+ /** This client's app, or a clear error for a call that needs one. */
40
+ private app;
41
+ /** The app's subscription token: an app's token id is its app id. */
42
+ tokenId(appId?: Hex): bigint;
54
43
  private executeWrite;
44
+ private read;
55
45
  /**
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.
46
+ * Claim this app, if nobody has. Claiming IS subscribing: it pays one period
47
+ * of `subscriptionFee()` in USDC and mints the app's token to the caller,
48
+ * who becomes the app's first accepted publisher.
59
49
  *
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.
50
+ * The fee read now is approved and passed as the most the claim may cost,
51
+ * so a fee raised in the meantime makes the claim revert instead of charging
52
+ * more.
62
53
  */
63
- registerApp(termsHash: Hex, termsUri: string, fee?: bigint): Promise<Hash>;
54
+ registerApp(): Promise<Hash>;
64
55
  /**
65
- * Publish new terms for this app.
56
+ * Pay for one more period (the owner, or an address they approved for the
57
+ * app's token). Allowed once less than a period is left; the period is added
58
+ * to the current expiry, or to now if it has passed.
66
59
  *
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.
60
+ * The standard gives the contract no maximum-fee argument, so the allowance
61
+ * is the cap: exactly the fee read now is approved.
70
62
  */
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>;
63
+ renewSubscription(): Promise<Hash>;
74
64
  /**
75
- * Eject a publisher from THIS app. Their global DataRegistry standing and
76
- * their membership of every other app are untouched.
65
+ * End this app's subscription now (owner only): the expiry becomes zero and
66
+ * nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
77
67
  */
78
- suspendForApp(publisher: Address): Promise<Hash>;
79
- reinstateForApp(publisher: Address): Promise<Hash>;
68
+ cancelSubscription(): Promise<Hash>;
69
+ /** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
70
+ expiresAt(appId?: Hex): Promise<bigint>;
71
+ /** True while less than one period is left, or the subscription has expired. */
72
+ isRenewable(): Promise<boolean>;
73
+ /** How long one payment lasts, in seconds. */
74
+ subscriptionPeriod(): Promise<bigint>;
75
+ /** What claiming or renewing an app costs, in USDC base units (6 decimals), not wei. */
76
+ subscriptionFee(): Promise<bigint>;
77
+ /** The ERC-20 token (USDC) every fee is paid in. */
78
+ usdc(): Promise<Address>;
79
+ getAppOwner(appId?: Hex): Promise<Address>;
80
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.
81
+ * Point this app at its ERC-8004 agent card.
82
+ *
83
+ * Safe to call whenever the card moves: it leaves the app's publishers alone.
85
84
  */
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>;
85
+ setAppAgentUri(agentUri: string): Promise<Hash>;
86
+ /** Send the join fees the caller is still owed, from the old join flow, to `to`. */
87
+ withdrawJoinFees(to?: Address): Promise<Hash>;
88
+ /** Join fees still owed to `owner` from the old join flow, in USDC base units. Nothing adds to it. */
89
+ joinFeesOwed(owner?: Address): Promise<bigint>;
90
+ isAppSuspended(): Promise<boolean>;
91
+ /** The agent card URI of this app, or of `appId`. Empty if none is set. */
92
+ appAgentUri(appId?: Hex): Promise<string>;
91
93
  /**
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.
94
+ * Accept a publisher into this app (owner only). That is the whole
95
+ * membership: from here it uploads with storage the app provides, and the app
96
+ * includes its data, while `canPublish` holds. A suspended publisher comes
97
+ * back with `setPublisherSuspended(publisher, false)`.
98
+ */
99
+ acceptPublisher(publisher: Address): Promise<Hash>;
100
+ /**
101
+ * Suspend an accepted publisher from this app, or reinstate them (owner
102
+ * only). An owner cannot suspend themselves.
103
+ */
104
+ setPublisherSuspended(publisher: Address, suspended: boolean): Promise<Hash>;
105
+ /** `publisher`'s standing in this app. */
106
+ status(publisher: Address): Promise<PublisherStatus>;
107
+ /**
108
+ * May `publisher` publish to this app now: accepted and not suspended, not
109
+ * banned network-wide, and the app is live and paid up.
110
+ */
111
+ canPublish(publisher: Address, appId?: Hex): Promise<boolean>;
112
+ /** The single oracle the upload gate reads for one publisher under this app. */
113
+ access(publisher: Address, appId?: Hex): Promise<AppAccess>;
114
+ /**
115
+ * `AppAgentChanged` events, oldest first. The last one for an app is its
116
+ * current card; an empty `agentUri` means the owner unset it.
100
117
  *
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.
118
+ * Leave `appId` out to list every app that has ever set a card. The chain is
119
+ * the directory: one windowed log scan, no indexer and no registry namespace.
120
+ * `fromBlock` is required because scanning from genesis on an L2 costs
121
+ * hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
122
+ * a block you know to be before the app's registration.
104
123
  */
105
- registerForApp(): Promise<Hash>;
124
+ getAppAgentLogs(opts: {
125
+ appId?: Hex;
126
+ fromBlock: bigint;
127
+ toBlock?: bigint;
128
+ }): Promise<AppAgentLog[]>;
129
+ admin(): Promise<Address>;
130
+ /** The DataRegistry this contract names. */
131
+ dataRegistry(): Promise<Address>;
132
+ /** Whether the protocol admin has banned `wallet` network-wide. */
133
+ isGloballySuspended(wallet: Address): Promise<boolean>;
106
134
  /**
107
- * The same join, as an unsigned transaction for a wallet that signs elsewhere
108
- * (the sond3r relay never holds a key). Mirrors `prepareCommitStateRoot`.
135
+ * Ban `wallet` network-wide, or lift the ban. A banned wallet cannot claim an
136
+ * app or be accepted into one, and no app stores or includes it; a banned
137
+ * owner's app keeps running, but they cannot accept anyone or move its agent card.
109
138
  */
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>;
139
+ setGlobalSuspension(wallet: Address, suspended: boolean): Promise<Hash>;
140
+ /** Take this app down for every publisher at once, or restore it. */
141
+ setAppSuspended(suspended: boolean): Promise<Hash>;
142
+ setDataRegistry(registry: Address): Promise<Hash>;
143
+ setSubscriptionFee(fee: bigint): Promise<Hash>;
144
+ /** Applies from each app's next payment. */
145
+ setSubscriptionPeriod(period: bigint): Promise<Hash>;
115
146
  /**
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.
147
+ * Send `amount` of `token` to `to`. Of USDC, only the protocol's share: what
148
+ * app owners are owed in join fees stays (`ExceedsProtocolBalance`).
119
149
  */
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>;
150
+ withdrawToken(token: Address, to: Address, amount: bigint): Promise<Hash>;
129
151
  /**
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".
152
+ * Fees are pulled with `transferFrom`, so the registry needs an allowance.
153
+ * Without one the call reverts with a fee error that reads like a pricing
154
+ * problem but is really an allowance one. Approves exactly `amount`.
133
155
  */
134
- joinInfo(publisher: Address): Promise<AppJoinInfo>;
135
- private readJoinInfoTuple;
156
+ private approveUsdc;
136
157
  private senderAddress;
137
158
  }
138
159
  //#endregion
139
- export { AppJoinInfo, AppRegistryClient, needsReacceptance };
160
+ export { AppAccess, AppAgentLog, AppRegistryClient, type PreparedTx };