@fangorn-network/sdk 2026.3.11 → 2026.3.28

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 (89) hide show
  1. package/README.md +311 -198
  2. package/lib/builders/a2aCardBuilder.js +1 -0
  3. package/lib/cli/cli.d.ts +0 -0
  4. package/lib/cli/cli.js +399 -380
  5. package/lib/cli/index.d.ts +170 -170
  6. package/lib/cli/index.js +1 -4
  7. package/lib/config.d.ts +543 -163
  8. package/lib/config.js +11 -8
  9. package/lib/fangorn.d.ts +31 -43
  10. package/lib/fangorn.js +101 -117
  11. package/lib/index.d.ts +8 -5
  12. package/lib/index.js +8 -7
  13. package/lib/modules/encryption/index.d.ts +4 -3
  14. package/lib/modules/encryption/lit.d.ts +3 -18
  15. package/lib/modules/encryption/lit.js +20 -49
  16. package/lib/modules/encryption/rand.js +2 -2
  17. package/lib/modules/encryption/types.d.ts +23 -8
  18. package/lib/modules/gadgets/settledGadget.d.ts +31 -0
  19. package/lib/modules/gadgets/settledGadget.js +75 -0
  20. package/lib/modules/gadgets/types.d.ts +16 -4
  21. package/lib/providers/storage/index.d.ts +15 -4
  22. package/lib/providers/storage/pinata/index.d.ts +5 -4
  23. package/lib/providers/storage/pinata/index.js +17 -2
  24. package/lib/providers/storage/storacha/index.d.ts +13 -0
  25. package/lib/providers/storage/storacha/index.js +49 -0
  26. package/lib/providers/storage/storacha/readOnly.d.ts +8 -0
  27. package/lib/providers/storage/storacha/readOnly.js +16 -0
  28. package/lib/{interface → registries}/datasource-registry/abi.d.ts +29 -43
  29. package/lib/registries/datasource-registry/abi.js +16 -0
  30. package/lib/registries/datasource-registry/index.d.ts +24 -0
  31. package/lib/{interface/datasource-registry/dataSourceRegistry.js → registries/datasource-registry/index.js} +35 -34
  32. package/lib/registries/index.d.ts +3 -0
  33. package/lib/registries/index.js +4 -0
  34. package/lib/registries/schema-registry/abi.d.ts +127 -0
  35. package/lib/registries/schema-registry/abi.js +19 -0
  36. package/lib/registries/schema-registry/index.d.ts +29 -0
  37. package/lib/registries/schema-registry/index.js +114 -0
  38. package/lib/registries/settlement-registry/abi.d.ts +228 -0
  39. package/lib/registries/settlement-registry/abi.js +29 -0
  40. package/lib/registries/settlement-registry/index.d.ts +72 -0
  41. package/lib/registries/settlement-registry/index.js +316 -0
  42. package/lib/registries/settlement-registry/types.d.ts +51 -0
  43. package/lib/roles/consumer/index.d.ts +64 -0
  44. package/lib/roles/consumer/index.js +114 -0
  45. package/lib/roles/consumer/types.d.ts +66 -0
  46. package/lib/roles/index.js +1 -0
  47. package/lib/roles/publisher/index.d.ts +68 -0
  48. package/lib/roles/publisher/index.js +205 -0
  49. package/lib/roles/publisher/types.d.ts +93 -0
  50. package/lib/roles/publisher/types.js +1 -0
  51. package/lib/roles/schema/index.d.ts +44 -0
  52. package/lib/roles/schema/index.js +137 -0
  53. package/lib/roles/schema/types.d.ts +67 -0
  54. package/lib/roles/schema/types.js +1 -0
  55. package/lib/test/index.d.ts +5 -2
  56. package/lib/test/index.js +5 -3
  57. package/lib/test/testbed.d.ts +52 -32
  58. package/lib/test/testbed.js +138 -137
  59. package/lib/types/index.d.ts +65 -21
  60. package/lib/types/index.js +1 -12
  61. package/lib/utils/index.d.ts +2 -3
  62. package/lib/utils/index.js +4 -18
  63. package/package.json +85 -81
  64. package/lib/cli/registry.d.ts +0 -29
  65. package/lib/cli/registry.js +0 -53
  66. package/lib/deployContract.d.ts +0 -23
  67. package/lib/deployContract.js +0 -78
  68. package/lib/interface/datasource-registry/abi.js +0 -110
  69. package/lib/interface/datasource-registry/dataSourceRegistry.d.ts +0 -24
  70. package/lib/interface/index.d.ts +0 -3
  71. package/lib/interface/index.js +0 -4
  72. package/lib/interface/manifest.d.ts +0 -7
  73. package/lib/interface/manifest.js +0 -10
  74. package/lib/interface/settlement-tracker/abi.d.ts +0 -26
  75. package/lib/interface/settlement-tracker/abi.js +0 -88
  76. package/lib/interface/settlement-tracker/settlementTracker.d.ts +0 -32
  77. package/lib/interface/settlement-tracker/settlementTracker.js +0 -64
  78. package/lib/modules/gadgets/acc/gadgets.d.ts +0 -7
  79. package/lib/modules/gadgets/acc/gadgets.js +0 -10
  80. package/lib/modules/gadgets/acc.d.ts +0 -15
  81. package/lib/modules/gadgets/acc.js +0 -24
  82. package/lib/modules/gadgets/builder.d.ts +0 -1
  83. package/lib/modules/gadgets/payment.d.ts +0 -23
  84. package/lib/modules/gadgets/payment.js +0 -88
  85. package/lib/test/test-gadget.d.ts +0 -7
  86. package/lib/test/test-gadget.js +0 -10
  87. /package/lib/{modules/gadgets/builder.js → registries/settlement-registry/types.js} +0 -0
  88. /package/lib/{providers/storage/s3/index.js → roles/consumer/types.js} +0 -0
  89. /package/lib/{providers/storage/s3 → roles}/index.d.ts +0 -0
@@ -0,0 +1,127 @@
1
+ //#region src/registries/schema-registry/abi.d.ts
2
+ declare const SCHEMA_REGISTRY_ABI: readonly [{
3
+ readonly name: "schemaId";
4
+ readonly type: "function";
5
+ readonly stateMutability: "view";
6
+ readonly inputs: readonly [{
7
+ readonly type: "string";
8
+ readonly name: "name";
9
+ }];
10
+ readonly outputs: readonly [{
11
+ readonly type: "bytes32";
12
+ }];
13
+ }, {
14
+ readonly name: "registerSchema";
15
+ readonly type: "function";
16
+ readonly stateMutability: "nonpayable";
17
+ readonly inputs: readonly [{
18
+ readonly type: "string";
19
+ readonly name: "name";
20
+ }, {
21
+ readonly type: "string";
22
+ readonly name: "spec_cid";
23
+ }, {
24
+ readonly type: "string";
25
+ readonly name: "agent_id";
26
+ }];
27
+ readonly outputs: readonly [{
28
+ readonly type: "bytes32";
29
+ }];
30
+ }, {
31
+ readonly name: "updateSchema";
32
+ readonly type: "function";
33
+ readonly stateMutability: "nonpayable";
34
+ readonly inputs: readonly [{
35
+ readonly type: "bytes32";
36
+ readonly name: "id";
37
+ }, {
38
+ readonly type: "string";
39
+ readonly name: "new_spec_cid";
40
+ }, {
41
+ readonly type: "string";
42
+ readonly name: "new_agent_id";
43
+ }];
44
+ readonly outputs: readonly [];
45
+ }, {
46
+ readonly name: "getSchemaSpec";
47
+ readonly type: "function";
48
+ readonly stateMutability: "view";
49
+ readonly inputs: readonly [{
50
+ readonly type: "bytes32";
51
+ readonly name: "id";
52
+ }];
53
+ readonly outputs: readonly [{
54
+ readonly type: "string";
55
+ }];
56
+ }, {
57
+ readonly name: "getSchemaAgent";
58
+ readonly type: "function";
59
+ readonly stateMutability: "view";
60
+ readonly inputs: readonly [{
61
+ readonly type: "bytes32";
62
+ readonly name: "id";
63
+ }];
64
+ readonly outputs: readonly [{
65
+ readonly type: "string";
66
+ }];
67
+ }, {
68
+ readonly name: "schemaExists";
69
+ readonly type: "function";
70
+ readonly stateMutability: "view";
71
+ readonly inputs: readonly [{
72
+ readonly type: "bytes32";
73
+ readonly name: "id";
74
+ }];
75
+ readonly outputs: readonly [{
76
+ readonly type: "bool";
77
+ }];
78
+ }, {
79
+ readonly name: "SchemaRegistered";
80
+ readonly type: "event";
81
+ readonly inputs: readonly [{
82
+ readonly type: "bytes32";
83
+ readonly name: "id";
84
+ readonly indexed: true;
85
+ }, {
86
+ readonly type: "address";
87
+ readonly name: "owner";
88
+ readonly indexed: true;
89
+ }, {
90
+ readonly type: "string";
91
+ readonly name: "name";
92
+ }, {
93
+ readonly type: "string";
94
+ readonly name: "spec_cid";
95
+ }, {
96
+ readonly type: "string";
97
+ readonly name: "agent_id";
98
+ }];
99
+ }, {
100
+ readonly name: "SchemaUpdated";
101
+ readonly type: "event";
102
+ readonly inputs: readonly [{
103
+ readonly type: "bytes32";
104
+ readonly name: "id";
105
+ readonly indexed: true;
106
+ }, {
107
+ readonly type: "string";
108
+ readonly name: "new_spec_cid";
109
+ }, {
110
+ readonly type: "string";
111
+ readonly name: "new_agent_id";
112
+ }];
113
+ }, {
114
+ readonly name: "NotOwner";
115
+ readonly type: "error";
116
+ readonly inputs: readonly [];
117
+ }, {
118
+ readonly name: "SchemaNotFound";
119
+ readonly type: "error";
120
+ readonly inputs: readonly [];
121
+ }, {
122
+ readonly name: "SchemaAlreadyExists";
123
+ readonly type: "error";
124
+ readonly inputs: readonly [];
125
+ }];
126
+ //#endregion
127
+ export { SCHEMA_REGISTRY_ABI };
@@ -0,0 +1,19 @@
1
+ import { parseAbi } from "viem";
2
+
3
+ //#region src/registries/schema-registry/abi.ts
4
+ const SCHEMA_REGISTRY_ABI = parseAbi([
5
+ "function schemaId(string calldata name) external view returns (bytes32)",
6
+ "function registerSchema(string calldata name, string calldata spec_cid, string calldata agent_id) external returns (bytes32)",
7
+ "function updateSchema(bytes32 id, string calldata new_spec_cid, string calldata new_agent_id) external",
8
+ "function getSchemaSpec(bytes32 id) external view returns (string memory)",
9
+ "function getSchemaAgent(bytes32 id) external view returns (string memory)",
10
+ "function schemaExists(bytes32 id) external view returns (bool)",
11
+ "event SchemaRegistered(bytes32 indexed id, address indexed owner, string name, string spec_cid, string agent_id)",
12
+ "event SchemaUpdated(bytes32 indexed id, string new_spec_cid, string new_agent_id)",
13
+ "error NotOwner()",
14
+ "error SchemaNotFound()",
15
+ "error SchemaAlreadyExists()"
16
+ ]);
17
+
18
+ //#endregion
19
+ export { SCHEMA_REGISTRY_ABI };
@@ -0,0 +1,29 @@
1
+ import * as viem429 from "viem";
2
+ import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
+
4
+ //#region src/registries/schema-registry/index.d.ts
5
+ interface Schema {
6
+ name: string;
7
+ cid: string;
8
+ agentId: string;
9
+ }
10
+ declare class SchemaRegistry {
11
+ private publicClient;
12
+ private walletClient;
13
+ private contractAddress;
14
+ constructor(contractAddress: Address, publicClient: PublicClient, walletClient: WalletClient);
15
+ private getWriteConfig;
16
+ getContractAddress(): `0x${string}`;
17
+ schemaId(name: string): Promise<Hex>;
18
+ registerSchema(name: string, specCid: string, agentId: string): Promise<{
19
+ hash: Hash;
20
+ schemaId: Hex;
21
+ }>;
22
+ updateSchema(nameOrId: string, newSpecCid: string, newAgentId: string): Promise<Hash>;
23
+ getSchema(nameOrId: string): Promise<Schema>;
24
+ schemaExists(nameOrId: string): Promise<boolean>;
25
+ waitForTransaction(hash: Hash): Promise<viem429.TransactionReceipt>;
26
+ private resolveId;
27
+ }
28
+ //#endregion
29
+ export { Schema, SchemaRegistry };
@@ -0,0 +1,114 @@
1
+ import { SCHEMA_REGISTRY_ABI } from "./abi.js";
2
+ import { parseEventLogs } from "viem";
3
+
4
+ //#region src/registries/schema-registry/index.ts
5
+ var SchemaRegistry = class {
6
+ publicClient;
7
+ walletClient;
8
+ contractAddress;
9
+ constructor(contractAddress, publicClient, walletClient) {
10
+ this.publicClient = publicClient;
11
+ this.contractAddress = contractAddress;
12
+ this.walletClient = walletClient;
13
+ }
14
+ getWriteConfig() {
15
+ if (!this.walletClient.chain) throw new Error("Chain required");
16
+ if (!this.walletClient.account) throw new Error("Account required");
17
+ return {
18
+ chain: this.walletClient.chain,
19
+ account: this.walletClient.account
20
+ };
21
+ }
22
+ getContractAddress() {
23
+ return this.contractAddress;
24
+ }
25
+ async schemaId(name) {
26
+ return this.publicClient.readContract({
27
+ address: this.contractAddress,
28
+ abi: SCHEMA_REGISTRY_ABI,
29
+ functionName: "schemaId",
30
+ args: [name]
31
+ });
32
+ }
33
+ async registerSchema(name, specCid, agentId) {
34
+ const { chain, account } = this.getWriteConfig();
35
+ const hash = await this.walletClient.writeContract({
36
+ address: this.contractAddress,
37
+ abi: SCHEMA_REGISTRY_ABI,
38
+ functionName: "registerSchema",
39
+ args: [
40
+ name,
41
+ specCid,
42
+ agentId
43
+ ],
44
+ chain,
45
+ account
46
+ });
47
+ return {
48
+ hash,
49
+ schemaId: (parseEventLogs({
50
+ abi: SCHEMA_REGISTRY_ABI,
51
+ logs: (await this.waitForTransaction(hash)).logs
52
+ }).find((log) => log.eventName === "SchemaRegistered")?.args).id
53
+ };
54
+ }
55
+ async updateSchema(nameOrId, newSpecCid, newAgentId) {
56
+ const { chain, account } = this.getWriteConfig();
57
+ const id = await this.resolveId(nameOrId);
58
+ const hash = await this.walletClient.writeContract({
59
+ address: this.contractAddress,
60
+ abi: SCHEMA_REGISTRY_ABI,
61
+ functionName: "updateSchema",
62
+ args: [
63
+ id,
64
+ newSpecCid,
65
+ newAgentId
66
+ ],
67
+ chain,
68
+ account
69
+ });
70
+ await this.waitForTransaction(hash);
71
+ return hash;
72
+ }
73
+ async getSchema(nameOrId) {
74
+ const id = await this.resolveId(nameOrId);
75
+ const [specCid, agentId] = await Promise.all([this.publicClient.readContract({
76
+ address: this.contractAddress,
77
+ abi: SCHEMA_REGISTRY_ABI,
78
+ functionName: "getSchemaSpec",
79
+ args: [id]
80
+ }), this.publicClient.readContract({
81
+ address: this.contractAddress,
82
+ abi: SCHEMA_REGISTRY_ABI,
83
+ functionName: "getSchemaAgent",
84
+ args: [id]
85
+ })]);
86
+ return {
87
+ name: typeof nameOrId === "string" ? nameOrId : id,
88
+ cid: specCid,
89
+ agentId
90
+ };
91
+ }
92
+ async schemaExists(nameOrId) {
93
+ const id = await this.resolveId(nameOrId);
94
+ return this.publicClient.readContract({
95
+ address: this.contractAddress,
96
+ abi: SCHEMA_REGISTRY_ABI,
97
+ functionName: "schemaExists",
98
+ args: [id]
99
+ });
100
+ }
101
+ async waitForTransaction(hash) {
102
+ return this.publicClient.waitForTransactionReceipt({ hash });
103
+ }
104
+ async resolveId(nameOrId) {
105
+ if (isBytes32Hex(nameOrId)) return nameOrId;
106
+ return this.schemaId(nameOrId);
107
+ }
108
+ };
109
+ function isBytes32Hex(value) {
110
+ return /^0x[0-9a-fA-F]{64}$/.test(value);
111
+ }
112
+
113
+ //#endregion
114
+ export { SchemaRegistry };
@@ -0,0 +1,228 @@
1
+ //#region src/registries/settlement-registry/abi.d.ts
2
+ declare const SETTLEMENT_REGISTRY_ABI: readonly [{
3
+ readonly name: "createResource";
4
+ readonly type: "function";
5
+ readonly stateMutability: "nonpayable";
6
+ readonly inputs: readonly [{
7
+ readonly type: "bytes32";
8
+ readonly name: "resource_id";
9
+ }, {
10
+ readonly type: "uint256";
11
+ readonly name: "price";
12
+ }];
13
+ readonly outputs: readonly [{
14
+ readonly type: "uint256";
15
+ }];
16
+ }, {
17
+ readonly name: "addSeedMember";
18
+ readonly type: "function";
19
+ readonly stateMutability: "nonpayable";
20
+ readonly inputs: readonly [{
21
+ readonly type: "bytes32";
22
+ readonly name: "resource_id";
23
+ }];
24
+ readonly outputs: readonly [];
25
+ }, {
26
+ readonly name: "updatePrice";
27
+ readonly type: "function";
28
+ readonly stateMutability: "nonpayable";
29
+ readonly inputs: readonly [{
30
+ readonly type: "bytes32";
31
+ readonly name: "resource_id";
32
+ }, {
33
+ readonly type: "uint256";
34
+ readonly name: "price";
35
+ }];
36
+ readonly outputs: readonly [];
37
+ }, {
38
+ readonly name: "registerHook";
39
+ readonly type: "function";
40
+ readonly stateMutability: "nonpayable";
41
+ readonly inputs: readonly [{
42
+ readonly type: "bytes32";
43
+ readonly name: "resource_id";
44
+ }, {
45
+ readonly type: "address";
46
+ readonly name: "hook";
47
+ }];
48
+ readonly outputs: readonly [];
49
+ }, {
50
+ readonly name: "register";
51
+ readonly type: "function";
52
+ readonly stateMutability: "payable";
53
+ readonly inputs: readonly [{
54
+ readonly type: "bytes32";
55
+ readonly name: "resource_id";
56
+ }, {
57
+ readonly type: "uint256";
58
+ readonly name: "identity_commitment";
59
+ }, {
60
+ readonly type: "address";
61
+ readonly name: "from";
62
+ }, {
63
+ readonly type: "address";
64
+ readonly name: "to";
65
+ }, {
66
+ readonly type: "uint256";
67
+ readonly name: "amount";
68
+ }, {
69
+ readonly type: "uint256";
70
+ readonly name: "valid_after";
71
+ }, {
72
+ readonly type: "uint256";
73
+ readonly name: "valid_before";
74
+ }, {
75
+ readonly type: "bytes32";
76
+ readonly name: "nonce";
77
+ }, {
78
+ readonly type: "uint8";
79
+ readonly name: "v";
80
+ }, {
81
+ readonly type: "bytes32";
82
+ readonly name: "r";
83
+ }, {
84
+ readonly type: "bytes32";
85
+ readonly name: "s";
86
+ }];
87
+ readonly outputs: readonly [];
88
+ }, {
89
+ readonly name: "settle";
90
+ readonly type: "function";
91
+ readonly stateMutability: "nonpayable";
92
+ readonly inputs: readonly [{
93
+ readonly type: "bytes32";
94
+ readonly name: "resource_id";
95
+ }, {
96
+ readonly type: "address";
97
+ readonly name: "stealth_address";
98
+ }, {
99
+ readonly type: "uint256";
100
+ readonly name: "merkle_tree_depth";
101
+ }, {
102
+ readonly type: "uint256";
103
+ readonly name: "merkle_tree_root";
104
+ }, {
105
+ readonly type: "uint256";
106
+ readonly name: "nullifier";
107
+ }, {
108
+ readonly type: "uint256";
109
+ readonly name: "message";
110
+ }, {
111
+ readonly type: "uint256[8]";
112
+ readonly name: "points";
113
+ }, {
114
+ readonly type: "uint8[]";
115
+ readonly name: "hook_data";
116
+ }];
117
+ readonly outputs: readonly [];
118
+ }, {
119
+ readonly name: "isSettled";
120
+ readonly type: "function";
121
+ readonly stateMutability: "view";
122
+ readonly inputs: readonly [{
123
+ readonly type: "address";
124
+ readonly name: "stealth_address";
125
+ }, {
126
+ readonly type: "bytes32";
127
+ readonly name: "resource_id";
128
+ }];
129
+ readonly outputs: readonly [{
130
+ readonly type: "bool";
131
+ }];
132
+ }, {
133
+ readonly name: "getGroupId";
134
+ readonly type: "function";
135
+ readonly stateMutability: "view";
136
+ readonly inputs: readonly [{
137
+ readonly type: "bytes32";
138
+ readonly name: "resource_id";
139
+ }];
140
+ readonly outputs: readonly [{
141
+ readonly type: "uint256";
142
+ }];
143
+ }, {
144
+ readonly name: "getHook";
145
+ readonly type: "function";
146
+ readonly stateMutability: "view";
147
+ readonly inputs: readonly [{
148
+ readonly type: "bytes32";
149
+ readonly name: "resource_id";
150
+ }];
151
+ readonly outputs: readonly [{
152
+ readonly type: "address";
153
+ }];
154
+ }, {
155
+ readonly name: "getOwner";
156
+ readonly type: "function";
157
+ readonly stateMutability: "view";
158
+ readonly inputs: readonly [{
159
+ readonly type: "bytes32";
160
+ readonly name: "resource_id";
161
+ }];
162
+ readonly outputs: readonly [{
163
+ readonly type: "address";
164
+ }];
165
+ }, {
166
+ readonly name: "getPrice";
167
+ readonly type: "function";
168
+ readonly stateMutability: "view";
169
+ readonly inputs: readonly [{
170
+ readonly type: "bytes32";
171
+ readonly name: "resource_id";
172
+ }];
173
+ readonly outputs: readonly [{
174
+ readonly type: "uint256";
175
+ }];
176
+ }, {
177
+ readonly name: "isRegistered";
178
+ readonly type: "function";
179
+ readonly stateMutability: "view";
180
+ readonly inputs: readonly [{
181
+ readonly type: "bytes32";
182
+ readonly name: "resource_id";
183
+ }, {
184
+ readonly type: "uint256";
185
+ readonly name: "identity_commitment";
186
+ }];
187
+ readonly outputs: readonly [{
188
+ readonly type: "bool";
189
+ }];
190
+ }, {
191
+ readonly name: "AlreadyRegistered";
192
+ readonly type: "error";
193
+ readonly inputs: readonly [];
194
+ }, {
195
+ readonly name: "AlreadySettled";
196
+ readonly type: "error";
197
+ readonly inputs: readonly [];
198
+ }, {
199
+ readonly name: "IncorrectPaymentAmount";
200
+ readonly type: "error";
201
+ readonly inputs: readonly [];
202
+ }, {
203
+ readonly name: "TransferFailed";
204
+ readonly type: "error";
205
+ readonly inputs: readonly [];
206
+ }, {
207
+ readonly name: "VerificationFailed";
208
+ readonly type: "error";
209
+ readonly inputs: readonly [];
210
+ }, {
211
+ readonly name: "NotResourceOwner";
212
+ readonly type: "error";
213
+ readonly inputs: readonly [];
214
+ }, {
215
+ readonly name: "ResourceNotFound";
216
+ readonly type: "error";
217
+ readonly inputs: readonly [];
218
+ }, {
219
+ readonly name: "HookFailed";
220
+ readonly type: "error";
221
+ readonly inputs: readonly [];
222
+ }, {
223
+ readonly name: "GroupCreationFailed";
224
+ readonly type: "error";
225
+ readonly inputs: readonly [];
226
+ }];
227
+ //#endregion
228
+ export { SETTLEMENT_REGISTRY_ABI };
@@ -0,0 +1,29 @@
1
+ import { parseAbi } from "viem";
2
+
3
+ //#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
+ ]);
27
+
28
+ //#endregion
29
+ export { SETTLEMENT_REGISTRY_ABI };
@@ -0,0 +1,72 @@
1
+ import { PrepareSettleParams, PrepareSettleResult, RegisterParams, SettleParams, TransferWithAuthParams, TransferWithAuthPayload } from "./types.js";
2
+ import * as viem430 from "viem";
3
+ import { Address, Hex, PublicClient, WalletClient } from "viem";
4
+
5
+ //#region src/registries/settlement-registry/index.d.ts
6
+
7
+ declare class SettlementRegistry {
8
+ readonly contractAddress: Address;
9
+ private readonly publicClient;
10
+ private readonly walletClient;
11
+ constructor(contractAddress: Address, publicClient: PublicClient, walletClient: WalletClient);
12
+ /**
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.
18
+ */
19
+ createResource(resourceId: Hex, price: bigint): Promise<Hex>;
20
+ /**
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
24
+ */
25
+ prepareTransferWithAuth(params: TransferWithAuthParams): Promise<TransferWithAuthPayload>;
26
+ /**
27
+ * Submit a payment and register with the specified semaphore group
28
+ * @param params
29
+ * @returns
30
+ */
31
+ register(params: RegisterParams): Promise<Hex>;
32
+ prepareSettle(params: PrepareSettleParams): Promise<PrepareSettleResult>;
33
+ settle(params: SettleParams): Promise<{
34
+ hash: Hex;
35
+ nullifier: bigint;
36
+ }>;
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
+ isSettled(stealthAddress: Address, resourceId: Hex): Promise<boolean>;
42
+ /**
43
+ * Check if an identity commitment is registered for a resource (completed Phase 1).
44
+ */
45
+ 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
+ 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
+ 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;
63
+ /**
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
+ */
68
+ private fetchGroup;
69
+ waitForTransaction(hash: Hex): Promise<viem430.TransactionReceipt>;
70
+ }
71
+ //#endregion
72
+ export { SettlementRegistry };