@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,29 +1,335 @@
1
- import { parseAbi } from "viem";
2
-
3
1
  //#region src/registries/settlement-registry/abi.ts
4
- const SETTLEMENT_REGISTRY_ABI = parseAbi([
5
- "function createResource(bytes32 resource_id, uint256 price) external returns (uint256)",
6
- "function addSeedMember(bytes32 resource_id) external",
7
- "function updatePrice(bytes32 resource_id, uint256 price) external",
8
- "function registerHook(bytes32 resource_id, address hook) external",
9
- "function register(bytes32 resource_id, uint256 identity_commitment, address from, address to, uint256 amount, uint256 valid_after, uint256 valid_before, bytes32 nonce, uint8 v, bytes32 r, bytes32 s) external payable",
10
- "function settle(bytes32 resource_id, address stealth_address, uint256 merkle_tree_depth, uint256 merkle_tree_root, uint256 nullifier, uint256 message, uint256[8] calldata points, uint8[] memory hook_data) external",
11
- "function isSettled(address stealth_address, bytes32 resource_id) external view returns (bool)",
12
- "function getGroupId(bytes32 resource_id) external view returns (uint256)",
13
- "function getHook(bytes32 resource_id) external view returns (address)",
14
- "function getOwner(bytes32 resource_id) external view returns (address)",
15
- "function getPrice(bytes32 resource_id) external view returns (uint256)",
16
- "function isRegistered(bytes32 resource_id, uint256 identity_commitment) external view returns (bool)",
17
- "error AlreadyRegistered()",
18
- "error AlreadySettled()",
19
- "error IncorrectPaymentAmount()",
20
- "error TransferFailed()",
21
- "error VerificationFailed()",
22
- "error NotResourceOwner()",
23
- "error ResourceNotFound()",
24
- "error HookFailed()",
25
- "error GroupCreationFailed()"
26
- ]);
2
+ const SETTLEMENT_REGISTRY_ABI = [
3
+ {
4
+ "inputs": [],
5
+ "name": "AlreadyRegistered",
6
+ "type": "error"
7
+ },
8
+ {
9
+ "inputs": [],
10
+ "name": "AlreadySettled",
11
+ "type": "error"
12
+ },
13
+ {
14
+ "inputs": [],
15
+ "name": "GroupCreationFailed",
16
+ "type": "error"
17
+ },
18
+ {
19
+ "inputs": [],
20
+ "name": "HookFailed",
21
+ "type": "error"
22
+ },
23
+ {
24
+ "inputs": [],
25
+ "name": "IncorrectPaymentAmount",
26
+ "type": "error"
27
+ },
28
+ {
29
+ "inputs": [],
30
+ "name": "NotAdmin",
31
+ "type": "error"
32
+ },
33
+ {
34
+ "inputs": [],
35
+ "name": "NotAuthorizedRegistry",
36
+ "type": "error"
37
+ },
38
+ {
39
+ "inputs": [],
40
+ "name": "NotResourceOwner",
41
+ "type": "error"
42
+ },
43
+ {
44
+ "inputs": [],
45
+ "name": "ResourceNotFound",
46
+ "type": "error"
47
+ },
48
+ {
49
+ "inputs": [],
50
+ "name": "TransferFailed",
51
+ "type": "error"
52
+ },
53
+ {
54
+ "inputs": [],
55
+ "name": "VerificationFailed",
56
+ "type": "error"
57
+ },
58
+ {
59
+ "inputs": [
60
+ {
61
+ "internalType": "bytes32",
62
+ "name": "resource_id",
63
+ "type": "bytes32"
64
+ },
65
+ {
66
+ "internalType": "uint256",
67
+ "name": "price",
68
+ "type": "uint256"
69
+ },
70
+ {
71
+ "internalType": "address",
72
+ "name": "owner",
73
+ "type": "address"
74
+ }
75
+ ],
76
+ "name": "createResource",
77
+ "outputs": [{
78
+ "internalType": "uint256",
79
+ "name": "",
80
+ "type": "uint256"
81
+ }],
82
+ "stateMutability": "nonpayable",
83
+ "type": "function"
84
+ },
85
+ {
86
+ "inputs": [{
87
+ "internalType": "bytes32",
88
+ "name": "resource_id",
89
+ "type": "bytes32"
90
+ }],
91
+ "name": "getGroupId",
92
+ "outputs": [{
93
+ "internalType": "uint256",
94
+ "name": "",
95
+ "type": "uint256"
96
+ }],
97
+ "stateMutability": "view",
98
+ "type": "function"
99
+ },
100
+ {
101
+ "inputs": [{
102
+ "internalType": "bytes32",
103
+ "name": "resource_id",
104
+ "type": "bytes32"
105
+ }],
106
+ "name": "getOwner",
107
+ "outputs": [{
108
+ "internalType": "address",
109
+ "name": "",
110
+ "type": "address"
111
+ }],
112
+ "stateMutability": "view",
113
+ "type": "function"
114
+ },
115
+ {
116
+ "inputs": [{
117
+ "internalType": "bytes32",
118
+ "name": "resource_id",
119
+ "type": "bytes32"
120
+ }],
121
+ "name": "getPrice",
122
+ "outputs": [{
123
+ "internalType": "uint256",
124
+ "name": "",
125
+ "type": "uint256"
126
+ }],
127
+ "stateMutability": "view",
128
+ "type": "function"
129
+ },
130
+ {
131
+ "inputs": [{
132
+ "internalType": "bytes32",
133
+ "name": "resource_id",
134
+ "type": "bytes32"
135
+ }, {
136
+ "internalType": "uint256",
137
+ "name": "identity_commitment",
138
+ "type": "uint256"
139
+ }],
140
+ "name": "isRegistered",
141
+ "outputs": [{
142
+ "internalType": "bool",
143
+ "name": "",
144
+ "type": "bool"
145
+ }],
146
+ "stateMutability": "view",
147
+ "type": "function"
148
+ },
149
+ {
150
+ "inputs": [{
151
+ "internalType": "address",
152
+ "name": "stealth_address",
153
+ "type": "address"
154
+ }, {
155
+ "internalType": "bytes32",
156
+ "name": "resource_id",
157
+ "type": "bytes32"
158
+ }],
159
+ "name": "isSettled",
160
+ "outputs": [{
161
+ "internalType": "bool",
162
+ "name": "",
163
+ "type": "bool"
164
+ }],
165
+ "stateMutability": "view",
166
+ "type": "function"
167
+ },
168
+ {
169
+ "inputs": [
170
+ {
171
+ "internalType": "bytes32",
172
+ "name": "resource_id",
173
+ "type": "bytes32"
174
+ },
175
+ {
176
+ "internalType": "uint256",
177
+ "name": "identity_commitment",
178
+ "type": "uint256"
179
+ },
180
+ {
181
+ "internalType": "address",
182
+ "name": "from",
183
+ "type": "address"
184
+ },
185
+ {
186
+ "internalType": "address",
187
+ "name": "to",
188
+ "type": "address"
189
+ },
190
+ {
191
+ "internalType": "uint256",
192
+ "name": "amount",
193
+ "type": "uint256"
194
+ },
195
+ {
196
+ "internalType": "uint256",
197
+ "name": "valid_after",
198
+ "type": "uint256"
199
+ },
200
+ {
201
+ "internalType": "uint256",
202
+ "name": "valid_before",
203
+ "type": "uint256"
204
+ },
205
+ {
206
+ "internalType": "bytes32",
207
+ "name": "nonce",
208
+ "type": "bytes32"
209
+ },
210
+ {
211
+ "internalType": "uint8",
212
+ "name": "v",
213
+ "type": "uint8"
214
+ },
215
+ {
216
+ "internalType": "bytes32",
217
+ "name": "r",
218
+ "type": "bytes32"
219
+ },
220
+ {
221
+ "internalType": "bytes32",
222
+ "name": "s",
223
+ "type": "bytes32"
224
+ }
225
+ ],
226
+ "name": "register",
227
+ "outputs": [],
228
+ "stateMutability": "payable",
229
+ "type": "function"
230
+ },
231
+ {
232
+ "inputs": [{
233
+ "internalType": "bytes32",
234
+ "name": "resource_id",
235
+ "type": "bytes32"
236
+ }, {
237
+ "internalType": "address",
238
+ "name": "hook",
239
+ "type": "address"
240
+ }],
241
+ "name": "registerHook",
242
+ "outputs": [],
243
+ "stateMutability": "nonpayable",
244
+ "type": "function"
245
+ },
246
+ {
247
+ "inputs": [{
248
+ "internalType": "address",
249
+ "name": "registry",
250
+ "type": "address"
251
+ }, {
252
+ "internalType": "bool",
253
+ "name": "authorized",
254
+ "type": "bool"
255
+ }],
256
+ "name": "setRegistry",
257
+ "outputs": [],
258
+ "stateMutability": "nonpayable",
259
+ "type": "function"
260
+ },
261
+ {
262
+ "inputs": [
263
+ {
264
+ "internalType": "bytes32",
265
+ "name": "resource_id",
266
+ "type": "bytes32"
267
+ },
268
+ {
269
+ "internalType": "address",
270
+ "name": "stealth_address",
271
+ "type": "address"
272
+ },
273
+ {
274
+ "internalType": "uint256",
275
+ "name": "merkle_tree_depth",
276
+ "type": "uint256"
277
+ },
278
+ {
279
+ "internalType": "uint256",
280
+ "name": "merkle_tree_root",
281
+ "type": "uint256"
282
+ },
283
+ {
284
+ "internalType": "uint256",
285
+ "name": "nullifier",
286
+ "type": "uint256"
287
+ },
288
+ {
289
+ "internalType": "uint256",
290
+ "name": "message",
291
+ "type": "uint256"
292
+ },
293
+ {
294
+ "internalType": "uint256[8]",
295
+ "name": "points",
296
+ "type": "uint256[8]"
297
+ },
298
+ {
299
+ "internalType": "uint8[]",
300
+ "name": "hook_data",
301
+ "type": "uint8[]"
302
+ }
303
+ ],
304
+ "name": "settle",
305
+ "outputs": [],
306
+ "stateMutability": "nonpayable",
307
+ "type": "function"
308
+ },
309
+ {
310
+ "inputs": [
311
+ {
312
+ "internalType": "bytes32",
313
+ "name": "resource_id",
314
+ "type": "bytes32"
315
+ },
316
+ {
317
+ "internalType": "uint256",
318
+ "name": "price",
319
+ "type": "uint256"
320
+ },
321
+ {
322
+ "internalType": "address",
323
+ "name": "owner",
324
+ "type": "address"
325
+ }
326
+ ],
327
+ "name": "updatePrice",
328
+ "outputs": [],
329
+ "stateMutability": "nonpayable",
330
+ "type": "function"
331
+ }
332
+ ];
27
333
 
28
334
  //#endregion
29
335
  export { SETTLEMENT_REGISTRY_ABI };
@@ -3,70 +3,67 @@ import * as viem0 from "viem";
3
3
  import { Address, Hex, PublicClient, WalletClient } from "viem";
4
4
 
5
5
  //#region src/registries/settlement-registry/index.d.ts
6
-
7
6
  declare class SettlementRegistry {
8
7
  readonly contractAddress: Address;
9
8
  private readonly publicClient;
10
9
  private readonly walletClient;
11
10
  constructor(contractAddress: Address, publicClient: PublicClient, walletClient: WalletClient);
11
+ private getAccount;
12
+ private getChain;
13
+ /**
14
+ * Authorize or revoke a DataSourceRegistry contract.
15
+ * Only callable by the contract admin.
16
+ */
17
+ setRegistry(registry: Address, authorized: boolean): Promise<Hex>;
18
+ /**
19
+ * Create a Semaphore group for a resource.
20
+ * In production this is called by the DataSourceRegistry, which passes
21
+ * the publisher wallet as `owner`. Direct calls require the caller to
22
+ * be an authorized registry.
23
+ */
24
+ createResource(resourceId: Hex, price: bigint, owner: Address): Promise<Hex>;
25
+ /**
26
+ * Update the price for a resource.
27
+ * In production this is called by the DataSourceRegistry.
28
+ */
29
+ updatePrice(resourceId: Hex, price: bigint, owner: Address): Promise<Hex>;
12
30
  /**
13
- * Create a Semaphore group for a resource. Called by the schema owner once per (schemaId, tag) asset.
14
- *
15
- * @param resourceId: The hex encoded resource id
16
- * @param price : The USDC price for the resource
17
- * @returns The finalized transaction hash.
31
+ * Register a hook contract for a resource.
32
+ * Called directly by the publisher wallet (msg.sender must be resource owner).
18
33
  */
19
- createResource(resourceId: Hex, price: bigint): Promise<Hex>;
34
+ registerHook(resourceId: Hex, hook: Address): Promise<Hex>;
20
35
  /**
21
- * Prepares the EIP-3009 transferWithAuthorization call and signs it w/ an EIP-712 sig
22
- * @param params The transferWithAuth params
23
- * @returns The payload containing the signed call data
36
+ * Prepare the EIP-3009 transferWithAuthorization signature.
24
37
  */
25
38
  prepareTransferWithAuth(params: TransferWithAuthParams): Promise<TransferWithAuthPayload>;
26
39
  /**
27
- * Submit a payment and register with the specified semaphore group
28
- * @param params
29
- * @returns
40
+ * Phase 1 — submit payment and join the Semaphore group.
41
+ * Submitted via a relayer so the buyer's burner wallet is never linked
42
+ * to their identity commitment on-chain.
30
43
  */
31
44
  register(params: RegisterParams): Promise<Hex>;
45
+ /**
46
+ * Build the Semaphore proof for Phase 2.
47
+ */
32
48
  prepareSettle(params: PrepareSettleParams): Promise<PrepareSettleResult>;
49
+ /**
50
+ * Phase 2 — prove group membership and claim access.
51
+ * Submitted via a relayer for unlinkability.
52
+ */
33
53
  settle(params: SettleParams): Promise<{
34
54
  hash: Hex;
35
55
  nullifier: bigint;
36
56
  }>;
37
- /**
38
- * Check if a nullifier has been settled (i.e. the user completed Phase 2).
39
- * Used to gate decryptFile() in the Fangorn class.
40
- */
41
57
  isSettled(stealthAddress: Address, resourceId: Hex): Promise<boolean>;
42
- /**
43
- * Check if an identity commitment is registered for a resource (completed Phase 1).
44
- */
45
58
  isRegistered(resourceId: Hex, identityCommitment: bigint): Promise<boolean>;
46
- /**
47
- * Get the semaphore group id for a resource
48
- * @param resourceId The resource id
49
- * @returns The group id (if it exists), else null
50
- */
51
59
  getGroupId(resourceId: Hex): Promise<bigint>;
52
- /**
53
- * Get the price associated with a resource
54
- * @param resourceId The resource id
55
- * @returns The price
56
- */
57
60
  getPrice(resourceId: Hex): Promise<bigint>;
58
- /**
59
- * Deterministic resource_id = keccak256(ownerAddress ++ schemaName ++ tag).
60
- * This can be implemented in any way as long as owner/schema/tag produces a unique output
61
- */
62
- static deriveResourceId(owner: Address, schemaName: string, tag: string): Hex;
61
+ getOwner(resourceId: Hex): Promise<Address>;
62
+ waitForTransaction(hash: Hex): Promise<viem0.TransactionReceipt>;
63
63
  /**
64
64
  * Reconstruct the Semaphore group from MemberRegistered events.
65
- * Fetches all logs (no topic filter) and filters in JS to avoid
66
- * viem topic-encoding edge cases with indexed params.
67
65
  */
68
66
  private fetchGroup;
69
- waitForTransaction(hash: Hex): Promise<viem0.TransactionReceipt>;
70
67
  }
71
68
  //#endregion
72
69
  export { SettlementRegistry };