@semaphore-protocol/utils 4.0.0-beta.1 → 4.0.0-beta.11
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.
- package/README.md +4 -4
- package/dist/index.cjs +171 -227
- package/dist/index.js +164 -226
- package/dist/lib.commonjs/constants.cjs +17 -0
- package/dist/lib.commonjs/decode-message.cjs +28 -0
- package/dist/lib.commonjs/index.cjs +14 -5
- package/dist/lib.commonjs/networks/deployed-contracts.json.cjs +94 -0
- package/dist/lib.commonjs/networks/index.cjs +66 -0
- package/dist/lib.commonjs/networks/supported-networks.cjs +38 -0
- package/dist/lib.esm/constants.js +14 -0
- package/dist/lib.esm/decode-message.js +26 -0
- package/dist/lib.esm/index.js +7 -5
- package/dist/lib.esm/networks/deployed-contracts.json.js +92 -0
- package/dist/lib.esm/networks/index.js +59 -0
- package/dist/lib.esm/networks/supported-networks.js +36 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/decode-message.d.ts +12 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/networks/index.d.ts +34 -0
- package/dist/types/networks/supported-networks.d.ts +27 -0
- package/package.json +21 -12
- package/src/constants.ts +5 -0
- package/src/decode-message.ts +17 -0
- package/src/index.ts +4 -3
- package/src/networks/deployed-contracts.json +82 -0
- package/src/networks/index.ts +66 -0
- package/src/networks/supported-networks.ts +26 -0
- package/dist/lib.commonjs/errors.cjs +0 -131
- package/dist/lib.commonjs/types.cjs +0 -130
- package/dist/lib.esm/errors.js +0 -121
- package/dist/lib.esm/types.js +0 -119
- package/dist/types/errors.d.ts +0 -64
- package/dist/types/types.d.ts +0 -73
- package/src/errors.ts +0 -132
- 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.
|
|
3
|
+
* @version 4.0.0-beta.11
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
17
|
+
var constants = /*#__PURE__*/Object.freeze({
|
|
120
18
|
__proto__: null,
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
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
|
|
158
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
throw new TypeError("Parameter '".concat(parameterName, "' is not an array"));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
153
|
+
// Default Semaphore network.
|
|
154
|
+
const defaultNetwork = "sepolia";
|
|
192
155
|
/**
|
|
193
|
-
*
|
|
194
|
-
* @param
|
|
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
|
|
198
|
-
|
|
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
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @param
|
|
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
|
|
208
|
-
if (!
|
|
209
|
-
|
|
168
|
+
function getHardhatNetworks(privateKey) {
|
|
169
|
+
if (!privateKey) {
|
|
170
|
+
return {};
|
|
210
171
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* @param
|
|
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
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
190
|
+
const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork);
|
|
191
|
+
return deployedContract.contracts.find(({ name }) => name === "Semaphore");
|
|
241
192
|
}
|
|
242
193
|
|
|
243
|
-
|
|
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.11
|
|
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.11
|
|
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.
|
|
3
|
+
* @version 4.0.0-beta.11
|
|
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
|
|
12
|
-
var
|
|
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.
|
|
17
|
-
exports.
|
|
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.11
|
|
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.11
|
|
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;
|