@cofhe/hardhat-plugin 0.2.0 → 0.3.0

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 CHANGED
@@ -30,12 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- MockACLArtifact: () => import_mock_contracts4.MockACLArtifact,
34
- MockQueryDecrypterArtifact: () => import_mock_contracts4.MockQueryDecrypterArtifact,
35
- MockTaskManagerArtifact: () => import_mock_contracts4.MockTaskManagerArtifact,
36
- MockZkVerifierArtifact: () => import_mock_contracts4.MockZkVerifierArtifact,
37
- TestBedArtifact: () => import_mock_contracts4.TestBedArtifact,
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
38
  deployMocks: () => deployMocks,
39
+ getFixedMockContract: () => getFixedMockContract,
39
40
  localcofheFundAccount: () => localcofheFundAccount,
40
41
  localcofheFundWalletIfNeeded: () => localcofheFundWalletIfNeeded,
41
42
  mock_expectPlaintext: () => mock_expectPlaintext,
@@ -50,7 +51,7 @@ var import_viem = require("viem");
50
51
  var import_config = require("hardhat/config");
51
52
  var import_task_names = require("hardhat/builtin-tasks/task-names");
52
53
  var import_signers = require("@nomicfoundation/hardhat-ethers/signers");
53
- var import_sdk2 = require("@cofhe/sdk");
54
+ var import_sdk3 = require("@cofhe/sdk");
54
55
  var import_node = require("@cofhe/sdk/node");
55
56
  var import_adapters = require("@cofhe/sdk/adapters");
56
57
 
@@ -110,170 +111,199 @@ async function localcofheFundWalletIfNeeded(hre, walletAddress) {
110
111
  var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
111
112
  var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
112
113
  var TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
113
- var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
114
- var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000000100";
115
- var MOCKS_QUERY_DECRYPTER_ADDRESS = "0x0000000000000000000000000000000000000200";
116
- var TEST_BED_ADDRESS = "0x0000000000000000000000000000000000000300";
117
114
 
118
115
  // src/deploy.ts
119
116
  var import_types2 = require("hardhat/types");
120
117
  var import_chalk = __toESM(require("chalk"));
121
- var import_ethers = require("ethers");
118
+ var import_ethers2 = require("ethers");
122
119
  var import_mock_contracts = require("@cofhe/mock-contracts");
120
+ var import_sdk2 = require("@cofhe/sdk");
121
+
122
+ // src/utils.ts
123
123
  var import_sdk = require("@cofhe/sdk");
124
- var deployMockTaskManager = async (hre) => {
125
- const [signer] = await hre.ethers.getSigners();
126
- await hardhatSetCode(hre, TASK_MANAGER_ADDRESS, import_mock_contracts.MockTaskManagerArtifact.deployedBytecode);
127
- const taskManager = await hre.ethers.getContractAt(import_mock_contracts.MockTaskManagerArtifact.abi, TASK_MANAGER_ADDRESS);
128
- const initTx = await taskManager.initialize(signer.address);
129
- await initTx.wait();
130
- const tmExists = await taskManager.exists();
131
- if (!tmExists) {
132
- throw new Error("MockTaskManager does not exist");
133
- }
134
- return taskManager;
135
- };
136
- var deployMockACL = async (hre) => {
137
- const acl = await ethersDeployContract(hre, import_mock_contracts.MockACLArtifact.abi, import_mock_contracts.MockACLArtifact.bytecode);
138
- const exists = await acl.exists();
139
- if (!exists) {
140
- logError("MockACL does not exist", 2);
141
- throw new Error("MockACL does not exist");
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);
142
131
  }
143
- return acl;
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;
144
139
  };
145
- var deployMockZkVerifier = async (hre) => {
146
- await hardhatSetCode(hre, MOCKS_ZK_VERIFIER_ADDRESS, import_mock_contracts.MockZkVerifierArtifact.deployedBytecode);
147
- const zkVerifier = await hre.ethers.getContractAt(import_mock_contracts.MockZkVerifierArtifact.abi, MOCKS_ZK_VERIFIER_ADDRESS);
148
- const zkVerifierExists = await zkVerifier.exists();
149
- if (!zkVerifierExists) {
150
- logError("MockZkVerifier does not exist", 2);
151
- throw new Error("MockZkVerifier does not exist");
140
+ var getFixedMockContract = async (hre, artifact) => {
141
+ if (!artifact.isFixed) {
142
+ throw new Error("Artifact is not fixed");
152
143
  }
153
- return zkVerifier;
144
+ return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
154
145
  };
155
- var deployMockQueryDecrypter = async (hre, acl) => {
156
- await hardhatSetCode(hre, MOCKS_QUERY_DECRYPTER_ADDRESS, import_mock_contracts.MockQueryDecrypterArtifact.deployedBytecode);
157
- const queryDecrypter = await hre.ethers.getContractAt(import_mock_contracts.MockQueryDecrypterArtifact.abi, MOCKS_QUERY_DECRYPTER_ADDRESS);
158
- const initTx = await queryDecrypter.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());
159
- await initTx.wait();
160
- const queryDecrypterExists = await queryDecrypter.exists();
161
- if (!queryDecrypterExists) {
162
- logError("MockQueryDecrypter does not exist", 2);
163
- throw new Error("MockQueryDecrypter does not exist");
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`);
164
151
  }
165
- return queryDecrypter;
152
+ return isTestnet;
166
153
  };
167
- var deployTestBedContract = async (hre) => {
168
- await hardhatSetCode(hre, TEST_BED_ADDRESS, import_mock_contracts.TestBedArtifact.deployedBytecode);
169
- const testBed = await hre.ethers.getContractAt(import_mock_contracts.TestBedArtifact.abi, TEST_BED_ADDRESS);
170
- await testBed.waitForDeployment();
171
- return testBed;
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(ctHash);
163
+ return plaintext;
172
164
  };
173
- var fundZkVerifierSigner = async (hre) => {
174
- const zkVerifierSigner = await hre.ethers.getSigner(import_sdk.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
175
- await hre.network.provider.send("hardhat_setBalance", [
176
- zkVerifierSigner.address,
177
- "0x" + hre.ethers.parseEther("10").toString(16)
178
- ]);
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(ctHash);
174
+ return plaintextExists;
179
175
  };
180
- var setTaskManagerACL = async (taskManager, acl) => {
181
- const setAclTx = await taskManager.setACLContract(await acl.getAddress());
182
- await setAclTx.wait();
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
183
  };
184
+
185
+ // src/deploy.ts
184
186
  var deployMocks = async (hre, options = {
185
187
  deployTestBed: true,
186
188
  gasWarning: true,
187
189
  silent: false
188
190
  }) => {
189
- const isHardhat = await checkNetworkAndSkip(hre);
190
- if (!isHardhat)
191
+ const isHardhat = await getIsHardhat(hre);
192
+ if (!isHardhat) {
193
+ logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);
191
194
  return;
192
- const logEmptyIfNoisy = () => {
193
- if (!options.silent) {
194
- logEmpty();
195
- }
196
- };
197
- const logSuccessIfNoisy = (message, indent = 0) => {
198
- if (!options.silent) {
199
- logSuccess(message, indent);
200
- }
201
- };
202
- const logDeploymentIfNoisy = (contractName, address) => {
203
- if (!options.silent) {
204
- logDeployment(contractName, address);
205
- }
206
- };
207
- const logWarningIfNoisy = (message, indent = 0) => {
208
- if (!options.silent) {
209
- logWarning(message, indent);
210
- }
211
- };
212
- logEmptyIfNoisy();
213
- logSuccessIfNoisy(import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
214
- logEmptyIfNoisy();
195
+ }
196
+ isSilent = options.silent ?? false;
197
+ logEmpty();
198
+ logSuccess(import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
199
+ logEmpty();
215
200
  const taskManager = await deployMockTaskManager(hre);
216
- logDeploymentIfNoisy("MockTaskManager", await taskManager.getAddress());
201
+ logDeployment("MockTaskManager", await taskManager.getAddress());
217
202
  const acl = await deployMockACL(hre);
218
- logDeploymentIfNoisy("MockACL", await acl.getAddress());
219
- await setTaskManagerACL(taskManager, acl);
220
- logSuccessIfNoisy("ACL address set in TaskManager", 2);
203
+ logDeployment("MockACL", await acl.getAddress());
204
+ await linkTaskManagerAndACL(taskManager, acl);
205
+ logSuccess("ACL address set in TaskManager", 2);
221
206
  await fundZkVerifierSigner(hre);
222
- logSuccessIfNoisy(`ZkVerifier signer (${import_sdk.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
223
- const zkVerifierSignerBalance = await hre.ethers.provider.getBalance(import_sdk.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
224
- logSuccessIfNoisy(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
207
+ logSuccess(`ZkVerifier signer (${import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
208
+ const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);
209
+ logSuccess(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
225
210
  const zkVerifier = await deployMockZkVerifier(hre);
226
- logDeploymentIfNoisy("MockZkVerifier", await zkVerifier.getAddress());
227
- const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
228
- logDeploymentIfNoisy("MockQueryDecrypter", await queryDecrypter.getAddress());
211
+ logDeployment("MockZkVerifier", await zkVerifier.getAddress());
212
+ const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);
213
+ logDeployment("MockThresholdNetwork", await thresholdNetwork.getAddress());
229
214
  if (options.deployTestBed) {
230
- logSuccessIfNoisy("TestBed deployment enabled", 2);
215
+ logSuccess("TestBed deployment enabled", 2);
231
216
  const testBed = await deployTestBedContract(hre);
232
- logDeploymentIfNoisy("TestBed", await testBed.getAddress());
217
+ logDeployment("TestBed", await testBed.getAddress());
233
218
  }
234
- logEmptyIfNoisy();
235
- logSuccessIfNoisy(import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
219
+ logEmpty();
220
+ logSuccess(import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
236
221
  if (options.gasWarning) {
237
- logEmptyIfNoisy();
238
- logWarningIfNoisy(
222
+ logEmpty();
223
+ logWarning(
239
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/sdk.gasWarning' to false in your hardhat config",
240
225
  0
241
226
  );
242
227
  }
243
- logEmptyIfNoisy();
228
+ logEmpty();
244
229
  };
245
- var hardhatSetCode = async (hre, address, bytecode) => {
246
- await hre.network.provider.send("hardhat_setCode", [address, bytecode]);
230
+ var getIsHardhat = async (hre) => {
231
+ return hre.network.name === "hardhat";
247
232
  };
248
- var ethersDeployContract = async (hre, abi, bytecode) => {
233
+ var deployMockTaskManager = async (hre) => {
249
234
  const [signer] = await hre.ethers.getSigners();
250
- const factory = new hre.ethers.ContractFactory(abi, bytecode, signer);
251
- const contract = await factory.deploy(
252
- /* constructor args */
253
- );
254
- await contract.waitForDeployment();
255
- return contract;
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 deployMockZkVerifier = async (hre) => {
268
+ const zkVerifier = await deployMockContractFromArtifact(hre, import_mock_contracts.MockZkVerifierArtifact);
269
+ const zkVerifierExists = await zkVerifier.exists();
270
+ if (!zkVerifierExists) {
271
+ throw new Error("MockZkVerifier does not exist");
272
+ }
273
+ return zkVerifier;
274
+ };
275
+ var deployMockThresholdNetwork = async (hre, acl) => {
276
+ const thresholdNetwork = await deployMockContractFromArtifact(hre, import_mock_contracts.MockThresholdNetworkArtifact);
277
+ const initTx = await thresholdNetwork.initialize(import_sdk2.TASK_MANAGER_ADDRESS, await acl.getAddress());
278
+ await initTx.wait();
279
+ const exists = await thresholdNetwork.exists();
280
+ if (!exists) {
281
+ throw new Error("MockThresholdNetwork does not exist");
282
+ }
283
+ return thresholdNetwork;
256
284
  };
257
- var checkNetworkAndSkip = async (hre) => {
258
- const network = hre.network.name;
259
- const isHardhat = network === "hardhat";
260
- if (!isHardhat)
261
- logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${network}`, 0);
262
- return isHardhat;
285
+ var deployTestBedContract = async (hre) => {
286
+ return deployMockContractFromArtifact(hre, import_mock_contracts.TestBedArtifact);
263
287
  };
288
+ var isSilent = false;
264
289
  var logEmpty = () => {
290
+ if (isSilent)
291
+ return;
265
292
  console.log("");
266
293
  };
267
294
  var logSuccess = (message, indent = 1) => {
295
+ if (isSilent)
296
+ return;
268
297
  console.log(import_chalk.default.green(`${" ".repeat(indent)}\u2713 ${message}`));
269
298
  };
270
299
  var logWarning = (message, indent = 1) => {
300
+ if (isSilent)
301
+ return;
271
302
  console.log(import_chalk.default.bold(import_chalk.default.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
272
303
  };
273
- var logError = (message, indent = 1) => {
274
- console.log(import_chalk.default.red(`${" ".repeat(indent)}\u2717 ${message}`));
275
- };
276
304
  var logDeployment = (contractName, address) => {
305
+ if (isSilent)
306
+ return;
277
307
  const paddedName = `${contractName} deployed`.padEnd(36);
278
308
  logSuccess(`${paddedName} ${import_chalk.default.bold(address)}`);
279
309
  };
@@ -282,17 +312,14 @@ var logDeployment = (contractName, address) => {
282
312
  var import_chalk2 = __toESM(require("chalk"));
283
313
  var import_types3 = require("hardhat/types");
284
314
  var import_mock_contracts2 = require("@cofhe/mock-contracts");
285
- var getDeployedMockTaskManager = async (hre) => {
286
- const taskManager = await hre.ethers.getContractAt(import_mock_contracts2.MockTaskManagerArtifact.abi, TASK_MANAGER_ADDRESS);
287
- return taskManager;
288
- };
289
315
  var getLoggingEnabled = async (hre) => {
290
- const taskManager = await getDeployedMockTaskManager(hre);
291
- return await taskManager.logOps();
316
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
317
+ return taskManager.logOps();
292
318
  };
293
319
  var setLoggingEnabled = async (hre, enabled) => {
294
- const taskManager = await getDeployedMockTaskManager(hre);
295
- await taskManager.setLogOps(enabled);
320
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
321
+ const tx = await taskManager.setLogOps(enabled);
322
+ await tx.wait();
296
323
  };
297
324
  var printLogsEnabledMessage = (closureMessage) => {
298
325
  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");
@@ -327,53 +354,9 @@ var mock_withLogs = async (hre, closureName, closure) => {
327
354
  }
328
355
  };
329
356
 
330
- // src/utils.ts
331
- var import_chai = require("chai");
332
- var import_ethers2 = require("ethers");
333
- var import_hardhat_ethers_provider = require("@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider");
334
- var mock_checkIsTestnet = async (fnName, provider) => {
335
- const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
336
- const isTestnet = bytecode.length === 0;
337
- if (isTestnet) {
338
- console.log(`${fnName} - skipped on non-testnet chain`);
339
- }
340
- return isTestnet;
341
- };
342
- var mock_getPlaintext = async (provider, ctHash) => {
343
- if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
344
- return;
345
- const taskManager = new import_ethers2.ethers.Contract(
346
- TASK_MANAGER_ADDRESS,
347
- ["function mockStorage(uint256) view returns (uint256)"],
348
- provider
349
- );
350
- const plaintext = await taskManager.mockStorage(ctHash);
351
- return plaintext;
352
- };
353
- var mock_getPlaintextExists = async (provider, ctHash) => {
354
- if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
355
- return;
356
- const taskManager = new import_ethers2.ethers.Contract(
357
- TASK_MANAGER_ADDRESS,
358
- ["function inMockStorage(uint256) view returns (bool)"],
359
- provider
360
- );
361
- const plaintextExists = await taskManager.inMockStorage(ctHash);
362
- return plaintextExists;
363
- };
364
- var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
365
- if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
366
- return;
367
- const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
368
- (0, import_chai.expect)(plaintextExists).equal(true, "Plaintext does not exist");
369
- const plaintext = await mock_getPlaintext(provider, ctHash);
370
- (0, import_chai.expect)(plaintext).equal(expectedValue, "Plaintext value is incorrect");
371
- };
372
-
373
357
  // src/index.ts
374
- var import_mock_contracts3 = require("@cofhe/mock-contracts");
375
358
  var import_chains = require("@cofhe/sdk/chains");
376
- var import_mock_contracts4 = require("@cofhe/mock-contracts");
359
+ var import_mock_contracts3 = require("@cofhe/mock-contracts");
377
360
  (0, import_config.extendConfig)((config, userConfig) => {
378
361
  if (userConfig.networks && userConfig.networks.localcofhe) {
379
362
  return;
@@ -416,9 +399,9 @@ var import_mock_contracts4 = require("@cofhe/mock-contracts");
416
399
  httpHeaders: {}
417
400
  };
418
401
  }
419
- config.cofhesdk = {
420
- logMocks: userConfig.cofhesdk?.logMocks ?? true,
421
- gasWarning: userConfig.cofhesdk?.gasWarning ?? true
402
+ config.cofhe = {
403
+ logMocks: userConfig.cofhe?.logMocks ?? true,
404
+ gasWarning: userConfig.cofhe?.gasWarning ?? true
422
405
  };
423
406
  });
424
407
  (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) => {
@@ -442,44 +425,65 @@ var import_mock_contracts4 = require("@cofhe/mock-contracts");
442
425
  (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).addOptionalParam("silent", "Whether to suppress output", false, import_config.types.boolean).setAction(async ({ deployTestBed, silent }, hre) => {
443
426
  await deployMocks(hre, {
444
427
  deployTestBed: deployTestBed ?? true,
445
- gasWarning: hre.config.cofhesdk.gasWarning ?? true,
428
+ gasWarning: hre.config.cofhe.gasWarning ?? true,
446
429
  silent: silent ?? false
447
430
  });
448
431
  });
449
432
  (0, import_config.task)(import_task_names.TASK_TEST, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
450
- await deployMocks(hre, {
451
- deployTestBed: true,
452
- gasWarning: hre.config.cofhesdk.gasWarning ?? true
453
- });
433
+ const skipAutoDeploy = (() => {
434
+ const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
435
+ const normalized = raw.trim().toLowerCase();
436
+ return normalized === "1" || normalized === "true" || normalized === "yes";
437
+ })();
438
+ if (!skipAutoDeploy) {
439
+ await deployMocks(hre, {
440
+ deployTestBed: true,
441
+ gasWarning: hre.config.cofhe.gasWarning ?? true
442
+ });
443
+ }
454
444
  return runSuper();
455
445
  });
456
446
  (0, import_config.task)(import_task_names.TASK_NODE, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
457
- await deployMocks(hre, {
458
- deployTestBed: true,
459
- gasWarning: hre.config.cofhesdk.gasWarning ?? true
460
- });
447
+ const skipAutoDeploy = (() => {
448
+ const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
449
+ const normalized = raw.trim().toLowerCase();
450
+ return normalized === "1" || normalized === "true" || normalized === "yes";
451
+ })();
452
+ if (!skipAutoDeploy) {
453
+ await deployMocks(hre, {
454
+ deployTestBed: true,
455
+ gasWarning: hre.config.cofhe.gasWarning ?? true
456
+ });
457
+ }
461
458
  return runSuper();
462
459
  });
463
460
  (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) => {
464
461
  await mock_setLoggingEnabled(hre, enable);
465
462
  });
463
+ function buildHardhatPluginMocksConfig(mocksConfig) {
464
+ return {
465
+ ...mocksConfig,
466
+ encryptDelay: mocksConfig?.encryptDelay ?? 0
467
+ };
468
+ }
466
469
  (0, import_config.extendEnvironment)((hre) => {
467
- hre.cofhesdk = {
468
- createCofhesdkConfig: async (config) => {
469
- const zkvHhSigner = await hre.ethers.getImpersonatedSigner(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
470
+ hre.cofhe = {
471
+ createConfig: async (config) => {
472
+ const zkvHhSigner = await hre.ethers.getImpersonatedSigner(import_sdk3.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
470
473
  const { walletClient: zkvWalletClient } = await (0, import_adapters.HardhatSignerAdapter)(zkvHhSigner);
471
474
  const configWithZkvWalletClient = {
472
475
  environment: "hardhat",
473
476
  ...config,
477
+ mocks: buildHardhatPluginMocksConfig(config.mocks),
474
478
  _internal: {
475
479
  ...config._internal,
476
480
  zkvWalletClient
477
481
  }
478
482
  };
479
- return (0, import_node.createCofhesdkConfig)(configWithZkvWalletClient);
483
+ return (0, import_node.createCofheConfig)(configWithZkvWalletClient);
480
484
  },
481
- createCofhesdkClient: (config) => {
482
- return (0, import_node.createCofhesdkClient)(config);
485
+ createClient: (config) => {
486
+ return (0, import_node.createCofheClient)(config);
483
487
  },
484
488
  hardhatSignerAdapter: async (signer) => {
485
489
  return (0, import_adapters.HardhatSignerAdapter)(signer);
@@ -488,16 +492,16 @@ var import_mock_contracts4 = require("@cofhe/mock-contracts");
488
492
  const { publicClient, walletClient } = await (0, import_adapters.HardhatSignerAdapter)(signer);
489
493
  return client.connect(publicClient, walletClient);
490
494
  },
491
- createBatteriesIncludedCofhesdkClient: async (signer) => {
495
+ createClientWithBatteries: async (signer) => {
492
496
  if (!signer) {
493
497
  [signer] = await hre.ethers.getSigners();
494
498
  }
495
- const config = await hre.cofhesdk.createCofhesdkConfig({
499
+ const config = await hre.cofhe.createConfig({
496
500
  environment: "hardhat",
497
501
  supportedChains: [import_chains.hardhat]
498
502
  });
499
- const client = hre.cofhesdk.createCofhesdkClient(config);
500
- await hre.cofhesdk.connectWithHardhatSigner(client, signer);
503
+ const client = hre.cofhe.createClient(config);
504
+ await hre.cofhe.connectWithHardhatSigner(client, signer);
501
505
  await client.permits.createSelf({
502
506
  issuer: signer.address
503
507
  });
@@ -524,34 +528,27 @@ var import_mock_contracts4 = require("@cofhe/mock-contracts");
524
528
  const [signer] = await hre.ethers.getSigners();
525
529
  return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
526
530
  },
527
- getMockTaskManager: async () => {
528
- return await hre.ethers.getContractAt(import_mock_contracts3.MockTaskManagerArtifact.abi, import_mock_contracts3.MockTaskManagerArtifact.fixedAddress);
529
- },
531
+ getMockTaskManager: async () => getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact),
530
532
  getMockACL: async () => {
531
- const tm = await hre.ethers.getContractAt(import_mock_contracts3.MockTaskManagerArtifact.abi, import_mock_contracts3.MockTaskManagerArtifact.fixedAddress);
532
- const aclAddress = await tm.acl();
533
- return await hre.ethers.getContractAt(import_mock_contracts3.MockACLArtifact.abi, aclAddress);
534
- },
535
- getMockQueryDecrypter: async () => {
536
- return await hre.ethers.getContractAt(import_mock_contracts3.MockQueryDecrypterArtifact.abi, import_mock_contracts3.MockQueryDecrypterArtifact.fixedAddress);
533
+ const taskManager = await getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact);
534
+ const aclAddress = await taskManager.acl();
535
+ return hre.ethers.getContractAt(import_mock_contracts3.MockACLArtifact.abi, aclAddress);
537
536
  },
538
- getMockZkVerifier: async () => {
539
- return await hre.ethers.getContractAt(import_mock_contracts3.MockZkVerifierArtifact.abi, import_mock_contracts3.MockZkVerifierArtifact.fixedAddress);
540
- },
541
- getTestBed: async () => {
542
- return await hre.ethers.getContractAt(import_mock_contracts3.TestBedArtifact.abi, import_mock_contracts3.TestBedArtifact.fixedAddress);
543
- }
537
+ getMockThresholdNetwork: async () => getFixedMockContract(hre, import_mock_contracts3.MockThresholdNetworkArtifact),
538
+ getMockZkVerifier: async () => getFixedMockContract(hre, import_mock_contracts3.MockZkVerifierArtifact),
539
+ getTestBed: async () => getFixedMockContract(hre, import_mock_contracts3.TestBedArtifact)
544
540
  }
545
541
  };
546
542
  });
547
543
  // Annotate the CommonJS export names for ESM import in node:
548
544
  0 && (module.exports = {
549
- MockACLArtifact,
550
- MockQueryDecrypterArtifact,
551
- MockTaskManagerArtifact,
552
- MockZkVerifierArtifact,
553
- TestBedArtifact,
545
+ TASK_COFHE_MOCKS_DEPLOY,
546
+ TASK_COFHE_MOCKS_SET_LOG_OPS,
547
+ TASK_COFHE_USE_FAUCET,
548
+ buildHardhatPluginMocksConfig,
549
+ deployMockContractFromArtifact,
554
550
  deployMocks,
551
+ getFixedMockContract,
555
552
  localcofheFundAccount,
556
553
  localcofheFundWalletIfNeeded,
557
554
  mock_expectPlaintext,