@cofhe/hardhat-plugin 0.0.0-alpha-20260409113701

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.js ADDED
@@ -0,0 +1,580 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ TASK_COFHE_MOCKS_DEPLOY: () => TASK_COFHE_MOCKS_DEPLOY,
34
+ TASK_COFHE_MOCKS_SET_LOG_OPS: () => TASK_COFHE_MOCKS_SET_LOG_OPS,
35
+ TASK_COFHE_USE_FAUCET: () => TASK_COFHE_USE_FAUCET,
36
+ buildHardhatPluginMocksConfig: () => buildHardhatPluginMocksConfig,
37
+ deployMockContractFromArtifact: () => deployMockContractFromArtifact,
38
+ deployMocks: () => deployMocks,
39
+ getFixedMockContract: () => getFixedMockContract,
40
+ localcofheFundAccount: () => localcofheFundAccount,
41
+ localcofheFundWalletIfNeeded: () => localcofheFundWalletIfNeeded,
42
+ mock_expectPlaintext: () => mock_expectPlaintext,
43
+ mock_getPlaintext: () => mock_getPlaintext,
44
+ mock_getPlaintextExists: () => mock_getPlaintextExists,
45
+ mock_setLoggingEnabled: () => mock_setLoggingEnabled,
46
+ mock_withLogs: () => mock_withLogs
47
+ });
48
+ module.exports = __toCommonJS(src_exports);
49
+ var import_chalk3 = __toESM(require("chalk"));
50
+ var import_viem = require("viem");
51
+ var import_config = require("hardhat/config");
52
+ var import_task_names = require("hardhat/builtin-tasks/task-names");
53
+ var import_signers = require("@nomicfoundation/hardhat-ethers/signers");
54
+ var import_sdk3 = require("@cofhe/sdk");
55
+ var import_node = require("@cofhe/sdk/node");
56
+ var import_adapters = require("@cofhe/sdk/adapters");
57
+
58
+ // src/fund.ts
59
+ var import_types = require("hardhat/types");
60
+ var import_hardhat_ethers = require("@nomicfoundation/hardhat-ethers");
61
+ async function localcofheFundAccount(hre, toAddress, amount = "10") {
62
+ const privateKey = process.env.FUNDER_PRIVATE_KEY ?? "0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659";
63
+ if (!privateKey) {
64
+ console.error("Error: FUNDER_PRIVATE_KEY environment variable not set");
65
+ return null;
66
+ }
67
+ try {
68
+ const wallet = new hre.ethers.Wallet(privateKey, hre.ethers.provider);
69
+ const balance = await hre.ethers.provider.getBalance(wallet.address);
70
+ console.log(`Funder wallet address: ${wallet.address}`);
71
+ console.log(`Funder wallet balance: ${hre.ethers.formatEther(balance)} ETH`);
72
+ const amountToSend = hre.ethers.parseEther(amount);
73
+ if (balance < amountToSend) {
74
+ console.error(
75
+ `Error: Funder wallet doesn't have enough funds. Current balance: ${hre.ethers.formatEther(balance)} ETH`
76
+ );
77
+ return null;
78
+ }
79
+ console.log(`Sending ${amount} ETH to ${toAddress}...`);
80
+ const tx = await wallet.sendTransaction({
81
+ to: toAddress,
82
+ value: amountToSend
83
+ });
84
+ console.log(`Transaction sent! Hash: ${tx.hash}`);
85
+ console.log("Waiting for confirmation...");
86
+ const receipt = await tx.wait();
87
+ console.log(`Transaction confirmed in block ${receipt?.blockNumber}`);
88
+ console.log(`Successfully sent ${amount} ETH to ${toAddress}`);
89
+ return receipt;
90
+ } catch (error) {
91
+ console.error("Error sending funds:", error);
92
+ return null;
93
+ }
94
+ }
95
+ async function localcofheFundWalletIfNeeded(hre, walletAddress) {
96
+ const walletBalance = await hre.ethers.provider.getBalance(walletAddress);
97
+ console.log(`Wallet balance: ${hre.ethers.formatEther(walletBalance)} ETH`);
98
+ if (walletBalance < hre.ethers.parseEther("1")) {
99
+ console.log(`Wallet balance is less than 1 ETH. Funding ${walletAddress}...`);
100
+ const receipt = await localcofheFundAccount(hre, walletAddress);
101
+ if (receipt) {
102
+ const newBalance = await hre.ethers.provider.getBalance(walletAddress);
103
+ console.log(`Wallet new balance: ${hre.ethers.formatEther(newBalance)} ETH`);
104
+ } else {
105
+ console.error(`Failed to fund ${walletAddress}`);
106
+ }
107
+ }
108
+ }
109
+
110
+ // src/consts.ts
111
+ var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
112
+ var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
113
+ var TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
114
+
115
+ // src/deploy.ts
116
+ var import_types2 = require("hardhat/types");
117
+ var import_chalk = __toESM(require("chalk"));
118
+ var import_ethers2 = require("ethers");
119
+ var import_mock_contracts = require("@cofhe/mock-contracts");
120
+ var import_sdk2 = require("@cofhe/sdk");
121
+
122
+ // src/utils.ts
123
+ var import_sdk = require("@cofhe/sdk");
124
+ var import_chai = require("chai");
125
+ var import_ethers = require("ethers");
126
+ var import_hardhat_ethers_provider = require("@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider");
127
+ var deployMockContractFromArtifact = async (hre, artifact) => {
128
+ if (artifact.isFixed) {
129
+ await hre.network.provider.send("hardhat_setCode", [artifact.fixedAddress, artifact.deployedBytecode]);
130
+ return getFixedMockContract(hre, artifact);
131
+ }
132
+ const [signer] = await hre.ethers.getSigners();
133
+ const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);
134
+ const contract = await factory.deploy(
135
+ /* constructor args */
136
+ );
137
+ await contract.waitForDeployment();
138
+ return contract;
139
+ };
140
+ var getFixedMockContract = async (hre, artifact) => {
141
+ if (!artifact.isFixed) {
142
+ throw new Error("Artifact is not fixed");
143
+ }
144
+ return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
145
+ };
146
+ var mock_checkIsTestnet = async (fnName, provider) => {
147
+ const bytecode = await provider.getCode(import_sdk.MOCKS_ZK_VERIFIER_ADDRESS);
148
+ const isTestnet = bytecode.length === 0;
149
+ if (isTestnet) {
150
+ console.log(`${fnName} - skipped on non-testnet chain`);
151
+ }
152
+ return isTestnet;
153
+ };
154
+ var mock_getPlaintext = async (provider, ctHash) => {
155
+ if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
156
+ return;
157
+ const taskManager = new import_ethers.ethers.Contract(
158
+ import_sdk.TASK_MANAGER_ADDRESS,
159
+ ["function mockStorage(uint256) view returns (uint256)"],
160
+ provider
161
+ );
162
+ const plaintext = await taskManager.mockStorage(BigInt(ctHash));
163
+ return plaintext;
164
+ };
165
+ var mock_getPlaintextExists = async (provider, ctHash) => {
166
+ if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
167
+ return;
168
+ const taskManager = new import_ethers.ethers.Contract(
169
+ import_sdk.TASK_MANAGER_ADDRESS,
170
+ ["function inMockStorage(uint256) view returns (bool)"],
171
+ provider
172
+ );
173
+ const plaintextExists = await taskManager.inMockStorage(BigInt(ctHash));
174
+ return plaintextExists;
175
+ };
176
+ var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
177
+ if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
178
+ return;
179
+ const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
180
+ (0, import_chai.expect)(plaintextExists).equal(true, "Plaintext does not exist");
181
+ const plaintext = await mock_getPlaintext(provider, ctHash);
182
+ (0, import_chai.expect)(plaintext).equal(expectedValue, "Plaintext value is incorrect");
183
+ };
184
+
185
+ // src/deploy.ts
186
+ var deployMocks = async (hre, options = {
187
+ deployTestBed: true,
188
+ gasWarning: true,
189
+ mocksDeployVerbosity: "v"
190
+ }) => {
191
+ verbosity = options.mocksDeployVerbosity ?? "v";
192
+ const isHardhat = await getIsHardhat(hre);
193
+ if (!isHardhat) {
194
+ log("v", `cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);
195
+ return;
196
+ }
197
+ log("vv", import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
198
+ const taskManager = await deployMockTaskManager(hre);
199
+ logDeployment("MockTaskManager", await taskManager.getAddress());
200
+ const acl = await deployMockACL(hre);
201
+ logDeployment("MockACL", await acl.getAddress());
202
+ await linkTaskManagerAndACL(taskManager, acl);
203
+ log("vv", "ACL address set in TaskManager", 2);
204
+ await setVerifierSigner(taskManager);
205
+ log("vv", "Verifier signer set", 2);
206
+ await setDecryptResultSigner(taskManager);
207
+ log("vv", "Decrypt result signer set", 2);
208
+ await fundZkVerifierSigner(hre);
209
+ log("vv", `ZkVerifier signer (${import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
210
+ const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);
211
+ log("vv", `ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
212
+ const zkVerifier = await deployMockZkVerifier(hre);
213
+ logDeployment("MockZkVerifier", await zkVerifier.getAddress());
214
+ const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);
215
+ logDeployment("MockThresholdNetwork", await thresholdNetwork.getAddress());
216
+ if (options.deployTestBed) {
217
+ const testBed = await deployTestBedContract(hre);
218
+ logDeployment("TestBed", await testBed.getAddress());
219
+ }
220
+ log("v", import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed"), 0);
221
+ if (options.gasWarning) {
222
+ logEmpty("v");
223
+ logWarning(
224
+ "When using mocks, FHE operations (eg FHE.add / FHE.mul) report a higher gas price due to additional on-chain mocking logic. Deploy your contracts on a testnet chain to check the true gas costs.\n(Disable this warning by setting 'cofhe.gasWarning: false' in your hardhat config)",
225
+ 0
226
+ );
227
+ }
228
+ logEmpty("v");
229
+ };
230
+ var getIsHardhat = async (hre) => {
231
+ return hre.network.name === "hardhat";
232
+ };
233
+ var deployMockTaskManager = async (hre) => {
234
+ const [signer] = await hre.ethers.getSigners();
235
+ const taskManager = await deployMockContractFromArtifact(hre, import_mock_contracts.MockTaskManagerArtifact);
236
+ const initTx = await taskManager.initialize(signer.address);
237
+ await initTx.wait();
238
+ const tmExists = await taskManager.exists();
239
+ if (!tmExists) {
240
+ throw new Error("MockTaskManager does not exist");
241
+ }
242
+ return taskManager;
243
+ };
244
+ var deployMockACL = async (hre) => {
245
+ const acl = await deployMockContractFromArtifact(hre, import_mock_contracts.MockACLArtifact);
246
+ const exists = await acl.exists();
247
+ if (!exists) {
248
+ throw new Error("MockACL does not exist");
249
+ }
250
+ return acl;
251
+ };
252
+ var fundZkVerifierSigner = async (hre) => {
253
+ const zkVerifierSigner = await hre.ethers.getSigner(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
254
+ await hre.network.provider.send("hardhat_setBalance", [
255
+ zkVerifierSigner.address,
256
+ "0x" + hre.ethers.parseEther("10").toString(16)
257
+ ]);
258
+ };
259
+ var getZkVerifierSignerBalance = async (hre) => {
260
+ return hre.ethers.provider.getBalance(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
261
+ };
262
+ var linkTaskManagerAndACL = async (taskManager, acl) => {
263
+ const aclAddress = await acl.getAddress();
264
+ const linkAclTx = await taskManager.setACLContract(aclAddress);
265
+ await linkAclTx.wait();
266
+ };
267
+ var setVerifierSigner = async (taskManager) => {
268
+ const signer = new import_ethers2.Wallet(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY);
269
+ const setSignerTx = await taskManager.setVerifierSigner(signer.address);
270
+ await setSignerTx.wait();
271
+ };
272
+ var setDecryptResultSigner = async (taskManager) => {
273
+ const signer = new import_ethers2.Wallet(import_sdk2.MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY);
274
+ const setSignerTx = await taskManager.setDecryptResultSigner(signer.address);
275
+ await setSignerTx.wait();
276
+ };
277
+ var deployMockZkVerifier = async (hre) => {
278
+ const zkVerifier = await deployMockContractFromArtifact(hre, import_mock_contracts.MockZkVerifierArtifact);
279
+ const zkVerifierExists = await zkVerifier.exists();
280
+ if (!zkVerifierExists) {
281
+ throw new Error("MockZkVerifier does not exist");
282
+ }
283
+ return zkVerifier;
284
+ };
285
+ var deployMockThresholdNetwork = async (hre, acl) => {
286
+ const thresholdNetwork = await deployMockContractFromArtifact(hre, import_mock_contracts.MockThresholdNetworkArtifact);
287
+ const initTx = await thresholdNetwork.initialize(import_sdk2.TASK_MANAGER_ADDRESS, await acl.getAddress());
288
+ await initTx.wait();
289
+ const exists = await thresholdNetwork.exists();
290
+ if (!exists) {
291
+ throw new Error("MockThresholdNetwork does not exist");
292
+ }
293
+ return thresholdNetwork;
294
+ };
295
+ var deployTestBedContract = async (hre) => {
296
+ return deployMockContractFromArtifact(hre, import_mock_contracts.TestBedArtifact);
297
+ };
298
+ var verbosity = "v";
299
+ var log = (minVerbosity, message, indent = 1) => {
300
+ if (verbosity === "")
301
+ return;
302
+ if (minVerbosity === "vv" && verbosity !== "vv")
303
+ return;
304
+ console.log(import_chalk.default.green(`${" ".repeat(indent)}\u2713 ${message}`));
305
+ };
306
+ var logEmpty = (minVerbosity = "v") => {
307
+ if (verbosity === "")
308
+ return;
309
+ if (minVerbosity === "vv" && verbosity !== "vv")
310
+ return;
311
+ console.log("");
312
+ };
313
+ var logWarning = (message, indent = 1) => {
314
+ if (verbosity === "")
315
+ return;
316
+ console.log(import_chalk.default.bold(import_chalk.default.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
317
+ };
318
+ var logDeployment = (contractName, address) => {
319
+ if (verbosity !== "vv")
320
+ return;
321
+ const paddedName = `${contractName} deployed`.padEnd(36);
322
+ console.log(import_chalk.default.green(` \u2713 ${paddedName} ${import_chalk.default.bold(address)}`));
323
+ };
324
+
325
+ // src/logging.ts
326
+ var import_chalk2 = __toESM(require("chalk"));
327
+ var import_types3 = require("hardhat/types");
328
+ var import_mock_contracts2 = require("@cofhe/mock-contracts");
329
+ var getLoggingEnabled = async (hre) => {
330
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
331
+ return taskManager.logOps();
332
+ };
333
+ var setLoggingEnabled = async (hre, enabled) => {
334
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
335
+ const tx = await taskManager.setLogOps(enabled);
336
+ await tx.wait();
337
+ };
338
+ var printLogsEnabledMessage = (closureMessage) => {
339
+ console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
340
+ console.log(`\u2502 [COFHE-MOCKS] \u2502 ${closureMessage}`);
341
+ console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
342
+ };
343
+ var printLogsBlockEnd = () => {
344
+ console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
345
+ };
346
+ var mock_setLoggingEnabled = async (hre, enabled, closureName) => {
347
+ try {
348
+ const initiallyEnabled = await getLoggingEnabled(hre);
349
+ await setLoggingEnabled(hre, enabled);
350
+ if (enabled) {
351
+ printLogsEnabledMessage(`${closureName ? `"${import_chalk2.default.bold(closureName)}" logs:` : "Logs:"}`);
352
+ }
353
+ if (!enabled && initiallyEnabled) {
354
+ printLogsBlockEnd();
355
+ }
356
+ } catch (error) {
357
+ console.log(import_chalk2.default.red("mock_setLoggingEnabled error"), error);
358
+ }
359
+ };
360
+ var mock_withLogs = async (hre, closureName, closure) => {
361
+ const initiallyEnabled = await getLoggingEnabled(hre);
362
+ await setLoggingEnabled(hre, true);
363
+ printLogsEnabledMessage(`"${import_chalk2.default.bold(closureName)}" logs:`);
364
+ try {
365
+ await closure();
366
+ } finally {
367
+ printLogsBlockEnd();
368
+ if (!initiallyEnabled) {
369
+ await setLoggingEnabled(hre, false);
370
+ }
371
+ }
372
+ };
373
+
374
+ // src/index.ts
375
+ var import_chains = require("@cofhe/sdk/chains");
376
+ var import_mock_contracts3 = require("@cofhe/mock-contracts");
377
+ (0, import_config.extendConfig)((config, userConfig) => {
378
+ if (userConfig.networks && userConfig.networks.localcofhe) {
379
+ return;
380
+ }
381
+ config.networks.localcofhe = {
382
+ gas: "auto",
383
+ gasMultiplier: 1.2,
384
+ gasPrice: "auto",
385
+ timeout: 1e4,
386
+ httpHeaders: {},
387
+ url: "http://127.0.0.1:42069",
388
+ accounts: [
389
+ "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
390
+ "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
391
+ "0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
392
+ "0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6"
393
+ ]
394
+ };
395
+ if (!userConfig.networks?.["eth-sepolia"]) {
396
+ config.networks["eth-sepolia"] = {
397
+ url: process.env.SEPOLIA_RPC_URL ?? "https://ethereum-sepolia.publicnode.com",
398
+ accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
399
+ chainId: 11155111,
400
+ gas: "auto",
401
+ gasMultiplier: 1.2,
402
+ gasPrice: "auto",
403
+ timeout: 6e4,
404
+ httpHeaders: {}
405
+ };
406
+ }
407
+ if (!userConfig.networks?.["arb-sepolia"]) {
408
+ config.networks["arb-sepolia"] = {
409
+ url: process.env.ARBITRUM_SEPOLIA_RPC_URL ?? "https://sepolia-rollup.arbitrum.io/rpc",
410
+ accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
411
+ chainId: 421614,
412
+ gas: "auto",
413
+ gasMultiplier: 1.2,
414
+ gasPrice: "auto",
415
+ timeout: 6e4,
416
+ httpHeaders: {}
417
+ };
418
+ }
419
+ config.cofhe = {
420
+ logMocks: userConfig.cofhe?.logMocks ?? false,
421
+ gasWarning: userConfig.cofhe?.gasWarning ?? false,
422
+ mocksDeployVerbosity: userConfig.cofhe?.mocksDeployVerbosity ?? "v"
423
+ };
424
+ });
425
+ (0, import_config.task)(TASK_COFHE_USE_FAUCET, "Fund an account from the funder").addOptionalParam("address", "Address to fund", void 0, import_config.types.string).setAction(async ({ address }, hre) => {
426
+ const { network } = hre;
427
+ const { name: networkName } = network;
428
+ if (networkName !== "localcofhe") {
429
+ console.info(import_chalk3.default.yellow(`Programmatic faucet only supported for localcofhe`));
430
+ return;
431
+ }
432
+ if (!address) {
433
+ console.info(import_chalk3.default.red(`Failed to get address to fund`));
434
+ return;
435
+ }
436
+ console.info(import_chalk3.default.green(`Getting funds from faucet for ${address}`));
437
+ try {
438
+ await localcofheFundAccount(hre, address);
439
+ } catch (e) {
440
+ console.info(import_chalk3.default.red(`failed to get funds from localcofhe for ${address}: ${e}`));
441
+ }
442
+ });
443
+ (0, import_config.task)(TASK_COFHE_MOCKS_DEPLOY, "Deploys the mock contracts on the Hardhat network").addOptionalParam("deployTestBed", "Whether to deploy the test bed", true, import_config.types.boolean).setAction(async ({ deployTestBed }, hre) => {
444
+ await deployMocks(hre, {
445
+ deployTestBed: deployTestBed ?? true,
446
+ gasWarning: hre.config.cofhe.gasWarning ?? true,
447
+ mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
448
+ });
449
+ });
450
+ (0, import_config.task)(import_task_names.TASK_TEST, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
451
+ const skipAutoDeploy = (() => {
452
+ const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
453
+ const normalized = raw.trim().toLowerCase();
454
+ return normalized === "1" || normalized === "true" || normalized === "yes";
455
+ })();
456
+ if (!skipAutoDeploy) {
457
+ await deployMocks(hre, {
458
+ deployTestBed: true,
459
+ gasWarning: hre.config.cofhe.gasWarning ?? true,
460
+ mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
461
+ });
462
+ }
463
+ return runSuper();
464
+ });
465
+ (0, import_config.task)(import_task_names.TASK_NODE, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
466
+ const skipAutoDeploy = (() => {
467
+ const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
468
+ const normalized = raw.trim().toLowerCase();
469
+ return normalized === "1" || normalized === "true" || normalized === "yes";
470
+ })();
471
+ if (!skipAutoDeploy) {
472
+ await deployMocks(hre, {
473
+ deployTestBed: true,
474
+ gasWarning: hre.config.cofhe.gasWarning ?? true,
475
+ mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
476
+ });
477
+ }
478
+ return runSuper();
479
+ });
480
+ (0, import_config.task)(TASK_COFHE_MOCKS_SET_LOG_OPS, "Set logging for the Mock CoFHE contracts").addParam("enable", "Whether to enable logging", false, import_config.types.boolean).setAction(async ({ enable }, hre) => {
481
+ await mock_setLoggingEnabled(hre, enable);
482
+ });
483
+ function buildHardhatPluginMocksConfig(mocksConfig) {
484
+ return {
485
+ ...mocksConfig,
486
+ encryptDelay: mocksConfig?.encryptDelay ?? 0
487
+ };
488
+ }
489
+ (0, import_config.extendEnvironment)((hre) => {
490
+ hre.cofhe = {
491
+ createConfig: async (config) => {
492
+ const zkvHhSigner = await hre.ethers.getImpersonatedSigner(import_sdk3.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
493
+ const { walletClient: zkvWalletClient } = await (0, import_adapters.HardhatSignerAdapter)(zkvHhSigner);
494
+ const configWithZkvWalletClient = {
495
+ environment: "hardhat",
496
+ ...config,
497
+ mocks: buildHardhatPluginMocksConfig(config.mocks),
498
+ _internal: {
499
+ ...config._internal,
500
+ zkvWalletClient
501
+ }
502
+ };
503
+ return (0, import_node.createCofheConfig)(configWithZkvWalletClient);
504
+ },
505
+ createClient: (config) => {
506
+ return (0, import_node.createCofheClient)(config);
507
+ },
508
+ hardhatSignerAdapter: async (signer) => {
509
+ return (0, import_adapters.HardhatSignerAdapter)(signer);
510
+ },
511
+ connectWithHardhatSigner: async (client, signer) => {
512
+ const { publicClient, walletClient } = await (0, import_adapters.HardhatSignerAdapter)(signer);
513
+ return client.connect(publicClient, walletClient);
514
+ },
515
+ createClientWithBatteries: async (signer) => {
516
+ if (!signer) {
517
+ [signer] = await hre.ethers.getSigners();
518
+ }
519
+ const config = await hre.cofhe.createConfig({
520
+ environment: "hardhat",
521
+ supportedChains: [import_chains.hardhat]
522
+ });
523
+ const client = hre.cofhe.createClient(config);
524
+ await hre.cofhe.connectWithHardhatSigner(client, signer);
525
+ await client.permits.createSelf({
526
+ issuer: signer.address
527
+ });
528
+ return client;
529
+ },
530
+ mocks: {
531
+ withLogs: async (closureName, closure) => {
532
+ return mock_withLogs(hre, closureName, closure);
533
+ },
534
+ enableLogs: async (closureName) => {
535
+ return mock_setLoggingEnabled(hre, true, closureName);
536
+ },
537
+ disableLogs: async () => {
538
+ return mock_setLoggingEnabled(hre, false);
539
+ },
540
+ deployMocks: async (options = {}) => {
541
+ return deployMocks(hre, { mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity, ...options });
542
+ },
543
+ getPlaintext: async (ctHash) => {
544
+ const [signer] = await hre.ethers.getSigners();
545
+ return mock_getPlaintext(signer.provider, ctHash);
546
+ },
547
+ expectPlaintext: async (ctHash, expectedValue) => {
548
+ const [signer] = await hre.ethers.getSigners();
549
+ return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
550
+ },
551
+ getMockTaskManager: async () => getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact),
552
+ getMockACL: async () => {
553
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact);
554
+ const aclAddress = await taskManager.acl();
555
+ return hre.ethers.getContractAt([...import_mock_contracts3.MockACLArtifact.abi], aclAddress);
556
+ },
557
+ getMockThresholdNetwork: async () => getFixedMockContract(hre, import_mock_contracts3.MockThresholdNetworkArtifact),
558
+ getMockZkVerifier: async () => getFixedMockContract(hre, import_mock_contracts3.MockZkVerifierArtifact),
559
+ getTestBed: async () => getFixedMockContract(hre, import_mock_contracts3.TestBedArtifact)
560
+ }
561
+ };
562
+ });
563
+ // Annotate the CommonJS export names for ESM import in node:
564
+ 0 && (module.exports = {
565
+ TASK_COFHE_MOCKS_DEPLOY,
566
+ TASK_COFHE_MOCKS_SET_LOG_OPS,
567
+ TASK_COFHE_USE_FAUCET,
568
+ buildHardhatPluginMocksConfig,
569
+ deployMockContractFromArtifact,
570
+ deployMocks,
571
+ getFixedMockContract,
572
+ localcofheFundAccount,
573
+ localcofheFundWalletIfNeeded,
574
+ mock_expectPlaintext,
575
+ mock_getPlaintext,
576
+ mock_getPlaintextExists,
577
+ mock_setLoggingEnabled,
578
+ mock_withLogs
579
+ });
580
+ //# sourceMappingURL=index.js.map