@semaphore-protocol/utils 4.0.0-beta.1 → 4.0.0-beta.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 (35) hide show
  1. package/README.md +4 -4
  2. package/dist/index.cjs +171 -227
  3. package/dist/index.js +164 -226
  4. package/dist/lib.commonjs/constants.cjs +17 -0
  5. package/dist/lib.commonjs/decode-message.cjs +28 -0
  6. package/dist/lib.commonjs/index.cjs +14 -5
  7. package/dist/lib.commonjs/networks/deployed-contracts.json.cjs +94 -0
  8. package/dist/lib.commonjs/networks/index.cjs +66 -0
  9. package/dist/lib.commonjs/networks/supported-networks.cjs +38 -0
  10. package/dist/lib.esm/constants.js +14 -0
  11. package/dist/lib.esm/decode-message.js +26 -0
  12. package/dist/lib.esm/index.js +7 -5
  13. package/dist/lib.esm/networks/deployed-contracts.json.js +92 -0
  14. package/dist/lib.esm/networks/index.js +59 -0
  15. package/dist/lib.esm/networks/supported-networks.js +36 -0
  16. package/dist/types/constants.d.ts +2 -0
  17. package/dist/types/decode-message.d.ts +12 -0
  18. package/dist/types/index.d.ts +4 -3
  19. package/dist/types/networks/index.d.ts +34 -0
  20. package/dist/types/networks/supported-networks.d.ts +27 -0
  21. package/package.json +21 -12
  22. package/src/constants.ts +5 -0
  23. package/src/decode-message.ts +17 -0
  24. package/src/index.ts +4 -3
  25. package/src/networks/deployed-contracts.json +82 -0
  26. package/src/networks/index.ts +66 -0
  27. package/src/networks/supported-networks.ts +26 -0
  28. package/dist/lib.commonjs/errors.cjs +0 -131
  29. package/dist/lib.commonjs/types.cjs +0 -130
  30. package/dist/lib.esm/errors.js +0 -121
  31. package/dist/lib.esm/types.js +0 -119
  32. package/dist/types/errors.d.ts +0 -64
  33. package/dist/types/types.d.ts +0 -73
  34. package/src/errors.ts +0 -132
  35. package/src/types.ts +0 -123
package/dist/index.js CHANGED
@@ -1,256 +1,194 @@
1
1
  /**
2
2
  * @module @semaphore-protocol/utils
3
- * @version 4.0.0-beta.1
3
+ * @version 4.0.0-beta.10
4
4
  * @file A library to provide utility functions to the other Semaphore packages.
5
5
  * @copyright Ethereum Foundation 2024
6
6
  * @license MIT
7
7
  * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
8
8
  */
9
- /**
10
- * @module Types
11
- * This module provides utility functions to check data types.
12
- * It defines a set of supported types and includes functions to check if
13
- * a value is defined and if it matches a supported type. These functions
14
- * are useful for type checking and validation in the other libraries,
15
- * enhancing code robustness and reliability.
16
- */
17
- // The list of types supported by this utility functions.
18
- var supportedTypes = ["number", "string", "function", "array", "uint8array", "object", "bigint"];
19
- /**
20
- * It returns true if the value is defined, false otherwise.
21
- * @param value The value to be checked.
22
- * @returns True or false.
23
- */
24
- function isDefined(value) {
25
- return typeof value !== "undefined";
26
- }
27
- /**
28
- * It returns true if the value is a number, false otherwise.
29
- * @param value The value to be checked.
30
- * @returns True or false.
31
- */
32
- function isNumber(value) {
33
- return typeof value === "number";
34
- }
35
- /**
36
- * It returns true if the value is a string, false otherwise.
37
- * @param value The value to be checked.
38
- * @returns True or false.
39
- */
40
- function isString(value) {
41
- return typeof value === "string";
42
- }
43
- /**
44
- * It returns true if the value is a function, false otherwise.
45
- * @param value The value to be checked.
46
- * @returns True or false.
47
- */
48
- function isFunction(value) {
49
- return typeof value === "function";
50
- }
51
- /**
52
- * It returns true if the value is an array, false otherwise.
53
- * @param value The value to be checked.
54
- * @returns True or false.
55
- */
56
- function isArray(value) {
57
- return typeof value === "object" && Array.isArray(value);
58
- }
59
- /**
60
- * It returns true if the value is a uint8array, false otherwise.
61
- * @param value The value to be checked.
62
- * @returns True or false.
63
- */
64
- function isUint8Array(value) {
65
- return value instanceof Uint8Array;
66
- }
67
- /**
68
- * It returns true if the value is an object, false otherwise.
69
- * @param value The value to be checked.
70
- * @returns True or false.
71
- */
72
- function isObject(value) {
73
- return typeof value === "object";
74
- }
75
- /**
76
- * It returns true if the value is a bigint, false otherwise.
77
- * @param value The value to be checked.
78
- * @returns True or false.
79
- */
80
- function isBigInt(value) {
81
- return typeof value === "bigint";
82
- }
83
- /**
84
- * It returns true if the value type is the same as the type passed
85
- * as the second parameter, false otherwise.
86
- * @param type The expected type.
87
- * @returns True or false.
88
- */
89
- function isType(value, type) {
90
- switch (type) {
91
- case "number":
92
- return isNumber(value);
93
- case "string":
94
- return isString(value);
95
- case "function":
96
- return isFunction(value);
97
- case "array":
98
- return isArray(value);
99
- case "uint8array":
100
- return isUint8Array(value);
101
- case "object":
102
- return isObject(value);
103
- case "bigint":
104
- return isBigInt(value);
105
- default:
106
- return false;
107
- }
108
- }
109
- /**
110
- * Return true if the type is being supported by this utility
111
- * functions, false otherwise.
112
- * @param type The type to be checked.
113
- * @returns True or false
114
- */
115
- function isSupportedType(type) {
116
- return supportedTypes.includes(type);
117
- }
9
+ import { decodeBytes32String } from 'ethers/abi';
10
+ import { toBeHex } from 'ethers/utils';
11
+
12
+ // Minimum supported tree depth.
13
+ const MIN_DEPTH = 1;
14
+ // Maximum supported tree depth.
15
+ const MAX_DEPTH = 32;
118
16
 
119
- var types = /*#__PURE__*/Object.freeze({
17
+ var constants = /*#__PURE__*/Object.freeze({
120
18
  __proto__: null,
121
- isArray: isArray,
122
- isBigInt: isBigInt,
123
- isDefined: isDefined,
124
- isFunction: isFunction,
125
- isNumber: isNumber,
126
- isObject: isObject,
127
- isString: isString,
128
- isSupportedType: isSupportedType,
129
- isType: isType,
130
- isUint8Array: isUint8Array
19
+ MAX_DEPTH: MAX_DEPTH,
20
+ MIN_DEPTH: MIN_DEPTH
131
21
  });
132
22
 
133
23
  /**
134
- * @module Errors
135
- * This module is designed to provide utility functions for validating
136
- * function parameters. It includes functions that throw type errors if
137
- * the parameters do not meet specified criteria, such as being defined,
138
- * a number, a string, a function, or an array. This module helps ensure
139
- * that functions receive the correct types of inputs, enhancing code
140
- * reliability and reducing runtime errors.
141
- */
142
- /**
143
- * It throws a type error if the parameter value has not been defined.
144
- * @param parameterValue The parameter value.
145
- * @param parameterName The parameter name.
146
- */
147
- function requireDefined(parameterValue, parameterName) {
148
- if (!isDefined(parameterValue)) {
149
- throw new TypeError("Parameter '".concat(parameterName, "' is not defined"));
150
- }
151
- }
152
- /**
153
- * It throws a type error if the parameter value is not a number.
154
- * @param parameterValue The parameter value.
155
- * @param parameterName The parameter name.
24
+ * Typically used for decoding on-chain Semaphore messages.
25
+ * When Semaphore messages are text they are converted to bigints before
26
+ * the proof is generated (and eventually sent on-chain).
27
+ * This function help devs converting bigint messages to text again.
28
+ * If the original message was not text the output of this
29
+ * function won't probably be human-readable text.
30
+ * @param message The Semaphore message as a bigint.
31
+ * @returns The Semaphore message as a text.
156
32
  */
157
- function requireNumber(parameterValue, parameterName) {
158
- if (!isNumber(parameterValue)) {
159
- throw new TypeError("Parameter '".concat(parameterName, "' is not a number"));
160
- }
161
- }
162
- /**
163
- * It throws a type error if the parameter value is not a string.
164
- * @param parameterValue The parameter value.
165
- * @param parameterName The parameter name.
166
- */
167
- function requireString(parameterValue, parameterName) {
168
- if (!isString(parameterValue)) {
169
- throw new TypeError("Parameter '".concat(parameterName, "' is not a string"));
170
- }
33
+ function decodeMessage(message) {
34
+ return decodeBytes32String(toBeHex(message, 32));
171
35
  }
172
- /**
173
- * It throws a type error if the parameter value is not a function.
174
- * @param parameterValue The parameter value.
175
- * @param parameterName The parameter name.
176
- */
177
- function requireFunction(parameterValue, parameterName) {
178
- if (!isFunction(parameterValue)) {
179
- throw new TypeError("Parameter '".concat(parameterName, "' is not a function"));
36
+
37
+ var deployedContracts = [
38
+ {
39
+ network: "sepolia",
40
+ contracts: [
41
+ {
42
+ name: "SemaphoreVerifier",
43
+ address: "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
44
+ startBlock: 5539276
45
+ },
46
+ {
47
+ name: "PoseidonT3",
48
+ address: "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
49
+ startBlock: 5539276
50
+ },
51
+ {
52
+ name: "Semaphore",
53
+ address: "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
54
+ startBlock: 5539276
55
+ }
56
+ ]
57
+ },
58
+ {
59
+ network: "arbitrum-sepolia",
60
+ contracts: [
61
+ {
62
+ name: "SemaphoreVerifier",
63
+ address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
64
+ startBlock: 25837653
65
+ },
66
+ {
67
+ name: "PoseidonT3",
68
+ address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
69
+ startBlock: 25837653
70
+ },
71
+ {
72
+ name: "Semaphore",
73
+ address: "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
74
+ startBlock: 25837653
75
+ }
76
+ ]
77
+ },
78
+ {
79
+ network: "optimism-sepolia",
80
+ contracts: [
81
+ {
82
+ name: "SemaphoreVerifier",
83
+ address: "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
84
+ startBlock: 9663266
85
+ },
86
+ {
87
+ name: "PoseidonT3",
88
+ address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
89
+ startBlock: 9663266
90
+ },
91
+ {
92
+ name: "Semaphore",
93
+ address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
94
+ startBlock: 9663266
95
+ }
96
+ ]
97
+ },
98
+ {
99
+ network: "matic-mumbai",
100
+ contracts: [
101
+ {
102
+ name: "SemaphoreVerifier",
103
+ address: "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
104
+ startBlock: 47356015
105
+ },
106
+ {
107
+ name: "PoseidonT3",
108
+ address: "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
109
+ startBlock: 47356015
110
+ },
111
+ {
112
+ name: "Semaphore",
113
+ address: "0x346a936b19071b2f619200848B8ADbb938D72250",
114
+ startBlock: 47356015
115
+ }
116
+ ]
117
+ }
118
+ ];
119
+
120
+ var supportedNetworks = {
121
+ sepolia: {
122
+ name: "Sepolia",
123
+ url: "https://rpc2.sepolia.org",
124
+ chainId: 11155111,
125
+ explorer: "https://sepolia.etherscan.io"
126
+ },
127
+ "arbitrum-sepolia": {
128
+ name: "Arbitrum Sepolia",
129
+ url: "https://sepolia-rollup.arbitrum.io/rpc",
130
+ chainId: 421614,
131
+ explorer: "https://sepolia.arbiscan.io"
132
+ },
133
+ "optimism-sepolia": {
134
+ name: "Optimism Sepolia",
135
+ url: "https://sepolia.optimism.io",
136
+ chainId: 11155420,
137
+ explorer: "https://sepolia-optimism.etherscan.io"
138
+ },
139
+ "matic-mumbai": {
140
+ name: "Matic Mumbai",
141
+ url: "https://rpc-mumbai.polygon.technology",
142
+ chainId: 80001,
143
+ explorer: "https://mumbai.polygonscan.com"
180
144
  }
181
- }
145
+ };
146
+
182
147
  /**
183
- * It throws a type error if the parameter value is not an array.
184
- * @param parameterValue The parameter value.
185
- * @param parameterName The parameter name.
148
+ * @module Networks
149
+ * This module provides a collection of utility functions to provide the other internal
150
+ * packages and developers with information on deployed contracts and networks supported
151
+ * by Semaphore.
186
152
  */
187
- function requireArray(parameterValue, parameterName) {
188
- if (!isArray(parameterValue)) {
189
- throw new TypeError("Parameter '".concat(parameterName, "' is not an array"));
190
- }
191
- }
153
+ // Default Semaphore network.
154
+ const defaultNetwork = "sepolia";
192
155
  /**
193
- * It throws a type error if the parameter value is not a uint8array.
194
- * @param parameterValue The parameter value.
195
- * @param parameterName The parameter name.
156
+ * Returns true if a network is supported by Semaphore, false otherwise.
157
+ * @param supportedNetwork The network to be checked.
196
158
  */
197
- function requireUint8Array(parameterValue, parameterName) {
198
- if (!isUint8Array(parameterValue)) {
199
- throw new TypeError("Parameter '".concat(parameterName, "' is not a Uint8Array"));
200
- }
159
+ function isSupportedNetwork(supportedNetwork) {
160
+ return Object.keys(supportedNetworks).includes(supportedNetwork);
201
161
  }
202
162
  /**
203
- * It throws a type error if the parameter value is not an object.
204
- * @param parameterValue The parameter value.
205
- * @param parameterName The parameter name.
163
+ * Utility function to get an object compatible with the Hardhat 'networks' option.
164
+ * If the private key is not defined it returns an empty object.
165
+ * @param privateKey Private key to be used with networks.
166
+ * @returns An object compatible with the Hardhat 'networks' option.
206
167
  */
207
- function requireObject(parameterValue, parameterName) {
208
- if (!isObject(parameterValue)) {
209
- throw new TypeError("Parameter '".concat(parameterName, "' is not an object"));
168
+ function getHardhatNetworks(privateKey) {
169
+ if (!privateKey) {
170
+ return {};
210
171
  }
211
- }
212
- /**
213
- * It throws a type error if the parameter value is not a bigint.
214
- * @param parameterValue The parameter value.
215
- * @param parameterName The parameter name.
216
- */
217
- function requireBigInt(parameterValue, parameterName) {
218
- if (!isBigInt(parameterValue)) {
219
- throw new TypeError("Parameter '".concat(parameterName, "' is not a bigint"));
172
+ const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks));
173
+ for (const key in supportedNetworksCopy) {
174
+ if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
175
+ supportedNetworksCopy[key].accounts = [`0x${privateKey}`];
176
+ }
220
177
  }
178
+ return supportedNetworksCopy;
221
179
  }
222
180
  /**
223
- * It throws a type error if the parameter value type is not part of the list of types.
224
- * @param parameterValue The parameter value.
225
- * @param parameterName The parameter name.
181
+ * Returns name, address and start block of a Semaphore contract deployed
182
+ * on a specific supported network.
183
+ * @param supportedNetwork The network supported by Semaphore.
184
+ * @returns An object with name, address and start block of the deployed contract.
226
185
  */
227
- function requireTypes(parameterValue, parameterName, types) {
228
- for (var _i = 0, types_1 = types; _i < types_1.length; _i++) {
229
- var type = types_1[_i];
230
- if (!isSupportedType(type)) {
231
- throw new Error("Type '".concat(type, "' is not supported"));
232
- }
233
- }
234
- for (var _a = 0, types_2 = types; _a < types_2.length; _a++) {
235
- var type = types_2[_a];
236
- if (isType(parameterValue, type)) {
237
- return;
238
- }
186
+ function getDeployedContract(supportedNetwork) {
187
+ if (!isSupportedNetwork(supportedNetwork)) {
188
+ throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`);
239
189
  }
240
- throw new TypeError("Parameter '".concat(parameterName, "' is none of the following types: ").concat(types.join(", ")));
190
+ const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork);
191
+ return deployedContract.contracts.find(({ name }) => name === "Semaphore");
241
192
  }
242
193
 
243
- var errors = /*#__PURE__*/Object.freeze({
244
- __proto__: null,
245
- requireArray: requireArray,
246
- requireBigInt: requireBigInt,
247
- requireDefined: requireDefined,
248
- requireFunction: requireFunction,
249
- requireNumber: requireNumber,
250
- requireObject: requireObject,
251
- requireString: requireString,
252
- requireTypes: requireTypes,
253
- requireUint8Array: requireUint8Array
254
- });
255
-
256
- export { errors, types };
194
+ export { constants, decodeMessage, defaultNetwork, deployedContracts, getDeployedContract, getHardhatNetworks, isSupportedNetwork, supportedNetworks };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @module @semaphore-protocol/utils
3
+ * @version 4.0.0-beta.10
4
+ * @file A library to provide utility functions to the other Semaphore packages.
5
+ * @copyright Ethereum Foundation 2024
6
+ * @license MIT
7
+ * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
8
+ */
9
+ 'use strict';
10
+
11
+ // Minimum supported tree depth.
12
+ const MIN_DEPTH = 1;
13
+ // Maximum supported tree depth.
14
+ const MAX_DEPTH = 32;
15
+
16
+ exports.MAX_DEPTH = MAX_DEPTH;
17
+ exports.MIN_DEPTH = MIN_DEPTH;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module @semaphore-protocol/utils
3
+ * @version 4.0.0-beta.10
4
+ * @file A library to provide utility functions to the other Semaphore packages.
5
+ * @copyright Ethereum Foundation 2024
6
+ * @license MIT
7
+ * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
8
+ */
9
+ 'use strict';
10
+
11
+ var abi = require('ethers/abi');
12
+ var utils = require('ethers/utils');
13
+
14
+ /**
15
+ * Typically used for decoding on-chain Semaphore messages.
16
+ * When Semaphore messages are text they are converted to bigints before
17
+ * the proof is generated (and eventually sent on-chain).
18
+ * This function help devs converting bigint messages to text again.
19
+ * If the original message was not text the output of this
20
+ * function won't probably be human-readable text.
21
+ * @param message The Semaphore message as a bigint.
22
+ * @returns The Semaphore message as a text.
23
+ */
24
+ function decodeMessage(message) {
25
+ return abi.decodeBytes32String(utils.toBeHex(message, 32));
26
+ }
27
+
28
+ module.exports = decodeMessage;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module @semaphore-protocol/utils
3
- * @version 4.0.0-beta.1
3
+ * @version 4.0.0-beta.10
4
4
  * @file A library to provide utility functions to the other Semaphore packages.
5
5
  * @copyright Ethereum Foundation 2024
6
6
  * @license MIT
@@ -8,10 +8,19 @@
8
8
  */
9
9
  'use strict';
10
10
 
11
- var errors = require('./errors.cjs');
12
- var types = require('./types.cjs');
11
+ var constants = require('./constants.cjs');
12
+ var decodeMessage = require('./decode-message.cjs');
13
+ var index = require('./networks/index.cjs');
14
+ var deployedContracts = require('./networks/deployed-contracts.json.cjs');
15
+ var supportedNetworks = require('./networks/supported-networks.cjs');
13
16
 
14
17
 
15
18
 
16
- exports.errors = errors;
17
- exports.types = types;
19
+ exports.constants = constants;
20
+ exports.decodeMessage = decodeMessage;
21
+ exports.defaultNetwork = index.defaultNetwork;
22
+ exports.getDeployedContract = index.getDeployedContract;
23
+ exports.getHardhatNetworks = index.getHardhatNetworks;
24
+ exports.isSupportedNetwork = index.isSupportedNetwork;
25
+ exports.deployedContracts = deployedContracts;
26
+ exports.supportedNetworks = supportedNetworks;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @module @semaphore-protocol/utils
3
+ * @version 4.0.0-beta.10
4
+ * @file A library to provide utility functions to the other Semaphore packages.
5
+ * @copyright Ethereum Foundation 2024
6
+ * @license MIT
7
+ * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
8
+ */
9
+ 'use strict';
10
+
11
+ var deployedContracts = [
12
+ {
13
+ network: "sepolia",
14
+ contracts: [
15
+ {
16
+ name: "SemaphoreVerifier",
17
+ address: "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
18
+ startBlock: 5539276
19
+ },
20
+ {
21
+ name: "PoseidonT3",
22
+ address: "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
23
+ startBlock: 5539276
24
+ },
25
+ {
26
+ name: "Semaphore",
27
+ address: "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
28
+ startBlock: 5539276
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ network: "arbitrum-sepolia",
34
+ contracts: [
35
+ {
36
+ name: "SemaphoreVerifier",
37
+ address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
38
+ startBlock: 25837653
39
+ },
40
+ {
41
+ name: "PoseidonT3",
42
+ address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
43
+ startBlock: 25837653
44
+ },
45
+ {
46
+ name: "Semaphore",
47
+ address: "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
48
+ startBlock: 25837653
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ network: "optimism-sepolia",
54
+ contracts: [
55
+ {
56
+ name: "SemaphoreVerifier",
57
+ address: "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
58
+ startBlock: 9663266
59
+ },
60
+ {
61
+ name: "PoseidonT3",
62
+ address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
63
+ startBlock: 9663266
64
+ },
65
+ {
66
+ name: "Semaphore",
67
+ address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
68
+ startBlock: 9663266
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ network: "matic-mumbai",
74
+ contracts: [
75
+ {
76
+ name: "SemaphoreVerifier",
77
+ address: "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
78
+ startBlock: 47356015
79
+ },
80
+ {
81
+ name: "PoseidonT3",
82
+ address: "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
83
+ startBlock: 47356015
84
+ },
85
+ {
86
+ name: "Semaphore",
87
+ address: "0x346a936b19071b2f619200848B8ADbb938D72250",
88
+ startBlock: 47356015
89
+ }
90
+ ]
91
+ }
92
+ ];
93
+
94
+ module.exports = deployedContracts;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @module @semaphore-protocol/utils
3
+ * @version 4.0.0-beta.10
4
+ * @file A library to provide utility functions to the other Semaphore packages.
5
+ * @copyright Ethereum Foundation 2024
6
+ * @license MIT
7
+ * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
8
+ */
9
+ 'use strict';
10
+
11
+ var deployedContracts = require('./deployed-contracts.json.cjs');
12
+ var supportedNetworks = require('./supported-networks.cjs');
13
+
14
+ /**
15
+ * @module Networks
16
+ * This module provides a collection of utility functions to provide the other internal
17
+ * packages and developers with information on deployed contracts and networks supported
18
+ * by Semaphore.
19
+ */
20
+ // Default Semaphore network.
21
+ const defaultNetwork = "sepolia";
22
+ /**
23
+ * Returns true if a network is supported by Semaphore, false otherwise.
24
+ * @param supportedNetwork The network to be checked.
25
+ */
26
+ function isSupportedNetwork(supportedNetwork) {
27
+ return Object.keys(supportedNetworks).includes(supportedNetwork);
28
+ }
29
+ /**
30
+ * Utility function to get an object compatible with the Hardhat 'networks' option.
31
+ * If the private key is not defined it returns an empty object.
32
+ * @param privateKey Private key to be used with networks.
33
+ * @returns An object compatible with the Hardhat 'networks' option.
34
+ */
35
+ function getHardhatNetworks(privateKey) {
36
+ if (!privateKey) {
37
+ return {};
38
+ }
39
+ const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks));
40
+ for (const key in supportedNetworksCopy) {
41
+ if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
42
+ supportedNetworksCopy[key].accounts = [`0x${privateKey}`];
43
+ }
44
+ }
45
+ return supportedNetworksCopy;
46
+ }
47
+ /**
48
+ * Returns name, address and start block of a Semaphore contract deployed
49
+ * on a specific supported network.
50
+ * @param supportedNetwork The network supported by Semaphore.
51
+ * @returns An object with name, address and start block of the deployed contract.
52
+ */
53
+ function getDeployedContract(supportedNetwork) {
54
+ if (!isSupportedNetwork(supportedNetwork)) {
55
+ throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`);
56
+ }
57
+ const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork);
58
+ return deployedContract.contracts.find(({ name }) => name === "Semaphore");
59
+ }
60
+
61
+ exports.deployedContracts = deployedContracts;
62
+ exports.supportedNetworks = supportedNetworks;
63
+ exports.defaultNetwork = defaultNetwork;
64
+ exports.getDeployedContract = getDeployedContract;
65
+ exports.getHardhatNetworks = getHardhatNetworks;
66
+ exports.isSupportedNetwork = isSupportedNetwork;