@fangorn-network/sdk 2026.6.16 → 2026.7.1-2.0

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 (105) hide show
  1. package/README.md +210 -266
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +261 -167
  4. package/lib/cli/index.d.ts +13 -651
  5. package/lib/config.d.ts +137 -792
  6. package/lib/config.js +6 -22
  7. package/lib/contracts/data-registry/abi.d.ts +38 -0
  8. package/lib/contracts/data-registry/abi.js +237 -0
  9. package/lib/contracts/data-registry/index.d.ts +81 -0
  10. package/lib/contracts/data-registry/index.js +184 -0
  11. package/lib/contracts/index.d.ts +3 -0
  12. package/lib/contracts/index.js +4 -0
  13. package/lib/crypto/aes.d.ts +26 -0
  14. package/lib/crypto/aes.js +58 -0
  15. package/lib/crypto/encryption.d.ts +53 -0
  16. package/lib/crypto/encryption.js +82 -0
  17. package/lib/{modules/encryption → crypto}/rand.d.ts +1 -1
  18. package/lib/{modules/encryption → crypto}/rand.js +1 -1
  19. package/lib/{modules/encryption → crypto}/types.d.ts +1 -1
  20. package/lib/engine/blockstore.d.ts +24 -0
  21. package/lib/engine/blockstore.js +85 -0
  22. package/lib/engine/index.d.ts +180 -0
  23. package/lib/engine/index.js +367 -0
  24. package/lib/fangorn.d.ts +149 -16
  25. package/lib/fangorn.js +256 -37
  26. package/lib/harness/examples/hackmd/build-markdown-graph.js +17 -0
  27. package/lib/harness/index.d.ts +57 -0
  28. package/lib/harness/index.js +67 -0
  29. package/lib/index.d.ts +2 -2
  30. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +218 -0
  31. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +261 -0
  32. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +156 -0
  33. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +299 -0
  34. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +532 -0
  35. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +344 -0
  36. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +137 -0
  37. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +262 -0
  38. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +150 -0
  39. package/lib/providers/storage/car.d.ts +36 -0
  40. package/lib/providers/storage/car.js +80 -0
  41. package/lib/providers/storage/pinata.d.ts +29 -1
  42. package/lib/providers/storage/pinata.js +135 -20
  43. package/lib/providers/storage/types.d.ts +25 -18
  44. package/lib/roles/repo/index.d.ts +56 -0
  45. package/lib/roles/repo/index.js +73 -0
  46. package/lib/test/car_smoke.d.ts +1 -0
  47. package/lib/test/car_smoke.js +81 -0
  48. package/lib/test/cleanup-embeddings-testdata.js +9 -38
  49. package/lib/test/setup-embeddings-testdata.d.ts +4 -6
  50. package/lib/test/setup-embeddings-testdata.js +40 -94
  51. package/lib/test/testbed.d.ts +35 -32
  52. package/lib/test/testbed.js +48 -138
  53. package/lib/types/index.d.ts +3 -19
  54. package/lib/utils/manifest.d.ts +23 -0
  55. package/lib/utils/manifest.js +77 -0
  56. package/package.json +99 -81
  57. package/lib/modules/encryption/actions.d.ts +0 -4
  58. package/lib/modules/encryption/actions.js +0 -18
  59. package/lib/modules/encryption/aes.d.ts +0 -10
  60. package/lib/modules/encryption/aes.js +0 -51
  61. package/lib/registries/datasource-registry/abi.d.ts +0 -186
  62. package/lib/registries/datasource-registry/abi.js +0 -229
  63. package/lib/registries/datasource-registry/index.d.ts +0 -39
  64. package/lib/registries/datasource-registry/index.js +0 -158
  65. package/lib/registries/index.d.ts +0 -3
  66. package/lib/registries/index.js +0 -4
  67. package/lib/registries/schema-registry/abi.d.ts +0 -218
  68. package/lib/registries/schema-registry/abi.js +0 -246
  69. package/lib/registries/schema-registry/index.d.ts +0 -34
  70. package/lib/registries/schema-registry/index.js +0 -179
  71. package/lib/registries/settlement-registry/abi.d.ts +0 -218
  72. package/lib/registries/settlement-registry/abi.js +0 -259
  73. package/lib/registries/settlement-registry/index.d.ts +0 -63
  74. package/lib/registries/settlement-registry/index.js +0 -325
  75. package/lib/registries/settlement-registry/types.d.ts +0 -54
  76. package/lib/registries/settlement-registry/types.js +0 -1
  77. package/lib/roles/consumer/index.d.ts +0 -39
  78. package/lib/roles/consumer/index.js +0 -150
  79. package/lib/roles/consumer/types.d.ts +0 -47
  80. package/lib/roles/consumer/types.js +0 -1
  81. package/lib/roles/publisher/builders/bundle.d.ts +0 -32
  82. package/lib/roles/publisher/builders/bundle.js +0 -137
  83. package/lib/roles/publisher/builders/record-set.d.ts +0 -17
  84. package/lib/roles/publisher/builders/record-set.js +0 -55
  85. package/lib/roles/publisher/builders/types.d.ts +0 -38
  86. package/lib/roles/publisher/builders/types.js +0 -1
  87. package/lib/roles/publisher/builders/utils.d.ts +0 -9
  88. package/lib/roles/publisher/builders/utils.js +0 -29
  89. package/lib/roles/publisher/encryption.d.ts +0 -18
  90. package/lib/roles/publisher/encryption.js +0 -38
  91. package/lib/roles/publisher/index.d.ts +0 -68
  92. package/lib/roles/publisher/index.js +0 -179
  93. package/lib/roles/publisher/types.d.ts +0 -114
  94. package/lib/roles/publisher/types.js +0 -1
  95. package/lib/roles/schema/index.d.ts +0 -44
  96. package/lib/roles/schema/index.js +0 -127
  97. package/lib/roles/schema/types.d.ts +0 -113
  98. package/lib/roles/schema/types.js +0 -1
  99. package/lib/roles/schema/validate.d.ts +0 -9
  100. package/lib/roles/schema/validate.js +0 -128
  101. package/lib/test/publish_mb_bundle.js +0 -296
  102. /package/lib/{modules/encryption/index.d.ts → contracts/data-registry/test.d.ts} +0 -0
  103. /package/lib/{modules/encryption/index.js → contracts/data-registry/test.js} +0 -0
  104. /package/lib/{modules/encryption → crypto}/types.js +0 -0
  105. /package/lib/{test/publish_mb_bundle.d.ts → harness/examples/hackmd/build-markdown-graph.d.ts} +0 -0
@@ -1,259 +0,0 @@
1
- //#region src/registries/settlement-registry/abi.ts
2
- const SETTLEMENT_REGISTRY_ABI = [
3
- {
4
- "inputs": [{
5
- "internalType": "uint8",
6
- "name": "",
7
- "type": "uint8"
8
- }],
9
- "name": "ErrCode",
10
- "type": "error"
11
- },
12
- {
13
- "inputs": [
14
- {
15
- "internalType": "bytes32",
16
- "name": "resource_id",
17
- "type": "bytes32"
18
- },
19
- {
20
- "internalType": "uint256",
21
- "name": "price",
22
- "type": "uint256"
23
- },
24
- {
25
- "internalType": "address",
26
- "name": "owner",
27
- "type": "address"
28
- }
29
- ],
30
- "name": "createResource",
31
- "outputs": [{
32
- "internalType": "uint256",
33
- "name": "",
34
- "type": "uint256"
35
- }],
36
- "stateMutability": "nonpayable",
37
- "type": "function"
38
- },
39
- {
40
- "inputs": [{
41
- "internalType": "bytes32",
42
- "name": "resource_id",
43
- "type": "bytes32"
44
- }],
45
- "name": "getGroupId",
46
- "outputs": [{
47
- "internalType": "uint256",
48
- "name": "",
49
- "type": "uint256"
50
- }],
51
- "stateMutability": "view",
52
- "type": "function"
53
- },
54
- {
55
- "inputs": [{
56
- "internalType": "bytes32",
57
- "name": "resource_id",
58
- "type": "bytes32"
59
- }],
60
- "name": "getPrice",
61
- "outputs": [{
62
- "internalType": "uint256",
63
- "name": "",
64
- "type": "uint256"
65
- }],
66
- "stateMutability": "view",
67
- "type": "function"
68
- },
69
- {
70
- "inputs": [{
71
- "internalType": "bytes32",
72
- "name": "resource_id",
73
- "type": "bytes32"
74
- }, {
75
- "internalType": "uint256",
76
- "name": "identity_commitment",
77
- "type": "uint256"
78
- }],
79
- "name": "isRegistered",
80
- "outputs": [{
81
- "internalType": "bool",
82
- "name": "",
83
- "type": "bool"
84
- }],
85
- "stateMutability": "view",
86
- "type": "function"
87
- },
88
- {
89
- "inputs": [{
90
- "internalType": "address",
91
- "name": "stealth_address",
92
- "type": "address"
93
- }, {
94
- "internalType": "bytes32",
95
- "name": "resource_id",
96
- "type": "bytes32"
97
- }],
98
- "name": "isSettled",
99
- "outputs": [{
100
- "internalType": "bool",
101
- "name": "",
102
- "type": "bool"
103
- }],
104
- "stateMutability": "view",
105
- "type": "function"
106
- },
107
- {
108
- "inputs": [
109
- {
110
- "internalType": "bytes32",
111
- "name": "resource_id",
112
- "type": "bytes32"
113
- },
114
- {
115
- "internalType": "uint256",
116
- "name": "identity_commitment",
117
- "type": "uint256"
118
- },
119
- {
120
- "internalType": "address",
121
- "name": "from",
122
- "type": "address"
123
- },
124
- {
125
- "internalType": "address",
126
- "name": "to",
127
- "type": "address"
128
- },
129
- {
130
- "internalType": "uint256",
131
- "name": "amount",
132
- "type": "uint256"
133
- },
134
- {
135
- "internalType": "uint256",
136
- "name": "valid_after",
137
- "type": "uint256"
138
- },
139
- {
140
- "internalType": "uint256",
141
- "name": "valid_before",
142
- "type": "uint256"
143
- },
144
- {
145
- "internalType": "bytes32",
146
- "name": "nonce",
147
- "type": "bytes32"
148
- },
149
- {
150
- "internalType": "uint8",
151
- "name": "v",
152
- "type": "uint8"
153
- },
154
- {
155
- "internalType": "bytes32",
156
- "name": "r",
157
- "type": "bytes32"
158
- },
159
- {
160
- "internalType": "bytes32",
161
- "name": "s",
162
- "type": "bytes32"
163
- }
164
- ],
165
- "name": "register",
166
- "outputs": [],
167
- "stateMutability": "payable",
168
- "type": "function"
169
- },
170
- {
171
- "inputs": [{
172
- "internalType": "address",
173
- "name": "registry",
174
- "type": "address"
175
- }, {
176
- "internalType": "bool",
177
- "name": "authorized",
178
- "type": "bool"
179
- }],
180
- "name": "setRegistry",
181
- "outputs": [],
182
- "stateMutability": "nonpayable",
183
- "type": "function"
184
- },
185
- {
186
- "inputs": [
187
- {
188
- "internalType": "bytes32",
189
- "name": "resource_id",
190
- "type": "bytes32"
191
- },
192
- {
193
- "internalType": "address",
194
- "name": "stealth_address",
195
- "type": "address"
196
- },
197
- {
198
- "internalType": "uint256",
199
- "name": "merkle_tree_depth",
200
- "type": "uint256"
201
- },
202
- {
203
- "internalType": "uint256",
204
- "name": "merkle_tree_root",
205
- "type": "uint256"
206
- },
207
- {
208
- "internalType": "uint256",
209
- "name": "nullifier",
210
- "type": "uint256"
211
- },
212
- {
213
- "internalType": "uint256",
214
- "name": "message",
215
- "type": "uint256"
216
- },
217
- {
218
- "internalType": "uint256[8]",
219
- "name": "points",
220
- "type": "uint256[8]"
221
- },
222
- {
223
- "internalType": "uint8[]",
224
- "name": "hook_data",
225
- "type": "uint8[]"
226
- }
227
- ],
228
- "name": "settle",
229
- "outputs": [],
230
- "stateMutability": "nonpayable",
231
- "type": "function"
232
- },
233
- {
234
- "inputs": [
235
- {
236
- "internalType": "bytes32",
237
- "name": "resource_id",
238
- "type": "bytes32"
239
- },
240
- {
241
- "internalType": "address",
242
- "name": "hook",
243
- "type": "address"
244
- },
245
- {
246
- "internalType": "uint256",
247
- "name": "price",
248
- "type": "uint256"
249
- }
250
- ],
251
- "name": "updateResource",
252
- "outputs": [],
253
- "stateMutability": "nonpayable",
254
- "type": "function"
255
- }
256
- ];
257
-
258
- //#endregion
259
- export { SETTLEMENT_REGISTRY_ABI };
@@ -1,63 +0,0 @@
1
- import { PrepareSettleParams, PrepareSettleResult, RegisterParams, SettleParams, TransferWithAuthParams, TransferWithAuthPayload } from "./types.js";
2
- import * as viem349 from "viem";
3
- import { Address, Hex, PublicClient, WalletClient } from "viem";
4
-
5
- //#region src/registries/settlement-registry/index.d.ts
6
- declare class SettlementRegistry {
7
- readonly contractAddress: Address;
8
- private readonly publicClient;
9
- private readonly walletClient;
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, hook: Address, price: bigint): Promise<Hex>;
30
- /**
31
- * Prepare the EIP-3009 transferWithAuthorization signature.
32
- */
33
- prepareTransferWithAuth(params: TransferWithAuthParams): Promise<TransferWithAuthPayload>;
34
- /**
35
- * Phase 1 — submit payment and join the Semaphore group.
36
- * Submitted via a relayer so the buyer's burner wallet is never linked
37
- * to their identity commitment on-chain.
38
- */
39
- register(params: RegisterParams): Promise<Hex>;
40
- /**
41
- * Build the Semaphore proof for Phase 2.
42
- */
43
- prepareSettle(params: PrepareSettleParams): Promise<PrepareSettleResult>;
44
- /**
45
- * Phase 2 — prove group membership and claim access.
46
- * Submitted via a relayer for unlinkability.
47
- */
48
- settle(params: SettleParams): Promise<{
49
- hash: Hex;
50
- nullifier: bigint;
51
- }>;
52
- isSettled(stealthAddress: Address, resourceId: Hex): Promise<boolean>;
53
- isRegistered(resourceId: Hex, identityCommitment: bigint): Promise<boolean>;
54
- getGroupId(resourceId: Hex): Promise<bigint>;
55
- getPrice(resourceId: Hex): Promise<bigint>;
56
- waitForTransaction(hash: Hex): Promise<viem349.TransactionReceipt>;
57
- /**
58
- * Reconstruct the Semaphore group from MemberRegistered events.
59
- */
60
- private fetchGroup;
61
- }
62
- //#endregion
63
- export { SettlementRegistry };
@@ -1,325 +0,0 @@
1
- import { SETTLEMENT_REGISTRY_ABI } from "./abi.js";
2
- import { createWalletClient, http, parseSignature } from "viem";
3
- import { privateKeyToAccount } from "viem/accounts";
4
- import { Group } from "@semaphore-protocol/group";
5
- import { generateProof } from "@semaphore-protocol/proof";
6
-
7
- //#region src/registries/settlement-registry/index.ts
8
- var SettlementRegistry = class {
9
- constructor(contractAddress, publicClient, walletClient) {
10
- this.contractAddress = contractAddress;
11
- this.publicClient = publicClient;
12
- this.walletClient = walletClient;
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
- }
24
- /**
25
- * Authorize or revoke a DataSourceRegistry contract.
26
- * Only callable by the contract admin.
27
- */
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();
49
- const hash = await this.walletClient.writeContract({
50
- address: this.contractAddress,
51
- abi: SETTLEMENT_REGISTRY_ABI,
52
- functionName: "createResource",
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, hook, price) {
69
- const account = this.getAccount();
70
- const hash = await this.walletClient.writeContract({
71
- address: this.contractAddress,
72
- abi: SETTLEMENT_REGISTRY_ABI,
73
- functionName: "updateResource",
74
- args: [
75
- resourceId,
76
- hook,
77
- price
78
- ],
79
- chain: this.getChain(),
80
- account
81
- });
82
- await this.publicClient.waitForTransactionReceipt({ hash });
83
- return hash;
84
- }
85
- /**
86
- * Prepare the EIP-3009 transferWithAuthorization signature.
87
- */
88
- async prepareTransferWithAuth(params) {
89
- const { paymentRecipient, amount, usdcAddress, usdcDomainName, usdcDomainVersion } = params;
90
- const walletClient = params.walletClient ?? this.walletClient;
91
- const chain = walletClient.chain;
92
- if (!chain) throw new Error("Wallet client must have a chain configured.");
93
- const account = walletClient.account;
94
- if (!account) throw new Error("Wallet client must have an account configured.");
95
- const validAfter = 0n;
96
- const validBefore = BigInt(Math.floor(Date.now() / 1e3) + 3600);
97
- const nonceBytes = crypto.getRandomValues(new Uint8Array(32));
98
- const nonce = `0x${Array.from(nonceBytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
99
- const { v, r, s } = parseSignature(await walletClient.signTypedData({
100
- account,
101
- domain: {
102
- name: usdcDomainName,
103
- version: usdcDomainVersion,
104
- chainId: chain.id,
105
- verifyingContract: usdcAddress
106
- },
107
- types: { TransferWithAuthorization: [
108
- {
109
- name: "from",
110
- type: "address"
111
- },
112
- {
113
- name: "to",
114
- type: "address"
115
- },
116
- {
117
- name: "value",
118
- type: "uint256"
119
- },
120
- {
121
- name: "validAfter",
122
- type: "uint256"
123
- },
124
- {
125
- name: "validBefore",
126
- type: "uint256"
127
- },
128
- {
129
- name: "nonce",
130
- type: "bytes32"
131
- }
132
- ] },
133
- primaryType: "TransferWithAuthorization",
134
- message: {
135
- from: account.address,
136
- to: paymentRecipient,
137
- value: amount,
138
- validAfter,
139
- validBefore,
140
- nonce
141
- }
142
- }));
143
- return {
144
- sender: account.address,
145
- paymentRecipient,
146
- amount,
147
- validAfter,
148
- validBefore,
149
- nonce,
150
- v: Number(v),
151
- r,
152
- s
153
- };
154
- }
155
- /**
156
- * Phase 1 — submit payment and join the Semaphore group.
157
- * Submitted via a relayer so the buyer's burner wallet is never linked
158
- * to their identity commitment on-chain.
159
- */
160
- async register(params) {
161
- const { resourceId, identityCommitment, relayerPrivateKey, preparedRegister } = params;
162
- const { sender, paymentRecipient, amount, validAfter, validBefore, nonce, v, r, s } = preparedRegister;
163
- const chain = this.getChain();
164
- const hash = await createWalletClient({
165
- account: privateKeyToAccount(relayerPrivateKey),
166
- chain,
167
- transport: http(chain.rpcUrls.default.http[0])
168
- }).writeContract({
169
- address: this.contractAddress,
170
- abi: SETTLEMENT_REGISTRY_ABI,
171
- functionName: "register",
172
- args: [
173
- resourceId,
174
- identityCommitment,
175
- sender,
176
- paymentRecipient,
177
- amount,
178
- validAfter,
179
- validBefore,
180
- nonce,
181
- v,
182
- r,
183
- s
184
- ],
185
- chain,
186
- account: privateKeyToAccount(relayerPrivateKey)
187
- });
188
- await this.publicClient.waitForTransactionReceipt({ hash });
189
- return hash;
190
- }
191
- /**
192
- * Build the Semaphore proof for Phase 2.
193
- */
194
- async prepareSettle(params) {
195
- const { resourceId, identity, stealthAddress } = params;
196
- const groupId = await this.publicClient.readContract({
197
- address: this.contractAddress,
198
- abi: SETTLEMENT_REGISTRY_ABI,
199
- functionName: "getGroupId",
200
- args: [resourceId]
201
- });
202
- if (groupId === 0n) throw new Error(`No group for resource ${resourceId} — was createResource() called?`);
203
- const proof = await generateProof(identity, await this.fetchGroup(resourceId), BigInt(stealthAddress), groupId);
204
- return {
205
- resourceId,
206
- stealthAddress,
207
- merkleTreeDepth: BigInt(proof.merkleTreeDepth),
208
- merkleTreeRoot: BigInt(proof.merkleTreeRoot),
209
- nullifier: BigInt(proof.nullifier),
210
- message: BigInt(proof.message),
211
- points: proof.points.map(BigInt),
212
- hookData: params.hookData ?? "0x"
213
- };
214
- }
215
- /**
216
- * Phase 2 — prove group membership and claim access.
217
- * Submitted via a relayer for unlinkability.
218
- */
219
- async settle(params) {
220
- const { relayerPrivateKey, preparedSettle } = params;
221
- const { resourceId, stealthAddress, merkleTreeDepth, merkleTreeRoot, nullifier, message, points, hookData } = preparedSettle;
222
- const chain = this.getChain();
223
- const submitter = createWalletClient({
224
- account: privateKeyToAccount(relayerPrivateKey),
225
- chain,
226
- transport: http(chain.rpcUrls.default.http[0])
227
- });
228
- const hookBytes = hookData !== "0x" ? Array.from(Buffer.from(hookData.slice(2), "hex")) : [];
229
- const hash = await submitter.writeContract({
230
- address: this.contractAddress,
231
- abi: SETTLEMENT_REGISTRY_ABI,
232
- functionName: "settle",
233
- gas: 8000000n,
234
- args: [
235
- resourceId,
236
- stealthAddress,
237
- merkleTreeDepth,
238
- merkleTreeRoot,
239
- nullifier,
240
- message,
241
- points,
242
- hookBytes
243
- ],
244
- chain,
245
- account: privateKeyToAccount(relayerPrivateKey)
246
- });
247
- const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
248
- console.log("settlement status " + receipt.status);
249
- return {
250
- hash,
251
- nullifier
252
- };
253
- }
254
- async isSettled(stealthAddress, resourceId) {
255
- return this.publicClient.readContract({
256
- address: this.contractAddress,
257
- abi: SETTLEMENT_REGISTRY_ABI,
258
- functionName: "isSettled",
259
- args: [stealthAddress, resourceId]
260
- });
261
- }
262
- async isRegistered(resourceId, identityCommitment) {
263
- return this.publicClient.readContract({
264
- address: this.contractAddress,
265
- abi: SETTLEMENT_REGISTRY_ABI,
266
- functionName: "isRegistered",
267
- args: [resourceId, identityCommitment]
268
- });
269
- }
270
- async getGroupId(resourceId) {
271
- return this.publicClient.readContract({
272
- address: this.contractAddress,
273
- abi: SETTLEMENT_REGISTRY_ABI,
274
- functionName: "getGroupId",
275
- args: [resourceId]
276
- });
277
- }
278
- async getPrice(resourceId) {
279
- return this.publicClient.readContract({
280
- address: this.contractAddress,
281
- abi: SETTLEMENT_REGISTRY_ABI,
282
- functionName: "getPrice",
283
- args: [resourceId]
284
- });
285
- }
286
- async waitForTransaction(hash) {
287
- return this.publicClient.waitForTransactionReceipt({ hash });
288
- }
289
- /**
290
- * Reconstruct the Semaphore group from MemberRegistered events.
291
- */
292
- async fetchGroup(resourceId) {
293
- const logs = await this.publicClient.getLogs({
294
- address: this.contractAddress,
295
- event: {
296
- name: "MemberRegistered",
297
- type: "event",
298
- inputs: [
299
- {
300
- name: "resourceId",
301
- type: "bytes32",
302
- indexed: true
303
- },
304
- {
305
- name: "groupId",
306
- type: "uint256",
307
- indexed: true
308
- },
309
- {
310
- name: "identityCommitment",
311
- type: "uint256",
312
- indexed: false
313
- }
314
- ]
315
- },
316
- fromBlock: 0n
317
- });
318
- const group = new Group();
319
- for (const log of logs.filter((l) => l.args.resourceId?.toLowerCase() === resourceId.toLowerCase())) group.addMember(String(log.args.identityCommitment));
320
- return group;
321
- }
322
- };
323
-
324
- //#endregion
325
- export { SettlementRegistry };
@@ -1,54 +0,0 @@
1
- import { Address, Hex, WalletClient } from "viem";
2
- import { Identity } from "@semaphore-protocol/identity";
3
-
4
- //#region src/registries/settlement-registry/types.d.ts
5
- interface TransferWithAuthParams {
6
- walletClient?: WalletClient;
7
- paymentRecipient: Address;
8
- amount: bigint;
9
- usdcAddress: Address;
10
- usdcDomainName: string;
11
- usdcDomainVersion: string;
12
- }
13
- interface TransferWithAuthPayload {
14
- sender: Address;
15
- paymentRecipient: Address;
16
- amount: bigint;
17
- validAfter: bigint;
18
- validBefore: bigint;
19
- nonce: Hex;
20
- v: number;
21
- r: Hex;
22
- s: Hex;
23
- }
24
- /**
25
- * The params for registering with a semaphore group
26
- */
27
- interface RegisterParams {
28
- resourceId: Hex;
29
- identityCommitment: bigint;
30
- relayerPrivateKey: Hex;
31
- preparedRegister: TransferWithAuthPayload;
32
- }
33
- interface PrepareSettleParams {
34
- resourceId: Hex;
35
- identity: Identity;
36
- stealthAddress: Address;
37
- hookData?: Hex;
38
- }
39
- interface PrepareSettleResult {
40
- resourceId: Hex;
41
- stealthAddress: Address;
42
- merkleTreeDepth: bigint;
43
- merkleTreeRoot: bigint;
44
- nullifier: bigint;
45
- message: bigint;
46
- points: [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint];
47
- hookData: Hex;
48
- }
49
- interface SettleParams {
50
- relayerPrivateKey: Hex;
51
- preparedSettle: PrepareSettleResult;
52
- }
53
- //#endregion
54
- export { PrepareSettleParams, PrepareSettleResult, RegisterParams, SettleParams, TransferWithAuthParams, TransferWithAuthPayload };
@@ -1 +0,0 @@
1
- export { };