@fangorn-network/sdk 2026.7.27 → 2026.7.29-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.
@@ -5,6 +5,16 @@ const DATA_REGISTRY_ABI = [
5
5
  "name": "AlreadyRegistered",
6
6
  "type": "error"
7
7
  },
8
+ {
9
+ "inputs": [],
10
+ "name": "AppAlreadyRegistered",
11
+ "type": "error"
12
+ },
13
+ {
14
+ "inputs": [],
15
+ "name": "AppNotFound",
16
+ "type": "error"
17
+ },
8
18
  {
9
19
  "inputs": [],
10
20
  "name": "NotRegistered",
@@ -30,6 +40,22 @@ const DATA_REGISTRY_ABI = [
30
40
  "name": "Unauthorized",
31
41
  "type": "error"
32
42
  },
43
+ {
44
+ "anonymous": false,
45
+ "inputs": [{
46
+ "indexed": true,
47
+ "internalType": "bytes32",
48
+ "name": "app_id",
49
+ "type": "bytes32"
50
+ }, {
51
+ "indexed": true,
52
+ "internalType": "address",
53
+ "name": "owner",
54
+ "type": "address"
55
+ }],
56
+ "name": "AppRegistered",
57
+ "type": "event"
58
+ },
33
59
  {
34
60
  "anonymous": false,
35
61
  "inputs": [{
@@ -87,6 +113,18 @@ const DATA_REGISTRY_ABI = [
87
113
  {
88
114
  "anonymous": false,
89
115
  "inputs": [
116
+ {
117
+ "indexed": true,
118
+ "internalType": "bytes32",
119
+ "name": "namespace_key",
120
+ "type": "bytes32"
121
+ },
122
+ {
123
+ "indexed": true,
124
+ "internalType": "bytes32",
125
+ "name": "app_id",
126
+ "type": "bytes32"
127
+ },
90
128
  {
91
129
  "indexed": true,
92
130
  "internalType": "address",
@@ -94,13 +132,19 @@ const DATA_REGISTRY_ABI = [
94
132
  "type": "address"
95
133
  },
96
134
  {
97
- "indexed": true,
135
+ "indexed": false,
136
+ "internalType": "bytes32",
137
+ "name": "subspace_id",
138
+ "type": "bytes32"
139
+ },
140
+ {
141
+ "indexed": false,
98
142
  "internalType": "bytes32",
99
143
  "name": "old_root",
100
144
  "type": "bytes32"
101
145
  },
102
146
  {
103
- "indexed": true,
147
+ "indexed": false,
104
148
  "internalType": "bytes32",
105
149
  "name": "new_root",
106
150
  "type": "bytes32"
@@ -121,15 +165,28 @@ const DATA_REGISTRY_ABI = [
121
165
  "type": "function"
122
166
  },
123
167
  {
124
- "inputs": [{
125
- "internalType": "bytes32",
126
- "name": "old_root",
127
- "type": "bytes32"
128
- }, {
129
- "internalType": "bytes32",
130
- "name": "new_root",
131
- "type": "bytes32"
132
- }],
168
+ "inputs": [
169
+ {
170
+ "internalType": "bytes32",
171
+ "name": "app_id",
172
+ "type": "bytes32"
173
+ },
174
+ {
175
+ "internalType": "bytes32",
176
+ "name": "subspace_id",
177
+ "type": "bytes32"
178
+ },
179
+ {
180
+ "internalType": "bytes32",
181
+ "name": "old_root",
182
+ "type": "bytes32"
183
+ },
184
+ {
185
+ "internalType": "bytes32",
186
+ "name": "new_root",
187
+ "type": "bytes32"
188
+ }
189
+ ],
133
190
  "name": "commitStateRoot",
134
191
  "outputs": [],
135
192
  "stateMutability": "nonpayable",
@@ -137,10 +194,37 @@ const DATA_REGISTRY_ABI = [
137
194
  },
138
195
  {
139
196
  "inputs": [{
197
+ "internalType": "bytes32",
198
+ "name": "app_id",
199
+ "type": "bytes32"
200
+ }],
201
+ "name": "getAppOwner",
202
+ "outputs": [{
140
203
  "internalType": "address",
141
- "name": "publisher",
204
+ "name": "",
142
205
  "type": "address"
143
206
  }],
207
+ "stateMutability": "view",
208
+ "type": "function"
209
+ },
210
+ {
211
+ "inputs": [
212
+ {
213
+ "internalType": "bytes32",
214
+ "name": "app_id",
215
+ "type": "bytes32"
216
+ },
217
+ {
218
+ "internalType": "address",
219
+ "name": "publisher",
220
+ "type": "address"
221
+ },
222
+ {
223
+ "internalType": "bytes32",
224
+ "name": "subspace_id",
225
+ "type": "bytes32"
226
+ }
227
+ ],
144
228
  "name": "getNamespaceHead",
145
229
  "outputs": [{
146
230
  "internalType": "bytes32",
@@ -198,6 +282,17 @@ const DATA_REGISTRY_ABI = [
198
282
  "stateMutability": "payable",
199
283
  "type": "function"
200
284
  },
285
+ {
286
+ "inputs": [{
287
+ "internalType": "bytes32",
288
+ "name": "app_id",
289
+ "type": "bytes32"
290
+ }],
291
+ "name": "registerApp",
292
+ "outputs": [],
293
+ "stateMutability": "nonpayable",
294
+ "type": "function"
295
+ },
201
296
  {
202
297
  "inputs": [],
203
298
  "name": "registrationFee",
@@ -7,42 +7,113 @@ declare enum PublisherStatus {
7
7
  SUSPENDED = 2,
8
8
  }
9
9
  /**
10
- * A decoded `StateCommitted(publisher, old_root, new_root)` log — the single
11
- * on-chain signal that a publisher's state root advanced. `logId` uniquely
12
- * identifies the emitting log (tx + index) so consumers can dedupe across the
13
- * catch-up (getLogs) and live (watch) paths.
10
+ * The on-chain id of a namespace within an app: the SDK's human-readable
11
+ * namespace name, hashed. Names never touch storage — the contract only ever
12
+ * sees these 32 bytes.
13
+ */
14
+ declare function subspaceId(namespace: string): Hex;
15
+ /**
16
+ * The composite storage key the contract derives for `app:publisher:subspace`.
17
+ * Mirrors `namespace_key()` in contracts/data_registry — keccak256 over the
18
+ * packed 84 bytes. Computing it client-side is what lets a subscriber filter
19
+ * one exact subspace with a single indexed topic.
20
+ */
21
+ declare function namespaceKey(appId: Hex, publisher: Address, subspace: Hex): Hex;
22
+ /**
23
+ * A decoded `StateCommitted` log — the single on-chain signal that one
24
+ * hierarchical namespace's state root advanced. `logId` uniquely identifies the
25
+ * emitting log (tx + index) so consumers can dedupe across the catch-up
26
+ * (getLogs) and live (watch) paths.
14
27
  */
15
28
  interface StateCommittedLog {
29
+ namespaceKey: Hex;
30
+ appId: Hex;
31
+ publisher: Address;
32
+ subspaceId: Hex;
16
33
  oldRoot: Hex;
17
34
  newRoot: Hex;
18
35
  blockNumber: bigint;
19
36
  logId: string;
20
37
  }
38
+ /**
39
+ * Which slice of the app's commit stream to read. Every field is an indexed
40
+ * topic, so filtering happens on the RPC node — no indexer, no subgraph:
41
+ *
42
+ * {} — the whole app, every publisher and subspace
43
+ * { publisher } — one publisher's commits across the app
44
+ * { publisher, namespace } — one exact subspace (the tightest filter)
45
+ *
46
+ * `namespace` alone is not filterable: the key binds the publisher too, so a
47
+ * subspace name across all publishers means filtering the app stream in memory.
48
+ */
49
+ interface CommitFilter {
50
+ publisher?: Address;
51
+ namespace?: string;
52
+ }
53
+ /**
54
+ * An unsigned transaction, hex-encoded and ready to hand to a browser wallet's
55
+ * `eth_sendTransaction` — no `from`, since the signing wallet supplies it.
56
+ */
57
+ interface PreparedTx {
58
+ to: Address;
59
+ data: Hex;
60
+ chainId: number | undefined;
61
+ gas: Hex;
62
+ maxFeePerGas: Hex;
63
+ maxPriorityFeePerGas: Hex;
64
+ }
21
65
  declare class DataRegistryClient {
22
66
  private contractAddress;
67
+ private appId;
23
68
  private publicClient;
24
69
  private walletClient;
25
- constructor(contractAddress: Address, publicClient: PublicClient, walletClient: WalletClient);
70
+ constructor(contractAddress: Address, appId: Hex, publicClient: PublicClient, walletClient: WalletClient);
71
+ /** The app namespace every call on this client is scoped to. */
72
+ getAppId(): Hex;
73
+ /** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
74
+ setAppId(appId: Hex): void;
26
75
  private getWriteConfig;
27
76
  /**
28
77
  * Internal helper to execute state-mutating transactions
29
78
  * matching the exact gas buffer and aggressive fee styling of the protocol.
30
79
  */
31
80
  private executeWrite;
81
+ /** The composite key for one of this app's namespaces. */
82
+ namespaceKey(publisher: Address, namespace: string): Hex;
83
+ /**
84
+ * Claim this client's `appId` on-chain. First come, first served — an app
85
+ * must own its id before any publisher can commit under it.
86
+ */
87
+ registerApp(): Promise<Hash>;
32
88
  /**
33
89
  * Register as a new data publisher or reactivate a suspended account.
34
90
  * Automatically reads the required on-chain fee and attaches it to the call.
35
91
  */
36
92
  register(): Promise<Hash>;
37
93
  /**
38
- * The single mutating state gateway route.
39
- * Enforces the sequential Compare-And-Swap (CAS) timeline rule.
94
+ * The single mutating state gateway route. Enforces the sequential
95
+ * Compare-And-Swap (CAS) timeline rule — per namespace, so concurrent pushes
96
+ * to *different* namespaces never contend.
97
+ */
98
+ commitStateRoot(namespace: string, oldRoot: Hex, newRoot: Hex): Promise<Hash>;
99
+ /**
100
+ * Build the `commitStateRoot` call as an UNSIGNED transaction for `publisher`
101
+ * to sign, instead of sending it from this client's wallet.
102
+ *
103
+ * This is the self-custodial publish path: a relay server builds and pins the
104
+ * commit with a keyless service wallet, then hands this back for the user's
105
+ * browser wallet to sign. The server never holds the key that moves the head,
106
+ * and the on-chain sender IS the publisher — which is what authenticates the
107
+ * publish, since the contract keys the namespace by `msg_sender`.
40
108
  */
41
- commitStateRoot(oldRoot: Hex, newRoot: Hex): Promise<Hash>;
109
+ prepareCommitStateRoot(publisher: Address, namespace: string, oldRoot: Hex, newRoot: Hex): Promise<PreparedTx>;
42
110
  /**
43
- * Obtains the authoritative timeline tracking anchor for a specific publisher's tree.
111
+ * Obtains the authoritative timeline tracking anchor for one publisher's
112
+ * namespace within this app.
44
113
  */
45
- getNamespaceHead(publisher: Address): Promise<Hex>;
114
+ getNamespaceHead(publisher: Address, namespace: string): Promise<Hex>;
115
+ /** Owner of this client's app id, or the zero address if unclaimed. */
116
+ getAppOwner(): Promise<Address>;
46
117
  /**
47
118
  * Reads the explicit enum lifecycle state from the registry status machine.
48
119
  */
@@ -53,18 +124,21 @@ declare class DataRegistryClient {
53
124
  isRegistered(publisher: Address): Promise<boolean>;
54
125
  /** Current chain head block number — the default "start here" for a fresh subscription. */
55
126
  currentBlock(): Promise<bigint>;
127
+ /** Translate a `CommitFilter` into indexed-topic args for this app. */
128
+ private topicsFor;
56
129
  /**
57
- * Historical `StateCommitted` logs for one publisher, oldest → newest — the
58
- * catch-up path for a subscriber resuming from a saved block cursor. Node-side
59
- * filtered by the indexed `publisher` topic, so no indexer is involved.
130
+ * Historical `StateCommitted` logs for one slice of this app, oldest →
131
+ * newest — the catch-up path for a subscriber resuming from a saved block
132
+ * cursor. Node-side filtered by indexed topics, so no indexer is involved.
60
133
  */
61
- getStateCommittedLogs(publisher: Address, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
134
+ getStateCommittedLogs(filter: CommitFilter, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
62
135
  /**
63
- * Live-watch `StateCommitted` for one publisher. Returns an unsubscribe
64
- * function. Uses the client's transport (polling over HTTP, push over a
65
- * WebSocket transport) — reads logs straight from the RPC node, no subgraph.
136
+ * Live-watch `StateCommitted` for one slice of this app. Returns an
137
+ * unsubscribe function. Uses the client's transport (polling over HTTP, push
138
+ * over a WebSocket transport) — reads logs straight from the RPC node, no
139
+ * subgraph.
66
140
  */
67
- watchStateCommitted(publisher: Address, onCommit: (log: StateCommittedLog) => void, onError?: (err: Error) => void, pollingInterval?: number): () => void;
141
+ watchStateCommitted(filter: CommitFilter, onCommit: (log: StateCommittedLog) => void, onError?: (err: Error) => void, pollingInterval?: number): () => void;
68
142
  publisherCount(): Promise<bigint>;
69
143
  registrationFee(): Promise<bigint>;
70
144
  admin(): Promise<Address>;
@@ -78,4 +152,4 @@ declare class DataRegistryClient {
78
152
  setRegistrationFee(fee: bigint): Promise<Hash>;
79
153
  }
80
154
  //#endregion
81
- export { DataRegistryClient, PublisherStatus, StateCommittedLog };
155
+ export { CommitFilter, DataRegistryClient, PreparedTx, PublisherStatus, StateCommittedLog, namespaceKey, subspaceId };
@@ -1,4 +1,5 @@
1
1
  import { DATA_REGISTRY_ABI } from "./abi.js";
2
+ import { concatHex, encodeFunctionData, keccak256, toHex } from "viem";
2
3
 
3
4
  //#region src/contracts/data-registry/index.ts
4
5
  let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
@@ -7,21 +8,56 @@ let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
7
8
  PublisherStatus$1[PublisherStatus$1["SUSPENDED"] = 2] = "SUSPENDED";
8
9
  return PublisherStatus$1;
9
10
  }({});
11
+ /**
12
+ * The on-chain id of a namespace within an app: the SDK's human-readable
13
+ * namespace name, hashed. Names never touch storage — the contract only ever
14
+ * sees these 32 bytes.
15
+ */
16
+ function subspaceId(namespace) {
17
+ return keccak256(toHex(namespace));
18
+ }
19
+ /**
20
+ * The composite storage key the contract derives for `app:publisher:subspace`.
21
+ * Mirrors `namespace_key()` in contracts/data_registry — keccak256 over the
22
+ * packed 84 bytes. Computing it client-side is what lets a subscriber filter
23
+ * one exact subspace with a single indexed topic.
24
+ */
25
+ function namespaceKey(appId, publisher, subspace) {
26
+ return keccak256(concatHex([
27
+ appId,
28
+ publisher,
29
+ subspace
30
+ ]));
31
+ }
10
32
  function decodeStateCommitted(log) {
11
- if (log.args.old_root === void 0 || log.args.new_root === void 0) throw new Error("Malformed log event: missing state roots");
33
+ const a = log.args;
34
+ 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");
12
35
  return {
13
- oldRoot: log.args.old_root,
14
- newRoot: log.args.new_root,
36
+ namespaceKey: a.namespace_key,
37
+ appId: a.app_id,
38
+ publisher: a.publisher,
39
+ subspaceId: a.subspace_id,
40
+ oldRoot: a.old_root,
41
+ newRoot: a.new_root,
15
42
  blockNumber: log.blockNumber,
16
43
  logId: `${log.transactionHash}:${log.logIndex.toString()}`
17
44
  };
18
45
  }
19
46
  var DataRegistryClient = class {
20
- constructor(contractAddress, publicClient, walletClient) {
47
+ constructor(contractAddress, appId, publicClient, walletClient) {
21
48
  this.contractAddress = contractAddress;
49
+ this.appId = appId;
22
50
  this.publicClient = publicClient;
23
51
  this.walletClient = walletClient;
24
52
  }
53
+ /** The app namespace every call on this client is scoped to. */
54
+ getAppId() {
55
+ return this.appId;
56
+ }
57
+ /** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
58
+ setAppId(appId) {
59
+ this.appId = appId;
60
+ }
25
61
  getWriteConfig() {
26
62
  if (!this.walletClient.chain) throw new Error("Chain required");
27
63
  if (!this.walletClient.account) throw new Error("Account required");
@@ -60,6 +96,17 @@ var DataRegistryClient = class {
60
96
  await this.publicClient.waitForTransactionReceipt({ hash });
61
97
  return hash;
62
98
  }
99
+ /** The composite key for one of this app's namespaces. */
100
+ namespaceKey(publisher, namespace) {
101
+ return namespaceKey(this.appId, publisher, subspaceId(namespace));
102
+ }
103
+ /**
104
+ * Claim this client's `appId` on-chain. First come, first served — an app
105
+ * must own its id before any publisher can commit under it.
106
+ */
107
+ async registerApp() {
108
+ return this.executeWrite("registerApp", [this.appId]);
109
+ }
63
110
  /**
64
111
  * Register as a new data publisher or reactivate a suspended account.
65
112
  * Automatically reads the required on-chain fee and attaches it to the call.
@@ -69,21 +116,84 @@ var DataRegistryClient = class {
69
116
  return this.executeWrite("register", [], fee);
70
117
  }
71
118
  /**
72
- * The single mutating state gateway route.
73
- * Enforces the sequential Compare-And-Swap (CAS) timeline rule.
119
+ * The single mutating state gateway route. Enforces the sequential
120
+ * Compare-And-Swap (CAS) timeline rule — per namespace, so concurrent pushes
121
+ * to *different* namespaces never contend.
122
+ */
123
+ async commitStateRoot(namespace, oldRoot, newRoot) {
124
+ return this.executeWrite("commitStateRoot", [
125
+ this.appId,
126
+ subspaceId(namespace),
127
+ oldRoot,
128
+ newRoot
129
+ ]);
130
+ }
131
+ /**
132
+ * Build the `commitStateRoot` call as an UNSIGNED transaction for `publisher`
133
+ * to sign, instead of sending it from this client's wallet.
134
+ *
135
+ * This is the self-custodial publish path: a relay server builds and pins the
136
+ * commit with a keyless service wallet, then hands this back for the user's
137
+ * browser wallet to sign. The server never holds the key that moves the head,
138
+ * and the on-chain sender IS the publisher — which is what authenticates the
139
+ * publish, since the contract keys the namespace by `msg_sender`.
74
140
  */
75
- async commitStateRoot(oldRoot, newRoot) {
76
- return this.executeWrite("commitStateRoot", [oldRoot, newRoot]);
141
+ async prepareCommitStateRoot(publisher, namespace, oldRoot, newRoot) {
142
+ const data = encodeFunctionData({
143
+ abi: DATA_REGISTRY_ABI,
144
+ functionName: "commitStateRoot",
145
+ args: [
146
+ this.appId,
147
+ subspaceId(namespace),
148
+ oldRoot,
149
+ newRoot
150
+ ]
151
+ });
152
+ const fees = await this.publicClient.estimateFeesPerGas();
153
+ let gas;
154
+ try {
155
+ gas = await this.publicClient.estimateGas({
156
+ account: publisher,
157
+ to: this.contractAddress,
158
+ data
159
+ }) * 3n / 2n;
160
+ } catch (err) {
161
+ const message = err instanceof Error ? err.message : String(err);
162
+ if (/revert/i.test(message)) throw new Error(`settlement would revert — the head may have moved on-chain, or the app is unregistered: ${message}`);
163
+ gas = 5000000n;
164
+ }
165
+ return {
166
+ to: this.contractAddress,
167
+ data,
168
+ chainId: this.publicClient.chain?.id,
169
+ gas: toHex(gas),
170
+ maxFeePerGas: toHex(fees.maxFeePerGas * 2n),
171
+ maxPriorityFeePerGas: toHex(fees.maxPriorityFeePerGas)
172
+ };
77
173
  }
78
174
  /**
79
- * Obtains the authoritative timeline tracking anchor for a specific publisher's tree.
175
+ * Obtains the authoritative timeline tracking anchor for one publisher's
176
+ * namespace within this app.
80
177
  */
81
- async getNamespaceHead(publisher) {
178
+ async getNamespaceHead(publisher, namespace) {
82
179
  return this.publicClient.readContract({
83
180
  address: this.contractAddress,
84
181
  abi: DATA_REGISTRY_ABI,
85
182
  functionName: "getNamespaceHead",
86
- args: [publisher]
183
+ args: [
184
+ this.appId,
185
+ publisher,
186
+ subspaceId(namespace)
187
+ ]
188
+ });
189
+ }
190
+ /** Owner of this client's app id, or the zero address if unclaimed. */
191
+ async getAppOwner() {
192
+ return this.publicClient.readContract({
193
+ address: this.contractAddress,
194
+ abi: DATA_REGISTRY_ABI,
195
+ functionName: "getAppOwner",
196
+ args: [this.appId]
87
197
  });
88
198
  }
89
199
  /**
@@ -112,35 +222,48 @@ var DataRegistryClient = class {
112
222
  async currentBlock() {
113
223
  return this.publicClient.getBlockNumber();
114
224
  }
225
+ /** Translate a `CommitFilter` into indexed-topic args for this app. */
226
+ topicsFor(filter) {
227
+ const { publisher, namespace } = filter;
228
+ return {
229
+ app_id: this.appId,
230
+ ...publisher ? { publisher } : {},
231
+ ...publisher && namespace ? { namespace_key: this.namespaceKey(publisher, namespace) } : {}
232
+ };
233
+ }
115
234
  /**
116
- * Historical `StateCommitted` logs for one publisher, oldest → newest — the
117
- * catch-up path for a subscriber resuming from a saved block cursor. Node-side
118
- * filtered by the indexed `publisher` topic, so no indexer is involved.
235
+ * Historical `StateCommitted` logs for one slice of this app, oldest →
236
+ * newest — the catch-up path for a subscriber resuming from a saved block
237
+ * cursor. Node-side filtered by indexed topics, so no indexer is involved.
119
238
  */
120
- async getStateCommittedLogs(publisher, fromBlock, toBlock) {
239
+ async getStateCommittedLogs(filter, fromBlock, toBlock) {
121
240
  return (await this.publicClient.getContractEvents({
122
241
  address: this.contractAddress,
123
242
  abi: DATA_REGISTRY_ABI,
124
243
  eventName: "StateCommitted",
125
- args: { publisher },
244
+ args: this.topicsFor(filter),
126
245
  fromBlock,
127
246
  toBlock: toBlock ?? "latest"
128
- })).map(decodeStateCommitted).sort((a, b) => a.blockNumber === b.blockNumber ? a.logId.localeCompare(b.logId) : a.blockNumber < b.blockNumber ? -1 : 1);
247
+ })).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);
129
248
  }
130
249
  /**
131
- * Live-watch `StateCommitted` for one publisher. Returns an unsubscribe
132
- * function. Uses the client's transport (polling over HTTP, push over a
133
- * WebSocket transport) — reads logs straight from the RPC node, no subgraph.
250
+ * Live-watch `StateCommitted` for one slice of this app. Returns an
251
+ * unsubscribe function. Uses the client's transport (polling over HTTP, push
252
+ * over a WebSocket transport) — reads logs straight from the RPC node, no
253
+ * subgraph.
134
254
  */
135
- watchStateCommitted(publisher, onCommit, onError, pollingInterval) {
255
+ watchStateCommitted(filter, onCommit, onError, pollingInterval) {
136
256
  return this.publicClient.watchContractEvent({
137
257
  address: this.contractAddress,
138
258
  abi: DATA_REGISTRY_ABI,
139
259
  eventName: "StateCommitted",
140
- args: { publisher },
260
+ args: this.topicsFor(filter),
141
261
  pollingInterval,
142
262
  onLogs: (logs) => {
143
- for (const log of logs) onCommit(decodeStateCommitted(log));
263
+ for (const raw of logs) {
264
+ const log = decodeStateCommitted(raw);
265
+ if (matchesFilter(log, filter)) onCommit(log);
266
+ }
144
267
  },
145
268
  onError
146
269
  });
@@ -179,6 +302,16 @@ var DataRegistryClient = class {
179
302
  return this.executeWrite("setRegistrationFee", [fee]);
180
303
  }
181
304
  };
305
+ /**
306
+ * The in-memory half of a filter. `subspace_id` is not an indexed topic (the
307
+ * three slots go to namespace_key/app_id/publisher), so a namespace-without-
308
+ * publisher filter — "every publisher's `docs` namespace" — narrows here
309
+ * instead of on the node.
310
+ */
311
+ function matchesFilter(log, filter) {
312
+ if (!filter.namespace || filter.publisher) return true;
313
+ return log.subspaceId === subspaceId(filter.namespace);
314
+ }
182
315
 
183
316
  //#endregion
184
- export { DataRegistryClient, PublisherStatus };
317
+ export { DataRegistryClient, PublisherStatus, namespaceKey, subspaceId };
@@ -1,5 +1,5 @@
1
1
  import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
2
- import { DataRegistryClient, PublisherStatus, StateCommittedLog } from "./data-registry/index.js";
2
+ import { CommitFilter, DataRegistryClient, PreparedTx, PublisherStatus, StateCommittedLog, namespaceKey, subspaceId } from "./data-registry/index.js";
3
3
  import { SettlementRegistryClient } from "./settlement-registry/index.js";
4
4
  import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
5
- export { DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, StateCommittedLog };
5
+ export { CommitFilter, DATA_REGISTRY_ABI, DataRegistryClient, PreparedTx, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, StateCommittedLog, namespaceKey, subspaceId };
@@ -1,6 +1,6 @@
1
1
  import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
2
- import { DataRegistryClient, PublisherStatus } from "./data-registry/index.js";
2
+ import { DataRegistryClient, PublisherStatus, namespaceKey, subspaceId } from "./data-registry/index.js";
3
3
  import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
4
4
  import { SettlementRegistryClient } from "./settlement-registry/index.js";
5
5
 
6
- export { DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient };
6
+ export { DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, namespaceKey, subspaceId };