@semaphore-protocol/utils 4.0.0-beta.3 → 4.0.0-beta.5
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/dist/index.cjs +165 -6
- package/dist/index.js +160 -6
- package/dist/lib.commonjs/constants.cjs +3 -3
- package/dist/lib.commonjs/decode-message.cjs +1 -1
- package/dist/lib.commonjs/index.cjs +9 -2
- 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 +3 -3
- package/dist/lib.esm/decode-message.js +1 -1
- package/dist/lib.esm/index.js +4 -2
- 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/index.d.ts +2 -3
- package/dist/types/networks/index.d.ts +34 -0
- package/dist/types/networks/supported-networks.d.ts +27 -0
- package/package.json +6 -5
- package/src/index.ts +2 -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/supported-networks.cjs +0 -14
- package/dist/lib.esm/supported-networks.js +0 -12
- package/dist/types/supported-networks.d.ts +0 -3
- package/dist/types/types/index.d.ts +0 -1
- package/src/supported-networks.ts +0 -6
- package/src/types/index.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
4
4
|
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
@@ -12,8 +12,8 @@ var abi = require('ethers/abi');
|
|
|
12
12
|
var utils = require('ethers/utils');
|
|
13
13
|
|
|
14
14
|
// TODO: Support all tree depths after trusted-setup. MAX_DEPTH would be 32.
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const MIN_DEPTH = 1;
|
|
16
|
+
const MAX_DEPTH = 12;
|
|
17
17
|
|
|
18
18
|
var constants = /*#__PURE__*/Object.freeze({
|
|
19
19
|
__proto__: null,
|
|
@@ -35,9 +35,168 @@ function decodeMessage(message) {
|
|
|
35
35
|
return abi.decodeBytes32String(utils.toBeHex(message, 32));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
var deployedContracts = [
|
|
39
|
+
{
|
|
40
|
+
network: "sepolia",
|
|
41
|
+
contracts: [
|
|
42
|
+
{
|
|
43
|
+
name: "SemaphoreVerifier",
|
|
44
|
+
address: "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
|
|
45
|
+
startBlock: 5539276
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "PoseidonT3",
|
|
49
|
+
address: "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
|
|
50
|
+
startBlock: 5539276
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "Semaphore",
|
|
54
|
+
address: "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
|
|
55
|
+
startBlock: 5539276
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
network: "arbitrum-sepolia",
|
|
61
|
+
contracts: [
|
|
62
|
+
{
|
|
63
|
+
name: "SemaphoreVerifier",
|
|
64
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
65
|
+
startBlock: 25837653
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "PoseidonT3",
|
|
69
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
70
|
+
startBlock: 25837653
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "Semaphore",
|
|
74
|
+
address: "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
|
|
75
|
+
startBlock: 25837653
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
network: "optimism-sepolia",
|
|
81
|
+
contracts: [
|
|
82
|
+
{
|
|
83
|
+
name: "SemaphoreVerifier",
|
|
84
|
+
address: "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
|
|
85
|
+
startBlock: 9663266
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "PoseidonT3",
|
|
89
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
90
|
+
startBlock: 9663266
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "Semaphore",
|
|
94
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
95
|
+
startBlock: 9663266
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
network: "matic-mumbai",
|
|
101
|
+
contracts: [
|
|
102
|
+
{
|
|
103
|
+
name: "SemaphoreVerifier",
|
|
104
|
+
address: "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
|
|
105
|
+
startBlock: 47356015
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "PoseidonT3",
|
|
109
|
+
address: "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
|
|
110
|
+
startBlock: 47356015
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "Semaphore",
|
|
114
|
+
address: "0x346a936b19071b2f619200848B8ADbb938D72250",
|
|
115
|
+
startBlock: 47356015
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
var supportedNetworks = {
|
|
122
|
+
sepolia: {
|
|
123
|
+
name: "Sepolia",
|
|
124
|
+
url: "https://rpc2.sepolia.org",
|
|
125
|
+
chainId: 11155111,
|
|
126
|
+
explorer: "https://sepolia.etherscan.io"
|
|
127
|
+
},
|
|
128
|
+
"arbitrum-sepolia": {
|
|
129
|
+
name: "Arbitrum Sepolia",
|
|
130
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
131
|
+
chainId: 421614,
|
|
132
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
133
|
+
},
|
|
134
|
+
"optimism-sepolia": {
|
|
135
|
+
name: "Optimism Sepolia",
|
|
136
|
+
url: "https://sepolia.optimism.io",
|
|
137
|
+
chainId: 11155420,
|
|
138
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
139
|
+
},
|
|
140
|
+
"matic-mumbai": {
|
|
141
|
+
name: "Matic Mumbai",
|
|
142
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
143
|
+
chainId: 80001,
|
|
144
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @module Networks
|
|
150
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
151
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
152
|
+
* by Semaphore.
|
|
153
|
+
*/
|
|
154
|
+
// Default Semaphore network.
|
|
155
|
+
const defaultNetwork = "sepolia";
|
|
156
|
+
/**
|
|
157
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
158
|
+
* @param supportedNetwork The network to be checked.
|
|
159
|
+
*/
|
|
160
|
+
function isSupportedNetwork(supportedNetwork) {
|
|
161
|
+
return Object.keys(supportedNetworks).includes(supportedNetwork);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
165
|
+
* If the private key is not defined it returns an empty object.
|
|
166
|
+
* @param privateKey Private key to be used with networks.
|
|
167
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
168
|
+
*/
|
|
169
|
+
function getHardhatNetworks(privateKey) {
|
|
170
|
+
if (!privateKey) {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks));
|
|
174
|
+
for (const key in supportedNetworksCopy) {
|
|
175
|
+
if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
|
|
176
|
+
supportedNetworksCopy[key].accounts = [`0x${privateKey}`];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return supportedNetworksCopy;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
183
|
+
* on a specific supported network.
|
|
184
|
+
* @param The network supported by Semaphore.
|
|
185
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
186
|
+
*/
|
|
187
|
+
function getDeployedContract(supportedNetwork) {
|
|
188
|
+
if (!isSupportedNetwork(supportedNetwork)) {
|
|
189
|
+
throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`);
|
|
190
|
+
}
|
|
191
|
+
const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork);
|
|
192
|
+
return deployedContract.contracts.find(({ name }) => name === "Semaphore");
|
|
193
|
+
}
|
|
40
194
|
|
|
41
195
|
exports.constants = constants;
|
|
42
196
|
exports.decodeMessage = decodeMessage;
|
|
43
|
-
exports.
|
|
197
|
+
exports.defaultNetwork = defaultNetwork;
|
|
198
|
+
exports.deployedContracts = deployedContracts;
|
|
199
|
+
exports.getDeployedContract = getDeployedContract;
|
|
200
|
+
exports.getHardhatNetworks = getHardhatNetworks;
|
|
201
|
+
exports.isSupportedNetwork = isSupportedNetwork;
|
|
202
|
+
exports.supportedNetworks = supportedNetworks;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
4
4
|
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
@@ -10,8 +10,8 @@ import { decodeBytes32String } from 'ethers/abi';
|
|
|
10
10
|
import { toBeHex } from 'ethers/utils';
|
|
11
11
|
|
|
12
12
|
// TODO: Support all tree depths after trusted-setup. MAX_DEPTH would be 32.
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const MIN_DEPTH = 1;
|
|
14
|
+
const MAX_DEPTH = 12;
|
|
15
15
|
|
|
16
16
|
var constants = /*#__PURE__*/Object.freeze({
|
|
17
17
|
__proto__: null,
|
|
@@ -33,7 +33,161 @@ function decodeMessage(message) {
|
|
|
33
33
|
return decodeBytes32String(toBeHex(message, 32));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
var deployedContracts = [
|
|
37
|
+
{
|
|
38
|
+
network: "sepolia",
|
|
39
|
+
contracts: [
|
|
40
|
+
{
|
|
41
|
+
name: "SemaphoreVerifier",
|
|
42
|
+
address: "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
|
|
43
|
+
startBlock: 5539276
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "PoseidonT3",
|
|
47
|
+
address: "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
|
|
48
|
+
startBlock: 5539276
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "Semaphore",
|
|
52
|
+
address: "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
|
|
53
|
+
startBlock: 5539276
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
network: "arbitrum-sepolia",
|
|
59
|
+
contracts: [
|
|
60
|
+
{
|
|
61
|
+
name: "SemaphoreVerifier",
|
|
62
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
63
|
+
startBlock: 25837653
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "PoseidonT3",
|
|
67
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
68
|
+
startBlock: 25837653
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "Semaphore",
|
|
72
|
+
address: "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
|
|
73
|
+
startBlock: 25837653
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
network: "optimism-sepolia",
|
|
79
|
+
contracts: [
|
|
80
|
+
{
|
|
81
|
+
name: "SemaphoreVerifier",
|
|
82
|
+
address: "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
|
|
83
|
+
startBlock: 9663266
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "PoseidonT3",
|
|
87
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
88
|
+
startBlock: 9663266
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "Semaphore",
|
|
92
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
93
|
+
startBlock: 9663266
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
network: "matic-mumbai",
|
|
99
|
+
contracts: [
|
|
100
|
+
{
|
|
101
|
+
name: "SemaphoreVerifier",
|
|
102
|
+
address: "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
|
|
103
|
+
startBlock: 47356015
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: "PoseidonT3",
|
|
107
|
+
address: "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
|
|
108
|
+
startBlock: 47356015
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "Semaphore",
|
|
112
|
+
address: "0x346a936b19071b2f619200848B8ADbb938D72250",
|
|
113
|
+
startBlock: 47356015
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
];
|
|
38
118
|
|
|
39
|
-
|
|
119
|
+
var supportedNetworks = {
|
|
120
|
+
sepolia: {
|
|
121
|
+
name: "Sepolia",
|
|
122
|
+
url: "https://rpc2.sepolia.org",
|
|
123
|
+
chainId: 11155111,
|
|
124
|
+
explorer: "https://sepolia.etherscan.io"
|
|
125
|
+
},
|
|
126
|
+
"arbitrum-sepolia": {
|
|
127
|
+
name: "Arbitrum Sepolia",
|
|
128
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
129
|
+
chainId: 421614,
|
|
130
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
131
|
+
},
|
|
132
|
+
"optimism-sepolia": {
|
|
133
|
+
name: "Optimism Sepolia",
|
|
134
|
+
url: "https://sepolia.optimism.io",
|
|
135
|
+
chainId: 11155420,
|
|
136
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
137
|
+
},
|
|
138
|
+
"matic-mumbai": {
|
|
139
|
+
name: "Matic Mumbai",
|
|
140
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
141
|
+
chainId: 80001,
|
|
142
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @module Networks
|
|
148
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
149
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
150
|
+
* by Semaphore.
|
|
151
|
+
*/
|
|
152
|
+
// Default Semaphore network.
|
|
153
|
+
const defaultNetwork = "sepolia";
|
|
154
|
+
/**
|
|
155
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
156
|
+
* @param supportedNetwork The network to be checked.
|
|
157
|
+
*/
|
|
158
|
+
function isSupportedNetwork(supportedNetwork) {
|
|
159
|
+
return Object.keys(supportedNetworks).includes(supportedNetwork);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
163
|
+
* If the private key is not defined it returns an empty object.
|
|
164
|
+
* @param privateKey Private key to be used with networks.
|
|
165
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
166
|
+
*/
|
|
167
|
+
function getHardhatNetworks(privateKey) {
|
|
168
|
+
if (!privateKey) {
|
|
169
|
+
return {};
|
|
170
|
+
}
|
|
171
|
+
const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks));
|
|
172
|
+
for (const key in supportedNetworksCopy) {
|
|
173
|
+
if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
|
|
174
|
+
supportedNetworksCopy[key].accounts = [`0x${privateKey}`];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return supportedNetworksCopy;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
181
|
+
* on a specific supported network.
|
|
182
|
+
* @param The network supported by Semaphore.
|
|
183
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
184
|
+
*/
|
|
185
|
+
function getDeployedContract(supportedNetwork) {
|
|
186
|
+
if (!isSupportedNetwork(supportedNetwork)) {
|
|
187
|
+
throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`);
|
|
188
|
+
}
|
|
189
|
+
const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork);
|
|
190
|
+
return deployedContract.contracts.find(({ name }) => name === "Semaphore");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { constants, decodeMessage, defaultNetwork, deployedContracts, getDeployedContract, getHardhatNetworks, isSupportedNetwork, supportedNetworks };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
4
4
|
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
11
|
// TODO: Support all tree depths after trusted-setup. MAX_DEPTH would be 32.
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const MIN_DEPTH = 1;
|
|
13
|
+
const MAX_DEPTH = 12;
|
|
14
14
|
|
|
15
15
|
exports.MAX_DEPTH = MAX_DEPTH;
|
|
16
16
|
exports.MIN_DEPTH = MIN_DEPTH;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
4
4
|
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
@@ -10,10 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
var constants = require('./constants.cjs');
|
|
12
12
|
var decodeMessage = require('./decode-message.cjs');
|
|
13
|
-
var
|
|
13
|
+
var index = require('./networks/index.cjs');
|
|
14
|
+
var deployedContracts = require('./networks/deployed-contracts.json.cjs');
|
|
15
|
+
var supportedNetworks = require('./networks/supported-networks.cjs');
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
exports.constants = constants;
|
|
18
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;
|
|
19
26
|
exports.supportedNetworks = supportedNetworks;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
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.5
|
|
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 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;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
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 supportedNetworks = {
|
|
12
|
+
sepolia: {
|
|
13
|
+
name: "Sepolia",
|
|
14
|
+
url: "https://rpc2.sepolia.org",
|
|
15
|
+
chainId: 11155111,
|
|
16
|
+
explorer: "https://sepolia.etherscan.io"
|
|
17
|
+
},
|
|
18
|
+
"arbitrum-sepolia": {
|
|
19
|
+
name: "Arbitrum Sepolia",
|
|
20
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
21
|
+
chainId: 421614,
|
|
22
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
23
|
+
},
|
|
24
|
+
"optimism-sepolia": {
|
|
25
|
+
name: "Optimism Sepolia",
|
|
26
|
+
url: "https://sepolia.optimism.io",
|
|
27
|
+
chainId: 11155420,
|
|
28
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
29
|
+
},
|
|
30
|
+
"matic-mumbai": {
|
|
31
|
+
name: "Matic Mumbai",
|
|
32
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
33
|
+
chainId: 80001,
|
|
34
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = supportedNetworks;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
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
9
|
// TODO: Support all tree depths after trusted-setup. MAX_DEPTH would be 32.
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const MIN_DEPTH = 1;
|
|
11
|
+
const MAX_DEPTH = 12;
|
|
12
12
|
|
|
13
13
|
export { MAX_DEPTH, MIN_DEPTH };
|
package/dist/lib.esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
4
4
|
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
@@ -9,4 +9,6 @@
|
|
|
9
9
|
import * as constants from './constants.js';
|
|
10
10
|
export { constants };
|
|
11
11
|
export { default as decodeMessage } from './decode-message.js';
|
|
12
|
-
export {
|
|
12
|
+
export { defaultNetwork, getDeployedContract, getHardhatNetworks, isSupportedNetwork } from './networks/index.js';
|
|
13
|
+
export { default as deployedContracts } from './networks/deployed-contracts.json.js';
|
|
14
|
+
export { default as supportedNetworks } from './networks/supported-networks.js';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
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
|
+
var deployedContracts = [
|
|
10
|
+
{
|
|
11
|
+
network: "sepolia",
|
|
12
|
+
contracts: [
|
|
13
|
+
{
|
|
14
|
+
name: "SemaphoreVerifier",
|
|
15
|
+
address: "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
|
|
16
|
+
startBlock: 5539276
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "PoseidonT3",
|
|
20
|
+
address: "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
|
|
21
|
+
startBlock: 5539276
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "Semaphore",
|
|
25
|
+
address: "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
|
|
26
|
+
startBlock: 5539276
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
network: "arbitrum-sepolia",
|
|
32
|
+
contracts: [
|
|
33
|
+
{
|
|
34
|
+
name: "SemaphoreVerifier",
|
|
35
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
36
|
+
startBlock: 25837653
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "PoseidonT3",
|
|
40
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
41
|
+
startBlock: 25837653
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "Semaphore",
|
|
45
|
+
address: "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
|
|
46
|
+
startBlock: 25837653
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
network: "optimism-sepolia",
|
|
52
|
+
contracts: [
|
|
53
|
+
{
|
|
54
|
+
name: "SemaphoreVerifier",
|
|
55
|
+
address: "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
|
|
56
|
+
startBlock: 9663266
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "PoseidonT3",
|
|
60
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
61
|
+
startBlock: 9663266
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "Semaphore",
|
|
65
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
66
|
+
startBlock: 9663266
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
network: "matic-mumbai",
|
|
72
|
+
contracts: [
|
|
73
|
+
{
|
|
74
|
+
name: "SemaphoreVerifier",
|
|
75
|
+
address: "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
|
|
76
|
+
startBlock: 47356015
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "PoseidonT3",
|
|
80
|
+
address: "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
|
|
81
|
+
startBlock: 47356015
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "Semaphore",
|
|
85
|
+
address: "0x346a936b19071b2f619200848B8ADbb938D72250",
|
|
86
|
+
startBlock: 47356015
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
export { deployedContracts as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
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
|
+
import deployedContracts from './deployed-contracts.json.js';
|
|
10
|
+
import supportedNetworks from './supported-networks.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @module Networks
|
|
14
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
15
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
16
|
+
* by Semaphore.
|
|
17
|
+
*/
|
|
18
|
+
// Default Semaphore network.
|
|
19
|
+
const defaultNetwork = "sepolia";
|
|
20
|
+
/**
|
|
21
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
22
|
+
* @param supportedNetwork The network to be checked.
|
|
23
|
+
*/
|
|
24
|
+
function isSupportedNetwork(supportedNetwork) {
|
|
25
|
+
return Object.keys(supportedNetworks).includes(supportedNetwork);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
29
|
+
* If the private key is not defined it returns an empty object.
|
|
30
|
+
* @param privateKey Private key to be used with networks.
|
|
31
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
32
|
+
*/
|
|
33
|
+
function getHardhatNetworks(privateKey) {
|
|
34
|
+
if (!privateKey) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks));
|
|
38
|
+
for (const key in supportedNetworksCopy) {
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
|
|
40
|
+
supportedNetworksCopy[key].accounts = [`0x${privateKey}`];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return supportedNetworksCopy;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
47
|
+
* on a specific supported network.
|
|
48
|
+
* @param The network supported by Semaphore.
|
|
49
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
50
|
+
*/
|
|
51
|
+
function getDeployedContract(supportedNetwork) {
|
|
52
|
+
if (!isSupportedNetwork(supportedNetwork)) {
|
|
53
|
+
throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`);
|
|
54
|
+
}
|
|
55
|
+
const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork);
|
|
56
|
+
return deployedContract.contracts.find(({ name }) => name === "Semaphore");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { defaultNetwork, deployedContracts, getDeployedContract, getHardhatNetworks, isSupportedNetwork, supportedNetworks };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.5
|
|
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
|
+
var supportedNetworks = {
|
|
10
|
+
sepolia: {
|
|
11
|
+
name: "Sepolia",
|
|
12
|
+
url: "https://rpc2.sepolia.org",
|
|
13
|
+
chainId: 11155111,
|
|
14
|
+
explorer: "https://sepolia.etherscan.io"
|
|
15
|
+
},
|
|
16
|
+
"arbitrum-sepolia": {
|
|
17
|
+
name: "Arbitrum Sepolia",
|
|
18
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
19
|
+
chainId: 421614,
|
|
20
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
21
|
+
},
|
|
22
|
+
"optimism-sepolia": {
|
|
23
|
+
name: "Optimism Sepolia",
|
|
24
|
+
url: "https://sepolia.optimism.io",
|
|
25
|
+
chainId: 11155420,
|
|
26
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
27
|
+
},
|
|
28
|
+
"matic-mumbai": {
|
|
29
|
+
name: "Matic Mumbai",
|
|
30
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
31
|
+
chainId: 80001,
|
|
32
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { supportedNetworks as default };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as constants from "./constants";
|
|
2
2
|
import decodeMessage from "./decode-message";
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export { constants, decodeMessage, supportedNetworks };
|
|
3
|
+
export * from "./networks";
|
|
4
|
+
export { constants, decodeMessage };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Networks
|
|
3
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
4
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
5
|
+
* by Semaphore.
|
|
6
|
+
*/
|
|
7
|
+
import deployedContracts from "./deployed-contracts.json";
|
|
8
|
+
import supportedNetworks from "./supported-networks";
|
|
9
|
+
export type SupportedNetwork = keyof typeof supportedNetworks;
|
|
10
|
+
export declare const defaultNetwork: SupportedNetwork;
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
13
|
+
* @param supportedNetwork The network to be checked.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSupportedNetwork(supportedNetwork: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
18
|
+
* If the private key is not defined it returns an empty object.
|
|
19
|
+
* @param privateKey Private key to be used with networks.
|
|
20
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getHardhatNetworks(privateKey?: string): any;
|
|
23
|
+
/**
|
|
24
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
25
|
+
* on a specific supported network.
|
|
26
|
+
* @param The network supported by Semaphore.
|
|
27
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDeployedContract(supportedNetwork: SupportedNetwork): {
|
|
30
|
+
name: string;
|
|
31
|
+
address: string;
|
|
32
|
+
startBlock: number;
|
|
33
|
+
};
|
|
34
|
+
export { deployedContracts, supportedNetworks };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
sepolia: {
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
chainId: number;
|
|
6
|
+
explorer: string;
|
|
7
|
+
};
|
|
8
|
+
"arbitrum-sepolia": {
|
|
9
|
+
name: string;
|
|
10
|
+
url: string;
|
|
11
|
+
chainId: number;
|
|
12
|
+
explorer: string;
|
|
13
|
+
};
|
|
14
|
+
"optimism-sepolia": {
|
|
15
|
+
name: string;
|
|
16
|
+
url: string;
|
|
17
|
+
chainId: number;
|
|
18
|
+
explorer: string;
|
|
19
|
+
};
|
|
20
|
+
"matic-mumbai": {
|
|
21
|
+
name: string;
|
|
22
|
+
url: string;
|
|
23
|
+
chainId: number;
|
|
24
|
+
explorer: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/utils",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.5",
|
|
4
4
|
"description": "A library to provide utility functions to the other Semaphore packages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"require": "./dist/index.cjs",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
-
"./
|
|
16
|
-
"types": "./dist/types/
|
|
17
|
-
"require": "./dist/lib.commonjs/
|
|
18
|
-
"default": "./dist/lib.esm/
|
|
15
|
+
"./networks": {
|
|
16
|
+
"types": "./dist/types/networks/index.d.ts",
|
|
17
|
+
"require": "./dist/lib.commonjs/networks/index.cjs",
|
|
18
|
+
"default": "./dist/lib.esm/networks/index.js"
|
|
19
19
|
},
|
|
20
20
|
"./constants": {
|
|
21
21
|
"types": "./dist/types/constants.d.ts",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
50
51
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
51
52
|
"rimraf": "^5.0.5",
|
|
52
53
|
"rollup": "^4.12.0",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as constants from "./constants"
|
|
2
2
|
import decodeMessage from "./decode-message"
|
|
3
|
-
import supportedNetworks from "./supported-networks"
|
|
4
3
|
|
|
5
|
-
export * from "./
|
|
6
|
-
export { constants, decodeMessage
|
|
4
|
+
export * from "./networks"
|
|
5
|
+
export { constants, decodeMessage }
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"network": "sepolia",
|
|
4
|
+
"contracts": [
|
|
5
|
+
{
|
|
6
|
+
"name": "SemaphoreVerifier",
|
|
7
|
+
"address": "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
|
|
8
|
+
"startBlock": 5539276
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "PoseidonT3",
|
|
12
|
+
"address": "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
|
|
13
|
+
"startBlock": 5539276
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "Semaphore",
|
|
17
|
+
"address": "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
|
|
18
|
+
"startBlock": 5539276
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"network": "arbitrum-sepolia",
|
|
24
|
+
"contracts": [
|
|
25
|
+
{
|
|
26
|
+
"name": "SemaphoreVerifier",
|
|
27
|
+
"address": "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
28
|
+
"startBlock": 25837653
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "PoseidonT3",
|
|
32
|
+
"address": "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
33
|
+
"startBlock": 25837653
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "Semaphore",
|
|
37
|
+
"address": "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
|
|
38
|
+
"startBlock": 25837653
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"network": "optimism-sepolia",
|
|
44
|
+
"contracts": [
|
|
45
|
+
{
|
|
46
|
+
"name": "SemaphoreVerifier",
|
|
47
|
+
"address": "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
|
|
48
|
+
"startBlock": 9663266
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "PoseidonT3",
|
|
52
|
+
"address": "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
53
|
+
"startBlock": 9663266
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "Semaphore",
|
|
57
|
+
"address": "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
58
|
+
"startBlock": 9663266
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"network": "matic-mumbai",
|
|
64
|
+
"contracts": [
|
|
65
|
+
{
|
|
66
|
+
"name": "SemaphoreVerifier",
|
|
67
|
+
"address": "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
|
|
68
|
+
"startBlock": 47356015
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "PoseidonT3",
|
|
72
|
+
"address": "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
|
|
73
|
+
"startBlock": 47356015
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "Semaphore",
|
|
77
|
+
"address": "0x346a936b19071b2f619200848B8ADbb938D72250",
|
|
78
|
+
"startBlock": 47356015
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Networks
|
|
3
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
4
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
5
|
+
* by Semaphore.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import deployedContracts from "./deployed-contracts.json"
|
|
9
|
+
import supportedNetworks from "./supported-networks"
|
|
10
|
+
|
|
11
|
+
export type SupportedNetwork = keyof typeof supportedNetworks
|
|
12
|
+
|
|
13
|
+
// Default Semaphore network.
|
|
14
|
+
export const defaultNetwork: SupportedNetwork = "sepolia"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
18
|
+
* @param supportedNetwork The network to be checked.
|
|
19
|
+
*/
|
|
20
|
+
export function isSupportedNetwork(supportedNetwork: string): boolean {
|
|
21
|
+
return Object.keys(supportedNetworks).includes(supportedNetwork)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
26
|
+
* If the private key is not defined it returns an empty object.
|
|
27
|
+
* @param privateKey Private key to be used with networks.
|
|
28
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
29
|
+
*/
|
|
30
|
+
export function getHardhatNetworks(privateKey?: string) {
|
|
31
|
+
if (!privateKey) {
|
|
32
|
+
return {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks))
|
|
36
|
+
|
|
37
|
+
for (const key in supportedNetworksCopy) {
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
|
|
39
|
+
supportedNetworksCopy[key].accounts = [`0x${privateKey}`]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return supportedNetworksCopy
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
48
|
+
* on a specific supported network.
|
|
49
|
+
* @param The network supported by Semaphore.
|
|
50
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
51
|
+
*/
|
|
52
|
+
export function getDeployedContract(supportedNetwork: SupportedNetwork) {
|
|
53
|
+
if (!isSupportedNetwork(supportedNetwork)) {
|
|
54
|
+
throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork)
|
|
58
|
+
|
|
59
|
+
return deployedContract!.contracts.find(({ name }) => name === "Semaphore") as {
|
|
60
|
+
name: string
|
|
61
|
+
address: string
|
|
62
|
+
startBlock: number
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { deployedContracts, supportedNetworks }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
sepolia: {
|
|
3
|
+
name: "Sepolia",
|
|
4
|
+
url: "https://rpc2.sepolia.org",
|
|
5
|
+
chainId: 11155111,
|
|
6
|
+
explorer: "https://sepolia.etherscan.io"
|
|
7
|
+
},
|
|
8
|
+
"arbitrum-sepolia": {
|
|
9
|
+
name: "Arbitrum Sepolia",
|
|
10
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
11
|
+
chainId: 421614,
|
|
12
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
13
|
+
},
|
|
14
|
+
"optimism-sepolia": {
|
|
15
|
+
name: "Optimism Sepolia",
|
|
16
|
+
url: "https://sepolia.optimism.io",
|
|
17
|
+
chainId: 11155420,
|
|
18
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
19
|
+
},
|
|
20
|
+
"matic-mumbai": {
|
|
21
|
+
name: "Matic Mumbai",
|
|
22
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
23
|
+
chainId: 80001,
|
|
24
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.3
|
|
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
|
-
// List of Semaphore supported networks.
|
|
12
|
-
var supportedNetwork = ["sepolia", "mumbai", "optimism-sepolia", "arbitrum-sepolia", "arbitrum"];
|
|
13
|
-
|
|
14
|
-
module.exports = supportedNetwork;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.3
|
|
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
|
-
// List of Semaphore supported networks.
|
|
10
|
-
var supportedNetwork = ["sepolia", "mumbai", "optimism-sepolia", "arbitrum-sepolia", "arbitrum"];
|
|
11
|
-
|
|
12
|
-
export { supportedNetwork as default };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type SupportedNetwork = "sepolia" | "mumbai" | "optimism-sepolia" | "arbitrum-sepolia" | "arbitrum";
|
package/src/types/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type SupportedNetwork = "sepolia" | "mumbai" | "optimism-sepolia" | "arbitrum-sepolia" | "arbitrum"
|