@cofhe/hardhat-plugin 0.2.1 → 0.3.1

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/fund.ts","../src/consts.ts","../src/deploy.ts","../src/utils.ts","../src/logging.ts"],"sourcesContent":["/* eslint-disable no-empty-pattern */\n/* eslint-disable turbo/no-undeclared-env-vars */\nimport chalk from 'chalk';\nimport { type PublicClient, type WalletClient } from 'viem';\nimport { extendConfig, extendEnvironment, task, types } from 'hardhat/config';\nimport { TASK_TEST, TASK_NODE } from 'hardhat/builtin-tasks/task-names';\nimport { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';\nimport {\n type CofhesdkClient,\n type CofhesdkConfig,\n type CofhesdkInputConfig,\n MOCKS_ZK_VERIFIER_SIGNER_ADDRESS,\n} from '@cofhe/sdk';\nimport { createCofhesdkClient, createCofhesdkConfig } from '@cofhe/sdk/node';\nimport { HardhatSignerAdapter } from '@cofhe/sdk/adapters';\n\nimport { localcofheFundAccount } from './fund.js';\nimport { TASK_COFHE_MOCKS_DEPLOY, TASK_COFHE_MOCKS_SET_LOG_OPS, TASK_COFHE_USE_FAUCET } from './consts.js';\nimport { deployMocks, type DeployMocksArgs } from './deploy.js';\nimport { mock_setLoggingEnabled, mock_withLogs } from './logging.js';\nimport { getFixedMockContract, mock_expectPlaintext } from './utils.js';\nimport { mock_getPlaintext } from './utils.js';\nimport type { Contract } from 'ethers';\nimport { hardhat } from '@cofhe/sdk/chains';\nimport {\n MockACLArtifact,\n MockQueryDecrypterArtifact,\n MockTaskManagerArtifact,\n MockZkVerifierArtifact,\n TestBedArtifact,\n} from '@cofhe/mock-contracts';\n\n/**\n * Configuration interface for the CoFHE Hardhat plugin.\n * Allows users to configure mock logging and gas warning settings.\n */\ndeclare module 'hardhat/types/config' {\n interface HardhatUserConfig {\n cofhesdk?: {\n /** Whether to log mock operations (default: true) */\n logMocks?: boolean;\n /** Whether to show gas usage warnings for mock operations (default: true) */\n gasWarning?: boolean;\n };\n }\n\n interface HardhatConfig {\n cofhesdk: {\n /** Whether to log mock operations (default: true) */\n logMocks: boolean;\n /** Whether to show gas usage warnings for mock operations (default: true) */\n gasWarning: boolean;\n };\n }\n}\n\nextendConfig((config, userConfig) => {\n // Allow users to override the localcofhe network config\n if (userConfig.networks && userConfig.networks.localcofhe) {\n return;\n }\n\n // Default config\n config.networks.localcofhe = {\n gas: 'auto',\n gasMultiplier: 1.2,\n gasPrice: 'auto',\n timeout: 10_000,\n httpHeaders: {},\n url: 'http://127.0.0.1:42069',\n accounts: [\n '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',\n '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',\n '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',\n '0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6',\n ],\n };\n\n // Only add Sepolia config if user hasn't defined it\n if (!userConfig.networks?.['eth-sepolia']) {\n config.networks['eth-sepolia'] = {\n url: process.env.SEPOLIA_RPC_URL ?? 'https://ethereum-sepolia.publicnode.com',\n accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],\n chainId: 11155111,\n gas: 'auto',\n gasMultiplier: 1.2,\n gasPrice: 'auto',\n timeout: 60_000,\n httpHeaders: {},\n };\n }\n\n // Only add Arbitrum Sepolia config if user hasn't defined it\n if (!userConfig.networks?.['arb-sepolia']) {\n config.networks['arb-sepolia'] = {\n url: process.env.ARBITRUM_SEPOLIA_RPC_URL ?? 'https://sepolia-rollup.arbitrum.io/rpc',\n accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],\n chainId: 421614,\n gas: 'auto',\n gasMultiplier: 1.2,\n gasPrice: 'auto',\n timeout: 60_000,\n httpHeaders: {},\n };\n }\n\n // Add cofhe config\n config.cofhesdk = {\n logMocks: userConfig.cofhesdk?.logMocks ?? true,\n gasWarning: userConfig.cofhesdk?.gasWarning ?? true,\n };\n});\n\ntype UseFaucetArgs = {\n address?: string;\n};\n\ntask(TASK_COFHE_USE_FAUCET, 'Fund an account from the funder')\n .addOptionalParam('address', 'Address to fund', undefined, types.string)\n .setAction(async ({ address }: UseFaucetArgs, hre) => {\n const { network } = hre;\n const { name: networkName } = network;\n\n if (networkName !== 'localcofhe') {\n console.info(chalk.yellow(`Programmatic faucet only supported for localcofhe`));\n return;\n }\n\n if (!address) {\n console.info(chalk.red(`Failed to get address to fund`));\n return;\n }\n\n console.info(chalk.green(`Getting funds from faucet for ${address}`));\n\n try {\n await localcofheFundAccount(hre, address);\n } catch (e) {\n console.info(chalk.red(`failed to get funds from localcofhe for ${address}: ${e}`));\n }\n });\n\n// DEPLOY TASKS\n\ntask(TASK_COFHE_MOCKS_DEPLOY, 'Deploys the mock contracts on the Hardhat network')\n .addOptionalParam('deployTestBed', 'Whether to deploy the test bed', true, types.boolean)\n .addOptionalParam('silent', 'Whether to suppress output', false, types.boolean)\n .setAction(async ({ deployTestBed, silent }: DeployMocksArgs, hre) => {\n await deployMocks(hre, {\n deployTestBed: deployTestBed ?? true,\n gasWarning: hre.config.cofhesdk.gasWarning ?? true,\n silent: silent ?? false,\n });\n });\n\ntask(TASK_TEST, 'Deploy mock contracts on hardhat').setAction(async ({}, hre, runSuper) => {\n await deployMocks(hre, {\n deployTestBed: true,\n gasWarning: hre.config.cofhesdk.gasWarning ?? true,\n });\n return runSuper();\n});\n\ntask(TASK_NODE, 'Deploy mock contracts on hardhat').setAction(async ({}, hre, runSuper) => {\n await deployMocks(hre, {\n deployTestBed: true,\n gasWarning: hre.config.cofhesdk.gasWarning ?? true,\n });\n return runSuper();\n});\n\n// SET LOG OPS\n\ntask(TASK_COFHE_MOCKS_SET_LOG_OPS, 'Set logging for the Mock CoFHE contracts')\n .addParam('enable', 'Whether to enable logging', false, types.boolean)\n .setAction(async ({ enable }, hre) => {\n await mock_setLoggingEnabled(hre, enable);\n });\n\n// MOCK UTILS\n\nexport * from './consts.js';\nexport * from './utils.js';\nexport * from './fund.js';\nexport * from './logging.js';\nexport * from './deploy.js';\n\n/**\n * Runtime environment extensions for the CoFHE Hardhat plugin.\n * Provides access to CoFHE initialization, environment checks, and mock utilities.\n */\ndeclare module 'hardhat/types/runtime' {\n export interface HardhatRuntimeEnvironment {\n cofhesdk: {\n /**\n * Create a CoFHE SDK configuration for use with cofhesdk.createCofhesdkClient(...)\n * @param {CofhesdkInputConfig} config - The CoFHE SDK input configuration\n * @returns {CofhesdkConfig} The CoFHE SDK configuration\n */\n createCofhesdkConfig: (config: CofhesdkInputConfig) => Promise<CofhesdkConfig>;\n /**\n * Create a CoFHE SDK client instance\n * @param {CofhesdkConfig} config - The CoFHE SDK configuration (use createCofhesdkConfig to create with Node.js defaults)\n * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance\n */\n createCofhesdkClient: (config: CofhesdkConfig) => CofhesdkClient;\n /**\n * Create viem clients from a Hardhat ethers signer, to be used with `cofhesdkClient.connect(...)`\n * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use\n * @returns {Promise<{ publicClient: PublicClient; walletClient: WalletClient }>} The viem clients\n */\n hardhatSignerAdapter: (\n signer: HardhatEthersSigner\n ) => Promise<{ publicClient: PublicClient; walletClient: WalletClient }>;\n /**\n * Connect a CoFHE SDK client with a Hardhat ethers signer\n * @param {CofhesdkClient} client - The CoFHE SDK client to connect\n * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use\n * @returns {Promise<void>}\n */\n connectWithHardhatSigner: (client: CofhesdkClient, signer: HardhatEthersSigner) => Promise<void>;\n /**\n * Create and connect to a batteries included client.\n * Also generates a self-usage a permit for the signer.\n * If customization is needed, use createCofhesdkClient and connectWithHardhatSigner.\n * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use (optional - defaults to first signer)\n * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance\n */\n createBatteriesIncludedCofhesdkClient: (signer?: HardhatEthersSigner) => Promise<CofhesdkClient>;\n\n mocks: {\n /**\n * **[MOCKS ONLY]**\n *\n * Execute a block of code with cofhe mock contracts logging enabled.\n *\n * _(If logging only a function, we recommend passing the function name as the closureName (ex \"counter.increment()\"))_\n *\n * Example usage:\n *\n * ```ts\n * await hre.cofhesdk.mocks.withLogs(\"counter.increment()\", async () => {\n * await counter.increment();\n * });\n * ```\n *\n * Expected output:\n * ```\n * ┌──────────────────┬──────────────────────────────────────────────────\n * │ [COFHE-MOCKS] │ \"counter.increment()\" logs:\n * ├──────────────────┴──────────────────────────────────────────────────\n * ├ FHE.add | euint32(4473..3424)[0] + euint32(1157..3648)[1] => euint32(1106..1872)[1]\n * ├ FHE.allowThis | euint32(1106..1872)[1] -> 0x663f..6602\n * ├ FHE.allow | euint32(1106..1872)[1] -> 0x3c44..93bc\n * └─────────────────────────────────────────────────────────────────────\n * ```\n * @param {string} closureName - Name of the code block to log within\n * @param {() => Promise<void>} closure - The async function to execute\n */\n withLogs: (closureName: string, closure: () => Promise<void>) => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Enable logging from cofhe mock contracts\n * @param {string} closureName - Optional name of the code block to enable logging for\n */\n enableLogs: (closureName?: string) => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Disable logging from cofhe mock contracts\n */\n disableLogs: () => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Deploy the cofhe mock contracts (normally this is done automatically)\n * @param {DeployMocksArgs} options - Deployment options\n */\n deployMocks: (options: DeployMocksArgs) => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Get the plaintext value for a ciphertext hash\n * @param {bigint} ctHash - The ciphertext hash to look up\n * @returns {Promise<bigint>} The plaintext value\n */\n getPlaintext: (ctHash: bigint) => Promise<bigint>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Assert that a ciphertext hash represents an expected plaintext value\n * @param {bigint} ctHash - The ciphertext hash to check\n * @param {bigint} expectedValue - The expected plaintext value\n */\n expectPlaintext: (ctHash: bigint, expectedValue: bigint) => Promise<void>;\n\n /**\n * Get the MockTaskManager contract\n * @returns {Promise<Contract>} The MockTaskManager contract\n */\n getMockTaskManager: () => Promise<Contract>;\n\n /**\n * Get the MockACL contract\n * @returns {Promise<Contract>} The MockACL contract\n */\n getMockACL: () => Promise<Contract>;\n\n /**\n * Get the MockQueryDecrypter contract\n * @returns {Promise<Contract>} The MockQueryDecrypter contract\n */\n getMockQueryDecrypter: () => Promise<Contract>;\n\n /**\n * Get the MockZkVerifier contract\n * @returns {Promise<Contract>} The MockZkVerifier contract\n */\n getMockZkVerifier: () => Promise<Contract>;\n\n /**\n * Get the TestBed contract\n * @returns {Promise<Contract>} The TestBed contract\n */\n getTestBed: () => Promise<Contract>;\n };\n };\n }\n}\n\nextendEnvironment((hre) => {\n hre.cofhesdk = {\n createCofhesdkConfig: async (config: CofhesdkInputConfig) => {\n // Create zkv wallet client\n // This wallet interacts with the MockZkVerifier contract so that the user's connected wallet doesn't have to\n const zkvHhSigner = await hre.ethers.getImpersonatedSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);\n const { walletClient: zkvWalletClient } = await HardhatSignerAdapter(zkvHhSigner);\n\n // Inject zkv wallet client into config\n const configWithZkvWalletClient = {\n environment: 'hardhat' as const,\n ...config,\n _internal: {\n ...config._internal,\n zkvWalletClient,\n },\n };\n\n return createCofhesdkConfig(configWithZkvWalletClient);\n },\n createCofhesdkClient: (config: CofhesdkConfig) => {\n return createCofhesdkClient(config);\n },\n hardhatSignerAdapter: async (signer: HardhatEthersSigner) => {\n return HardhatSignerAdapter(signer);\n },\n connectWithHardhatSigner: async (client: CofhesdkClient, signer: HardhatEthersSigner) => {\n const { publicClient, walletClient } = await HardhatSignerAdapter(signer);\n return client.connect(publicClient, walletClient);\n },\n createBatteriesIncludedCofhesdkClient: async (signer?: HardhatEthersSigner) => {\n // Get signer if not provided\n if (!signer) {\n [signer] = await hre.ethers.getSigners();\n }\n\n // Create config\n const config = await hre.cofhesdk.createCofhesdkConfig({\n environment: 'hardhat',\n supportedChains: [hardhat],\n });\n\n // Create client\n const client = hre.cofhesdk.createCofhesdkClient(config);\n\n // Connect client\n await hre.cofhesdk.connectWithHardhatSigner(client, signer);\n\n // Create self-usage permit\n await client.permits.createSelf({\n issuer: signer.address,\n });\n\n // Return client\n return client;\n },\n mocks: {\n withLogs: async (closureName: string, closure: () => Promise<void>) => {\n return mock_withLogs(hre, closureName, closure);\n },\n enableLogs: async (closureName?: string) => {\n return mock_setLoggingEnabled(hre, true, closureName);\n },\n disableLogs: async () => {\n return mock_setLoggingEnabled(hre, false);\n },\n deployMocks: async (options: DeployMocksArgs) => {\n return deployMocks(hre, options);\n },\n getPlaintext: async (ctHash: bigint) => {\n const [signer] = await hre.ethers.getSigners();\n return mock_getPlaintext(signer.provider, ctHash);\n },\n expectPlaintext: async (ctHash: bigint, expectedValue: bigint) => {\n const [signer] = await hre.ethers.getSigners();\n return mock_expectPlaintext(signer.provider, ctHash, expectedValue);\n },\n getMockTaskManager: async () => getFixedMockContract(hre, MockTaskManagerArtifact),\n getMockACL: async () => {\n const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);\n const aclAddress = await taskManager.acl();\n return hre.ethers.getContractAt(MockACLArtifact.abi, aclAddress);\n },\n getMockQueryDecrypter: async () => getFixedMockContract(hre, MockQueryDecrypterArtifact),\n getMockZkVerifier: async () => getFixedMockContract(hre, MockZkVerifierArtifact),\n getTestBed: async () => getFixedMockContract(hre, TestBedArtifact),\n },\n };\n});\n","/* eslint-disable turbo/no-undeclared-env-vars */\nimport { type HardhatRuntimeEnvironment } from 'hardhat/types';\nimport '@nomicfoundation/hardhat-ethers';\n\n/**\n * Sends funds to the specified address\n * @param hre Hardhat Runtime Environment\n * @param toAddress Address to send funds to\n * @param amount Amount to send in ETH (default: 10)\n * @returns Transaction receipt or null if failed\n */\nexport async function localcofheFundAccount(hre: HardhatRuntimeEnvironment, toAddress: string, amount: string = '10') {\n // Load private key from environment\n const privateKey =\n process.env.FUNDER_PRIVATE_KEY ?? '0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659';\n if (!privateKey) {\n console.error('Error: FUNDER_PRIVATE_KEY environment variable not set');\n return null;\n }\n\n try {\n // Create wallet from private key\n const wallet = new hre.ethers.Wallet(privateKey, hre.ethers.provider);\n\n // Get wallet balance\n const balance = await hre.ethers.provider.getBalance(wallet.address);\n console.log(`Funder wallet address: ${wallet.address}`);\n console.log(`Funder wallet balance: ${hre.ethers.formatEther(balance)} ETH`);\n\n // Check if wallet has enough funds\n const amountToSend = hre.ethers.parseEther(amount);\n if (balance < amountToSend) {\n console.error(\n `Error: Funder wallet doesn't have enough funds. Current balance: ${hre.ethers.formatEther(balance)} ETH`\n );\n return null;\n }\n\n // Send transaction\n console.log(`Sending ${amount} ETH to ${toAddress}...`);\n const tx = await wallet.sendTransaction({\n to: toAddress,\n value: amountToSend,\n });\n\n console.log(`Transaction sent! Hash: ${tx.hash}`);\n console.log('Waiting for confirmation...');\n\n // Wait for transaction to be mined\n const receipt = await tx.wait();\n console.log(`Transaction confirmed in block ${receipt?.blockNumber}`);\n console.log(`Successfully sent ${amount} ETH to ${toAddress}`);\n\n return receipt;\n } catch (error) {\n console.error('Error sending funds:', error);\n return null;\n }\n}\n\n/**\n * Checks a wallet's balance and funds it if below 1 ETH\n * @param hre Hardhat Runtime Environment\n * @param walletAddress Address of the wallet to check and potentially fund\n * @returns Promise that resolves when the funding operation completes (if needed)\n */\nexport async function localcofheFundWalletIfNeeded(hre: HardhatRuntimeEnvironment, walletAddress: string) {\n // Check wallet balance and fund if needed\n const walletBalance = await hre.ethers.provider.getBalance(walletAddress);\n console.log(`Wallet balance: ${hre.ethers.formatEther(walletBalance)} ETH`);\n\n if (walletBalance < hre.ethers.parseEther('1')) {\n console.log(`Wallet balance is less than 1 ETH. Funding ${walletAddress}...`);\n const receipt = await localcofheFundAccount(hre, walletAddress);\n if (receipt) {\n const newBalance = await hre.ethers.provider.getBalance(walletAddress);\n console.log(`Wallet new balance: ${hre.ethers.formatEther(newBalance)} ETH`);\n } else {\n console.error(`Failed to fund ${walletAddress}`);\n }\n }\n}\n","export const TASK_COFHE_USE_FAUCET = 'task:cofhe:usefaucet';\nexport const TASK_COFHE_MOCKS_SET_LOG_OPS = 'task:cofhe-mocks:setlogops';\nexport const TASK_COFHE_MOCKS_DEPLOY = 'task:cofhe-mocks:deploy';\n","import { type HardhatRuntimeEnvironment } from 'hardhat/types';\nimport chalk from 'chalk';\nimport { Contract } from 'ethers';\n\nimport {\n MockTaskManagerArtifact,\n MockACLArtifact,\n MockZkVerifierArtifact,\n MockQueryDecrypterArtifact,\n TestBedArtifact,\n} from '@cofhe/mock-contracts';\n\nimport { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS } from '@cofhe/sdk';\nimport { deployMockContractFromArtifact } from './utils';\n\n// Deployment\n\nexport type DeployMocksArgs = {\n deployTestBed?: boolean;\n gasWarning?: boolean;\n silent?: boolean;\n};\n\nexport const deployMocks = async (\n hre: HardhatRuntimeEnvironment,\n options: DeployMocksArgs = {\n deployTestBed: true,\n gasWarning: true,\n silent: false,\n }\n) => {\n // Check if network is Hardhat, if not log skip message and return\n const isHardhat = await getIsHardhat(hre);\n if (!isHardhat) {\n logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);\n return;\n }\n\n isSilent = options.silent ?? false;\n\n // Log start message\n logEmpty();\n logSuccess(chalk.bold('cofhe-hardhat-plugin :: deploy mocks'), 0);\n logEmpty();\n\n // Deploy mock contracts\n const taskManager = await deployMockTaskManager(hre);\n logDeployment('MockTaskManager', await taskManager.getAddress());\n\n const acl = await deployMockACL(hre);\n logDeployment('MockACL', await acl.getAddress());\n\n await linkTaskManagerAndACL(taskManager, acl);\n logSuccess('ACL address set in TaskManager', 2);\n\n await fundZkVerifierSigner(hre);\n logSuccess(`ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);\n\n const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);\n logSuccess(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);\n\n const zkVerifier = await deployMockZkVerifier(hre);\n logDeployment('MockZkVerifier', await zkVerifier.getAddress());\n\n const queryDecrypter = await deployMockQueryDecrypter(hre, acl);\n logDeployment('MockQueryDecrypter', await queryDecrypter.getAddress());\n\n if (options.deployTestBed) {\n logSuccess('TestBed deployment enabled', 2);\n const testBed = await deployTestBedContract(hre);\n logDeployment('TestBed', await testBed.getAddress());\n }\n\n // Log success message\n logEmpty();\n logSuccess(chalk.bold('cofhe-hardhat-plugin :: mocks deployed successfully'), 0);\n\n // Log warning about mocks increased gas costs\n if (options.gasWarning) {\n logEmpty();\n logWarning(\n \"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\",\n 0\n );\n }\n\n logEmpty();\n};\n\n// Network\n\nconst getIsHardhat = async (hre: HardhatRuntimeEnvironment) => {\n return hre.network.name === 'hardhat';\n};\n\nconst deployMockTaskManager = async (hre: HardhatRuntimeEnvironment) => {\n const [signer] = await hre.ethers.getSigners();\n\n // Deploy MockTaskManager\n const taskManager = await deployMockContractFromArtifact(hre, MockTaskManagerArtifact);\n\n // Initialize MockTaskManager\n const initTx = await taskManager.initialize(signer.address);\n await initTx.wait();\n\n // Check if MockTaskManager exists\n const tmExists = await taskManager.exists();\n if (!tmExists) {\n throw new Error('MockTaskManager does not exist');\n }\n\n return taskManager;\n};\n\nconst deployMockACL = async (hre: HardhatRuntimeEnvironment): Promise<Contract> => {\n // Deploy MockACL (uses ethers to deploy to ensure constructor called and EIP712 domain set)\n const acl = await deployMockContractFromArtifact(hre, MockACLArtifact);\n\n // Check if ACL exists\n const exists = await acl.exists();\n if (!exists) {\n throw new Error('MockACL does not exist');\n }\n\n return acl;\n};\n\nconst fundZkVerifierSigner = async (hre: HardhatRuntimeEnvironment) => {\n const zkVerifierSigner = await hre.ethers.getSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);\n await hre.network.provider.send('hardhat_setBalance', [\n zkVerifierSigner.address,\n '0x' + hre.ethers.parseEther('10').toString(16),\n ]);\n};\n\nconst getZkVerifierSignerBalance = async (hre: HardhatRuntimeEnvironment) => {\n return hre.ethers.provider.getBalance(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);\n};\n\nconst linkTaskManagerAndACL = async (taskManager: Contract, acl: Contract) => {\n const aclAddress = await acl.getAddress();\n const linkAclTx = await taskManager.setACLContract(aclAddress);\n await linkAclTx.wait();\n};\n\nconst deployMockZkVerifier = async (hre: HardhatRuntimeEnvironment) => {\n const zkVerifier = await deployMockContractFromArtifact(hre, MockZkVerifierArtifact);\n\n const zkVerifierExists = await zkVerifier.exists();\n if (!zkVerifierExists) {\n throw new Error('MockZkVerifier does not exist');\n }\n\n return zkVerifier;\n};\n\nconst deployMockQueryDecrypter = async (hre: HardhatRuntimeEnvironment, acl: Contract) => {\n const queryDecrypter = await deployMockContractFromArtifact(hre, MockQueryDecrypterArtifact);\n\n // Initialize MockQueryDecrypter\n const initTx = await queryDecrypter.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());\n await initTx.wait();\n\n // Check if MockQueryDecrypter exists\n const queryDecrypterExists = await queryDecrypter.exists();\n if (!queryDecrypterExists) {\n throw new Error('MockQueryDecrypter does not exist');\n }\n\n return queryDecrypter;\n};\n\nconst deployTestBedContract = async (hre: HardhatRuntimeEnvironment) => {\n return deployMockContractFromArtifact(hre, TestBedArtifact);\n};\n\n// Logging\n\nlet isSilent = false;\n\nconst logEmpty = () => {\n if (isSilent) return;\n console.log('');\n};\n\nconst logSuccess = (message: string, indent = 1) => {\n if (isSilent) return;\n console.log(chalk.green(`${' '.repeat(indent)}✓ ${message}`));\n};\n\nconst logWarning = (message: string, indent = 1) => {\n if (isSilent) return;\n console.log(chalk.bold(chalk.yellow(`${' '.repeat(indent)}⚠ NOTE:`)), message);\n};\n\nconst logError = (message: string, indent = 1) => {\n if (isSilent) return;\n console.log(chalk.red(`${' '.repeat(indent)}✗ ${message}`));\n};\n\nconst logDeployment = (contractName: string, address: string) => {\n if (isSilent) return;\n const paddedName = `${contractName} deployed`.padEnd(36);\n logSuccess(`${paddedName} ${chalk.bold(address)}`);\n};\n","import { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS } from '@cofhe/sdk';\nimport { expect } from 'chai';\nimport { Contract, ethers } from 'ethers';\nimport { type HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';\nimport type { MockArtifact } from '@cofhe/mock-contracts';\nimport type { HardhatRuntimeEnvironment } from 'hardhat/types';\n\n// Deployment utils\n\n/// Deploys a mock contract from a pre-built artifact from the mock-contracts package\n/// If the mock contract should be deployed to a fixed address, `hardhat_setCode` op is used to set the code at the fixed address\n/// Otherwise, we deploy the contract using ethers.js to a non-fixed address\nexport const deployMockContractFromArtifact = async (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => {\n // Use hardhat_setCode to deploy to fixed address\n if (artifact.isFixed) {\n await hre.network.provider.send('hardhat_setCode', [artifact.fixedAddress, artifact.deployedBytecode]);\n return getFixedMockContract(hre, artifact);\n }\n\n // Use ethers.js to deploy to variable address\n const [signer] = await hre.ethers.getSigners();\n const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);\n const contract = await factory.deploy(/* constructor args */);\n await contract.waitForDeployment();\n return contract as Contract;\n};\n\nexport const getFixedMockContract = async (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => {\n if (!artifact.isFixed) {\n throw new Error('Artifact is not fixed');\n }\n return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);\n};\n\n// Testing utils\n\nconst mock_checkIsTestnet = async (fnName: string, provider: HardhatEthersProvider | ethers.JsonRpcProvider) => {\n // Testnet is checked by testing if MockZkVerifier is deployed\n\n // Get bytecode at ZK_VERIFIER_ADDRESS\n const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);\n\n // If bytecode is empty, we are on a testnet\n const isTestnet = bytecode.length === 0;\n\n // Log if we are on a testnet\n if (isTestnet) {\n console.log(`${fnName} - skipped on non-testnet chain`);\n }\n\n return isTestnet;\n};\n\nexport const mock_getPlaintext = async (provider: HardhatEthersProvider | ethers.JsonRpcProvider, ctHash: bigint) => {\n // Skip with log if called on a non-testnet chain\n if (await mock_checkIsTestnet(mock_getPlaintext.name, provider)) return;\n\n // Connect to MockTaskManager\n const taskManager = new ethers.Contract(\n TASK_MANAGER_ADDRESS,\n ['function mockStorage(uint256) view returns (uint256)'],\n provider\n );\n\n // Fetch the plaintext\n const plaintext = await taskManager.mockStorage(ctHash);\n\n return plaintext;\n};\n\nexport const mock_getPlaintextExists = async (\n provider: HardhatEthersProvider | ethers.JsonRpcProvider,\n ctHash: bigint\n) => {\n // Skip with log if called on a non-testnet chain\n if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider)) return;\n\n // Connect to MockTaskManager\n const taskManager = new ethers.Contract(\n TASK_MANAGER_ADDRESS,\n ['function inMockStorage(uint256) view returns (bool)'],\n provider\n );\n\n // Fetch the plaintext exists\n const plaintextExists = await taskManager.inMockStorage(ctHash);\n\n return plaintextExists;\n};\n\nexport const mock_expectPlaintext = async (\n provider: HardhatEthersProvider | ethers.JsonRpcProvider,\n ctHash: bigint,\n expectedValue: bigint\n) => {\n // Skip with log if called on a non-testnet chain\n if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider)) return;\n\n // Expect the plaintext to exist\n const plaintextExists = await mock_getPlaintextExists(provider, ctHash);\n expect(plaintextExists).equal(true, 'Plaintext does not exist');\n\n // Expect the plaintext to have the expected value\n const plaintext = await mock_getPlaintext(provider, ctHash);\n expect(plaintext).equal(expectedValue, 'Plaintext value is incorrect');\n};\n","import chalk from 'chalk';\nimport { type HardhatRuntimeEnvironment } from 'hardhat/types';\nimport { getFixedMockContract } from './utils';\nimport { MockTaskManagerArtifact } from '@cofhe/mock-contracts';\n\nconst getLoggingEnabled = async (hre: HardhatRuntimeEnvironment): Promise<boolean> => {\n const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);\n return taskManager.logOps();\n};\n\nconst setLoggingEnabled = async (hre: HardhatRuntimeEnvironment, enabled: boolean) => {\n const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);\n const tx = await taskManager.setLogOps(enabled);\n await tx.wait();\n};\n\n// prettier-ignore\nconst printLogsEnabledMessage = (closureMessage: string) => {\n console.log(\"┌──────────────────┬──────────────────────────────────────────────────\");\n console.log(`│ [COFHE-MOCKS] │ ${closureMessage}`);\n console.log(\"├──────────────────┴──────────────────────────────────────────────────\");\n};\n\n// prettier-ignore\nconst printLogsBlockEnd = () => {\n console.log(\"└─────────────────────────────────────────────────────────────────────\");\n};\n\nexport const mock_setLoggingEnabled = async (\n hre: HardhatRuntimeEnvironment,\n enabled: boolean,\n closureName?: string\n) => {\n try {\n const initiallyEnabled = await getLoggingEnabled(hre);\n\n await setLoggingEnabled(hre, enabled);\n\n // Only print if enabling logs\n if (enabled) {\n printLogsEnabledMessage(`${closureName ? `\"${chalk.bold(closureName)}\" logs:` : 'Logs:'}`);\n }\n\n // Only print if disabling logs AND logs currently enabled\n if (!enabled && initiallyEnabled) {\n printLogsBlockEnd();\n }\n } catch (error) {\n console.log(chalk.red('mock_setLoggingEnabled error'), error);\n }\n};\n\nexport const mock_withLogs = async (\n hre: HardhatRuntimeEnvironment,\n closureName: string,\n closure: () => Promise<void>\n) => {\n const initiallyEnabled = await getLoggingEnabled(hre);\n\n await setLoggingEnabled(hre, true);\n printLogsEnabledMessage(`\"${chalk.bold(closureName)}\" logs:`);\n await closure();\n printLogsBlockEnd();\n\n // If logs were disabled, disable them again\n if (!initiallyEnabled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,YAAY;AACvB,eAAO,uBAAuB,KAAK,KAAK;AAAA,MAC1C;AAAA,MACA,aAAa,OAAO,YAA6B;AAC/C,eAAO,YAAY,KAAK,OAAO;AAAA,MACjC;AAAA,MACA,cAAc,OAAO,WAAmB;AACtC,cAAM,CAAC,MAAM,IAAI,MAAM,IAAI,OAAO,WAAW;AAC7C,eAAO,kBAAkB,OAAO,UAAU,MAAM;AAAA,MAClD;AAAA,MACA,iBAAiB,OAAO,QAAgB,kBAA0B;AAChE,cAAM,CAAC,MAAM,IAAI,MAAM,IAAI,OAAO,WAAW;AAC7C,eAAO,qBAAqB,OAAO,UAAU,QAAQ,aAAa;AAAA,MACpE;AAAA,MACA,oBAAoB,YAAY,qBAAqB,KAAKJ,wBAAuB;AAAA,MACjF,YAAY,YAAY;AACtB,cAAM,cAAc,MAAM,qBAAqB,KAAKA,wBAAuB;AAC3E,cAAM,aAAa,MAAM,YAAY,IAAI;AACzC,eAAO,IAAI,OAAO,cAAcF,iBAAgB,KAAK,UAAU;AAAA,MACjE;AAAA,MACA,uBAAuB,YAAY,qBAAqB,KAAKC,2BAA0B;AAAA,MACvF,mBAAmB,YAAY,qBAAqB,KAAKE,uBAAsB;AAAA,MAC/E,YAAY,YAAY,qBAAqB,KAAKC,gBAAe;AAAA,IACnE;AAAA,EACF;AACF,CAAC;","names":["chalk","MOCKS_ZK_VERIFIER_SIGNER_ADDRESS","TASK_MANAGER_ADDRESS","TASK_MANAGER_ADDRESS","chalk","MockTaskManagerArtifact","chalk","MockACLArtifact","MockQueryDecrypterArtifact","MockTaskManagerArtifact","MockZkVerifierArtifact","TestBedArtifact","chalk","MOCKS_ZK_VERIFIER_SIGNER_ADDRESS"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/fund.ts","../src/consts.ts","../src/deploy.ts","../src/utils.ts","../src/logging.ts"],"sourcesContent":["/* eslint-disable no-empty-pattern */\n/* eslint-disable turbo/no-undeclared-env-vars */\nimport chalk from 'chalk';\nimport { type PublicClient, type WalletClient } from 'viem';\nimport { extendConfig, extendEnvironment, task, types } from 'hardhat/config';\nimport { TASK_TEST, TASK_NODE } from 'hardhat/builtin-tasks/task-names';\nimport { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';\nimport {\n type CofheClient,\n type CofheConfig,\n type CofheInputConfig,\n MOCKS_ZK_VERIFIER_SIGNER_ADDRESS,\n} from '@cofhe/sdk';\nimport { createCofheClient, createCofheConfig } from '@cofhe/sdk/node';\nimport { HardhatSignerAdapter } from '@cofhe/sdk/adapters';\n\nimport { localcofheFundAccount } from './fund.js';\nimport { TASK_COFHE_MOCKS_DEPLOY, TASK_COFHE_MOCKS_SET_LOG_OPS, TASK_COFHE_USE_FAUCET } from './consts.js';\nimport { deployMocks, type DeployMocksArgs } from './deploy.js';\nimport { mock_setLoggingEnabled, mock_withLogs } from './logging.js';\nimport { getFixedMockContract, mock_expectPlaintext } from './utils.js';\nimport { mock_getPlaintext } from './utils.js';\nimport type { Contract } from 'ethers';\nimport { hardhat } from '@cofhe/sdk/chains';\nimport {\n MockACLArtifact,\n MockThresholdNetworkArtifact,\n MockTaskManagerArtifact,\n MockZkVerifierArtifact,\n TestBedArtifact,\n} from '@cofhe/mock-contracts';\n\n/**\n * Configuration interface for the CoFHE Hardhat plugin.\n * Allows users to configure mock logging and gas warning settings.\n */\ndeclare module 'hardhat/types/config' {\n interface HardhatUserConfig {\n cofhe?: {\n /** Whether to log mock operations (default: true) */\n logMocks?: boolean;\n /** Whether to show gas usage warnings for mock operations (default: true) */\n gasWarning?: boolean;\n };\n }\n\n interface HardhatConfig {\n cofhe: {\n /** Whether to log mock operations (default: true) */\n logMocks: boolean;\n /** Whether to show gas usage warnings for mock operations (default: true) */\n gasWarning: boolean;\n };\n }\n}\n\nextendConfig((config, userConfig) => {\n // Allow users to override the localcofhe network config\n if (userConfig.networks && userConfig.networks.localcofhe) {\n return;\n }\n\n // Default config\n config.networks.localcofhe = {\n gas: 'auto',\n gasMultiplier: 1.2,\n gasPrice: 'auto',\n timeout: 10_000,\n httpHeaders: {},\n url: 'http://127.0.0.1:42069',\n accounts: [\n '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',\n '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',\n '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',\n '0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6',\n ],\n };\n\n // Only add Sepolia config if user hasn't defined it\n if (!userConfig.networks?.['eth-sepolia']) {\n config.networks['eth-sepolia'] = {\n url: process.env.SEPOLIA_RPC_URL ?? 'https://ethereum-sepolia.publicnode.com',\n accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],\n chainId: 11155111,\n gas: 'auto',\n gasMultiplier: 1.2,\n gasPrice: 'auto',\n timeout: 60_000,\n httpHeaders: {},\n };\n }\n\n // Only add Arbitrum Sepolia config if user hasn't defined it\n if (!userConfig.networks?.['arb-sepolia']) {\n config.networks['arb-sepolia'] = {\n url: process.env.ARBITRUM_SEPOLIA_RPC_URL ?? 'https://sepolia-rollup.arbitrum.io/rpc',\n accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],\n chainId: 421614,\n gas: 'auto',\n gasMultiplier: 1.2,\n gasPrice: 'auto',\n timeout: 60_000,\n httpHeaders: {},\n };\n }\n\n // Add cofhe config\n config.cofhe = {\n logMocks: userConfig.cofhe?.logMocks ?? true,\n gasWarning: userConfig.cofhe?.gasWarning ?? true,\n };\n});\n\ntype UseFaucetArgs = {\n address?: string;\n};\n\ntask(TASK_COFHE_USE_FAUCET, 'Fund an account from the funder')\n .addOptionalParam('address', 'Address to fund', undefined, types.string)\n .setAction(async ({ address }: UseFaucetArgs, hre) => {\n const { network } = hre;\n const { name: networkName } = network;\n\n if (networkName !== 'localcofhe') {\n console.info(chalk.yellow(`Programmatic faucet only supported for localcofhe`));\n return;\n }\n\n if (!address) {\n console.info(chalk.red(`Failed to get address to fund`));\n return;\n }\n\n console.info(chalk.green(`Getting funds from faucet for ${address}`));\n\n try {\n await localcofheFundAccount(hre, address);\n } catch (e) {\n console.info(chalk.red(`failed to get funds from localcofhe for ${address}: ${e}`));\n }\n });\n\n// DEPLOY TASKS\n\ntask(TASK_COFHE_MOCKS_DEPLOY, 'Deploys the mock contracts on the Hardhat network')\n .addOptionalParam('deployTestBed', 'Whether to deploy the test bed', true, types.boolean)\n .addOptionalParam('silent', 'Whether to suppress output', false, types.boolean)\n .setAction(async ({ deployTestBed, silent }: DeployMocksArgs, hre) => {\n await deployMocks(hre, {\n deployTestBed: deployTestBed ?? true,\n gasWarning: hre.config.cofhe.gasWarning ?? true,\n silent: silent ?? false,\n });\n });\n\n// Hardhat plugin auto-deploys mocks for every hardhat test run by overriding TASK_TEST and calling deployMocks(...) before runSuper()\ntask(TASK_TEST, 'Deploy mock contracts on hardhat').setAction(async ({}, hre, runSuper) => {\n const skipAutoDeploy = (() => {\n const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? '';\n const normalized = raw.trim().toLowerCase();\n return normalized === '1' || normalized === 'true' || normalized === 'yes';\n })();\n\n if (!skipAutoDeploy) {\n await deployMocks(hre, {\n deployTestBed: true,\n gasWarning: hre.config.cofhe.gasWarning ?? true,\n });\n }\n return runSuper();\n});\n\ntask(TASK_NODE, 'Deploy mock contracts on hardhat').setAction(async ({}, hre, runSuper) => {\n const skipAutoDeploy = (() => {\n const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? '';\n const normalized = raw.trim().toLowerCase();\n return normalized === '1' || normalized === 'true' || normalized === 'yes';\n })();\n\n if (!skipAutoDeploy) {\n await deployMocks(hre, {\n deployTestBed: true,\n gasWarning: hre.config.cofhe.gasWarning ?? true,\n });\n }\n return runSuper();\n});\n\n// SET LOG OPS\n\ntask(TASK_COFHE_MOCKS_SET_LOG_OPS, 'Set logging for the Mock CoFHE contracts')\n .addParam('enable', 'Whether to enable logging', false, types.boolean)\n .setAction(async ({ enable }, hre) => {\n await mock_setLoggingEnabled(hre, enable);\n });\n\n// MOCK UTILS\n\nexport * from './consts.js';\nexport * from './utils.js';\nexport * from './fund.js';\nexport * from './logging.js';\nexport * from './deploy.js';\n\n/**\n * Runtime environment extensions for the CoFHE Hardhat plugin.\n * Provides access to CoFHE initialization, environment checks, and mock utilities.\n */\ndeclare module 'hardhat/types/runtime' {\n export interface HardhatRuntimeEnvironment {\n cofhe: {\n /**\n * Create a CoFHE configuration for use with hre.cofhe.createClient(...)\n * @param {CofheInputConfig} config - The CoFHE input configuration\n * @returns {CofheConfig} The CoFHE configuration\n */\n createConfig: (config: CofheInputConfig) => Promise<CofheConfig>;\n /**\n * Create a CoFHE client instance\n * @param {CofheConfig} config - The CoFHE configuration (use createCofheConfig to create with Node.js defaults)\n * @returns {Promise<CofheClient>} The CoFHE client instance\n */\n createClient: (config: CofheConfig) => CofheClient;\n /**\n * Create viem clients from a Hardhat ethers signer, to be used with `cofheClient.connect(...)`\n * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use\n * @returns {Promise<{ publicClient: PublicClient; walletClient: WalletClient }>} The viem clients\n */\n hardhatSignerAdapter: (\n signer: HardhatEthersSigner\n ) => Promise<{ publicClient: PublicClient; walletClient: WalletClient }>;\n /**\n * Connect a CoFHE client with a Hardhat ethers signer\n * @param {CofheClient} client - The CoFHE client to connect\n * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use\n * @returns {Promise<void>}\n */\n connectWithHardhatSigner: (client: CofheClient, signer: HardhatEthersSigner) => Promise<void>;\n /**\n * Create and connect to a batteries included client.\n * Also generates a self-usage a permit for the signer.\n * If customization is needed, use createCofheClient and connectWithHardhatSigner.\n * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use (optional - defaults to first signer)\n * @returns {Promise<CofheClient>} The CoFHE client instance\n */\n createClientWithBatteries: (signer?: HardhatEthersSigner) => Promise<CofheClient>;\n\n mocks: {\n /**\n * **[MOCKS ONLY]**\n *\n * Execute a block of code with cofhe mock contracts logging enabled.\n *\n * _(If logging only a function, we recommend passing the function name as the closureName (ex \"counter.increment()\"))_\n *\n * Example usage:\n *\n * ```ts\n * await hre.cofhe.mocks.withLogs(\"counter.increment()\", async () => {\n * await counter.increment();\n * });\n * ```\n *\n * Expected output:\n * ```\n * ┌──────────────────┬──────────────────────────────────────────────────\n * │ [COFHE-MOCKS] │ \"counter.increment()\" logs:\n * ├──────────────────┴──────────────────────────────────────────────────\n * ├ FHE.add | euint32(4473..3424)[0] + euint32(1157..3648)[1] => euint32(1106..1872)[1]\n * ├ FHE.allowThis | euint32(1106..1872)[1] -> 0x663f..6602\n * ├ FHE.allow | euint32(1106..1872)[1] -> 0x3c44..93bc\n * └─────────────────────────────────────────────────────────────────────\n * ```\n * @param {string} closureName - Name of the code block to log within\n * @param {() => Promise<void>} closure - The async function to execute\n */\n withLogs: (closureName: string, closure: () => Promise<void>) => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Enable logging from cofhe mock contracts\n * @param {string} closureName - Optional name of the code block to enable logging for\n */\n enableLogs: (closureName?: string) => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Disable logging from cofhe mock contracts\n */\n disableLogs: () => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Deploy the cofhe mock contracts (normally this is done automatically)\n * @param {DeployMocksArgs} options - Deployment options\n */\n deployMocks: (options: DeployMocksArgs) => Promise<void>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Get the plaintext value for a ciphertext hash\n * @param {bigint} ctHash - The ciphertext hash to look up\n * @returns {Promise<bigint>} The plaintext value\n */\n getPlaintext: (ctHash: bigint) => Promise<bigint>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Assert that a ciphertext hash represents an expected plaintext value\n * @param {bigint} ctHash - The ciphertext hash to check\n * @param {bigint} expectedValue - The expected plaintext value\n */\n expectPlaintext: (ctHash: bigint, expectedValue: bigint) => Promise<void>;\n\n /**\n * Get the MockTaskManager contract\n * @returns {Promise<Contract>} The MockTaskManager contract\n */\n getMockTaskManager: () => Promise<Contract>;\n\n /**\n * Get the MockACL contract\n * @returns {Promise<Contract>} The MockACL contract\n */\n getMockACL: () => Promise<Contract>;\n\n /**\n * Get the MockThresholdNetwork contract\n * @returns {Promise<Contract>} The MockThresholdNetwork contract\n */\n getMockThresholdNetwork: () => Promise<Contract>;\n\n /**\n * Get the MockZkVerifier contract\n * @returns {Promise<Contract>} The MockZkVerifier contract\n */\n getMockZkVerifier: () => Promise<Contract>;\n\n /**\n * Get the TestBed contract\n * @returns {Promise<Contract>} The TestBed contract\n */\n getTestBed: () => Promise<Contract>;\n };\n };\n }\n}\n\n/**\n * Builds the mocks config for the hardhat plugin.\n * Defaults `encryptDelay` to `0` so tests run without artificial wait times,\n * unless the user has explicitly provided a value.\n */\nexport function buildHardhatPluginMocksConfig(\n mocksConfig: CofheInputConfig['mocks']\n): NonNullable<CofheInputConfig['mocks']> {\n return {\n ...mocksConfig,\n encryptDelay: mocksConfig?.encryptDelay ?? 0,\n };\n}\n\nextendEnvironment((hre) => {\n hre.cofhe = {\n createConfig: async (config: CofheInputConfig) => {\n // Create zkv wallet client\n // This wallet interacts with the MockZkVerifier contract so that the user's connected wallet doesn't have to\n const zkvHhSigner = await hre.ethers.getImpersonatedSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);\n const { walletClient: zkvWalletClient } = await HardhatSignerAdapter(zkvHhSigner);\n\n // Inject zkv wallet client into config\n // Set encryptDelay to 0 on hardhat to avoid waiting for delays during tests\n const configWithZkvWalletClient = {\n environment: 'hardhat' as const,\n ...config,\n mocks: buildHardhatPluginMocksConfig(config.mocks),\n _internal: {\n ...config._internal,\n zkvWalletClient,\n },\n };\n\n return createCofheConfig(configWithZkvWalletClient);\n },\n createClient: (config: CofheConfig) => {\n return createCofheClient(config);\n },\n hardhatSignerAdapter: async (signer: HardhatEthersSigner) => {\n return HardhatSignerAdapter(signer);\n },\n connectWithHardhatSigner: async (client: CofheClient, signer: HardhatEthersSigner) => {\n const { publicClient, walletClient } = await HardhatSignerAdapter(signer);\n return client.connect(publicClient, walletClient);\n },\n createClientWithBatteries: async (signer?: HardhatEthersSigner) => {\n // Get signer if not provided\n if (!signer) {\n [signer] = await hre.ethers.getSigners();\n }\n\n // Create config\n const config = await hre.cofhe.createConfig({\n environment: 'hardhat',\n supportedChains: [hardhat],\n });\n\n // Create client\n const client = hre.cofhe.createClient(config);\n\n // Connect client\n await hre.cofhe.connectWithHardhatSigner(client, signer);\n\n // Create self-usage permit\n await client.permits.createSelf({\n issuer: signer.address,\n });\n\n // Return client\n return client;\n },\n mocks: {\n withLogs: async (closureName: string, closure: () => Promise<void>) => {\n return mock_withLogs(hre, closureName, closure);\n },\n enableLogs: async (closureName?: string) => {\n return mock_setLoggingEnabled(hre, true, closureName);\n },\n disableLogs: async () => {\n return mock_setLoggingEnabled(hre, false);\n },\n deployMocks: async (options: DeployMocksArgs) => {\n return deployMocks(hre, options);\n },\n getPlaintext: async (ctHash: bigint) => {\n const [signer] = await hre.ethers.getSigners();\n return mock_getPlaintext(signer.provider, ctHash);\n },\n expectPlaintext: async (ctHash: bigint, expectedValue: bigint) => {\n const [signer] = await hre.ethers.getSigners();\n return mock_expectPlaintext(signer.provider, ctHash, expectedValue);\n },\n getMockTaskManager: async () => getFixedMockContract(hre, MockTaskManagerArtifact),\n getMockACL: async () => {\n const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);\n const aclAddress = await taskManager.acl();\n return hre.ethers.getContractAt(MockACLArtifact.abi, aclAddress);\n },\n getMockThresholdNetwork: async () => getFixedMockContract(hre, MockThresholdNetworkArtifact),\n getMockZkVerifier: async () => getFixedMockContract(hre, MockZkVerifierArtifact),\n getTestBed: async () => getFixedMockContract(hre, TestBedArtifact),\n },\n };\n});\n","/* eslint-disable turbo/no-undeclared-env-vars */\nimport { type HardhatRuntimeEnvironment } from 'hardhat/types';\nimport '@nomicfoundation/hardhat-ethers';\n\n/**\n * Sends funds to the specified address\n * @param hre Hardhat Runtime Environment\n * @param toAddress Address to send funds to\n * @param amount Amount to send in ETH (default: 10)\n * @returns Transaction receipt or null if failed\n */\nexport async function localcofheFundAccount(hre: HardhatRuntimeEnvironment, toAddress: string, amount: string = '10') {\n // Load private key from environment\n const privateKey =\n process.env.FUNDER_PRIVATE_KEY ?? '0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659';\n if (!privateKey) {\n console.error('Error: FUNDER_PRIVATE_KEY environment variable not set');\n return null;\n }\n\n try {\n // Create wallet from private key\n const wallet = new hre.ethers.Wallet(privateKey, hre.ethers.provider);\n\n // Get wallet balance\n const balance = await hre.ethers.provider.getBalance(wallet.address);\n console.log(`Funder wallet address: ${wallet.address}`);\n console.log(`Funder wallet balance: ${hre.ethers.formatEther(balance)} ETH`);\n\n // Check if wallet has enough funds\n const amountToSend = hre.ethers.parseEther(amount);\n if (balance < amountToSend) {\n console.error(\n `Error: Funder wallet doesn't have enough funds. Current balance: ${hre.ethers.formatEther(balance)} ETH`\n );\n return null;\n }\n\n // Send transaction\n console.log(`Sending ${amount} ETH to ${toAddress}...`);\n const tx = await wallet.sendTransaction({\n to: toAddress,\n value: amountToSend,\n });\n\n console.log(`Transaction sent! Hash: ${tx.hash}`);\n console.log('Waiting for confirmation...');\n\n // Wait for transaction to be mined\n const receipt = await tx.wait();\n console.log(`Transaction confirmed in block ${receipt?.blockNumber}`);\n console.log(`Successfully sent ${amount} ETH to ${toAddress}`);\n\n return receipt;\n } catch (error) {\n console.error('Error sending funds:', error);\n return null;\n }\n}\n\n/**\n * Checks a wallet's balance and funds it if below 1 ETH\n * @param hre Hardhat Runtime Environment\n * @param walletAddress Address of the wallet to check and potentially fund\n * @returns Promise that resolves when the funding operation completes (if needed)\n */\nexport async function localcofheFundWalletIfNeeded(hre: HardhatRuntimeEnvironment, walletAddress: string) {\n // Check wallet balance and fund if needed\n const walletBalance = await hre.ethers.provider.getBalance(walletAddress);\n console.log(`Wallet balance: ${hre.ethers.formatEther(walletBalance)} ETH`);\n\n if (walletBalance < hre.ethers.parseEther('1')) {\n console.log(`Wallet balance is less than 1 ETH. Funding ${walletAddress}...`);\n const receipt = await localcofheFundAccount(hre, walletAddress);\n if (receipt) {\n const newBalance = await hre.ethers.provider.getBalance(walletAddress);\n console.log(`Wallet new balance: ${hre.ethers.formatEther(newBalance)} ETH`);\n } else {\n console.error(`Failed to fund ${walletAddress}`);\n }\n }\n}\n","export const TASK_COFHE_USE_FAUCET = 'task:cofhe:usefaucet';\nexport const TASK_COFHE_MOCKS_SET_LOG_OPS = 'task:cofhe-mocks:setlogops';\nexport const TASK_COFHE_MOCKS_DEPLOY = 'task:cofhe-mocks:deploy';\n","import { type HardhatRuntimeEnvironment } from 'hardhat/types';\nimport chalk from 'chalk';\nimport { Contract } from 'ethers';\n\nimport {\n MockTaskManagerArtifact,\n MockACLArtifact,\n MockZkVerifierArtifact,\n MockThresholdNetworkArtifact,\n TestBedArtifact,\n} from '@cofhe/mock-contracts';\n\nimport { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS } from '@cofhe/sdk';\nimport { deployMockContractFromArtifact } from './utils';\n\n// Deployment\n\nexport type DeployMocksArgs = {\n deployTestBed?: boolean;\n gasWarning?: boolean;\n silent?: boolean;\n};\n\nexport const deployMocks = async (\n hre: HardhatRuntimeEnvironment,\n options: DeployMocksArgs = {\n deployTestBed: true,\n gasWarning: true,\n silent: false,\n }\n) => {\n // Check if network is Hardhat, if not log skip message and return\n const isHardhat = await getIsHardhat(hre);\n if (!isHardhat) {\n logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);\n return;\n }\n\n isSilent = options.silent ?? false;\n\n // Log start message\n logEmpty();\n logSuccess(chalk.bold('cofhe-hardhat-plugin :: deploy mocks'), 0);\n logEmpty();\n\n // Deploy mock contracts\n const taskManager = await deployMockTaskManager(hre);\n logDeployment('MockTaskManager', await taskManager.getAddress());\n\n const acl = await deployMockACL(hre);\n logDeployment('MockACL', await acl.getAddress());\n\n await linkTaskManagerAndACL(taskManager, acl);\n logSuccess('ACL address set in TaskManager', 2);\n\n await fundZkVerifierSigner(hre);\n logSuccess(`ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);\n\n const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);\n logSuccess(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);\n\n const zkVerifier = await deployMockZkVerifier(hre);\n logDeployment('MockZkVerifier', await zkVerifier.getAddress());\n\n const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);\n logDeployment('MockThresholdNetwork', await thresholdNetwork.getAddress());\n\n if (options.deployTestBed) {\n logSuccess('TestBed deployment enabled', 2);\n const testBed = await deployTestBedContract(hre);\n logDeployment('TestBed', await testBed.getAddress());\n }\n\n // Log success message\n logEmpty();\n logSuccess(chalk.bold('cofhe-hardhat-plugin :: mocks deployed successfully'), 0);\n\n // Log warning about mocks increased gas costs\n if (options.gasWarning) {\n logEmpty();\n logWarning(\n \"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\",\n 0\n );\n }\n\n logEmpty();\n};\n\n// Network\n\nconst getIsHardhat = async (hre: HardhatRuntimeEnvironment) => {\n return hre.network.name === 'hardhat';\n};\n\nconst deployMockTaskManager = async (hre: HardhatRuntimeEnvironment) => {\n const [signer] = await hre.ethers.getSigners();\n\n // Deploy MockTaskManager\n const taskManager = await deployMockContractFromArtifact(hre, MockTaskManagerArtifact);\n\n // Initialize MockTaskManager\n const initTx = await taskManager.initialize(signer.address);\n await initTx.wait();\n\n // Check if MockTaskManager exists\n const tmExists = await taskManager.exists();\n if (!tmExists) {\n throw new Error('MockTaskManager does not exist');\n }\n\n return taskManager;\n};\n\nconst deployMockACL = async (hre: HardhatRuntimeEnvironment): Promise<Contract> => {\n // Deploy MockACL (uses ethers to deploy to ensure constructor called and EIP712 domain set)\n const acl = await deployMockContractFromArtifact(hre, MockACLArtifact);\n\n // Check if ACL exists\n const exists = await acl.exists();\n if (!exists) {\n throw new Error('MockACL does not exist');\n }\n\n return acl;\n};\n\nconst fundZkVerifierSigner = async (hre: HardhatRuntimeEnvironment) => {\n const zkVerifierSigner = await hre.ethers.getSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);\n await hre.network.provider.send('hardhat_setBalance', [\n zkVerifierSigner.address,\n '0x' + hre.ethers.parseEther('10').toString(16),\n ]);\n};\n\nconst getZkVerifierSignerBalance = async (hre: HardhatRuntimeEnvironment) => {\n return hre.ethers.provider.getBalance(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);\n};\n\nconst linkTaskManagerAndACL = async (taskManager: Contract, acl: Contract) => {\n const aclAddress = await acl.getAddress();\n const linkAclTx = await taskManager.setACLContract(aclAddress);\n await linkAclTx.wait();\n};\n\nconst deployMockZkVerifier = async (hre: HardhatRuntimeEnvironment) => {\n const zkVerifier = await deployMockContractFromArtifact(hre, MockZkVerifierArtifact);\n\n const zkVerifierExists = await zkVerifier.exists();\n if (!zkVerifierExists) {\n throw new Error('MockZkVerifier does not exist');\n }\n\n return zkVerifier;\n};\n\nconst deployMockThresholdNetwork = async (hre: HardhatRuntimeEnvironment, acl: Contract) => {\n const thresholdNetwork = await deployMockContractFromArtifact(hre, MockThresholdNetworkArtifact);\n\n // Initialize MockThresholdNetwork\n const initTx = await thresholdNetwork.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());\n await initTx.wait();\n\n // Check if MockThresholdNetwork exists\n const exists = await thresholdNetwork.exists();\n if (!exists) {\n throw new Error('MockThresholdNetwork does not exist');\n }\n\n return thresholdNetwork;\n};\n\nconst deployTestBedContract = async (hre: HardhatRuntimeEnvironment) => {\n return deployMockContractFromArtifact(hre, TestBedArtifact);\n};\n\n// Logging\n\nlet isSilent = false;\n\nconst logEmpty = () => {\n if (isSilent) return;\n console.log('');\n};\n\nconst logSuccess = (message: string, indent = 1) => {\n if (isSilent) return;\n console.log(chalk.green(`${' '.repeat(indent)}✓ ${message}`));\n};\n\nconst logWarning = (message: string, indent = 1) => {\n if (isSilent) return;\n console.log(chalk.bold(chalk.yellow(`${' '.repeat(indent)}⚠ NOTE:`)), message);\n};\n\nconst logError = (message: string, indent = 1) => {\n if (isSilent) return;\n console.log(chalk.red(`${' '.repeat(indent)}✗ ${message}`));\n};\n\nconst logDeployment = (contractName: string, address: string) => {\n if (isSilent) return;\n const paddedName = `${contractName} deployed`.padEnd(36);\n logSuccess(`${paddedName} ${chalk.bold(address)}`);\n};\n","import { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS } from '@cofhe/sdk';\nimport { expect } from 'chai';\nimport { Contract, ethers } from 'ethers';\nimport { type HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';\nimport type { MockArtifact } from '@cofhe/mock-contracts';\nimport type { HardhatRuntimeEnvironment } from 'hardhat/types';\n\n// Deployment utils\n\n/// Deploys a mock contract from a pre-built artifact from the mock-contracts package\n/// If the mock contract should be deployed to a fixed address, `hardhat_setCode` op is used to set the code at the fixed address\n/// Otherwise, we deploy the contract using ethers.js to a non-fixed address\nexport const deployMockContractFromArtifact = async (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => {\n // Use hardhat_setCode to deploy to fixed address\n if (artifact.isFixed) {\n await hre.network.provider.send('hardhat_setCode', [artifact.fixedAddress, artifact.deployedBytecode]);\n return getFixedMockContract(hre, artifact);\n }\n\n // Use ethers.js to deploy to variable address\n const [signer] = await hre.ethers.getSigners();\n const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);\n const contract = await factory.deploy(/* constructor args */);\n await contract.waitForDeployment();\n return contract as Contract;\n};\n\nexport const getFixedMockContract = async (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => {\n if (!artifact.isFixed) {\n throw new Error('Artifact is not fixed');\n }\n return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);\n};\n\n// Testing utils\n\nconst mock_checkIsTestnet = async (fnName: string, provider: HardhatEthersProvider | ethers.JsonRpcProvider) => {\n // Testnet is checked by testing if MockZkVerifier is deployed\n\n // Get bytecode at ZK_VERIFIER_ADDRESS\n const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);\n\n // If bytecode is empty, we are on a testnet\n const isTestnet = bytecode.length === 0;\n\n // Log if we are on a testnet\n if (isTestnet) {\n console.log(`${fnName} - skipped on non-testnet chain`);\n }\n\n return isTestnet;\n};\n\nexport const mock_getPlaintext = async (provider: HardhatEthersProvider | ethers.JsonRpcProvider, ctHash: bigint) => {\n // Skip with log if called on a non-testnet chain\n if (await mock_checkIsTestnet(mock_getPlaintext.name, provider)) return;\n\n // Connect to MockTaskManager\n const taskManager = new ethers.Contract(\n TASK_MANAGER_ADDRESS,\n ['function mockStorage(uint256) view returns (uint256)'],\n provider\n );\n\n // Fetch the plaintext\n const plaintext = await taskManager.mockStorage(ctHash);\n\n return plaintext;\n};\n\nexport const mock_getPlaintextExists = async (\n provider: HardhatEthersProvider | ethers.JsonRpcProvider,\n ctHash: bigint\n) => {\n // Skip with log if called on a non-testnet chain\n if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider)) return;\n\n // Connect to MockTaskManager\n const taskManager = new ethers.Contract(\n TASK_MANAGER_ADDRESS,\n ['function inMockStorage(uint256) view returns (bool)'],\n provider\n );\n\n // Fetch the plaintext exists\n const plaintextExists = await taskManager.inMockStorage(ctHash);\n\n return plaintextExists;\n};\n\nexport const mock_expectPlaintext = async (\n provider: HardhatEthersProvider | ethers.JsonRpcProvider,\n ctHash: bigint,\n expectedValue: bigint\n) => {\n // Skip with log if called on a non-testnet chain\n if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider)) return;\n\n // Expect the plaintext to exist\n const plaintextExists = await mock_getPlaintextExists(provider, ctHash);\n expect(plaintextExists).equal(true, 'Plaintext does not exist');\n\n // Expect the plaintext to have the expected value\n const plaintext = await mock_getPlaintext(provider, ctHash);\n expect(plaintext).equal(expectedValue, 'Plaintext value is incorrect');\n};\n","import chalk from 'chalk';\nimport { type HardhatRuntimeEnvironment } from 'hardhat/types';\nimport { getFixedMockContract } from './utils';\nimport { MockTaskManagerArtifact } from '@cofhe/mock-contracts';\n\nconst getLoggingEnabled = async (hre: HardhatRuntimeEnvironment): Promise<boolean> => {\n const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);\n return taskManager.logOps();\n};\n\nconst setLoggingEnabled = async (hre: HardhatRuntimeEnvironment, enabled: boolean) => {\n const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);\n const tx = await taskManager.setLogOps(enabled);\n await tx.wait();\n};\n\n// prettier-ignore\nconst printLogsEnabledMessage = (closureMessage: string) => {\n console.log(\"┌──────────────────┬──────────────────────────────────────────────────\");\n console.log(`│ [COFHE-MOCKS] │ ${closureMessage}`);\n console.log(\"├──────────────────┴──────────────────────────────────────────────────\");\n};\n\n// prettier-ignore\nconst printLogsBlockEnd = () => {\n console.log(\"└─────────────────────────────────────────────────────────────────────\");\n};\n\nexport const mock_setLoggingEnabled = async (\n hre: HardhatRuntimeEnvironment,\n enabled: boolean,\n closureName?: string\n) => {\n try {\n const initiallyEnabled = await getLoggingEnabled(hre);\n\n await setLoggingEnabled(hre, enabled);\n\n // Only print if enabling logs\n if (enabled) {\n printLogsEnabledMessage(`${closureName ? `\"${chalk.bold(closureName)}\" logs:` : 'Logs:'}`);\n }\n\n // Only print if disabling logs AND logs currently enabled\n if (!enabled && initiallyEnabled) {\n printLogsBlockEnd();\n }\n } catch (error) {\n console.log(chalk.red('mock_setLoggingEnabled error'), error);\n }\n};\n\nexport const mock_withLogs = async (\n hre: HardhatRuntimeEnvironment,\n closureName: string,\n closure: () => Promise<void>\n) => {\n const initiallyEnabled = await getLoggingEnabled(hre);\n\n await setLoggingEnabled(hre, true);\n printLogsEnabledMessage(`\"${chalk.bold(closureName)}\" logs:`);\n await closure();\n printLogsBlockEnd();\n\n // If logs were disabled, disable them again\n if (!initiallyEnabled) {\n await setLoggingEnabled(hre, false);\n }\n};\n"],"mappings":";AAEA,OAAOA,YAAW;AAClB,OAAqD;AACrD,SAAS,cAAc,mBAAmB,MAAM,aAAa;AAC7D,SAAS,WAAW,iBAAiB;AACrC,OAAoC;AACpC;AAAA,EAIE,oCAAAC;AAAA,OACK;AACP,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,4BAA4B;;;ACbrC,OAA+C;AAC/C,OAAO;AASP,eAAsB,sBAAsB,KAAgC,WAAmB,SAAiB,MAAM;AAEpH,QAAM,aACJ,QAAQ,IAAI,sBAAsB;AACpC,MAAI,CAAC,YAAY;AACf,YAAQ,MAAM,wDAAwD;AACtE,WAAO;AAAA,EACT;AAEA,MAAI;AAEF,UAAM,SAAS,IAAI,IAAI,OAAO,OAAO,YAAY,IAAI,OAAO,QAAQ;AAGpE,UAAM,UAAU,MAAM,IAAI,OAAO,SAAS,WAAW,OAAO,OAAO;AACnE,YAAQ,IAAI,0BAA0B,OAAO,OAAO,EAAE;AACtD,YAAQ,IAAI,0BAA0B,IAAI,OAAO,YAAY,OAAO,CAAC,MAAM;AAG3E,UAAM,eAAe,IAAI,OAAO,WAAW,MAAM;AACjD,QAAI,UAAU,cAAc;AAC1B,cAAQ;AAAA,QACN,oEAAoE,IAAI,OAAO,YAAY,OAAO,CAAC;AAAA,MACrG;AACA,aAAO;AAAA,IACT;AAGA,YAAQ,IAAI,WAAW,MAAM,WAAW,SAAS,KAAK;AACtD,UAAM,KAAK,MAAM,OAAO,gBAAgB;AAAA,MACtC,IAAI;AAAA,MACJ,OAAO;AAAA,IACT,CAAC;AAED,YAAQ,IAAI,2BAA2B,GAAG,IAAI,EAAE;AAChD,YAAQ,IAAI,6BAA6B;AAGzC,UAAM,UAAU,MAAM,GAAG,KAAK;A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E,cAAM,aAAa,MAAM,YAAY,IAAI;AACzC,eAAO,IAAI,OAAO,cAAcF,iBAAgB,KAAK,UAAU;AAAA,MACjE;AAAA,MACA,yBAAyB,YAAY,qBAAqB,KAAKC,6BAA4B;AAAA,MAC3F,mBAAmB,YAAY,qBAAqB,KAAKE,uBAAsB;AAAA,MAC/E,YAAY,YAAY,qBAAqB,KAAKC,gBAAe;AAAA,IACnE;AAAA,EACF;AACF,CAAC;","names":["chalk","MOCKS_ZK_VERIFIER_SIGNER_ADDRESS","TASK_MANAGER_ADDRESS","TASK_MANAGER_ADDRESS","chalk","MockTaskManagerArtifact","chalk","MockACLArtifact","MockThresholdNetworkArtifact","MockTaskManagerArtifact","MockZkVerifierArtifact","TestBedArtifact","chalk","MOCKS_ZK_VERIFIER_SIGNER_ADDRESS"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofhe/hardhat-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "fast-glob": "^3.3.2",
22
22
  "viem": "^2.38.6",
23
23
  "chai": "^4.2.0",
24
- "@cofhe/sdk": "0.2.1",
25
- "@cofhe/mock-contracts": "0.2.1"
24
+ "@cofhe/sdk": "0.3.1",
25
+ "@cofhe/mock-contracts": "0.3.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@nomicfoundation/hardhat-ethers": "^3.0.5",
@@ -39,8 +39,8 @@
39
39
  "prettier-plugin-solidity": "^1.3.0",
40
40
  "tsup": "^8.0.2",
41
41
  "typescript": "5.5.4",
42
- "@cofhe/tsconfig": "0.1.1",
43
- "@cofhe/eslint-config": "0.2.0"
42
+ "@cofhe/tsconfig": "0.1.2",
43
+ "@cofhe/eslint-config": "0.2.1"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "hardhat": "^2.0.0",
package/src/deploy.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  MockTaskManagerArtifact,
7
7
  MockACLArtifact,
8
8
  MockZkVerifierArtifact,
9
- MockQueryDecrypterArtifact,
9
+ MockThresholdNetworkArtifact,
10
10
  TestBedArtifact,
11
11
  } from '@cofhe/mock-contracts';
12
12
 
@@ -62,8 +62,8 @@ export const deployMocks = async (
62
62
  const zkVerifier = await deployMockZkVerifier(hre);
63
63
  logDeployment('MockZkVerifier', await zkVerifier.getAddress());
64
64
 
65
- const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
66
- logDeployment('MockQueryDecrypter', await queryDecrypter.getAddress());
65
+ const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);
66
+ logDeployment('MockThresholdNetwork', await thresholdNetwork.getAddress());
67
67
 
68
68
  if (options.deployTestBed) {
69
69
  logSuccess('TestBed deployment enabled', 2);
@@ -154,20 +154,20 @@ const deployMockZkVerifier = async (hre: HardhatRuntimeEnvironment) => {
154
154
  return zkVerifier;
155
155
  };
156
156
 
157
- const deployMockQueryDecrypter = async (hre: HardhatRuntimeEnvironment, acl: Contract) => {
158
- const queryDecrypter = await deployMockContractFromArtifact(hre, MockQueryDecrypterArtifact);
157
+ const deployMockThresholdNetwork = async (hre: HardhatRuntimeEnvironment, acl: Contract) => {
158
+ const thresholdNetwork = await deployMockContractFromArtifact(hre, MockThresholdNetworkArtifact);
159
159
 
160
- // Initialize MockQueryDecrypter
161
- const initTx = await queryDecrypter.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());
160
+ // Initialize MockThresholdNetwork
161
+ const initTx = await thresholdNetwork.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());
162
162
  await initTx.wait();
163
163
 
164
- // Check if MockQueryDecrypter exists
165
- const queryDecrypterExists = await queryDecrypter.exists();
166
- if (!queryDecrypterExists) {
167
- throw new Error('MockQueryDecrypter does not exist');
164
+ // Check if MockThresholdNetwork exists
165
+ const exists = await thresholdNetwork.exists();
166
+ if (!exists) {
167
+ throw new Error('MockThresholdNetwork does not exist');
168
168
  }
169
169
 
170
- return queryDecrypter;
170
+ return thresholdNetwork;
171
171
  };
172
172
 
173
173
  const deployTestBedContract = async (hre: HardhatRuntimeEnvironment) => {
package/src/index.ts CHANGED
@@ -6,12 +6,12 @@ import { extendConfig, extendEnvironment, task, types } from 'hardhat/config';
6
6
  import { TASK_TEST, TASK_NODE } from 'hardhat/builtin-tasks/task-names';
7
7
  import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
8
8
  import {
9
- type CofhesdkClient,
10
- type CofhesdkConfig,
11
- type CofhesdkInputConfig,
9
+ type CofheClient,
10
+ type CofheConfig,
11
+ type CofheInputConfig,
12
12
  MOCKS_ZK_VERIFIER_SIGNER_ADDRESS,
13
13
  } from '@cofhe/sdk';
14
- import { createCofhesdkClient, createCofhesdkConfig } from '@cofhe/sdk/node';
14
+ import { createCofheClient, createCofheConfig } from '@cofhe/sdk/node';
15
15
  import { HardhatSignerAdapter } from '@cofhe/sdk/adapters';
16
16
 
17
17
  import { localcofheFundAccount } from './fund.js';
@@ -24,7 +24,7 @@ import type { Contract } from 'ethers';
24
24
  import { hardhat } from '@cofhe/sdk/chains';
25
25
  import {
26
26
  MockACLArtifact,
27
- MockQueryDecrypterArtifact,
27
+ MockThresholdNetworkArtifact,
28
28
  MockTaskManagerArtifact,
29
29
  MockZkVerifierArtifact,
30
30
  TestBedArtifact,
@@ -36,7 +36,7 @@ import {
36
36
  */
37
37
  declare module 'hardhat/types/config' {
38
38
  interface HardhatUserConfig {
39
- cofhesdk?: {
39
+ cofhe?: {
40
40
  /** Whether to log mock operations (default: true) */
41
41
  logMocks?: boolean;
42
42
  /** Whether to show gas usage warnings for mock operations (default: true) */
@@ -45,7 +45,7 @@ declare module 'hardhat/types/config' {
45
45
  }
46
46
 
47
47
  interface HardhatConfig {
48
- cofhesdk: {
48
+ cofhe: {
49
49
  /** Whether to log mock operations (default: true) */
50
50
  logMocks: boolean;
51
51
  /** Whether to show gas usage warnings for mock operations (default: true) */
@@ -105,9 +105,9 @@ extendConfig((config, userConfig) => {
105
105
  }
106
106
 
107
107
  // Add cofhe config
108
- config.cofhesdk = {
109
- logMocks: userConfig.cofhesdk?.logMocks ?? true,
110
- gasWarning: userConfig.cofhesdk?.gasWarning ?? true,
108
+ config.cofhe = {
109
+ logMocks: userConfig.cofhe?.logMocks ?? true,
110
+ gasWarning: userConfig.cofhe?.gasWarning ?? true,
111
111
  };
112
112
  });
113
113
 
@@ -148,24 +148,41 @@ task(TASK_COFHE_MOCKS_DEPLOY, 'Deploys the mock contracts on the Hardhat network
148
148
  .setAction(async ({ deployTestBed, silent }: DeployMocksArgs, hre) => {
149
149
  await deployMocks(hre, {
150
150
  deployTestBed: deployTestBed ?? true,
151
- gasWarning: hre.config.cofhesdk.gasWarning ?? true,
151
+ gasWarning: hre.config.cofhe.gasWarning ?? true,
152
152
  silent: silent ?? false,
153
153
  });
154
154
  });
155
155
 
156
+ // Hardhat plugin auto-deploys mocks for every hardhat test run by overriding TASK_TEST and calling deployMocks(...) before runSuper()
156
157
  task(TASK_TEST, 'Deploy mock contracts on hardhat').setAction(async ({}, hre, runSuper) => {
157
- await deployMocks(hre, {
158
- deployTestBed: true,
159
- gasWarning: hre.config.cofhesdk.gasWarning ?? true,
160
- });
158
+ const skipAutoDeploy = (() => {
159
+ const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? '';
160
+ const normalized = raw.trim().toLowerCase();
161
+ return normalized === '1' || normalized === 'true' || normalized === 'yes';
162
+ })();
163
+
164
+ if (!skipAutoDeploy) {
165
+ await deployMocks(hre, {
166
+ deployTestBed: true,
167
+ gasWarning: hre.config.cofhe.gasWarning ?? true,
168
+ });
169
+ }
161
170
  return runSuper();
162
171
  });
163
172
 
164
173
  task(TASK_NODE, 'Deploy mock contracts on hardhat').setAction(async ({}, hre, runSuper) => {
165
- await deployMocks(hre, {
166
- deployTestBed: true,
167
- gasWarning: hre.config.cofhesdk.gasWarning ?? true,
168
- });
174
+ const skipAutoDeploy = (() => {
175
+ const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? '';
176
+ const normalized = raw.trim().toLowerCase();
177
+ return normalized === '1' || normalized === 'true' || normalized === 'yes';
178
+ })();
179
+
180
+ if (!skipAutoDeploy) {
181
+ await deployMocks(hre, {
182
+ deployTestBed: true,
183
+ gasWarning: hre.config.cofhe.gasWarning ?? true,
184
+ });
185
+ }
169
186
  return runSuper();
170
187
  });
171
188
 
@@ -191,21 +208,21 @@ export * from './deploy.js';
191
208
  */
192
209
  declare module 'hardhat/types/runtime' {
193
210
  export interface HardhatRuntimeEnvironment {
194
- cofhesdk: {
211
+ cofhe: {
195
212
  /**
196
- * Create a CoFHE SDK configuration for use with cofhesdk.createCofhesdkClient(...)
197
- * @param {CofhesdkInputConfig} config - The CoFHE SDK input configuration
198
- * @returns {CofhesdkConfig} The CoFHE SDK configuration
213
+ * Create a CoFHE configuration for use with hre.cofhe.createClient(...)
214
+ * @param {CofheInputConfig} config - The CoFHE input configuration
215
+ * @returns {CofheConfig} The CoFHE configuration
199
216
  */
200
- createCofhesdkConfig: (config: CofhesdkInputConfig) => Promise<CofhesdkConfig>;
217
+ createConfig: (config: CofheInputConfig) => Promise<CofheConfig>;
201
218
  /**
202
- * Create a CoFHE SDK client instance
203
- * @param {CofhesdkConfig} config - The CoFHE SDK configuration (use createCofhesdkConfig to create with Node.js defaults)
204
- * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance
219
+ * Create a CoFHE client instance
220
+ * @param {CofheConfig} config - The CoFHE configuration (use createCofheConfig to create with Node.js defaults)
221
+ * @returns {Promise<CofheClient>} The CoFHE client instance
205
222
  */
206
- createCofhesdkClient: (config: CofhesdkConfig) => CofhesdkClient;
223
+ createClient: (config: CofheConfig) => CofheClient;
207
224
  /**
208
- * Create viem clients from a Hardhat ethers signer, to be used with `cofhesdkClient.connect(...)`
225
+ * Create viem clients from a Hardhat ethers signer, to be used with `cofheClient.connect(...)`
209
226
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
210
227
  * @returns {Promise<{ publicClient: PublicClient; walletClient: WalletClient }>} The viem clients
211
228
  */
@@ -213,20 +230,20 @@ declare module 'hardhat/types/runtime' {
213
230
  signer: HardhatEthersSigner
214
231
  ) => Promise<{ publicClient: PublicClient; walletClient: WalletClient }>;
215
232
  /**
216
- * Connect a CoFHE SDK client with a Hardhat ethers signer
217
- * @param {CofhesdkClient} client - The CoFHE SDK client to connect
233
+ * Connect a CoFHE client with a Hardhat ethers signer
234
+ * @param {CofheClient} client - The CoFHE client to connect
218
235
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
219
236
  * @returns {Promise<void>}
220
237
  */
221
- connectWithHardhatSigner: (client: CofhesdkClient, signer: HardhatEthersSigner) => Promise<void>;
238
+ connectWithHardhatSigner: (client: CofheClient, signer: HardhatEthersSigner) => Promise<void>;
222
239
  /**
223
240
  * Create and connect to a batteries included client.
224
241
  * Also generates a self-usage a permit for the signer.
225
- * If customization is needed, use createCofhesdkClient and connectWithHardhatSigner.
242
+ * If customization is needed, use createCofheClient and connectWithHardhatSigner.
226
243
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use (optional - defaults to first signer)
227
- * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance
244
+ * @returns {Promise<CofheClient>} The CoFHE client instance
228
245
  */
229
- createBatteriesIncludedCofhesdkClient: (signer?: HardhatEthersSigner) => Promise<CofhesdkClient>;
246
+ createClientWithBatteries: (signer?: HardhatEthersSigner) => Promise<CofheClient>;
230
247
 
231
248
  mocks: {
232
249
  /**
@@ -239,7 +256,7 @@ declare module 'hardhat/types/runtime' {
239
256
  * Example usage:
240
257
  *
241
258
  * ```ts
242
- * await hre.cofhesdk.mocks.withLogs("counter.increment()", async () => {
259
+ * await hre.cofhe.mocks.withLogs("counter.increment()", async () => {
243
260
  * await counter.increment();
244
261
  * });
245
262
  * ```
@@ -313,10 +330,10 @@ declare module 'hardhat/types/runtime' {
313
330
  getMockACL: () => Promise<Contract>;
314
331
 
315
332
  /**
316
- * Get the MockQueryDecrypter contract
317
- * @returns {Promise<Contract>} The MockQueryDecrypter contract
333
+ * Get the MockThresholdNetwork contract
334
+ * @returns {Promise<Contract>} The MockThresholdNetwork contract
318
335
  */
319
- getMockQueryDecrypter: () => Promise<Contract>;
336
+ getMockThresholdNetwork: () => Promise<Contract>;
320
337
 
321
338
  /**
322
339
  * Get the MockZkVerifier contract
@@ -334,53 +351,69 @@ declare module 'hardhat/types/runtime' {
334
351
  }
335
352
  }
336
353
 
354
+ /**
355
+ * Builds the mocks config for the hardhat plugin.
356
+ * Defaults `encryptDelay` to `0` so tests run without artificial wait times,
357
+ * unless the user has explicitly provided a value.
358
+ */
359
+ export function buildHardhatPluginMocksConfig(
360
+ mocksConfig: CofheInputConfig['mocks']
361
+ ): NonNullable<CofheInputConfig['mocks']> {
362
+ return {
363
+ ...mocksConfig,
364
+ encryptDelay: mocksConfig?.encryptDelay ?? 0,
365
+ };
366
+ }
367
+
337
368
  extendEnvironment((hre) => {
338
- hre.cofhesdk = {
339
- createCofhesdkConfig: async (config: CofhesdkInputConfig) => {
369
+ hre.cofhe = {
370
+ createConfig: async (config: CofheInputConfig) => {
340
371
  // Create zkv wallet client
341
372
  // This wallet interacts with the MockZkVerifier contract so that the user's connected wallet doesn't have to
342
373
  const zkvHhSigner = await hre.ethers.getImpersonatedSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
343
374
  const { walletClient: zkvWalletClient } = await HardhatSignerAdapter(zkvHhSigner);
344
375
 
345
376
  // Inject zkv wallet client into config
377
+ // Set encryptDelay to 0 on hardhat to avoid waiting for delays during tests
346
378
  const configWithZkvWalletClient = {
347
379
  environment: 'hardhat' as const,
348
380
  ...config,
381
+ mocks: buildHardhatPluginMocksConfig(config.mocks),
349
382
  _internal: {
350
383
  ...config._internal,
351
384
  zkvWalletClient,
352
385
  },
353
386
  };
354
387
 
355
- return createCofhesdkConfig(configWithZkvWalletClient);
388
+ return createCofheConfig(configWithZkvWalletClient);
356
389
  },
357
- createCofhesdkClient: (config: CofhesdkConfig) => {
358
- return createCofhesdkClient(config);
390
+ createClient: (config: CofheConfig) => {
391
+ return createCofheClient(config);
359
392
  },
360
393
  hardhatSignerAdapter: async (signer: HardhatEthersSigner) => {
361
394
  return HardhatSignerAdapter(signer);
362
395
  },
363
- connectWithHardhatSigner: async (client: CofhesdkClient, signer: HardhatEthersSigner) => {
396
+ connectWithHardhatSigner: async (client: CofheClient, signer: HardhatEthersSigner) => {
364
397
  const { publicClient, walletClient } = await HardhatSignerAdapter(signer);
365
398
  return client.connect(publicClient, walletClient);
366
399
  },
367
- createBatteriesIncludedCofhesdkClient: async (signer?: HardhatEthersSigner) => {
400
+ createClientWithBatteries: async (signer?: HardhatEthersSigner) => {
368
401
  // Get signer if not provided
369
402
  if (!signer) {
370
403
  [signer] = await hre.ethers.getSigners();
371
404
  }
372
405
 
373
406
  // Create config
374
- const config = await hre.cofhesdk.createCofhesdkConfig({
407
+ const config = await hre.cofhe.createConfig({
375
408
  environment: 'hardhat',
376
409
  supportedChains: [hardhat],
377
410
  });
378
411
 
379
412
  // Create client
380
- const client = hre.cofhesdk.createCofhesdkClient(config);
413
+ const client = hre.cofhe.createClient(config);
381
414
 
382
415
  // Connect client
383
- await hre.cofhesdk.connectWithHardhatSigner(client, signer);
416
+ await hre.cofhe.connectWithHardhatSigner(client, signer);
384
417
 
385
418
  // Create self-usage permit
386
419
  await client.permits.createSelf({
@@ -417,7 +450,7 @@ extendEnvironment((hre) => {
417
450
  const aclAddress = await taskManager.acl();
418
451
  return hre.ethers.getContractAt(MockACLArtifact.abi, aclAddress);
419
452
  },
420
- getMockQueryDecrypter: async () => getFixedMockContract(hre, MockQueryDecrypterArtifact),
453
+ getMockThresholdNetwork: async () => getFixedMockContract(hre, MockThresholdNetworkArtifact),
421
454
  getMockZkVerifier: async () => getFixedMockContract(hre, MockZkVerifierArtifact),
422
455
  getTestBed: async () => getFixedMockContract(hre, TestBedArtifact),
423
456
  },