@fangorn-network/sdk 2026.8.18-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.
@@ -99,6 +99,20 @@ declare const APP_REGISTRY_ABI: readonly [{
99
99
  }];
100
100
  readonly stateMutability: "view";
101
101
  readonly type: "function";
102
+ }, {
103
+ readonly inputs: readonly [{
104
+ readonly internalType: "bytes32";
105
+ readonly name: "app_id";
106
+ readonly type: "bytes32";
107
+ }];
108
+ readonly name: "appAgentUri";
109
+ readonly outputs: readonly [{
110
+ readonly internalType: "string";
111
+ readonly name: "";
112
+ readonly type: "string";
113
+ }];
114
+ readonly stateMutability: "view";
115
+ readonly type: "function";
102
116
  }, {
103
117
  readonly inputs: readonly [{
104
118
  readonly internalType: "bytes32";
@@ -277,6 +291,20 @@ declare const APP_REGISTRY_ABI: readonly [{
277
291
  readonly outputs: readonly [];
278
292
  readonly stateMutability: "nonpayable";
279
293
  readonly type: "function";
294
+ }, {
295
+ readonly inputs: readonly [{
296
+ readonly internalType: "bytes32";
297
+ readonly name: "app_id";
298
+ readonly type: "bytes32";
299
+ }, {
300
+ readonly internalType: "string";
301
+ readonly name: "agent_uri";
302
+ readonly type: "string";
303
+ }];
304
+ readonly name: "setAppAgentUri";
305
+ readonly outputs: readonly [];
306
+ readonly stateMutability: "nonpayable";
307
+ readonly type: "function";
280
308
  }, {
281
309
  readonly inputs: readonly [{
282
310
  readonly internalType: "bytes32";
@@ -391,6 +419,21 @@ declare const APP_REGISTRY_ABI: readonly [{
391
419
  }];
392
420
  readonly name: "AppFeeChanged";
393
421
  readonly type: "event";
422
+ }, {
423
+ readonly anonymous: false;
424
+ readonly inputs: readonly [{
425
+ readonly indexed: true;
426
+ readonly internalType: "bytes32";
427
+ readonly name: "app_id";
428
+ readonly type: "bytes32";
429
+ }, {
430
+ readonly indexed: false;
431
+ readonly internalType: "string";
432
+ readonly name: "agent_uri";
433
+ readonly type: "string";
434
+ }];
435
+ readonly name: "AppAgentChanged";
436
+ readonly type: "event";
394
437
  }, {
395
438
  readonly anonymous: false;
396
439
  readonly inputs: readonly [{
@@ -115,6 +115,21 @@ const APP_REGISTRY_ABI = [
115
115
  "stateMutability": "view",
116
116
  "type": "function"
117
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
+ },
118
133
  {
119
134
  "inputs": [{
120
135
  "internalType": "bytes32",
@@ -315,6 +330,21 @@ const APP_REGISTRY_ABI = [
315
330
  "stateMutability": "nonpayable",
316
331
  "type": "function"
317
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
+ },
318
348
  {
319
349
  "inputs": [
320
350
  {
@@ -444,6 +474,22 @@ const APP_REGISTRY_ABI = [
444
474
  "name": "AppFeeChanged",
445
475
  "type": "event"
446
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
+ },
447
493
  {
448
494
  "anonymous": false,
449
495
  "inputs": [
@@ -23,20 +23,17 @@ interface AppJoinInfo {
23
23
  /** The protocol admin has taken the whole app down — nobody is registered. */
24
24
  appSuspended: boolean;
25
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
+ }
26
33
  /** True when the publisher joined but the app's terms have since changed. */
27
34
  declare function needsReacceptance(info: AppJoinInfo): boolean;
28
35
  /**
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.
36
+ * Client for the AppRegistry
40
37
  */
41
38
  declare class AppRegistryClient {
42
39
  private contractAddress;
@@ -44,96 +41,80 @@ declare class AppRegistryClient {
44
41
  private publicClient;
45
42
  private walletClient;
46
43
  constructor(contractAddress: Address, appId: Hex, publicClient: PublicClient, walletClient: WalletClient);
47
- /** The app every call on this client is scoped to. */
48
44
  getAppId(): Hex;
49
- /** Re-scope every subsequent call to a different app. */
50
45
  setAppId(appId: Hex): void;
51
- /** The deployed AppRegistry this client talks to. */
52
46
  getAddress(): Address;
53
- /** Same gas buffer and fee styling as DataRegistryClient.executeWrite. */
54
47
  private executeWrite;
55
48
  /**
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.
49
+ * try to register an app (if it has not been claimed)
62
50
  */
63
51
  registerApp(termsHash: Hex, termsUri: string, fee?: bigint): Promise<Hash>;
64
52
  /**
65
53
  * Publish new terms for this app.
66
54
  *
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.
55
+ * Every registered must accept the new terms in order to publish again
70
56
  */
71
57
  setAppTerms(termsHash: Hex, termsUri: string): Promise<Hash>;
72
- /** Set what joining this app costs, in wei. Paid to the app owner. */
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>;
73
67
  setAppFee(fee: bigint): Promise<Hash>;
74
68
  /**
75
- * Eject a publisher from THIS app. Their global DataRegistry standing and
76
- * their membership of every other app are untouched.
69
+ * Suspend a publisher from this app
70
+ * only callable by the app owner
77
71
  */
78
72
  suspendForApp(publisher: Address): Promise<Hash>;
79
73
  reinstateForApp(publisher: Address): Promise<Hash>;
80
74
  /**
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.
75
+ * Suspend an app and all publish capabilities
85
76
  */
86
77
  suspendApp(): Promise<Hash>;
87
- /** Lift an admin takedown, restoring every membership as it was. */
88
78
  reinstateApp(): Promise<Hash>;
89
- /** The protocol admin of this AppRegistry — the only caller `suspendApp` accepts. */
90
79
  admin(): Promise<Address>;
91
80
  /**
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.
81
+ * Register as a publisher within an app
82
+ * Registration = accepting its current terms
104
83
  */
105
84
  registerForApp(): Promise<Hash>;
106
85
  /**
107
- * The same join, as an unsigned transaction for a wallet that signs elsewhere
108
- * (the sond3r relay never holds a key). Mirrors `prepareCommitStateRoot`.
86
+ * prepare the tx to register as a publisher for an app
109
87
  */
110
88
  prepareRegisterForApp(publisher: Address): Promise<PreparedTx & {
111
89
  value: Hex;
112
90
  }>;
113
- /** Owner of this client's app id, or the zero address if unclaimed. */
114
91
  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
92
  isRegisteredForApp(publisher: Address): Promise<boolean>;
121
- /** Has the protocol admin taken this app down? */
122
93
  isAppSuspended(): Promise<boolean>;
123
- /** This app's current terms hash, or the zero hash if it has published none. */
124
94
  appTerms(): Promise<Hex>;
125
95
  appTermsUri(): Promise<string>;
126
- appFee(): Promise<bigint>;
127
- /** The terms hash this publisher accepted, or the zero hash. */
128
- acceptedTerms(publisher: Address): Promise<Hex>;
96
+ /** The agent card URI of this app, or of `appId`. Empty if none is set. */
97
+ appAgentUri(appId?: Hex): Promise<string>;
129
98
  /**
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".
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.
133
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>;
134
115
  joinInfo(publisher: Address): Promise<AppJoinInfo>;
135
116
  private readJoinInfoTuple;
136
117
  private senderAddress;
137
118
  }
138
119
  //#endregion
139
- export { AppJoinInfo, AppRegistryClient, needsReacceptance };
120
+ export { AppAgentLog, AppJoinInfo, AppRegistryClient, needsReacceptance };
@@ -1,5 +1,6 @@
1
1
  import { APP_REGISTRY_ABI } from "./abi.js";
2
2
  import { requireWallet, sendWrite } from "../write.js";
3
+ import { getLogsInWindows } from "../logs.js";
3
4
  import { PublisherStatus } from "../types.js";
4
5
  import { encodeFunctionData, toHex } from "viem";
5
6
 
@@ -9,17 +10,7 @@ function needsReacceptance(info) {
9
10
  return !info.registered && info.status === PublisherStatus.ACTIVE && info.acceptedTerms !== info.termsHash;
10
11
  }
11
12
  /**
12
- * Client for the AppRegistry — app ids, per-app publisher terms, per-app join
13
- * fees, and per-app membership.
14
- *
15
- * This contract owns what an "app" is. `registerApp` and `getAppOwner` used to
16
- * live on the DataRegistry, which meant two contracts held partial opinions about
17
- * apps and neither could enforce membership. The dependency now runs one way:
18
- * `DataRegistry.commitStateRoot` cross-calls `isRegisteredForApp` here, so a
19
- * publisher must join an app *before* they can write under it.
20
- *
21
- * Scoped to one `appId`, like `DataRegistryClient` — the app is an identity the
22
- * client carries, not an argument every call repeats.
13
+ * Client for the AppRegistry
23
14
  */
24
15
  var AppRegistryClient = class {
25
16
  constructor(contractAddress, appId, publicClient, walletClient) {
@@ -28,29 +19,20 @@ var AppRegistryClient = class {
28
19
  this.publicClient = publicClient;
29
20
  this.walletClient = walletClient;
30
21
  }
31
- /** The app every call on this client is scoped to. */
32
22
  getAppId() {
33
23
  return this.appId;
34
24
  }
35
- /** Re-scope every subsequent call to a different app. */
36
25
  setAppId(appId) {
37
26
  this.appId = appId;
38
27
  }
39
- /** The deployed AppRegistry this client talks to. */
40
28
  getAddress() {
41
29
  return this.contractAddress;
42
30
  }
43
- /** Same gas buffer and fee styling as DataRegistryClient.executeWrite. */
44
31
  executeWrite(functionName, args, value) {
45
32
  return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, APP_REGISTRY_ABI, functionName, args, value);
46
33
  }
47
34
  /**
48
- * Claim this client's `appId` and open it in one transaction — owner, terms
49
- * and join fee together. First come, first served, and irreversible: there is
50
- * no transfer and no release.
51
- *
52
- * `termsHash` must be real. An app whose terms hash is zero cannot be joined
53
- * by anyone, so claiming an id without them creates a market nobody can enter.
35
+ * try to register an app (if it has not been claimed)
54
36
  */
55
37
  async registerApp(termsHash, termsUri, fee = 0n) {
56
38
  return this.executeWrite("registerApp", [
@@ -63,9 +45,7 @@ var AppRegistryClient = class {
63
45
  /**
64
46
  * Publish new terms for this app.
65
47
  *
66
- * This drops every publisher back to "must accept again" — `isRegisteredForApp`
67
- * is false for anyone whose accepted hash no longer matches — so it is a real
68
- * act with a real consequence, not a copy edit. Re-accepting is free for them.
48
+ * Every registered must accept the new terms in order to publish again
69
49
  */
70
50
  async setAppTerms(termsHash, termsUri) {
71
51
  return this.executeWrite("setAppTerms", [
@@ -74,13 +54,23 @@ var AppRegistryClient = class {
74
54
  termsUri
75
55
  ]);
76
56
  }
77
- /** Set what joining this app costs, in wei. Paid to the app owner. */
57
+ /**
58
+ * Point this app at its ERC-8004 agent card.
59
+ *
60
+ * Safe to call whenever the card moves. It is a separate field from the terms
61
+ * URI for one reason: publishers are bound to `termsHash`, so anything sharing
62
+ * that slot unregisters every publisher in the app the moment it changes (see
63
+ * `needsReacceptance`). A card holds endpoints and pubkeys, which rotate.
64
+ */
65
+ async setAppAgentUri(agentUri) {
66
+ return this.executeWrite("setAppAgentUri", [this.appId, agentUri]);
67
+ }
78
68
  async setAppFee(fee) {
79
69
  return this.executeWrite("setAppFee", [this.appId, fee]);
80
70
  }
81
71
  /**
82
- * Eject a publisher from THIS app. Their global DataRegistry standing and
83
- * their membership of every other app are untouched.
72
+ * Suspend a publisher from this app
73
+ * only callable by the app owner
84
74
  */
85
75
  async suspendForApp(publisher) {
86
76
  return this.executeWrite("suspendForApp", [this.appId, publisher]);
@@ -89,19 +79,14 @@ var AppRegistryClient = class {
89
79
  return this.executeWrite("reinstateForApp", [this.appId, publisher]);
90
80
  }
91
81
  /**
92
- * Take this whole app down. Protocol-admin only, and a level above
93
- * `suspendForApp`: every publisher of the app — its owner included — reads as
94
- * unregistered, so nothing commits under it until it is reinstated. The
95
- * memberships underneath are left intact, so reinstating restores them exactly.
82
+ * Suspend an app and all publish capabilities
96
83
  */
97
84
  async suspendApp() {
98
85
  return this.executeWrite("suspendApp", [this.appId]);
99
86
  }
100
- /** Lift an admin takedown, restoring every membership as it was. */
101
87
  async reinstateApp() {
102
88
  return this.executeWrite("reinstateApp", [this.appId]);
103
89
  }
104
- /** The protocol admin of this AppRegistry — the only caller `suspendApp` accepts. */
105
90
  async admin() {
106
91
  return this.publicClient.readContract({
107
92
  address: this.contractAddress,
@@ -110,18 +95,8 @@ var AppRegistryClient = class {
110
95
  });
111
96
  }
112
97
  /**
113
- * Join this app, accepting its current terms by the act of doing so.
114
- *
115
- * The hash is read immediately before sending and passed as an argument, and
116
- * the contract reverts `TermsMismatch` if it no longer matches. That is the
117
- * point: the transaction is only valid against the exact version that was in
118
- * front of the caller, so terms cannot change under a pending registration and
119
- * land as agreement to something else. A race here is a revert, not a
120
- * surprise obligation.
121
- *
122
- * The join fee is read from the chain rather than passed in, for the same
123
- * reason `DataRegistryClient.register()` reads the registration fee: a caller
124
- * who supplies it can supply the wrong one.
98
+ * Register as a publisher within an app
99
+ * Registration = accepting its current terms
125
100
  */
126
101
  async registerForApp() {
127
102
  const [termsHash, , fee] = await this.readJoinInfoTuple(this.senderAddress());
@@ -129,8 +104,7 @@ var AppRegistryClient = class {
129
104
  return this.executeWrite("registerForApp", [this.appId, termsHash], fee);
130
105
  }
131
106
  /**
132
- * The same join, as an unsigned transaction for a wallet that signs elsewhere
133
- * (the sond3r relay never holds a key). Mirrors `prepareCommitStateRoot`.
107
+ * prepare the tx to register as a publisher for an app
134
108
  */
135
109
  async prepareRegisterForApp(publisher) {
136
110
  const [termsHash, , fee] = await this.readJoinInfoTuple(publisher);
@@ -164,7 +138,6 @@ var AppRegistryClient = class {
164
138
  value: toHex(fee)
165
139
  };
166
140
  }
167
- /** Owner of this client's app id, or the zero address if unclaimed. */
168
141
  async getAppOwner() {
169
142
  return this.publicClient.readContract({
170
143
  address: this.contractAddress,
@@ -173,11 +146,6 @@ var AppRegistryClient = class {
173
146
  args: [this.appId]
174
147
  });
175
148
  }
176
- /**
177
- * May this publisher commit under this app? This is the exact question
178
- * `DataRegistry.commitStateRoot` asks on-chain, so a false here means a
179
- * publish would revert.
180
- */
181
149
  async isRegisteredForApp(publisher) {
182
150
  return this.publicClient.readContract({
183
151
  address: this.contractAddress,
@@ -186,7 +154,6 @@ var AppRegistryClient = class {
186
154
  args: [this.appId, publisher]
187
155
  });
188
156
  }
189
- /** Has the protocol admin taken this app down? */
190
157
  async isAppSuspended() {
191
158
  return this.publicClient.readContract({
192
159
  address: this.contractAddress,
@@ -195,7 +162,6 @@ var AppRegistryClient = class {
195
162
  args: [this.appId]
196
163
  });
197
164
  }
198
- /** This app's current terms hash, or the zero hash if it has published none. */
199
165
  async appTerms() {
200
166
  return this.publicClient.readContract({
201
167
  address: this.contractAddress,
@@ -212,6 +178,41 @@ var AppRegistryClient = class {
212
178
  args: [this.appId]
213
179
  });
214
180
  }
181
+ /** The agent card URI of this app, or of `appId`. Empty if none is set. */
182
+ async appAgentUri(appId = this.appId) {
183
+ return this.publicClient.readContract({
184
+ address: this.contractAddress,
185
+ abi: APP_REGISTRY_ABI,
186
+ functionName: "appAgentUri",
187
+ args: [appId]
188
+ });
189
+ }
190
+ /**
191
+ * `AppAgentChanged` events, oldest first. The last one for an app is its
192
+ * current card; an empty `agentUri` means the owner unset it.
193
+ *
194
+ * Leave `appId` out to list every app that has ever set a card. The chain is
195
+ * the directory: one windowed log scan, no indexer and no registry namespace.
196
+ * `fromBlock` is required because scanning from genesis on an L2 costs
197
+ * hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
198
+ * a block you know to be before the app's registration.
199
+ */
200
+ async getAppAgentLogs(opts) {
201
+ return (await getLogsInWindows(this.publicClient, opts.fromBlock, opts.toBlock, (from, to) => this.publicClient.getContractEvents({
202
+ address: this.contractAddress,
203
+ abi: APP_REGISTRY_ABI,
204
+ eventName: "AppAgentChanged",
205
+ args: opts.appId ? { app_id: opts.appId } : {},
206
+ fromBlock: from,
207
+ toBlock: to,
208
+ strict: true
209
+ }))).map((log) => ({
210
+ appId: log.args.app_id,
211
+ agentUri: log.args.agent_uri,
212
+ blockNumber: log.blockNumber,
213
+ transactionHash: log.transactionHash
214
+ }));
215
+ }
215
216
  async appFee() {
216
217
  return this.publicClient.readContract({
217
218
  address: this.contractAddress,
@@ -220,7 +221,6 @@ var AppRegistryClient = class {
220
221
  args: [this.appId]
221
222
  });
222
223
  }
223
- /** The terms hash this publisher accepted, or the zero hash. */
224
224
  async acceptedTerms(publisher) {
225
225
  return this.publicClient.readContract({
226
226
  address: this.contractAddress,
@@ -229,11 +229,6 @@ var AppRegistryClient = class {
229
229
  args: [this.appId, publisher]
230
230
  });
231
231
  }
232
- /**
233
- * Everything a join screen needs. Two reads rather than one, because the
234
- * accepted hash is what turns "not registered" into the far more useful "the
235
- * terms changed since you joined".
236
- */
237
232
  async joinInfo(publisher) {
238
233
  const [tuple, acceptedTerms, appSuspended] = await Promise.all([
239
234
  this.readJoinInfoTuple(publisher),
@@ -4,16 +4,12 @@ import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
4
4
  //#region src/contracts/data-registry/index.d.ts
5
5
 
6
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.
7
+ * The onchain id of a namespace within an app is the sha256 hash of its hex representation
8
+ * i.e. ns = 'a' => ns_id = sha256(hex('a'))
10
9
  */
11
10
  declare function subspaceId(namespace: string): Hex;
12
11
  /**
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.
12
+ * The composite storage key for a full path to a subspace: `app:publisher:subspace`.
17
13
  */
18
14
  declare function namespaceKey(appId: Hex, publisher: Address, subspace: Hex): Hex;
19
15
  /**
@@ -132,12 +128,7 @@ declare class DataRegistryClient {
132
128
  * Historical `StateCommitted` logs for one slice of this app, oldest →
133
129
  * newest — the catch-up path for a subscriber resuming from a saved block
134
130
  * 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.
131
+ * Fetched in block windows (see `getLogsInWindows`).
141
132
  */
142
133
  getStateCommittedLogs(filter: CommitFilter, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
143
134
  /**
@@ -1,21 +1,18 @@
1
1
  import { requireWallet, sendWrite } from "../write.js";
2
+ import { getLogsInWindows } from "../logs.js";
2
3
  import { DATA_REGISTRY_ABI } from "./abi.js";
3
4
  import { concatHex, encodeFunctionData, keccak256, toHex } from "viem";
4
5
 
5
6
  //#region src/contracts/data-registry/index.ts
6
7
  /**
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.
8
+ * The onchain id of a namespace within an app is the sha256 hash of its hex representation
9
+ * i.e. ns = 'a' => ns_id = sha256(hex('a'))
10
10
  */
11
11
  function subspaceId(namespace) {
12
12
  return keccak256(toHex(namespace));
13
13
  }
14
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.
15
+ * The composite storage key for a full path to a subspace: `app:publisher:subspace`.
19
16
  */
20
17
  function namespaceKey(appId, publisher, subspace) {
21
18
  return keccak256(concatHex([
@@ -204,29 +201,17 @@ var DataRegistryClient = class {
204
201
  * Historical `StateCommitted` logs for one slice of this app, oldest →
205
202
  * newest — the catch-up path for a subscriber resuming from a saved block
206
203
  * 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.
204
+ * Fetched in block windows (see `getLogsInWindows`).
213
205
  */
214
206
  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);
207
+ return (await getLogsInWindows(this.publicClient, fromBlock, toBlock, (from, to) => this.publicClient.getContractEvents({
208
+ address: this.contractAddress,
209
+ abi: DATA_REGISTRY_ABI,
210
+ eventName: "StateCommitted",
211
+ args: this.topicsFor(filter),
212
+ fromBlock: from,
213
+ toBlock: to
214
+ }))).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
215
  }
231
216
  /**
232
217
  * Live-watch `StateCommitted` for one slice of this app. Returns an
@@ -1,10 +1,10 @@
1
1
  import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
2
2
  import { PublisherStatus } from "./types.js";
3
3
  import { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId } from "./data-registry/index.js";
4
- import { AppJoinInfo, AppRegistryClient, needsReacceptance } from "./app-registry/index.js";
4
+ import { AppAgentLog, AppJoinInfo, AppRegistryClient, needsReacceptance } from "./app-registry/index.js";
5
5
  import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
6
6
  import { Resource, SemaphoreProof, SettlementRegistryClient, TransferAuthorization, packResourceUri, resourceIdOf } from "./settlement-registry/index.js";
7
7
  import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
8
8
  import { SubscriptionAccess, SubscriptionRegistryClient } from "./subscription-registry/index.js";
9
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 };
10
+ export { APP_REGISTRY_ABI, AppAgentLog, 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 };
@@ -0,0 +1,18 @@
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
+ declare function getLogsInWindows<T>(publicClient: PublicClient, fromBlock: bigint, toBlock: bigint | undefined, fetch: (fromBlock: bigint, toBlock: bigint) => Promise<T[]>): Promise<T[]>;
17
+ //#endregion
18
+ export { getLogsInWindows };