@fangorn-network/sdk 2026.4.7-0 → 2026.4.10

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 (39) hide show
  1. package/README.md +30 -26
  2. package/lib/cli/cli.js +115 -153
  3. package/lib/config.d.ts +241 -241
  4. package/lib/config.js +3 -3
  5. package/lib/fangorn.d.ts +5 -0
  6. package/lib/fangorn.js +13 -8
  7. package/lib/index.js +1 -2
  8. package/lib/modules/encryption/lit.d.ts +0 -1
  9. package/lib/modules/encryption/lit.js +1 -7
  10. package/lib/modules/gadgets/settledGadget.d.ts +1 -8
  11. package/lib/modules/gadgets/settledGadget.js +1 -13
  12. package/lib/providers/storage/index.d.ts +1 -1
  13. package/lib/providers/storage/index.js +3 -1
  14. package/lib/providers/storage/pinata.js +1 -1
  15. package/lib/registries/datasource-registry/abi.d.ts +116 -43
  16. package/lib/registries/datasource-registry/abi.js +190 -12
  17. package/lib/registries/datasource-registry/index.d.ts +11 -6
  18. package/lib/registries/datasource-registry/index.js +89 -25
  19. package/lib/registries/index.js +1 -1
  20. package/lib/registries/schema-registry/abi.d.ts +157 -66
  21. package/lib/registries/schema-registry/abi.js +242 -15
  22. package/lib/registries/schema-registry/index.d.ts +8 -3
  23. package/lib/registries/schema-registry/index.js +82 -17
  24. package/lib/registries/settlement-registry/abi.d.ts +199 -145
  25. package/lib/registries/settlement-registry/abi.js +331 -25
  26. package/lib/registries/settlement-registry/index.d.ts +35 -38
  27. package/lib/registries/settlement-registry/index.js +125 -91
  28. package/lib/registries/settlement-registry/types.d.ts +6 -3
  29. package/lib/roles/consumer/index.d.ts +6 -5
  30. package/lib/roles/consumer/index.js +21 -20
  31. package/lib/roles/consumer/types.d.ts +4 -4
  32. package/lib/roles/publisher/index.d.ts +22 -19
  33. package/lib/roles/publisher/index.js +63 -59
  34. package/lib/roles/publisher/types.d.ts +3 -3
  35. package/lib/roles/schema/index.d.ts +1 -7
  36. package/lib/roles/schema/index.js +4 -34
  37. package/lib/test/testbed.d.ts +7 -32
  38. package/lib/test/testbed.js +20 -43
  39. package/package.json +1 -1
@@ -1,69 +1,120 @@
1
1
  import { SETTLEMENT_REGISTRY_ABI } from "./abi.js";
2
- import { arbitrumSepolia } from "viem/chains";
3
- import { createWalletClient, encodePacked, http, keccak256, parseSignature } from "viem";
2
+ import { createWalletClient, http, parseSignature } from "viem";
4
3
  import { privateKeyToAccount } from "viem/accounts";
5
4
  import { Group } from "@semaphore-protocol/group";
6
5
  import { generateProof } from "@semaphore-protocol/proof";
7
6
 
8
7
  //#region src/registries/settlement-registry/index.ts
9
- /**
10
- *
11
- * SDK wrapper for the on-chain SettlementRegistry Stylus contract.
12
- *
13
- * Responsible for:
14
- * - createResource(): owner calls once per (schemaId, tag) asset
15
- * - register(): buyer pays + joins Semaphore group
16
- * - settle(): buyer proves membership + fires hook (NFT/timelock)
17
- * - isSettled(): access check — used to gate decryptFile()
18
- * - deriveResourceId(): deterministic (owner, schemaId, tag) → bytes32
19
- */
20
8
  var SettlementRegistry = class {
21
9
  constructor(contractAddress, publicClient, walletClient) {
22
10
  this.contractAddress = contractAddress;
23
11
  this.publicClient = publicClient;
24
12
  this.walletClient = walletClient;
25
13
  }
14
+ getAccount() {
15
+ const account = this.walletClient.account;
16
+ if (!account) throw new Error("Wallet client must have an account configured");
17
+ return account;
18
+ }
19
+ getChain() {
20
+ const chain = this.walletClient.chain;
21
+ if (!chain) throw new Error("Wallet client must have a chain configured");
22
+ return chain;
23
+ }
26
24
  /**
27
- * Create a Semaphore group for a resource. Called by the schema owner once per (schemaId, tag) asset.
28
- *
29
- * @param resourceId: The hex encoded resource id
30
- * @param price : The USDC price for the resource
31
- * @returns The finalized transaction hash.
25
+ * Authorize or revoke a DataSourceRegistry contract.
26
+ * Only callable by the contract admin.
32
27
  */
33
- async createResource(resourceId, price) {
34
- const account = this.walletClient.account;
35
- if (!account) throw new Error("The wallet client must have an account configured");
28
+ async setRegistry(registry, authorized) {
29
+ const account = this.getAccount();
30
+ const hash = await this.walletClient.writeContract({
31
+ address: this.contractAddress,
32
+ abi: SETTLEMENT_REGISTRY_ABI,
33
+ functionName: "setRegistry",
34
+ args: [registry, authorized],
35
+ chain: this.getChain(),
36
+ account
37
+ });
38
+ await this.publicClient.waitForTransactionReceipt({ hash });
39
+ return hash;
40
+ }
41
+ /**
42
+ * Create a Semaphore group for a resource.
43
+ * In production this is called by the DataSourceRegistry, which passes
44
+ * the publisher wallet as `owner`. Direct calls require the caller to
45
+ * be an authorized registry.
46
+ */
47
+ async createResource(resourceId, price, owner) {
48
+ const account = this.getAccount();
36
49
  const hash = await this.walletClient.writeContract({
37
50
  address: this.contractAddress,
38
51
  abi: SETTLEMENT_REGISTRY_ABI,
39
52
  functionName: "createResource",
40
- args: [resourceId, price],
41
- chain: arbitrumSepolia,
53
+ args: [
54
+ resourceId,
55
+ price,
56
+ owner
57
+ ],
58
+ chain: this.getChain(),
59
+ account
60
+ });
61
+ await this.publicClient.waitForTransactionReceipt({ hash });
62
+ return hash;
63
+ }
64
+ /**
65
+ * Update the price for a resource.
66
+ * In production this is called by the DataSourceRegistry.
67
+ */
68
+ async updatePrice(resourceId, price, owner) {
69
+ const account = this.getAccount();
70
+ const hash = await this.walletClient.writeContract({
71
+ address: this.contractAddress,
72
+ abi: SETTLEMENT_REGISTRY_ABI,
73
+ functionName: "updatePrice",
74
+ args: [
75
+ resourceId,
76
+ price,
77
+ owner
78
+ ],
79
+ chain: this.getChain(),
80
+ account
81
+ });
82
+ await this.publicClient.waitForTransactionReceipt({ hash });
83
+ return hash;
84
+ }
85
+ /**
86
+ * Register a hook contract for a resource.
87
+ * Called directly by the publisher wallet (msg.sender must be resource owner).
88
+ */
89
+ async registerHook(resourceId, hook) {
90
+ const account = this.getAccount();
91
+ const hash = await this.walletClient.writeContract({
92
+ address: this.contractAddress,
93
+ abi: SETTLEMENT_REGISTRY_ABI,
94
+ functionName: "registerHook",
95
+ args: [resourceId, hook],
96
+ chain: this.getChain(),
42
97
  account
43
98
  });
44
99
  await this.publicClient.waitForTransactionReceipt({ hash });
45
100
  return hash;
46
101
  }
47
102
  /**
48
- * Prepares the EIP-3009 transferWithAuthorization call and signs it w/ an EIP-712 sig
49
- * @param params The transferWithAuth params
50
- * @returns The payload containing the signed call data
103
+ * Prepare the EIP-3009 transferWithAuthorization signature.
51
104
  */
52
105
  async prepareTransferWithAuth(params) {
53
- const { burnerPrivateKey, paymentRecipient, amount, usdcAddress, usdcDomainName, usdcDomainVersion } = params;
54
- const chain = this.walletClient.chain;
106
+ const { paymentRecipient, amount, usdcAddress, usdcDomainName, usdcDomainVersion } = params;
107
+ const walletClient = params.walletClient ?? this.walletClient;
108
+ const chain = walletClient.chain;
55
109
  if (!chain) throw new Error("Wallet client must have a chain configured.");
56
- const burner = privateKeyToAccount(burnerPrivateKey);
57
- const burnerWallet = createWalletClient({
58
- account: burner,
59
- chain,
60
- transport: http(chain.rpcUrls.default.http[0])
61
- });
110
+ const account = walletClient.account;
111
+ if (!account) throw new Error("Wallet client must have an account configured.");
62
112
  const validAfter = 0n;
63
113
  const validBefore = BigInt(Math.floor(Date.now() / 1e3) + 3600);
64
114
  const nonceBytes = crypto.getRandomValues(new Uint8Array(32));
65
115
  const nonce = `0x${Array.from(nonceBytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
66
- const { v, r, s } = parseSignature(await burnerWallet.signTypedData({
116
+ const { v, r, s } = parseSignature(await walletClient.signTypedData({
117
+ account,
67
118
  domain: {
68
119
  name: usdcDomainName,
69
120
  version: usdcDomainVersion,
@@ -98,7 +149,7 @@ var SettlementRegistry = class {
98
149
  ] },
99
150
  primaryType: "TransferWithAuthorization",
100
151
  message: {
101
- from: burner.address,
152
+ from: account.address,
102
153
  to: paymentRecipient,
103
154
  value: amount,
104
155
  validAfter,
@@ -107,7 +158,7 @@ var SettlementRegistry = class {
107
158
  }
108
159
  }));
109
160
  return {
110
- burnerAddress: burner.address,
161
+ sender: account.address,
111
162
  paymentRecipient,
112
163
  amount,
113
164
  validAfter,
@@ -119,15 +170,14 @@ var SettlementRegistry = class {
119
170
  };
120
171
  }
121
172
  /**
122
- * Submit a payment and register with the specified semaphore group
123
- * @param params
124
- * @returns
173
+ * Phase 1 — submit payment and join the Semaphore group.
174
+ * Submitted via a relayer so the buyer's burner wallet is never linked
175
+ * to their identity commitment on-chain.
125
176
  */
126
177
  async register(params) {
127
178
  const { resourceId, identityCommitment, relayerPrivateKey, preparedRegister } = params;
128
- const { burnerAddress, paymentRecipient, amount, validAfter, validBefore, nonce, v, r, s } = preparedRegister;
129
- const chain = this.walletClient.chain;
130
- if (!chain) throw new Error("Wallet client must have a chain configured.");
179
+ const { sender, paymentRecipient, amount, validAfter, validBefore, nonce, v, r, s } = preparedRegister;
180
+ const chain = this.getChain();
131
181
  const hash = await createWalletClient({
132
182
  account: privateKeyToAccount(relayerPrivateKey),
133
183
  chain,
@@ -139,7 +189,7 @@ var SettlementRegistry = class {
139
189
  args: [
140
190
  resourceId,
141
191
  identityCommitment,
142
- burnerAddress,
192
+ sender,
143
193
  paymentRecipient,
144
194
  amount,
145
195
  validAfter,
@@ -148,11 +198,16 @@ var SettlementRegistry = class {
148
198
  v,
149
199
  r,
150
200
  s
151
- ]
201
+ ],
202
+ chain,
203
+ account: privateKeyToAccount(relayerPrivateKey)
152
204
  });
153
205
  await this.publicClient.waitForTransactionReceipt({ hash });
154
206
  return hash;
155
207
  }
208
+ /**
209
+ * Build the Semaphore proof for Phase 2.
210
+ */
156
211
  async prepareSettle(params) {
157
212
  const { resourceId, identity, stealthAddress } = params;
158
213
  const groupId = await this.publicClient.readContract({
@@ -174,16 +229,21 @@ var SettlementRegistry = class {
174
229
  hookData: params.hookData ?? "0x"
175
230
  };
176
231
  }
232
+ /**
233
+ * Phase 2 — prove group membership and claim access.
234
+ * Submitted via a relayer for unlinkability.
235
+ */
177
236
  async settle(params) {
178
237
  const { relayerPrivateKey, preparedSettle } = params;
179
- const { resourceId, stealthAddress, merkleTreeDepth, merkleTreeRoot, nullifier, message, points } = preparedSettle;
180
- const chain = this.walletClient.chain;
181
- if (!chain) throw new Error("Wallet client must have a chain configured.");
182
- const hash = await createWalletClient({
238
+ const { resourceId, stealthAddress, merkleTreeDepth, merkleTreeRoot, nullifier, message, points, hookData } = preparedSettle;
239
+ const chain = this.getChain();
240
+ const submitter = createWalletClient({
183
241
  account: privateKeyToAccount(relayerPrivateKey),
184
242
  chain,
185
243
  transport: http(chain.rpcUrls.default.http[0])
186
- }).writeContract({
244
+ });
245
+ const hookBytes = hookData !== "0x" ? Array.from(Buffer.from(hookData.slice(2), "hex")) : [];
246
+ const hash = await submitter.writeContract({
187
247
  address: this.contractAddress,
188
248
  abi: SETTLEMENT_REGISTRY_ABI,
189
249
  functionName: "settle",
@@ -196,9 +256,9 @@ var SettlementRegistry = class {
196
256
  nullifier,
197
257
  message,
198
258
  points,
199
- []
259
+ hookBytes
200
260
  ],
201
- chain: arbitrumSepolia,
261
+ chain,
202
262
  account: privateKeyToAccount(relayerPrivateKey)
203
263
  });
204
264
  const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
@@ -208,10 +268,6 @@ var SettlementRegistry = class {
208
268
  nullifier
209
269
  };
210
270
  }
211
- /**
212
- * Check if a nullifier has been settled (i.e. the user completed Phase 2).
213
- * Used to gate decryptFile() in the Fangorn class.
214
- */
215
271
  async isSettled(stealthAddress, resourceId) {
216
272
  return this.publicClient.readContract({
217
273
  address: this.contractAddress,
@@ -220,9 +276,6 @@ var SettlementRegistry = class {
220
276
  args: [stealthAddress, resourceId]
221
277
  });
222
278
  }
223
- /**
224
- * Check if an identity commitment is registered for a resource (completed Phase 1).
225
- */
226
279
  async isRegistered(resourceId, identityCommitment) {
227
280
  return this.publicClient.readContract({
228
281
  address: this.contractAddress,
@@ -231,11 +284,6 @@ var SettlementRegistry = class {
231
284
  args: [resourceId, identityCommitment]
232
285
  });
233
286
  }
234
- /**
235
- * Get the semaphore group id for a resource
236
- * @param resourceId The resource id
237
- * @returns The group id (if it exists), else null
238
- */
239
287
  async getGroupId(resourceId) {
240
288
  return this.publicClient.readContract({
241
289
  address: this.contractAddress,
@@ -244,11 +292,6 @@ var SettlementRegistry = class {
244
292
  args: [resourceId]
245
293
  });
246
294
  }
247
- /**
248
- * Get the price associated with a resource
249
- * @param resourceId The resource id
250
- * @returns The price
251
- */
252
295
  async getPrice(resourceId) {
253
296
  return this.publicClient.readContract({
254
297
  address: this.contractAddress,
@@ -257,28 +300,22 @@ var SettlementRegistry = class {
257
300
  args: [resourceId]
258
301
  });
259
302
  }
260
- /**
261
- * Deterministic resource_id = keccak256(ownerAddress ++ schemaName ++ tag).
262
- * This can be implemented in any way as long as owner/schema/tag produces a unique output
263
- */
264
- static deriveResourceId(owner, schemaName, tag) {
265
- return keccak256(encodePacked([
266
- "address",
267
- "string",
268
- "string"
269
- ], [
270
- owner,
271
- schemaName,
272
- tag
273
- ]));
303
+ async getOwner(resourceId) {
304
+ return this.publicClient.readContract({
305
+ address: this.contractAddress,
306
+ abi: SETTLEMENT_REGISTRY_ABI,
307
+ functionName: "getOwner",
308
+ args: [resourceId]
309
+ });
310
+ }
311
+ async waitForTransaction(hash) {
312
+ return this.publicClient.waitForTransactionReceipt({ hash });
274
313
  }
275
314
  /**
276
315
  * Reconstruct the Semaphore group from MemberRegistered events.
277
- * Fetches all logs (no topic filter) and filters in JS to avoid
278
- * viem topic-encoding edge cases with indexed params.
279
316
  */
280
317
  async fetchGroup(resourceId) {
281
- const filtered = (await this.publicClient.getLogs({
318
+ const logs = await this.publicClient.getLogs({
282
319
  address: this.contractAddress,
283
320
  event: {
284
321
  name: "MemberRegistered",
@@ -302,14 +339,11 @@ var SettlementRegistry = class {
302
339
  ]
303
340
  },
304
341
  fromBlock: 0n
305
- })).filter((log) => log.args.resourceId?.toLowerCase() === resourceId.toLowerCase());
342
+ });
306
343
  const group = new Group();
307
- for (const log of filtered) group.addMember(String(log.args.identityCommitment));
344
+ for (const log of logs.filter((l) => l.args.resourceId?.toLowerCase() === resourceId.toLowerCase())) group.addMember(String(log.args.identityCommitment));
308
345
  return group;
309
346
  }
310
- async waitForTransaction(hash) {
311
- return await this.publicClient.waitForTransactionReceipt({ hash });
312
- }
313
347
  };
314
348
 
315
349
  //#endregion
@@ -1,9 +1,9 @@
1
- import { Address, Hex } from "viem";
1
+ import { Address, Hex, WalletClient } from "viem";
2
2
  import { Identity } from "@semaphore-protocol/identity";
3
3
 
4
4
  //#region src/registries/settlement-registry/types.d.ts
5
5
  interface TransferWithAuthParams {
6
- burnerPrivateKey: Hex;
6
+ walletClient?: WalletClient;
7
7
  paymentRecipient: Address;
8
8
  amount: bigint;
9
9
  usdcAddress: Address;
@@ -11,7 +11,7 @@ interface TransferWithAuthParams {
11
11
  usdcDomainVersion: string;
12
12
  }
13
13
  interface TransferWithAuthPayload {
14
- burnerAddress: Address;
14
+ sender: Address;
15
15
  paymentRecipient: Address;
16
16
  amount: bigint;
17
17
  validAfter: bigint;
@@ -21,6 +21,9 @@ interface TransferWithAuthPayload {
21
21
  r: Hex;
22
22
  s: Hex;
23
23
  }
24
+ /**
25
+ * The params for registering with a semaphore group
26
+ */
24
27
  interface RegisterParams {
25
28
  resourceId: Hex;
26
29
  identityCommitment: bigint;
@@ -10,7 +10,8 @@ import { Identity } from "@semaphore-protocol/identity";
10
10
  //#region src/roles/consumer/index.d.ts
11
11
 
12
12
  /**
13
- * The consumer namespace encapsulates all functionality relative to accessing and consuming data.
13
+ * The consumer namespace encapsulates all functionality relative to
14
+ * accessing and consuming data.
14
15
  */
15
16
  declare class ConsumerRole {
16
17
  private readonly dataSourceRegistry;
@@ -27,15 +28,15 @@ declare class ConsumerRole {
27
28
  * Decrypt a specific encrypted field within a record.
28
29
  *
29
30
  * One purchase + claim unlocks ALL encrypted fields in the record —
30
- * the resource is at the record (tag) level, not the field level.
31
+ * the resource is at the record (name) level, not the field level.
31
32
  * This method can be called once per encrypted field without re-purchasing.
32
33
  *
33
34
  * Plain fields can be read freely via getEntry() without any of this.
34
35
  */
35
36
  decrypt(params: DecryptParams): Promise<Uint8Array>;
36
- getManifest(owner: Address, schemaId: Hex): Promise<Manifest | undefined>;
37
- getEntry(owner: Address, schemaId: Hex, tag: string): Promise<ManifestEntry>;
38
- isRegistered(owner: Address, schemaId: Hex, tag: string, identity: Identity): Promise<boolean>;
37
+ getManifest(owner: Address, schemaId: Hex, name: string): Promise<Manifest | undefined>;
38
+ getEntry(owner: Address, schemaId: Hex, name: string): Promise<ManifestEntry>;
39
+ isRegistered(owner: Address, schemaId: Hex, name: string, identity: Identity): Promise<boolean>;
39
40
  private deriveResourceId;
40
41
  }
41
42
  //#endregion
@@ -1,9 +1,10 @@
1
1
  import { retrieveByCid } from "../../providers/storage/index.js";
2
- import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
2
+ import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
3
3
 
4
4
  //#region src/roles/consumer/index.ts
5
5
  /**
6
- * The consumer namespace encapsulates all functionality relative to accessing and consuming data.
6
+ * The consumer namespace encapsulates all functionality relative to
7
+ * accessing and consuming data.
7
8
  */
8
9
  var ConsumerRole = class {
9
10
  constructor(dataSourceRegistry, settlementRegistry, encryptionService, domain, ipfsGateway) {
@@ -20,7 +21,7 @@ var ConsumerRole = class {
20
21
  return this.settlementRegistry.prepareSettle(params);
21
22
  }
22
23
  async register(params) {
23
- const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.tag);
24
+ const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.name);
24
25
  return {
25
26
  txHash: await this.settlementRegistry.register({
26
27
  resourceId,
@@ -32,7 +33,7 @@ var ConsumerRole = class {
32
33
  };
33
34
  }
34
35
  async claim(params) {
35
- const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.tag);
36
+ const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.name);
36
37
  const { hash, nullifier } = await this.settlementRegistry.settle({
37
38
  relayerPrivateKey: params.relayerPrivateKey,
38
39
  preparedSettle: params.preparedSettle
@@ -47,45 +48,45 @@ var ConsumerRole = class {
47
48
  * Decrypt a specific encrypted field within a record.
48
49
  *
49
50
  * One purchase + claim unlocks ALL encrypted fields in the record —
50
- * the resource is at the record (tag) level, not the field level.
51
+ * the resource is at the record (name) level, not the field level.
51
52
  * This method can be called once per encrypted field without re-purchasing.
52
53
  *
53
54
  * Plain fields can be read freely via getEntry() without any of this.
54
55
  */
55
56
  async decrypt(params) {
56
- const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.tag);
57
+ const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.name);
57
58
  if (!params.skipSettlementCheck) {
58
59
  if (!params.identity) throw new Error("identity is required for settlement verification. Pass skipSettlementCheck: true for owner / out-of-band flows.");
59
- if (!await this.settlementRegistry.isRegistered(resourceId, params.identity.commitment)) throw new Error(`Access denied: identity not registered for resource ${resourceId}. Call purchase() and wait for confirmation before decrypting.`);
60
+ if (!await this.settlementRegistry.isRegistered(resourceId, params.identity.commitment)) throw new Error(`Access denied: identity not registered for resource ${resourceId}. Call register() and wait for confirmation before decrypting.`);
60
61
  }
61
- const fieldValue = (await this.getEntry(params.owner, params.schemaId, params.tag)).fields[params.field];
62
+ const fieldValue = (await this.getEntry(params.owner, params.schemaId, params.name)).fields[params.field];
62
63
  if (!fieldValue || typeof fieldValue !== "object") throw new Error(`Field "${params.field}" is missing or invalid`);
63
64
  const encrypted = await retrieveByCid(fieldValue.handle.cid, this.ipfsGateway);
64
65
  const authContext = params.authContext ?? await this.encryptionService.createAuthContext(params.walletClient, this.domain, params.nullifierHash);
65
66
  return (await this.encryptionService.decrypt(encrypted, authContext)).data;
66
67
  }
67
- async getManifest(owner, schemaId) {
68
+ async getManifest(owner, schemaId, name) {
68
69
  try {
69
- const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
70
+ const ds = await this.dataSourceRegistry.get(owner, schemaId, name);
70
71
  if (!ds.manifestCid || ds.manifestCid === "") return void 0;
71
- return retrieveByCid(ds.manifestCid, this.ipfsGateway);
72
+ return await retrieveByCid(ds.manifestCid, this.ipfsGateway);
72
73
  } catch {
73
74
  return;
74
75
  }
75
76
  }
76
- async getEntry(owner, schemaId, tag) {
77
- const manifest = await this.getManifest(owner, schemaId);
78
- if (!manifest) throw new Error(`No manifest found for owner ${owner} / schemaId ${schemaId}`);
79
- const entry = manifest.entries.find((e) => e.tag === tag);
80
- if (!entry) throw new Error(`Entry not found: "${tag}"`);
77
+ async getEntry(owner, schemaId, name) {
78
+ const manifest = await this.getManifest(owner, schemaId, name);
79
+ if (!manifest) throw new Error(`No manifest found for owner ${owner} / schemaId ${schemaId} / name ${name}`);
80
+ const entry = manifest.entries.find((e) => e.name === name);
81
+ if (!entry) throw new Error(`Entry not found: "${name}"`);
81
82
  return entry;
82
83
  }
83
- async isRegistered(owner, schemaId, tag, identity) {
84
- const resourceId = this.deriveResourceId(owner, schemaId, tag);
84
+ async isRegistered(owner, schemaId, name, identity) {
85
+ const resourceId = this.deriveResourceId(owner, schemaId, name);
85
86
  return this.settlementRegistry.isRegistered(resourceId, identity.commitment);
86
87
  }
87
- deriveResourceId(owner, schemaId, tag) {
88
- return SettlementRegistry.deriveResourceId(owner, schemaId, tag);
88
+ deriveResourceId(owner, schemaId, name) {
89
+ return DataSourceRegistry.resourceIdLocal(owner, schemaId, name);
89
90
  }
90
91
  };
91
92
 
@@ -8,7 +8,7 @@ import { Identity } from "@semaphore-protocol/identity";
8
8
  interface PurchaseParams {
9
9
  owner: Address;
10
10
  schemaId: Hex;
11
- tag: string;
11
+ name: string;
12
12
  identityCommitment: bigint;
13
13
  relayerPrivateKey: Hex;
14
14
  preparedRegister: TransferWithAuthPayload;
@@ -16,7 +16,7 @@ interface PurchaseParams {
16
16
  interface ClaimParams {
17
17
  owner: Address;
18
18
  schemaId: Hex;
19
- tag: string;
19
+ name: string;
20
20
  relayerPrivateKey: Hex;
21
21
  preparedSettle: PrepareSettleResult;
22
22
  }
@@ -26,7 +26,7 @@ interface DecryptParams {
26
26
  schemaId: Hex;
27
27
  nullifierHash: bigint;
28
28
  /** The record tag — maps to the resourceId */
29
- tag: string;
29
+ name: string;
30
30
  /** The specific encrypted field within the record to decrypt */
31
31
  field: string;
32
32
  identity?: Identity;
@@ -40,7 +40,7 @@ interface DecryptParams {
40
40
  interface AccessParams {
41
41
  owner: Address;
42
42
  schemaId: Hex;
43
- tag: string;
43
+ name: string;
44
44
  /** The encrypted field to decrypt after settling */
45
45
  field: string;
46
46
  identity: Identity;
@@ -2,7 +2,6 @@ import { AppConfig } from "../../config.js";
2
2
  import { SchemaRegistry } from "../../registries/schema-registry/index.js";
3
3
  import { PinningService } from "../../providers/storage/index.js";
4
4
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
5
- import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
6
5
  import { EncryptionService } from "../../modules/encryption/index.js";
7
6
  import { CommitResult, EncryptedFieldInput, FieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedEncryptedField, ResolvedField, ResolvedPlainField, UploadParams } from "./types.js";
8
7
  import { Hex, WalletClient } from "viem";
@@ -10,7 +9,6 @@ import { Hex, WalletClient } from "viem";
10
9
  //#region src/roles/publisher/index.d.ts
11
10
  declare class PublisherRole {
12
11
  private readonly dataSourceRegistry;
13
- private readonly settlementRegistry;
14
12
  private readonly schemaRegistry;
15
13
  private readonly storage;
16
14
  private readonly encryptionService;
@@ -18,34 +16,36 @@ declare class PublisherRole {
18
16
  private readonly config;
19
17
  private pendingEntries;
20
18
  private readonly schemaCache;
21
- constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, schemaRegistry: SchemaRegistry, storage: PinningService, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
19
+ constructor(dataSourceRegistry: DataSourceRegistry, schemaRegistry: SchemaRegistry, storage: PinningService, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
22
20
  /**
23
- * Encrypt and upload data with Fangorn.
24
- * Validates records against the schema, encrypts encrypted fields,
25
- * stages all resolved entries, then commits to IPFS + on-chain.
21
+ * Encrypt and upload schema-conformant data.
26
22
  *
27
- * Each encrypted field within a record is stored as a separate IPFS object
28
- * (the ciphertext). The manifest entry stores the handle (CID + gateway)
29
- * alongside plain fields. Consumers can read plain fields freely and
30
- * only need to purchase + decrypt for encrypted fields.
23
+ * Validates records against the schema, encrypts fields as required,
24
+ * stages all resolved entries, then commits to IPFS and publishes on-chain.
25
+ *
26
+ * Each encrypted field within a record is stored as a separate IPFS object.
27
+ * The manifest entry stores the handle (CID + gateway) alongside plain fields.
28
+ * Consumers can read plain fields freely and only need to purchase and decrypt
29
+ * for encrypted fields.
31
30
  */
32
31
  upload(params: UploadParams, price: bigint): Promise<CommitResult>;
33
32
  stage(entry: ManifestEntry): void;
34
- remove(tag: string): boolean;
33
+ remove(name: string): boolean;
35
34
  getPending(): ManifestEntry[];
36
35
  clearPending(): void;
37
36
  /**
38
- * Serialize all staged entries into a manifest, create SettlementRegistry
39
- * resources for each entry, pin the manifest to IPFS, and publish on-chain.
37
+ * Serialize all staged entries into a manifest, publish each entry
38
+ * on-chain via the DataSourceRegistry (which calls into the
39
+ * SettlementRegistry to create/update the Semaphore group), pin the
40
+ * manifest to IPFS, and record the manifest CID on-chain.
40
41
  */
41
42
  commit(schemaId: Hex, price: bigint, overwrite: boolean): Promise<CommitResult>;
42
- getManifest(schemaId: Hex): Promise<Manifest | undefined>;
43
- getEntry(schemaId: Hex, tag: string): Promise<ManifestEntry>;
43
+ getManifest(schemaId: Hex, name: string): Promise<Manifest | undefined>;
44
+ getEntry(schemaId: Hex, name: string): Promise<ManifestEntry>;
44
45
  private requireAccount;
45
46
  /**
46
47
  * Resolve the schema definition and id by name, with in-memory caching.
47
- * Schema resolution is concurrent-safe — parallel calls for the same name
48
- * share a single in-flight promise.
48
+ * Concurrent calls for the same name share a single in-flight promise.
49
49
  */
50
50
  private resolveSchema;
51
51
  /**
@@ -62,9 +62,12 @@ declare class PublisherRole {
62
62
  private validateRecord;
63
63
  private validateField;
64
64
  /**
65
- * Load the existing manifest for merge behaviour and unpin the old CID.
65
+ * Load existing entries for merge behaviour, keyed by name.
66
+ * Unpins the old manifest CID after loading.
67
+ * Pending entries take precedence — existing entries with the same name
68
+ * are overwritten.
66
69
  */
67
- private loadExistingManifest;
70
+ private loadExistingEntries;
68
71
  }
69
72
  //#endregion
70
73
  export { CommitResult, EncryptedFieldInput, FieldInput, Manifest, ManifestEntry, PublishRecord, PublisherRole, ResolvedEncryptedField, ResolvedField, ResolvedPlainField, UploadParams };