@semaphore-protocol/hardhat 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 +15 -5
- package/dist/index.cjs +63 -163
- package/dist/index.js +63 -163
- package/package.json +7 -5
- package/src/index.ts +8 -0
- package/src/tasks/deploy-semaphore-verifier.ts +4 -0
- package/src/tasks/deploy-semaphore.ts +7 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<h1 align="center">
|
|
3
3
|
Semaphore Hardhat plugin
|
|
4
4
|
</h1>
|
|
5
|
-
<p align="center">A
|
|
5
|
+
<p align="center">A Hardhat plugin to deploy Semaphore contracts.</p>
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
</h4>
|
|
47
47
|
</div>
|
|
48
48
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
49
|
+
| The Semaphore Hardhat plugin simplifies the deployment of Semaphore contracts, reducing setup time and complexity. |
|
|
50
|
+
| ------------------------------------------------------------------------------------------------------------------ |
|
|
51
51
|
|
|
52
52
|
## 🛠 Install
|
|
53
53
|
|
|
54
54
|
### npm or yarn
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
To install the Semaphore Hardhat plugin, use npm or yarn:
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
59
|
npm i @semaphore-protocol/hardhat
|
|
@@ -67,7 +67,7 @@ yarn add @semaphore-protocol/hardhat
|
|
|
67
67
|
|
|
68
68
|
## 📜 Usage
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
To use the plugin, import it in your Hardhat configuration file (`hardhat.config.ts`):
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
73
|
import "@semaphore-protocol/hardhat"
|
|
@@ -110,3 +110,13 @@ task("deploy", "Deploy a Greeter contract")
|
|
|
110
110
|
return greeter
|
|
111
111
|
})
|
|
112
112
|
```
|
|
113
|
+
|
|
114
|
+
### Deploying Contracts
|
|
115
|
+
|
|
116
|
+
Use the provided tasks to deploy your Semaphore contracts:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx hardhat deploy
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
This command will deploy a Semaphore contract using the addresses provided or deploy necessary dependencies like Semaphore Verifier and Poseidon library.
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/hardhat
|
|
3
|
-
* @version 4.0.0-beta.
|
|
4
|
-
* @file A
|
|
3
|
+
* @version 4.0.0-beta.11
|
|
4
|
+
* @file A Hardhat plugin to deploy Semaphore contracts.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/hardhat}
|
|
@@ -12,182 +12,82 @@ var config = require('hardhat/config');
|
|
|
12
12
|
require('hardhat-dependency-compiler');
|
|
13
13
|
require('@nomicfoundation/hardhat-ethers');
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
purpose with or without fee is hereby granted.
|
|
20
|
-
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
22
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
23
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
24
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
25
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
26
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
27
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
28
|
-
***************************************************************************** */
|
|
29
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function __generator(thisArg, body) {
|
|
43
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
44
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
45
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
46
|
-
function step(op) {
|
|
47
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
48
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
49
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
50
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
51
|
-
switch (op[0]) {
|
|
52
|
-
case 0: case 1: t = op; break;
|
|
53
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
54
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
55
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
56
|
-
default:
|
|
57
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
58
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
59
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
60
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
61
|
-
if (t[2]) _.ops.pop();
|
|
62
|
-
_.trys.pop(); continue;
|
|
63
|
-
}
|
|
64
|
-
op = body.call(thisArg, _);
|
|
65
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
66
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function __spreadArray(to, from, pack) {
|
|
71
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
72
|
-
if (ar || !(i in from)) {
|
|
73
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
74
|
-
ar[i] = from[i];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
81
|
-
var e = new Error(message);
|
|
82
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
83
|
-
};
|
|
84
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Defines a Hardhat task to deploy the Semaphore contract.
|
|
17
|
+
* This task handles the deployment of dependent contracts like SemaphoreVerifier and PoseidonT3 if not provided.
|
|
18
|
+
*/
|
|
85
19
|
config.task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
86
20
|
.addOptionalParam("semaphoreVerifier", "SemaphoreVerifier contract address", undefined, config.types.string)
|
|
87
21
|
.addOptionalParam("poseidon", "Poseidon library address", undefined, config.types.string)
|
|
88
22
|
.addOptionalParam("logs", "Print the logs", true, config.types.boolean)
|
|
89
|
-
.setAction(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return [4 /*yield*/, ethers.getContractFactory("PoseidonT3")];
|
|
114
|
-
case 5:
|
|
115
|
-
PoseidonT3Factory = _f.sent();
|
|
116
|
-
return [4 /*yield*/, PoseidonT3Factory.deploy()];
|
|
117
|
-
case 6:
|
|
118
|
-
poseidonT3 = _f.sent();
|
|
119
|
-
return [4 /*yield*/, poseidonT3.getAddress()];
|
|
120
|
-
case 7:
|
|
121
|
-
poseidonAddress = _f.sent();
|
|
122
|
-
if (logs) {
|
|
123
|
-
console.info("Poseidon library has been deployed to: ".concat(poseidonAddress));
|
|
124
|
-
}
|
|
125
|
-
_f.label = 8;
|
|
126
|
-
case 8: return [4 /*yield*/, ethers.getContractFactory("Semaphore", {
|
|
127
|
-
libraries: {
|
|
128
|
-
PoseidonT3: poseidonAddress
|
|
129
|
-
}
|
|
130
|
-
})];
|
|
131
|
-
case 9:
|
|
132
|
-
SemaphoreFactory = _f.sent();
|
|
133
|
-
return [4 /*yield*/, SemaphoreFactory.deploy(semaphoreVerifierAddress)];
|
|
134
|
-
case 10:
|
|
135
|
-
semaphore = _f.sent();
|
|
136
|
-
if (!logs) return [3 /*break*/, 12];
|
|
137
|
-
_d = (_c = console).info;
|
|
138
|
-
_e = "Semaphore contract has been deployed to: ".concat;
|
|
139
|
-
return [4 /*yield*/, semaphore.getAddress()];
|
|
140
|
-
case 11:
|
|
141
|
-
_d.apply(_c, [_e.apply("Semaphore contract has been deployed to: ", [_f.sent()])]);
|
|
142
|
-
_f.label = 12;
|
|
143
|
-
case 12: return [2 /*return*/, {
|
|
144
|
-
semaphore: semaphore,
|
|
145
|
-
semaphoreVerifierAddress: semaphoreVerifierAddress,
|
|
146
|
-
poseidonAddress: poseidonAddress
|
|
147
|
-
}];
|
|
148
|
-
}
|
|
149
|
-
});
|
|
23
|
+
.setAction(async ({ logs, semaphoreVerifier: semaphoreVerifierAddress, poseidon: poseidonAddress }, { ethers }) => {
|
|
24
|
+
// Deploy SemaphoreVerifier if not provided.
|
|
25
|
+
if (!semaphoreVerifierAddress) {
|
|
26
|
+
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier");
|
|
27
|
+
const semaphoreVerifier = await SemaphoreVerifierFactory.deploy();
|
|
28
|
+
semaphoreVerifierAddress = await semaphoreVerifier.getAddress();
|
|
29
|
+
if (logs) {
|
|
30
|
+
console.info(`SemaphoreVerifier contract has been deployed to: ${semaphoreVerifierAddress}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Deploy PoseidonT3 if not provided.
|
|
34
|
+
if (!poseidonAddress) {
|
|
35
|
+
const PoseidonT3Factory = await ethers.getContractFactory("PoseidonT3");
|
|
36
|
+
const poseidonT3 = await PoseidonT3Factory.deploy();
|
|
37
|
+
poseidonAddress = await poseidonT3.getAddress();
|
|
38
|
+
if (logs) {
|
|
39
|
+
console.info(`Poseidon library has been deployed to: ${poseidonAddress}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Deploy the Semaphore contract with the necessary library.
|
|
43
|
+
const SemaphoreFactory = await ethers.getContractFactory("Semaphore", {
|
|
44
|
+
libraries: {
|
|
45
|
+
PoseidonT3: poseidonAddress
|
|
46
|
+
}
|
|
150
47
|
});
|
|
48
|
+
const semaphore = await SemaphoreFactory.deploy(semaphoreVerifierAddress);
|
|
49
|
+
if (logs) {
|
|
50
|
+
console.info(`Semaphore contract has been deployed to: ${await semaphore.getAddress()}`);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
semaphore,
|
|
54
|
+
semaphoreVerifierAddress,
|
|
55
|
+
poseidonAddress
|
|
56
|
+
};
|
|
151
57
|
});
|
|
152
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Defines a Hardhat task to deploy the SemaphoreVerifier contract.
|
|
61
|
+
* This task can optionally log the deployment address.
|
|
62
|
+
*/
|
|
153
63
|
config.task("deploy:semaphore-verifier", "Deploy a SemaphoreVerifier contract")
|
|
154
64
|
.addOptionalParam("logs", "Print the logs", true, config.types.boolean)
|
|
155
|
-
.setAction(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
SemaphoreVerifierFactory = _f.sent();
|
|
165
|
-
return [4 /*yield*/, SemaphoreVerifierFactory.deploy()];
|
|
166
|
-
case 2:
|
|
167
|
-
semaphoreVerifier = _f.sent();
|
|
168
|
-
if (!logs) return [3 /*break*/, 4];
|
|
169
|
-
_d = (_c = console).info;
|
|
170
|
-
_e = "SemaphoreVerifier contract has been deployed to: ".concat;
|
|
171
|
-
return [4 /*yield*/, semaphoreVerifier.getAddress()];
|
|
172
|
-
case 3:
|
|
173
|
-
_d.apply(_c, [_e.apply("SemaphoreVerifier contract has been deployed to: ", [_f.sent()])]);
|
|
174
|
-
_f.label = 4;
|
|
175
|
-
case 4: return [2 /*return*/, {
|
|
176
|
-
semaphoreVerifier: semaphoreVerifier
|
|
177
|
-
}];
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
65
|
+
.setAction(async ({ logs }, { ethers }) => {
|
|
66
|
+
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier");
|
|
67
|
+
const semaphoreVerifier = await SemaphoreVerifierFactory.deploy();
|
|
68
|
+
if (logs) {
|
|
69
|
+
console.info(`SemaphoreVerifier contract has been deployed to: ${await semaphoreVerifier.getAddress()}`);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
semaphoreVerifier
|
|
73
|
+
};
|
|
181
74
|
});
|
|
182
75
|
|
|
183
|
-
|
|
184
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Extends the Hardhat configuration to include paths for dependency compilation.
|
|
78
|
+
* This setup ensures that specific contracts are pre-compiled, optimizing the deployment process.
|
|
79
|
+
* @param config The Hardhat configuration object that is being extended.
|
|
80
|
+
* @param userConfig The user-provided configuration, if any, which may override or extend the default settings.
|
|
81
|
+
*/
|
|
82
|
+
config.extendConfig((config, userConfig) => {
|
|
83
|
+
// Default paths for contracts that need to be compiled before deployment.
|
|
185
84
|
config.dependencyCompiler.paths = [
|
|
186
85
|
"@semaphore-protocol/contracts/base/SemaphoreVerifier.sol",
|
|
187
86
|
"@semaphore-protocol/contracts/Semaphore.sol",
|
|
188
87
|
"poseidon-solidity/PoseidonT3.sol"
|
|
189
88
|
];
|
|
190
|
-
|
|
191
|
-
|
|
89
|
+
// Merge user-specified paths with the default paths.
|
|
90
|
+
if (userConfig.dependencyCompiler?.paths) {
|
|
91
|
+
config.dependencyCompiler.paths = [...config.dependencyCompiler.paths, ...userConfig.dependencyCompiler.paths];
|
|
192
92
|
}
|
|
193
93
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/hardhat
|
|
3
|
-
* @version 4.0.0-beta.
|
|
4
|
-
* @file A
|
|
3
|
+
* @version 4.0.0-beta.11
|
|
4
|
+
* @file A Hardhat plugin to deploy Semaphore contracts.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/hardhat}
|
|
@@ -10,182 +10,82 @@ import { task, types, extendConfig } from 'hardhat/config';
|
|
|
10
10
|
import 'hardhat-dependency-compiler';
|
|
11
11
|
import '@nomicfoundation/hardhat-ethers';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
purpose with or without fee is hereby granted.
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
-
***************************************************************************** */
|
|
27
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
31
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
32
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
33
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
34
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
35
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
36
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function __generator(thisArg, body) {
|
|
41
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
42
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
43
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
44
|
-
function step(op) {
|
|
45
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
46
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
47
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
48
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
49
|
-
switch (op[0]) {
|
|
50
|
-
case 0: case 1: t = op; break;
|
|
51
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
52
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
53
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
54
|
-
default:
|
|
55
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
56
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
57
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
58
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
59
|
-
if (t[2]) _.ops.pop();
|
|
60
|
-
_.trys.pop(); continue;
|
|
61
|
-
}
|
|
62
|
-
op = body.call(thisArg, _);
|
|
63
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
64
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function __spreadArray(to, from, pack) {
|
|
69
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
70
|
-
if (ar || !(i in from)) {
|
|
71
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
72
|
-
ar[i] = from[i];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
79
|
-
var e = new Error(message);
|
|
80
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
81
|
-
};
|
|
82
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Defines a Hardhat task to deploy the Semaphore contract.
|
|
15
|
+
* This task handles the deployment of dependent contracts like SemaphoreVerifier and PoseidonT3 if not provided.
|
|
16
|
+
*/
|
|
83
17
|
task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
84
18
|
.addOptionalParam("semaphoreVerifier", "SemaphoreVerifier contract address", undefined, types.string)
|
|
85
19
|
.addOptionalParam("poseidon", "Poseidon library address", undefined, types.string)
|
|
86
20
|
.addOptionalParam("logs", "Print the logs", true, types.boolean)
|
|
87
|
-
.setAction(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return [4 /*yield*/, ethers.getContractFactory("PoseidonT3")];
|
|
112
|
-
case 5:
|
|
113
|
-
PoseidonT3Factory = _f.sent();
|
|
114
|
-
return [4 /*yield*/, PoseidonT3Factory.deploy()];
|
|
115
|
-
case 6:
|
|
116
|
-
poseidonT3 = _f.sent();
|
|
117
|
-
return [4 /*yield*/, poseidonT3.getAddress()];
|
|
118
|
-
case 7:
|
|
119
|
-
poseidonAddress = _f.sent();
|
|
120
|
-
if (logs) {
|
|
121
|
-
console.info("Poseidon library has been deployed to: ".concat(poseidonAddress));
|
|
122
|
-
}
|
|
123
|
-
_f.label = 8;
|
|
124
|
-
case 8: return [4 /*yield*/, ethers.getContractFactory("Semaphore", {
|
|
125
|
-
libraries: {
|
|
126
|
-
PoseidonT3: poseidonAddress
|
|
127
|
-
}
|
|
128
|
-
})];
|
|
129
|
-
case 9:
|
|
130
|
-
SemaphoreFactory = _f.sent();
|
|
131
|
-
return [4 /*yield*/, SemaphoreFactory.deploy(semaphoreVerifierAddress)];
|
|
132
|
-
case 10:
|
|
133
|
-
semaphore = _f.sent();
|
|
134
|
-
if (!logs) return [3 /*break*/, 12];
|
|
135
|
-
_d = (_c = console).info;
|
|
136
|
-
_e = "Semaphore contract has been deployed to: ".concat;
|
|
137
|
-
return [4 /*yield*/, semaphore.getAddress()];
|
|
138
|
-
case 11:
|
|
139
|
-
_d.apply(_c, [_e.apply("Semaphore contract has been deployed to: ", [_f.sent()])]);
|
|
140
|
-
_f.label = 12;
|
|
141
|
-
case 12: return [2 /*return*/, {
|
|
142
|
-
semaphore: semaphore,
|
|
143
|
-
semaphoreVerifierAddress: semaphoreVerifierAddress,
|
|
144
|
-
poseidonAddress: poseidonAddress
|
|
145
|
-
}];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
21
|
+
.setAction(async ({ logs, semaphoreVerifier: semaphoreVerifierAddress, poseidon: poseidonAddress }, { ethers }) => {
|
|
22
|
+
// Deploy SemaphoreVerifier if not provided.
|
|
23
|
+
if (!semaphoreVerifierAddress) {
|
|
24
|
+
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier");
|
|
25
|
+
const semaphoreVerifier = await SemaphoreVerifierFactory.deploy();
|
|
26
|
+
semaphoreVerifierAddress = await semaphoreVerifier.getAddress();
|
|
27
|
+
if (logs) {
|
|
28
|
+
console.info(`SemaphoreVerifier contract has been deployed to: ${semaphoreVerifierAddress}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Deploy PoseidonT3 if not provided.
|
|
32
|
+
if (!poseidonAddress) {
|
|
33
|
+
const PoseidonT3Factory = await ethers.getContractFactory("PoseidonT3");
|
|
34
|
+
const poseidonT3 = await PoseidonT3Factory.deploy();
|
|
35
|
+
poseidonAddress = await poseidonT3.getAddress();
|
|
36
|
+
if (logs) {
|
|
37
|
+
console.info(`Poseidon library has been deployed to: ${poseidonAddress}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Deploy the Semaphore contract with the necessary library.
|
|
41
|
+
const SemaphoreFactory = await ethers.getContractFactory("Semaphore", {
|
|
42
|
+
libraries: {
|
|
43
|
+
PoseidonT3: poseidonAddress
|
|
44
|
+
}
|
|
148
45
|
});
|
|
46
|
+
const semaphore = await SemaphoreFactory.deploy(semaphoreVerifierAddress);
|
|
47
|
+
if (logs) {
|
|
48
|
+
console.info(`Semaphore contract has been deployed to: ${await semaphore.getAddress()}`);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
semaphore,
|
|
52
|
+
semaphoreVerifierAddress,
|
|
53
|
+
poseidonAddress
|
|
54
|
+
};
|
|
149
55
|
});
|
|
150
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Defines a Hardhat task to deploy the SemaphoreVerifier contract.
|
|
59
|
+
* This task can optionally log the deployment address.
|
|
60
|
+
*/
|
|
151
61
|
task("deploy:semaphore-verifier", "Deploy a SemaphoreVerifier contract")
|
|
152
62
|
.addOptionalParam("logs", "Print the logs", true, types.boolean)
|
|
153
|
-
.setAction(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
SemaphoreVerifierFactory = _f.sent();
|
|
163
|
-
return [4 /*yield*/, SemaphoreVerifierFactory.deploy()];
|
|
164
|
-
case 2:
|
|
165
|
-
semaphoreVerifier = _f.sent();
|
|
166
|
-
if (!logs) return [3 /*break*/, 4];
|
|
167
|
-
_d = (_c = console).info;
|
|
168
|
-
_e = "SemaphoreVerifier contract has been deployed to: ".concat;
|
|
169
|
-
return [4 /*yield*/, semaphoreVerifier.getAddress()];
|
|
170
|
-
case 3:
|
|
171
|
-
_d.apply(_c, [_e.apply("SemaphoreVerifier contract has been deployed to: ", [_f.sent()])]);
|
|
172
|
-
_f.label = 4;
|
|
173
|
-
case 4: return [2 /*return*/, {
|
|
174
|
-
semaphoreVerifier: semaphoreVerifier
|
|
175
|
-
}];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
63
|
+
.setAction(async ({ logs }, { ethers }) => {
|
|
64
|
+
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier");
|
|
65
|
+
const semaphoreVerifier = await SemaphoreVerifierFactory.deploy();
|
|
66
|
+
if (logs) {
|
|
67
|
+
console.info(`SemaphoreVerifier contract has been deployed to: ${await semaphoreVerifier.getAddress()}`);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
semaphoreVerifier
|
|
71
|
+
};
|
|
179
72
|
});
|
|
180
73
|
|
|
181
|
-
|
|
182
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Extends the Hardhat configuration to include paths for dependency compilation.
|
|
76
|
+
* This setup ensures that specific contracts are pre-compiled, optimizing the deployment process.
|
|
77
|
+
* @param config The Hardhat configuration object that is being extended.
|
|
78
|
+
* @param userConfig The user-provided configuration, if any, which may override or extend the default settings.
|
|
79
|
+
*/
|
|
80
|
+
extendConfig((config, userConfig) => {
|
|
81
|
+
// Default paths for contracts that need to be compiled before deployment.
|
|
183
82
|
config.dependencyCompiler.paths = [
|
|
184
83
|
"@semaphore-protocol/contracts/base/SemaphoreVerifier.sol",
|
|
185
84
|
"@semaphore-protocol/contracts/Semaphore.sol",
|
|
186
85
|
"poseidon-solidity/PoseidonT3.sol"
|
|
187
86
|
];
|
|
188
|
-
|
|
189
|
-
|
|
87
|
+
// Merge user-specified paths with the default paths.
|
|
88
|
+
if (userConfig.dependencyCompiler?.paths) {
|
|
89
|
+
config.dependencyCompiler.paths = [...config.dependencyCompiler.paths, ...userConfig.dependencyCompiler.paths];
|
|
190
90
|
}
|
|
191
91
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/hardhat",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "4.0.0-beta.11",
|
|
4
|
+
"description": "A Hardhat plugin to deploy Semaphore contracts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -30,16 +30,18 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
33
34
|
"hardhat": "^2.19.4",
|
|
34
|
-
"
|
|
35
|
-
"rollup
|
|
35
|
+
"rimraf": "^5.0.5",
|
|
36
|
+
"rollup": "^4.12.0",
|
|
37
|
+
"rollup-plugin-cleanup": "^3.2.1"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
40
|
"hardhat": "^2.19.4"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
|
42
|
-
"@semaphore-protocol/contracts": "4.0.0-beta.
|
|
44
|
+
"@semaphore-protocol/contracts": "4.0.0-beta.11",
|
|
43
45
|
"ethers": "^6.4.0",
|
|
44
46
|
"hardhat-dependency-compiler": "^1.1.3"
|
|
45
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,13 +6,21 @@ import "@nomicfoundation/hardhat-ethers"
|
|
|
6
6
|
import "./tasks/deploy-semaphore"
|
|
7
7
|
import "./tasks/deploy-semaphore-verifier"
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Extends the Hardhat configuration to include paths for dependency compilation.
|
|
11
|
+
* This setup ensures that specific contracts are pre-compiled, optimizing the deployment process.
|
|
12
|
+
* @param config The Hardhat configuration object that is being extended.
|
|
13
|
+
* @param userConfig The user-provided configuration, if any, which may override or extend the default settings.
|
|
14
|
+
*/
|
|
9
15
|
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
|
|
16
|
+
// Default paths for contracts that need to be compiled before deployment.
|
|
10
17
|
config.dependencyCompiler.paths = [
|
|
11
18
|
"@semaphore-protocol/contracts/base/SemaphoreVerifier.sol",
|
|
12
19
|
"@semaphore-protocol/contracts/Semaphore.sol",
|
|
13
20
|
"poseidon-solidity/PoseidonT3.sol"
|
|
14
21
|
]
|
|
15
22
|
|
|
23
|
+
// Merge user-specified paths with the default paths.
|
|
16
24
|
if (userConfig.dependencyCompiler?.paths) {
|
|
17
25
|
config.dependencyCompiler.paths = [...config.dependencyCompiler.paths, ...userConfig.dependencyCompiler.paths]
|
|
18
26
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { task, types } from "hardhat/config"
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Defines a Hardhat task to deploy the SemaphoreVerifier contract.
|
|
5
|
+
* This task can optionally log the deployment address.
|
|
6
|
+
*/
|
|
3
7
|
task("deploy:semaphore-verifier", "Deploy a SemaphoreVerifier contract")
|
|
4
8
|
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
|
|
5
9
|
.setAction(async ({ logs }, { ethers }): Promise<any> => {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { task, types } from "hardhat/config"
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Defines a Hardhat task to deploy the Semaphore contract.
|
|
5
|
+
* This task handles the deployment of dependent contracts like SemaphoreVerifier and PoseidonT3 if not provided.
|
|
6
|
+
*/
|
|
3
7
|
task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
4
8
|
.addOptionalParam<boolean>("semaphoreVerifier", "SemaphoreVerifier contract address", undefined, types.string)
|
|
5
9
|
.addOptionalParam<boolean>("poseidon", "Poseidon library address", undefined, types.string)
|
|
@@ -9,6 +13,7 @@ task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
|
9
13
|
{ logs, semaphoreVerifier: semaphoreVerifierAddress, poseidon: poseidonAddress },
|
|
10
14
|
{ ethers }
|
|
11
15
|
): Promise<any> => {
|
|
16
|
+
// Deploy SemaphoreVerifier if not provided.
|
|
12
17
|
if (!semaphoreVerifierAddress) {
|
|
13
18
|
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier")
|
|
14
19
|
|
|
@@ -21,6 +26,7 @@ task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
// Deploy PoseidonT3 if not provided.
|
|
24
30
|
if (!poseidonAddress) {
|
|
25
31
|
const PoseidonT3Factory = await ethers.getContractFactory("PoseidonT3")
|
|
26
32
|
const poseidonT3 = await PoseidonT3Factory.deploy()
|
|
@@ -32,6 +38,7 @@ task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
// Deploy the Semaphore contract with the necessary library.
|
|
35
42
|
const SemaphoreFactory = await ethers.getContractFactory("Semaphore", {
|
|
36
43
|
libraries: {
|
|
37
44
|
PoseidonT3: poseidonAddress
|