@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,163 +1,7 @@
1
- import { PublisherStatus } from "../types.js";
2
- import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
1
+ import { Hex } from "viem";
3
2
 
4
3
  //#region src/contracts/data-registry/index.d.ts
5
-
6
- /**
7
- * The on-chain id of a namespace within an app: the SDK's human-readable
8
- * namespace name, hashed. Names never touch storage — the contract only ever
9
- * sees these 32 bytes.
10
- */
11
- declare function subspaceId(namespace: string): Hex;
12
- /**
13
- * The composite storage key the contract derives for `app:publisher:subspace`.
14
- * Mirrors `namespace_key()` in contracts/data_registry — keccak256 over the
15
- * packed 84 bytes. Computing it client-side is what lets a subscriber filter
16
- * one exact subspace with a single indexed topic.
17
- */
18
- declare function namespaceKey(appId: Hex, publisher: Address, subspace: Hex): Hex;
19
- /**
20
- * A decoded `StateCommitted` log — the single on-chain signal that one
21
- * hierarchical namespace's state root advanced. `logId` uniquely identifies the
22
- * emitting log (tx + index) so consumers can dedupe across the catch-up
23
- * (getLogs) and live (watch) paths.
24
- */
25
- interface StateCommittedLog {
26
- namespaceKey: Hex;
27
- appId: Hex;
28
- publisher: Address;
29
- subspaceId: Hex;
30
- oldRoot: Hex;
31
- newRoot: Hex;
32
- blockNumber: bigint;
33
- logId: string;
34
- }
35
- /**
36
- * Which slice of the app's commit stream to read. Every field is an indexed
37
- * topic, so filtering happens on the RPC node — no indexer, no subgraph:
38
- *
39
- * {} — the whole app, every publisher and subspace
40
- * { publisher } — one publisher's commits across the app
41
- * { publisher, namespace } — one exact subspace (the tightest filter)
42
- *
43
- * `namespace` alone is not filterable: the key binds the publisher too, so a
44
- * subspace name across all publishers means filtering the app stream in memory.
45
- */
46
- interface CommitFilter {
47
- publisher?: Address;
48
- namespace?: string;
49
- }
50
- /**
51
- * An unsigned transaction, hex-encoded and ready to hand to a browser wallet's
52
- * `eth_sendTransaction` — no `from`, since the signing wallet supplies it.
53
- */
54
- interface PreparedTx {
55
- to: Address;
56
- data: Hex;
57
- chainId: number | undefined;
58
- gas: Hex;
59
- maxFeePerGas: Hex;
60
- maxPriorityFeePerGas: Hex;
61
- }
62
- /**
63
- * Publisher registration, the state-root timeline, and nothing about apps.
64
- *
65
- * `registerApp` and `getAppOwner` used to live here. They are on
66
- * {@link AppRegistryClient} now, together with the per-app terms and membership
67
- * they belong with — and `commitStateRoot` cross-calls that contract, so a
68
- * publisher must join an app before they can write under it. A commit for an app
69
- * this wallet never joined reverts `NotRegisteredForApp`.
70
- */
71
- declare class DataRegistryClient {
72
- private contractAddress;
73
- private appId;
74
- private publicClient;
75
- private walletClient;
76
- constructor(contractAddress: Address, appId: Hex, publicClient: PublicClient, walletClient: WalletClient);
77
- /** The app namespace every call on this client is scoped to. */
78
- getAppId(): Hex;
79
- /** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
80
- setAppId(appId: Hex): void;
81
- /** The deployed DataRegistry this client talks to. */
82
- getAddress(): Address;
83
- /**
84
- * Internal helper to execute state-mutating transactions
85
- * matching the exact gas buffer and aggressive fee styling of the protocol.
86
- */
87
- private executeWrite;
88
- /** The composite key for one of this app's namespaces. */
89
- namespaceKey(publisher: Address, namespace: string): Hex;
90
- /**
91
- * Register as a new data publisher or reactivate a suspended account.
92
- * Automatically reads the required on-chain fee and attaches it to the call.
93
- */
94
- register(): Promise<Hash>;
95
- /**
96
- * The single mutating state gateway route. Enforces the sequential
97
- * Compare-And-Swap (CAS) timeline rule — per namespace, so concurrent pushes
98
- * to *different* namespaces never contend.
99
- */
100
- commitStateRoot(namespace: string, oldRoot: Hex, newRoot: Hex): Promise<Hash>;
101
- /**
102
- * Build the `commitStateRoot` call as an UNSIGNED transaction for `publisher`
103
- * to sign, instead of sending it from this client's wallet.
104
- *
105
- * This is the self-custodial publish path: a relay server builds and pins the
106
- * commit with a keyless service wallet, then hands this back for the user's
107
- * browser wallet to sign. The server never holds the key that moves the head,
108
- * and the on-chain sender IS the publisher — which is what authenticates the
109
- * publish, since the contract keys the namespace by `msg_sender`.
110
- */
111
- prepareCommitStateRoot(publisher: Address, namespace: string, oldRoot: Hex, newRoot: Hex): Promise<PreparedTx>;
112
- /**
113
- * Obtains the authoritative timeline tracking anchor for one publisher's
114
- * namespace within this app.
115
- */
116
- getNamespaceHead(publisher: Address, namespace: string): Promise<Hex>;
117
- /** The AppRegistry this contract defers to for apps and per-app membership. */
118
- appRegistry(): Promise<Address>;
119
- /**
120
- * Reads the explicit enum lifecycle state from the registry status machine.
121
- */
122
- getPublisherStatus(publisher: Address): Promise<PublisherStatus>;
123
- /**
124
- * Helper boolean view returning true if a publisher can currently commit data.
125
- */
126
- isRegistered(publisher: Address): Promise<boolean>;
127
- /** Current chain head block number — the default "start here" for a fresh subscription. */
128
- currentBlock(): Promise<bigint>;
129
- /** Translate a `CommitFilter` into indexed-topic args for this app. */
130
- private topicsFor;
131
- /**
132
- * Historical `StateCommitted` logs for one slice of this app, oldest →
133
- * newest — the catch-up path for a subscriber resuming from a saved block
134
- * cursor. Node-side filtered by indexed topics, so no indexer is involved.
135
- *
136
- * Fetched in windows: RPC providers cap the block span of a single
137
- * `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
138
- * couple of thousand blocks with a bare "internal server errror"), so one
139
- * wide-range call fails outright and takes the whole catch-up with it. Tune
140
- * the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
141
- */
142
- getStateCommittedLogs(filter: CommitFilter, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
143
- /**
144
- * Live-watch `StateCommitted` for one slice of this app. Returns an
145
- * unsubscribe function. Uses the client's transport (polling over HTTP, push
146
- * over a WebSocket transport) — reads logs straight from the RPC node, no
147
- * subgraph.
148
- */
149
- watchStateCommitted(filter: CommitFilter, onCommit: (log: StateCommittedLog) => void, onError?: (err: Error) => void, pollingInterval?: number): () => void;
150
- publisherCount(): Promise<bigint>;
151
- registrationFee(): Promise<bigint>;
152
- admin(): Promise<Address>;
153
- /**
154
- * Allows governance or protocol administrator to immediately freeze a publisher namespace.
155
- */
156
- suspendPublisher(publisher: Address): Promise<Hash>;
157
- /**
158
- * Adjusts the current native/token onboarding collateral tier.
159
- */
160
- setRegistrationFee(fee: bigint): Promise<Hash>;
161
- }
4
+ /** A repo's on-chain id: keccak256 of its name's UTF-8 bytes, never of the name as hex. */
5
+ declare function repoId(repo: string): Hex;
162
6
  //#endregion
163
- export { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId };
7
+ export { repoId };
@@ -1,299 +1,10 @@
1
- import { requireWallet, sendWrite } from "../write.js";
2
- import { DATA_REGISTRY_ABI } from "./abi.js";
3
- import { concatHex, encodeFunctionData, keccak256, toHex } from "viem";
1
+ import { keccak256, toHex } from "viem";
4
2
 
5
3
  //#region src/contracts/data-registry/index.ts
6
- /**
7
- * The on-chain id of a namespace within an app: the SDK's human-readable
8
- * namespace name, hashed. Names never touch storage — the contract only ever
9
- * sees these 32 bytes.
10
- */
11
- function subspaceId(namespace) {
12
- return keccak256(toHex(namespace));
13
- }
14
- /**
15
- * The composite storage key the contract derives for `app:publisher:subspace`.
16
- * Mirrors `namespace_key()` in contracts/data_registry — keccak256 over the
17
- * packed 84 bytes. Computing it client-side is what lets a subscriber filter
18
- * one exact subspace with a single indexed topic.
19
- */
20
- function namespaceKey(appId, publisher, subspace) {
21
- return keccak256(concatHex([
22
- appId,
23
- publisher,
24
- subspace
25
- ]));
26
- }
27
- function decodeStateCommitted(log) {
28
- const a = log.args;
29
- if (a.namespace_key === void 0 || a.app_id === void 0 || a.publisher === void 0 || a.subspace_id === void 0 || a.old_root === void 0 || a.new_root === void 0) throw new Error("Malformed log event: incomplete StateCommitted args");
30
- return {
31
- namespaceKey: a.namespace_key,
32
- appId: a.app_id,
33
- publisher: a.publisher,
34
- subspaceId: a.subspace_id,
35
- oldRoot: a.old_root,
36
- newRoot: a.new_root,
37
- blockNumber: log.blockNumber,
38
- logId: `${log.transactionHash}:${log.logIndex.toString()}`
39
- };
40
- }
41
- /**
42
- * Publisher registration, the state-root timeline, and nothing about apps.
43
- *
44
- * `registerApp` and `getAppOwner` used to live here. They are on
45
- * {@link AppRegistryClient} now, together with the per-app terms and membership
46
- * they belong with — and `commitStateRoot` cross-calls that contract, so a
47
- * publisher must join an app before they can write under it. A commit for an app
48
- * this wallet never joined reverts `NotRegisteredForApp`.
49
- */
50
- var DataRegistryClient = class {
51
- constructor(contractAddress, appId, publicClient, walletClient) {
52
- this.contractAddress = contractAddress;
53
- this.appId = appId;
54
- this.publicClient = publicClient;
55
- this.walletClient = walletClient;
56
- }
57
- /** The app namespace every call on this client is scoped to. */
58
- getAppId() {
59
- return this.appId;
60
- }
61
- /** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
62
- setAppId(appId) {
63
- this.appId = appId;
64
- }
65
- /** The deployed DataRegistry this client talks to. */
66
- getAddress() {
67
- return this.contractAddress;
68
- }
69
- /**
70
- * Internal helper to execute state-mutating transactions
71
- * matching the exact gas buffer and aggressive fee styling of the protocol.
72
- */
73
- executeWrite(functionName, args, value) {
74
- return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, DATA_REGISTRY_ABI, functionName, args, value);
75
- }
76
- /** The composite key for one of this app's namespaces. */
77
- namespaceKey(publisher, namespace) {
78
- return namespaceKey(this.appId, publisher, subspaceId(namespace));
79
- }
80
- /**
81
- * Register as a new data publisher or reactivate a suspended account.
82
- * Automatically reads the required on-chain fee and attaches it to the call.
83
- */
84
- async register() {
85
- const fee = await this.registrationFee();
86
- return this.executeWrite("register", [], fee);
87
- }
88
- /**
89
- * The single mutating state gateway route. Enforces the sequential
90
- * Compare-And-Swap (CAS) timeline rule — per namespace, so concurrent pushes
91
- * to *different* namespaces never contend.
92
- */
93
- async commitStateRoot(namespace, oldRoot, newRoot) {
94
- return this.executeWrite("commitStateRoot", [
95
- this.appId,
96
- subspaceId(namespace),
97
- oldRoot,
98
- newRoot
99
- ]);
100
- }
101
- /**
102
- * Build the `commitStateRoot` call as an UNSIGNED transaction for `publisher`
103
- * to sign, instead of sending it from this client's wallet.
104
- *
105
- * This is the self-custodial publish path: a relay server builds and pins the
106
- * commit with a keyless service wallet, then hands this back for the user's
107
- * browser wallet to sign. The server never holds the key that moves the head,
108
- * and the on-chain sender IS the publisher — which is what authenticates the
109
- * publish, since the contract keys the namespace by `msg_sender`.
110
- */
111
- async prepareCommitStateRoot(publisher, namespace, oldRoot, newRoot) {
112
- const data = encodeFunctionData({
113
- abi: DATA_REGISTRY_ABI,
114
- functionName: "commitStateRoot",
115
- args: [
116
- this.appId,
117
- subspaceId(namespace),
118
- oldRoot,
119
- newRoot
120
- ]
121
- });
122
- const fees = await this.publicClient.estimateFeesPerGas();
123
- let gas;
124
- try {
125
- gas = await this.publicClient.estimateGas({
126
- account: publisher,
127
- to: this.contractAddress,
128
- data
129
- }) * 3n / 2n;
130
- } catch (err) {
131
- const message = err instanceof Error ? err.message : String(err);
132
- if (/revert/i.test(message)) throw new Error(`settlement would revert — the head may have moved on-chain, or the app is unregistered: ${message}`);
133
- gas = 5000000n;
134
- }
135
- return {
136
- to: this.contractAddress,
137
- data,
138
- chainId: this.publicClient.chain?.id,
139
- gas: toHex(gas),
140
- maxFeePerGas: toHex(fees.maxFeePerGas * 2n),
141
- maxPriorityFeePerGas: toHex(fees.maxPriorityFeePerGas)
142
- };
143
- }
144
- /**
145
- * Obtains the authoritative timeline tracking anchor for one publisher's
146
- * namespace within this app.
147
- */
148
- async getNamespaceHead(publisher, namespace) {
149
- return this.publicClient.readContract({
150
- address: this.contractAddress,
151
- abi: DATA_REGISTRY_ABI,
152
- functionName: "getNamespaceHead",
153
- args: [
154
- this.appId,
155
- publisher,
156
- subspaceId(namespace)
157
- ]
158
- });
159
- }
160
- /** The AppRegistry this contract defers to for apps and per-app membership. */
161
- async appRegistry() {
162
- return this.publicClient.readContract({
163
- address: this.contractAddress,
164
- abi: DATA_REGISTRY_ABI,
165
- functionName: "appRegistry"
166
- });
167
- }
168
- /**
169
- * Reads the explicit enum lifecycle state from the registry status machine.
170
- */
171
- async getPublisherStatus(publisher) {
172
- return await this.publicClient.readContract({
173
- address: this.contractAddress,
174
- abi: DATA_REGISTRY_ABI,
175
- functionName: "getPublisherStatus",
176
- args: [publisher]
177
- });
178
- }
179
- /**
180
- * Helper boolean view returning true if a publisher can currently commit data.
181
- */
182
- async isRegistered(publisher) {
183
- return this.publicClient.readContract({
184
- address: this.contractAddress,
185
- abi: DATA_REGISTRY_ABI,
186
- functionName: "isRegistered",
187
- args: [publisher]
188
- });
189
- }
190
- /** Current chain head block number — the default "start here" for a fresh subscription. */
191
- async currentBlock() {
192
- return this.publicClient.getBlockNumber();
193
- }
194
- /** Translate a `CommitFilter` into indexed-topic args for this app. */
195
- topicsFor(filter) {
196
- const { publisher, namespace } = filter;
197
- return {
198
- app_id: this.appId,
199
- ...publisher ? { publisher } : {},
200
- ...publisher && namespace ? { namespace_key: this.namespaceKey(publisher, namespace) } : {}
201
- };
202
- }
203
- /**
204
- * Historical `StateCommitted` logs for one slice of this app, oldest →
205
- * newest — the catch-up path for a subscriber resuming from a saved block
206
- * cursor. Node-side filtered by indexed topics, so no indexer is involved.
207
- *
208
- * Fetched in windows: RPC providers cap the block span of a single
209
- * `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
210
- * couple of thousand blocks with a bare "internal server errror"), so one
211
- * wide-range call fails outright and takes the whole catch-up with it. Tune
212
- * the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
213
- */
214
- async getStateCommittedLogs(filter, fromBlock, toBlock) {
215
- const window = BigInt(process.env.FANGORN_LOG_WINDOW ?? 1e3);
216
- const end = toBlock ?? await this.publicClient.getBlockNumber();
217
- const logs = [];
218
- for (let start = fromBlock; start <= end; start += window) {
219
- const stop = start + window - 1n < end ? start + window - 1n : end;
220
- logs.push(...await this.publicClient.getContractEvents({
221
- address: this.contractAddress,
222
- abi: DATA_REGISTRY_ABI,
223
- eventName: "StateCommitted",
224
- args: this.topicsFor(filter),
225
- fromBlock: start,
226
- toBlock: stop
227
- }));
228
- }
229
- return logs.map(decodeStateCommitted).filter((log) => matchesFilter(log, filter)).sort((a, b) => a.blockNumber === b.blockNumber ? a.logId.localeCompare(b.logId) : a.blockNumber < b.blockNumber ? -1 : 1);
230
- }
231
- /**
232
- * Live-watch `StateCommitted` for one slice of this app. Returns an
233
- * unsubscribe function. Uses the client's transport (polling over HTTP, push
234
- * over a WebSocket transport) — reads logs straight from the RPC node, no
235
- * subgraph.
236
- */
237
- watchStateCommitted(filter, onCommit, onError, pollingInterval) {
238
- return this.publicClient.watchContractEvent({
239
- address: this.contractAddress,
240
- abi: DATA_REGISTRY_ABI,
241
- eventName: "StateCommitted",
242
- args: this.topicsFor(filter),
243
- pollingInterval,
244
- onLogs: (logs) => {
245
- for (const raw of logs) {
246
- const log = decodeStateCommitted(raw);
247
- if (matchesFilter(log, filter)) onCommit(log);
248
- }
249
- },
250
- onError
251
- });
252
- }
253
- async publisherCount() {
254
- return this.publicClient.readContract({
255
- address: this.contractAddress,
256
- abi: DATA_REGISTRY_ABI,
257
- functionName: "publisherCount"
258
- });
259
- }
260
- async registrationFee() {
261
- return this.publicClient.readContract({
262
- address: this.contractAddress,
263
- abi: DATA_REGISTRY_ABI,
264
- functionName: "registrationFee"
265
- });
266
- }
267
- async admin() {
268
- return this.publicClient.readContract({
269
- address: this.contractAddress,
270
- abi: DATA_REGISTRY_ABI,
271
- functionName: "admin"
272
- });
273
- }
274
- /**
275
- * Allows governance or protocol administrator to immediately freeze a publisher namespace.
276
- */
277
- async suspendPublisher(publisher) {
278
- return this.executeWrite("suspendPublisher", [publisher]);
279
- }
280
- /**
281
- * Adjusts the current native/token onboarding collateral tier.
282
- */
283
- async setRegistrationFee(fee) {
284
- return this.executeWrite("setRegistrationFee", [fee]);
285
- }
286
- };
287
- /**
288
- * The in-memory half of a filter. `subspace_id` is not an indexed topic (the
289
- * three slots go to namespace_key/app_id/publisher), so a namespace-without-
290
- * publisher filter — "every publisher's `docs` namespace" — narrows here
291
- * instead of on the node.
292
- */
293
- function matchesFilter(log, filter) {
294
- if (!filter.namespace || filter.publisher) return true;
295
- return log.subspaceId === subspaceId(filter.namespace);
4
+ /** A repo's on-chain id: keccak256 of its name's UTF-8 bytes, never of the name as hex. */
5
+ function repoId(repo) {
6
+ return keccak256(toHex(repo));
296
7
  }
297
8
 
298
9
  //#endregion
299
- export { DataRegistryClient, namespaceKey, subspaceId };
10
+ export { repoId };
@@ -1,10 +1,9 @@
1
1
  import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
2
2
  import { PublisherStatus } from "./types.js";
3
- import { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId } from "./data-registry/index.js";
4
- import { AppJoinInfo, AppRegistryClient, needsReacceptance } from "./app-registry/index.js";
3
+ import { PreparedTx } from "./write.js";
4
+ import { AppAccess, AppAgentLog, AppRegistryClient } from "./app-registry/index.js";
5
5
  import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
6
- import { Resource, SemaphoreProof, SettlementRegistryClient, TransferAuthorization, packResourceUri, resourceIdOf } from "./settlement-registry/index.js";
7
- import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
8
- import { SubscriptionAccess, SubscriptionRegistryClient } from "./subscription-registry/index.js";
9
- import { SUBSCRIPTION_REGISTRY_ABI } from "./subscription-registry/abi.js";
10
- export { APP_REGISTRY_ABI, AppJoinInfo, AppRegistryClient, CommitFilter, DATA_REGISTRY_ABI, DataRegistryClient, PreparedTx, PublisherStatus, Resource, SETTLEMENT_REGISTRY_ABI, SUBSCRIPTION_REGISTRY_ABI, SemaphoreProof, SettlementRegistryClient, StateCommittedLog, SubscriptionAccess, SubscriptionRegistryClient, TransferAuthorization, namespaceKey, needsReacceptance, packResourceUri, resourceIdOf, subspaceId };
6
+ import { repoId } from "./data-registry/index.js";
7
+ import { ClaimArgs, JoinArgs, MembershipPayment, MembershipRegistryClient, joinNonce, membershipScope, membershipTokenId } from "./membership-registry/index.js";
8
+ import { MEMBERSHIP_REGISTRY_ABI } from "./membership-registry/abi.js";
9
+ export { APP_REGISTRY_ABI, AppAccess, AppAgentLog, AppRegistryClient, ClaimArgs, DATA_REGISTRY_ABI, JoinArgs, MEMBERSHIP_REGISTRY_ABI, MembershipPayment, MembershipRegistryClient, PreparedTx, PublisherStatus, joinNonce, membershipScope, membershipTokenId, repoId };
@@ -1,11 +1,9 @@
1
1
  import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
2
- import { PublisherStatus } from "./types.js";
3
- import { AppRegistryClient, needsReacceptance } from "./app-registry/index.js";
2
+ import { AppRegistryClient } from "./app-registry/index.js";
3
+ import { repoId } from "./data-registry/index.js";
4
4
  import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
5
- import { DataRegistryClient, namespaceKey, subspaceId } from "./data-registry/index.js";
6
- import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
7
- import { SettlementRegistryClient, packResourceUri, resourceIdOf } from "./settlement-registry/index.js";
8
- import { SUBSCRIPTION_REGISTRY_ABI } from "./subscription-registry/abi.js";
9
- import { SubscriptionRegistryClient } from "./subscription-registry/index.js";
5
+ import { MEMBERSHIP_REGISTRY_ABI } from "./membership-registry/abi.js";
6
+ import { MembershipRegistryClient, joinNonce, membershipScope, membershipTokenId } from "./membership-registry/index.js";
7
+ import { PublisherStatus } from "./types.js";
10
8
 
11
- export { APP_REGISTRY_ABI, AppRegistryClient, DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SUBSCRIPTION_REGISTRY_ABI, SettlementRegistryClient, SubscriptionRegistryClient, namespaceKey, needsReacceptance, packResourceUri, resourceIdOf, subspaceId };
9
+ export { APP_REGISTRY_ABI, AppRegistryClient, DATA_REGISTRY_ABI, MEMBERSHIP_REGISTRY_ABI, MembershipRegistryClient, PublisherStatus, joinNonce, membershipScope, membershipTokenId, repoId };
@@ -0,0 +1,21 @@
1
+ import { PublicClient } from "viem";
2
+
3
+ //#region src/contracts/logs.d.ts
4
+
5
+ /**
6
+ * Run `fetch` over [fromBlock, toBlock] in consecutive block windows and
7
+ * concatenate the results, oldest window first.
8
+ *
9
+ * RPC providers limit how many blocks one `eth_getLogs` call can cover. The
10
+ * public Arbitrum Sepolia endpoint rejects anything past a couple of thousand
11
+ * blocks with a bare "internal server errror". So a single wide-range call fails
12
+ * outright, and whatever depends on it (a catch-up, a directory listing) fails
13
+ * with it. Tune the window with `FANGORN_LOG_WINDOW`; a private RPC will take far
14
+ * more.
15
+ *
16
+ * `defaultWindow` is for a query the endpoint is known to serve over a wider
17
+ * range. `FANGORN_LOG_WINDOW` still overrides it.
18
+ */
19
+ declare function getLogsInWindows<T>(publicClient: PublicClient, fromBlock: bigint, toBlock: bigint | undefined, fetch: (fromBlock: bigint, toBlock: bigint) => Promise<T[]>, defaultWindow?: bigint): Promise<T[]>;
20
+ //#endregion
21
+ export { getLogsInWindows };
@@ -0,0 +1,32 @@
1
+ import { nonBlank } from "../config.js";
2
+
3
+ //#region src/contracts/logs.ts
4
+ /**
5
+ * Run `fetch` over [fromBlock, toBlock] in consecutive block windows and
6
+ * concatenate the results, oldest window first.
7
+ *
8
+ * RPC providers limit how many blocks one `eth_getLogs` call can cover. The
9
+ * public Arbitrum Sepolia endpoint rejects anything past a couple of thousand
10
+ * blocks with a bare "internal server errror". So a single wide-range call fails
11
+ * outright, and whatever depends on it (a catch-up, a directory listing) fails
12
+ * with it. Tune the window with `FANGORN_LOG_WINDOW`; a private RPC will take far
13
+ * more.
14
+ *
15
+ * `defaultWindow` is for a query the endpoint is known to serve over a wider
16
+ * range. `FANGORN_LOG_WINDOW` still overrides it.
17
+ */
18
+ async function getLogsInWindows(publicClient, fromBlock, toBlock, fetch, defaultWindow = 1000n) {
19
+ const tuned = typeof process !== "undefined" ? nonBlank(process.env.FANGORN_LOG_WINDOW) : void 0;
20
+ const window = tuned === void 0 ? defaultWindow : BigInt(tuned);
21
+ if (window <= 0n) throw new Error(`FANGORN_LOG_WINDOW must be a positive number of blocks, not "${String(tuned)}"`);
22
+ const end = toBlock ?? await publicClient.getBlockNumber({ cacheTime: 0 });
23
+ const out = [];
24
+ for (let start = fromBlock; start <= end; start += window) {
25
+ const stop = start + window - 1n < end ? start + window - 1n : end;
26
+ out.push(...await fetch(start, stop));
27
+ }
28
+ return out;
29
+ }
30
+
31
+ //#endregion
32
+ export { getLogsInWindows };