@cofhe/hardhat-plugin 0.0.0-alpha-20260409113701
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +170 -0
- package/README.md +148 -0
- package/dist/index.d.mts +229 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.js +580 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +551 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
- package/src/consts.ts +3 -0
- package/src/deploy.ts +231 -0
- package/src/fund.ts +82 -0
- package/src/index.ts +475 -0
- package/src/logging.ts +72 -0
- package/src/utils.ts +109 -0
|
@@ -0,0 +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 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, type LogMocksDeploy } 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 { hardhat } from '@cofhe/sdk/chains';\nimport {\n MockACLArtifact,\n MockThresholdNetworkArtifact,\n MockTaskManagerArtifact,\n MockZkVerifierArtifact,\n TestBedArtifact,\n type MockACL,\n type MockTaskManager,\n type MockThresholdNetwork,\n type MockZkVerifier,\n type TestBed,\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 * Controls deploy-mocks console output.\n * - `''` — silent, no output\n * - `'v'` — single summary line (default)\n * - `'vv'` — full per-contract deployment logs\n */\n mocksDeployVerbosity?: LogMocksDeploy;\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 mocksDeployVerbosity: LogMocksDeploy;\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 ?? false,\n gasWarning: userConfig.cofhe?.gasWarning ?? false,\n mocksDeployVerbosity: (userConfig.cofhe?.mocksDeployVerbosity ?? 'v') as LogMocksDeploy,\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 .setAction(async ({ deployTestBed }: DeployMocksArgs, hre) => {\n await deployMocks(hre, {\n deployTestBed: deployTestBed ?? true,\n gasWarning: hre.config.cofhe.gasWarning ?? true,\n mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity,\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 mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity,\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 mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity,\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 | string} ctHash - The ciphertext hash to look up\n * @returns {Promise<bigint>} The plaintext value\n */\n getPlaintext: (ctHash: bigint | string) => Promise<bigint>;\n\n /**\n * **[MOCKS ONLY]**\n *\n * Assert that a ciphertext hash represents an expected plaintext value\n * @param {bigint | string} ctHash - The ciphertext hash to check\n * @param {bigint} expectedValue - The expected plaintext value\n */\n expectPlaintext: (ctHash: bigint | string, expectedValue: bigint) => Promise<void>;\n\n /**\n * Get the MockTaskManager contract (typed via typechain)\n * @returns {Promise<MockTaskManager>} The MockTaskManager contract\n */\n getMockTaskManager: () => Promise<MockTaskManager>;\n\n /**\n * Get the MockACL contract (typed via typechain)\n * @returns {Promise<MockACL>} The MockACL contract\n */\n getMockACL: () => Promise<MockACL>;\n\n /**\n * Get the MockThresholdNetwork contract (typed via typechain)\n * @returns {Promise<MockThresholdNetwork>} The MockThresholdNetwork contract\n */\n getMockThresholdNetwork: () => Promise<MockThresholdNetwork>;\n\n /**\n * Get the MockZkVerifier contract (typed via typechain)\n * @returns {Promise<MockZkVerifier>} The MockZkVerifier contract\n */\n getMockZkVerifier: () => Promise<MockZkVerifier>;\n\n /**\n * Get the TestBed contract (typed via typechain)\n * @returns {Promise<TestBed>} The TestBed contract\n */\n getTestBed: () => Promise<TestBed>;\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, { mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity, ...options });\n },\n getPlaintext: async (ctHash: bigint | string) => {\n const [signer] = await hre.ethers.getSigners();\n return mock_getPlaintext(signer.provider, ctHash);\n },\n expectPlaintext: async (ctHash: bigint | string, expectedValue: bigint) => {\n const [signer] = await hre.ethers.getSigners();\n return mock_expectPlaintext(signer.provider, ctHash, expectedValue);\n },\n getMockTaskManager: async () =>\n getFixedMockContract(hre, MockTaskManagerArtifact) as unknown as Promise<MockTaskManager>,\n getMockACL: async () => {\n const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact);\n const aclAddress = await taskManager.acl();\n return hre.ethers.getContractAt([...MockACLArtifact.abi], aclAddress) as unknown as MockACL;\n },\n getMockThresholdNetwork: async () =>\n getFixedMockContract(hre, MockThresholdNetworkArtifact) as unknown as Promise<MockThresholdNetwork>,\n getMockZkVerifier: async () =>\n getFixedMockContract(hre, MockZkVerifierArtifact) as unknown as Promise<MockZkVerifier>,\n getTestBed: async () => getFixedMockContract(hre, TestBedArtifact) as unknown as Promise<TestBed>,\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, Wallet } from 'ethers';\n\nimport {\n MockTaskManagerArtifact,\n MockACLArtifact,\n MockZkVerifierArtifact,\n MockThresholdNetworkArtifact,\n TestBedArtifact,\n} from '@cofhe/mock-contracts';\n\nimport {\n TASK_MANAGER_ADDRESS,\n MOCKS_ZK_VERIFIER_SIGNER_ADDRESS,\n MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY,\n MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY,\n} from '@cofhe/sdk';\nimport { deployMockContractFromArtifact } from './utils';\n\n// Deployment\n\n/**\n * Controls deploy-mocks console output.\n * - `''` — silent, no output\n * - `'v'` — single summary line (default)\n * - `'vv'` — full per-contract deployment logs\n */\nexport type LogMocksDeploy = '' | 'v' | 'vv';\n\nexport type DeployMocksArgs = {\n deployTestBed?: boolean;\n gasWarning?: boolean;\n mocksDeployVerbosity?: LogMocksDeploy;\n};\n\nexport const deployMocks = async (\n hre: HardhatRuntimeEnvironment,\n options: DeployMocksArgs = {\n deployTestBed: true,\n gasWarning: true,\n mocksDeployVerbosity: 'v',\n }\n) => {\n verbosity = options.mocksDeployVerbosity ?? 'v';\n\n // Check if network is Hardhat, if not log skip message and return\n const isHardhat = await getIsHardhat(hre);\n if (!isHardhat) {\n log('v', `cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);\n return;\n }\n\n log('vv', chalk.bold('cofhe-hardhat-plugin :: deploy mocks'), 0);\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 log('vv', 'ACL address set in TaskManager', 2);\n\n await setVerifierSigner(taskManager);\n log('vv', 'Verifier signer set', 2);\n\n await setDecryptResultSigner(taskManager);\n log('vv', 'Decrypt result signer set', 2);\n\n await fundZkVerifierSigner(hre);\n log('vv', `ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);\n\n const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);\n log('vv', `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 const testBed = await deployTestBedContract(hre);\n logDeployment('TestBed', await testBed.getAddress());\n }\n\n log('v', chalk.bold('cofhe-hardhat-plugin :: mocks deployed'), 0);\n\n if (options.gasWarning) {\n logEmpty('v');\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.gasWarning: false' in your hardhat config)\",\n 0\n );\n }\n\n logEmpty('v');\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 setVerifierSigner = async (taskManager: Contract) => {\n const signer = new Wallet(MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY);\n const setSignerTx = await taskManager.setVerifierSigner(signer.address);\n await setSignerTx.wait();\n};\n\nconst setDecryptResultSigner = async (taskManager: Contract) => {\n const signer = new Wallet(MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY);\n const setSignerTx = await taskManager.setDecryptResultSigner(signer.address);\n await setSignerTx.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 verbosity: LogMocksDeploy = 'v';\n\n/**\n * Emit a green ✓ line at `minVerbosity` or above.\n * - `minVerbosity = 'v'` → prints for both 'v' and 'vv'\n * - `minVerbosity = 'vv'` → prints only for 'vv'\n */\nconst log = (minVerbosity: 'v' | 'vv', message: string, indent = 1) => {\n if (verbosity === '') return;\n if (minVerbosity === 'vv' && verbosity !== 'vv') return;\n console.log(chalk.green(`${' '.repeat(indent)}✓ ${message}`));\n};\n\nconst logEmpty = (minVerbosity: 'v' | 'vv' = 'v') => {\n if (verbosity === '') return;\n if (minVerbosity === 'vv' && verbosity !== 'vv') return;\n console.log('');\n};\n\nconst logWarning = (message: string, indent = 1) => {\n if (verbosity === '') return;\n console.log(chalk.bold(chalk.yellow(`${' '.repeat(indent)}⚠ NOTE:`)), message);\n};\n\nconst logDeployment = (contractName: string, address: string) => {\n if (verbosity !== 'vv') return;\n const paddedName = `${contractName} deployed`.padEnd(36);\n console.log(chalk.green(` ✓ ${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 (\n provider: HardhatEthersProvider | ethers.JsonRpcProvider,\n ctHash: bigint | string\n) => {\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(BigInt(ctHash));\n\n return plaintext;\n};\n\nexport const mock_getPlaintextExists = async (\n provider: HardhatEthersProvider | ethers.JsonRpcProvider,\n ctHash: bigint | string\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(BigInt(ctHash));\n\n return plaintextExists;\n};\n\nexport const mock_expectPlaintext = async (\n provider: HardhatEthersProvider | ethers.JsonRpcProvider,\n ctHash: bigint | string,\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 try {\n await closure();\n } finally {\n printLogsBlockEnd();\n\n // If logs were disabled, disable them again\n if (!initiallyEnabled) {\n await setLoggingEnabled(hre, false);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAAkB;AAClB,kBAAqD;AACrD,oBAA6D;AAC7D,wBAAqC;AACrC,qBAAoC;AACpC,IAAAC,cAKO;AACP,kBAAqD;AACrD,sBAAqC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WAA4B;AAC/C,cAAM,CAAC,MAAM,IAAI,MAAM,IAAI,OAAO,WAAW;AAC7C,eAAO,kBAAkB,OAAO,UAAU,MAAM;AAAA,MAClD;AAAA,MACA,iBAAiB,OAAO,QAAyB,kBAA0B;AACzE,cAAM,CAAC,MAAM,IAAI,MAAM,IAAI,OAAO,WAAW;AAC7C,eAAO,qBAAqB,OAAO,UAAU,QAAQ,aAAa;AAAA,MACpE;AAAA,MACA,oBAAoB,YAClB,qBAAqB,KAAK,8CAAuB;AAAA,MACnD,YAAY,YAAY;AACtB,cAAM,cAAc,MAAM,qBAAqB,KAAK,8CAAuB;AAC3E,cAAM,aAAa,MAAM,YAAY,IAAI;AACzC,eAAO,IAAI,OAAO,cAAc,CAAC,GAAG,uCAAgB,GAAG,GAAG,UAAU;AAAA,MACtE;AAAA,MACA,yBAAyB,YACvB,qBAAqB,KAAK,mDAA4B;AAAA,MACxD,mBAAmB,YACjB,qBAAqB,KAAK,6CAAsB;AAAA,MAClD,YAAY,YAAY,qBAAqB,KAAK,sCAAe;AAAA,IACnE;AAAA,EACF;AACF,CAAC;","names":["import_chalk","import_sdk","import_types","import_ethers","import_sdk","chalk","import_chalk","import_types","import_mock_contracts","chalk","import_mock_contracts","chalk"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import chalk3 from "chalk";
|
|
3
|
+
import "viem";
|
|
4
|
+
import { extendConfig, extendEnvironment, task, types } from "hardhat/config";
|
|
5
|
+
import { TASK_TEST, TASK_NODE } from "hardhat/builtin-tasks/task-names";
|
|
6
|
+
import "@nomicfoundation/hardhat-ethers/signers";
|
|
7
|
+
import {
|
|
8
|
+
MOCKS_ZK_VERIFIER_SIGNER_ADDRESS as MOCKS_ZK_VERIFIER_SIGNER_ADDRESS2
|
|
9
|
+
} from "@cofhe/sdk";
|
|
10
|
+
import { createCofheClient, createCofheConfig } from "@cofhe/sdk/node";
|
|
11
|
+
import { HardhatSignerAdapter } from "@cofhe/sdk/adapters";
|
|
12
|
+
|
|
13
|
+
// src/fund.ts
|
|
14
|
+
import "hardhat/types";
|
|
15
|
+
import "@nomicfoundation/hardhat-ethers";
|
|
16
|
+
async function localcofheFundAccount(hre, toAddress, amount = "10") {
|
|
17
|
+
const privateKey = process.env.FUNDER_PRIVATE_KEY ?? "0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659";
|
|
18
|
+
if (!privateKey) {
|
|
19
|
+
console.error("Error: FUNDER_PRIVATE_KEY environment variable not set");
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const wallet = new hre.ethers.Wallet(privateKey, hre.ethers.provider);
|
|
24
|
+
const balance = await hre.ethers.provider.getBalance(wallet.address);
|
|
25
|
+
console.log(`Funder wallet address: ${wallet.address}`);
|
|
26
|
+
console.log(`Funder wallet balance: ${hre.ethers.formatEther(balance)} ETH`);
|
|
27
|
+
const amountToSend = hre.ethers.parseEther(amount);
|
|
28
|
+
if (balance < amountToSend) {
|
|
29
|
+
console.error(
|
|
30
|
+
`Error: Funder wallet doesn't have enough funds. Current balance: ${hre.ethers.formatEther(balance)} ETH`
|
|
31
|
+
);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
console.log(`Sending ${amount} ETH to ${toAddress}...`);
|
|
35
|
+
const tx = await wallet.sendTransaction({
|
|
36
|
+
to: toAddress,
|
|
37
|
+
value: amountToSend
|
|
38
|
+
});
|
|
39
|
+
console.log(`Transaction sent! Hash: ${tx.hash}`);
|
|
40
|
+
console.log("Waiting for confirmation...");
|
|
41
|
+
const receipt = await tx.wait();
|
|
42
|
+
console.log(`Transaction confirmed in block ${receipt?.blockNumber}`);
|
|
43
|
+
console.log(`Successfully sent ${amount} ETH to ${toAddress}`);
|
|
44
|
+
return receipt;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error("Error sending funds:", error);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function localcofheFundWalletIfNeeded(hre, walletAddress) {
|
|
51
|
+
const walletBalance = await hre.ethers.provider.getBalance(walletAddress);
|
|
52
|
+
console.log(`Wallet balance: ${hre.ethers.formatEther(walletBalance)} ETH`);
|
|
53
|
+
if (walletBalance < hre.ethers.parseEther("1")) {
|
|
54
|
+
console.log(`Wallet balance is less than 1 ETH. Funding ${walletAddress}...`);
|
|
55
|
+
const receipt = await localcofheFundAccount(hre, walletAddress);
|
|
56
|
+
if (receipt) {
|
|
57
|
+
const newBalance = await hre.ethers.provider.getBalance(walletAddress);
|
|
58
|
+
console.log(`Wallet new balance: ${hre.ethers.formatEther(newBalance)} ETH`);
|
|
59
|
+
} else {
|
|
60
|
+
console.error(`Failed to fund ${walletAddress}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/consts.ts
|
|
66
|
+
var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
67
|
+
var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
68
|
+
var TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
|
|
69
|
+
|
|
70
|
+
// src/deploy.ts
|
|
71
|
+
import "hardhat/types";
|
|
72
|
+
import chalk from "chalk";
|
|
73
|
+
import { Wallet } from "ethers";
|
|
74
|
+
import {
|
|
75
|
+
MockTaskManagerArtifact,
|
|
76
|
+
MockACLArtifact,
|
|
77
|
+
MockZkVerifierArtifact,
|
|
78
|
+
MockThresholdNetworkArtifact,
|
|
79
|
+
TestBedArtifact
|
|
80
|
+
} from "@cofhe/mock-contracts";
|
|
81
|
+
import {
|
|
82
|
+
TASK_MANAGER_ADDRESS as TASK_MANAGER_ADDRESS2,
|
|
83
|
+
MOCKS_ZK_VERIFIER_SIGNER_ADDRESS,
|
|
84
|
+
MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY,
|
|
85
|
+
MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY
|
|
86
|
+
} from "@cofhe/sdk";
|
|
87
|
+
|
|
88
|
+
// src/utils.ts
|
|
89
|
+
import { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS } from "@cofhe/sdk";
|
|
90
|
+
import { expect } from "chai";
|
|
91
|
+
import { ethers } from "ethers";
|
|
92
|
+
import "@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider";
|
|
93
|
+
var deployMockContractFromArtifact = async (hre, artifact) => {
|
|
94
|
+
if (artifact.isFixed) {
|
|
95
|
+
await hre.network.provider.send("hardhat_setCode", [artifact.fixedAddress, artifact.deployedBytecode]);
|
|
96
|
+
return getFixedMockContract(hre, artifact);
|
|
97
|
+
}
|
|
98
|
+
const [signer] = await hre.ethers.getSigners();
|
|
99
|
+
const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);
|
|
100
|
+
const contract = await factory.deploy(
|
|
101
|
+
/* constructor args */
|
|
102
|
+
);
|
|
103
|
+
await contract.waitForDeployment();
|
|
104
|
+
return contract;
|
|
105
|
+
};
|
|
106
|
+
var getFixedMockContract = async (hre, artifact) => {
|
|
107
|
+
if (!artifact.isFixed) {
|
|
108
|
+
throw new Error("Artifact is not fixed");
|
|
109
|
+
}
|
|
110
|
+
return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
|
|
111
|
+
};
|
|
112
|
+
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
113
|
+
const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
|
|
114
|
+
const isTestnet = bytecode.length === 0;
|
|
115
|
+
if (isTestnet) {
|
|
116
|
+
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
117
|
+
}
|
|
118
|
+
return isTestnet;
|
|
119
|
+
};
|
|
120
|
+
var mock_getPlaintext = async (provider, ctHash) => {
|
|
121
|
+
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
122
|
+
return;
|
|
123
|
+
const taskManager = new ethers.Contract(
|
|
124
|
+
TASK_MANAGER_ADDRESS,
|
|
125
|
+
["function mockStorage(uint256) view returns (uint256)"],
|
|
126
|
+
provider
|
|
127
|
+
);
|
|
128
|
+
const plaintext = await taskManager.mockStorage(BigInt(ctHash));
|
|
129
|
+
return plaintext;
|
|
130
|
+
};
|
|
131
|
+
var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
132
|
+
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
133
|
+
return;
|
|
134
|
+
const taskManager = new ethers.Contract(
|
|
135
|
+
TASK_MANAGER_ADDRESS,
|
|
136
|
+
["function inMockStorage(uint256) view returns (bool)"],
|
|
137
|
+
provider
|
|
138
|
+
);
|
|
139
|
+
const plaintextExists = await taskManager.inMockStorage(BigInt(ctHash));
|
|
140
|
+
return plaintextExists;
|
|
141
|
+
};
|
|
142
|
+
var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
|
|
143
|
+
if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
|
|
144
|
+
return;
|
|
145
|
+
const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
|
|
146
|
+
expect(plaintextExists).equal(true, "Plaintext does not exist");
|
|
147
|
+
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
148
|
+
expect(plaintext).equal(expectedValue, "Plaintext value is incorrect");
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/deploy.ts
|
|
152
|
+
var deployMocks = async (hre, options = {
|
|
153
|
+
deployTestBed: true,
|
|
154
|
+
gasWarning: true,
|
|
155
|
+
mocksDeployVerbosity: "v"
|
|
156
|
+
}) => {
|
|
157
|
+
verbosity = options.mocksDeployVerbosity ?? "v";
|
|
158
|
+
const isHardhat = await getIsHardhat(hre);
|
|
159
|
+
if (!isHardhat) {
|
|
160
|
+
log("v", `cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
log("vv", chalk.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
164
|
+
const taskManager = await deployMockTaskManager(hre);
|
|
165
|
+
logDeployment("MockTaskManager", await taskManager.getAddress());
|
|
166
|
+
const acl = await deployMockACL(hre);
|
|
167
|
+
logDeployment("MockACL", await acl.getAddress());
|
|
168
|
+
await linkTaskManagerAndACL(taskManager, acl);
|
|
169
|
+
log("vv", "ACL address set in TaskManager", 2);
|
|
170
|
+
await setVerifierSigner(taskManager);
|
|
171
|
+
log("vv", "Verifier signer set", 2);
|
|
172
|
+
await setDecryptResultSigner(taskManager);
|
|
173
|
+
log("vv", "Decrypt result signer set", 2);
|
|
174
|
+
await fundZkVerifierSigner(hre);
|
|
175
|
+
log("vv", `ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
|
|
176
|
+
const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);
|
|
177
|
+
log("vv", `ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
178
|
+
const zkVerifier = await deployMockZkVerifier(hre);
|
|
179
|
+
logDeployment("MockZkVerifier", await zkVerifier.getAddress());
|
|
180
|
+
const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);
|
|
181
|
+
logDeployment("MockThresholdNetwork", await thresholdNetwork.getAddress());
|
|
182
|
+
if (options.deployTestBed) {
|
|
183
|
+
const testBed = await deployTestBedContract(hre);
|
|
184
|
+
logDeployment("TestBed", await testBed.getAddress());
|
|
185
|
+
}
|
|
186
|
+
log("v", chalk.bold("cofhe-hardhat-plugin :: mocks deployed"), 0);
|
|
187
|
+
if (options.gasWarning) {
|
|
188
|
+
logEmpty("v");
|
|
189
|
+
logWarning(
|
|
190
|
+
"When using mocks, FHE operations (eg FHE.add / FHE.mul) report a higher gas price due to additional on-chain mocking logic. Deploy your contracts on a testnet chain to check the true gas costs.\n(Disable this warning by setting 'cofhe.gasWarning: false' in your hardhat config)",
|
|
191
|
+
0
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
logEmpty("v");
|
|
195
|
+
};
|
|
196
|
+
var getIsHardhat = async (hre) => {
|
|
197
|
+
return hre.network.name === "hardhat";
|
|
198
|
+
};
|
|
199
|
+
var deployMockTaskManager = async (hre) => {
|
|
200
|
+
const [signer] = await hre.ethers.getSigners();
|
|
201
|
+
const taskManager = await deployMockContractFromArtifact(hre, MockTaskManagerArtifact);
|
|
202
|
+
const initTx = await taskManager.initialize(signer.address);
|
|
203
|
+
await initTx.wait();
|
|
204
|
+
const tmExists = await taskManager.exists();
|
|
205
|
+
if (!tmExists) {
|
|
206
|
+
throw new Error("MockTaskManager does not exist");
|
|
207
|
+
}
|
|
208
|
+
return taskManager;
|
|
209
|
+
};
|
|
210
|
+
var deployMockACL = async (hre) => {
|
|
211
|
+
const acl = await deployMockContractFromArtifact(hre, MockACLArtifact);
|
|
212
|
+
const exists = await acl.exists();
|
|
213
|
+
if (!exists) {
|
|
214
|
+
throw new Error("MockACL does not exist");
|
|
215
|
+
}
|
|
216
|
+
return acl;
|
|
217
|
+
};
|
|
218
|
+
var fundZkVerifierSigner = async (hre) => {
|
|
219
|
+
const zkVerifierSigner = await hre.ethers.getSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
220
|
+
await hre.network.provider.send("hardhat_setBalance", [
|
|
221
|
+
zkVerifierSigner.address,
|
|
222
|
+
"0x" + hre.ethers.parseEther("10").toString(16)
|
|
223
|
+
]);
|
|
224
|
+
};
|
|
225
|
+
var getZkVerifierSignerBalance = async (hre) => {
|
|
226
|
+
return hre.ethers.provider.getBalance(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
227
|
+
};
|
|
228
|
+
var linkTaskManagerAndACL = async (taskManager, acl) => {
|
|
229
|
+
const aclAddress = await acl.getAddress();
|
|
230
|
+
const linkAclTx = await taskManager.setACLContract(aclAddress);
|
|
231
|
+
await linkAclTx.wait();
|
|
232
|
+
};
|
|
233
|
+
var setVerifierSigner = async (taskManager) => {
|
|
234
|
+
const signer = new Wallet(MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY);
|
|
235
|
+
const setSignerTx = await taskManager.setVerifierSigner(signer.address);
|
|
236
|
+
await setSignerTx.wait();
|
|
237
|
+
};
|
|
238
|
+
var setDecryptResultSigner = async (taskManager) => {
|
|
239
|
+
const signer = new Wallet(MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY);
|
|
240
|
+
const setSignerTx = await taskManager.setDecryptResultSigner(signer.address);
|
|
241
|
+
await setSignerTx.wait();
|
|
242
|
+
};
|
|
243
|
+
var deployMockZkVerifier = async (hre) => {
|
|
244
|
+
const zkVerifier = await deployMockContractFromArtifact(hre, MockZkVerifierArtifact);
|
|
245
|
+
const zkVerifierExists = await zkVerifier.exists();
|
|
246
|
+
if (!zkVerifierExists) {
|
|
247
|
+
throw new Error("MockZkVerifier does not exist");
|
|
248
|
+
}
|
|
249
|
+
return zkVerifier;
|
|
250
|
+
};
|
|
251
|
+
var deployMockThresholdNetwork = async (hre, acl) => {
|
|
252
|
+
const thresholdNetwork = await deployMockContractFromArtifact(hre, MockThresholdNetworkArtifact);
|
|
253
|
+
const initTx = await thresholdNetwork.initialize(TASK_MANAGER_ADDRESS2, await acl.getAddress());
|
|
254
|
+
await initTx.wait();
|
|
255
|
+
const exists = await thresholdNetwork.exists();
|
|
256
|
+
if (!exists) {
|
|
257
|
+
throw new Error("MockThresholdNetwork does not exist");
|
|
258
|
+
}
|
|
259
|
+
return thresholdNetwork;
|
|
260
|
+
};
|
|
261
|
+
var deployTestBedContract = async (hre) => {
|
|
262
|
+
return deployMockContractFromArtifact(hre, TestBedArtifact);
|
|
263
|
+
};
|
|
264
|
+
var verbosity = "v";
|
|
265
|
+
var log = (minVerbosity, message, indent = 1) => {
|
|
266
|
+
if (verbosity === "")
|
|
267
|
+
return;
|
|
268
|
+
if (minVerbosity === "vv" && verbosity !== "vv")
|
|
269
|
+
return;
|
|
270
|
+
console.log(chalk.green(`${" ".repeat(indent)}\u2713 ${message}`));
|
|
271
|
+
};
|
|
272
|
+
var logEmpty = (minVerbosity = "v") => {
|
|
273
|
+
if (verbosity === "")
|
|
274
|
+
return;
|
|
275
|
+
if (minVerbosity === "vv" && verbosity !== "vv")
|
|
276
|
+
return;
|
|
277
|
+
console.log("");
|
|
278
|
+
};
|
|
279
|
+
var logWarning = (message, indent = 1) => {
|
|
280
|
+
if (verbosity === "")
|
|
281
|
+
return;
|
|
282
|
+
console.log(chalk.bold(chalk.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
|
|
283
|
+
};
|
|
284
|
+
var logDeployment = (contractName, address) => {
|
|
285
|
+
if (verbosity !== "vv")
|
|
286
|
+
return;
|
|
287
|
+
const paddedName = `${contractName} deployed`.padEnd(36);
|
|
288
|
+
console.log(chalk.green(` \u2713 ${paddedName} ${chalk.bold(address)}`));
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// src/logging.ts
|
|
292
|
+
import chalk2 from "chalk";
|
|
293
|
+
import "hardhat/types";
|
|
294
|
+
import { MockTaskManagerArtifact as MockTaskManagerArtifact2 } from "@cofhe/mock-contracts";
|
|
295
|
+
var getLoggingEnabled = async (hre) => {
|
|
296
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact2);
|
|
297
|
+
return taskManager.logOps();
|
|
298
|
+
};
|
|
299
|
+
var setLoggingEnabled = async (hre, enabled) => {
|
|
300
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact2);
|
|
301
|
+
const tx = await taskManager.setLogOps(enabled);
|
|
302
|
+
await tx.wait();
|
|
303
|
+
};
|
|
304
|
+
var printLogsEnabledMessage = (closureMessage) => {
|
|
305
|
+
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");
|
|
306
|
+
console.log(`\u2502 [COFHE-MOCKS] \u2502 ${closureMessage}`);
|
|
307
|
+
console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
308
|
+
};
|
|
309
|
+
var printLogsBlockEnd = () => {
|
|
310
|
+
console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
311
|
+
};
|
|
312
|
+
var mock_setLoggingEnabled = async (hre, enabled, closureName) => {
|
|
313
|
+
try {
|
|
314
|
+
const initiallyEnabled = await getLoggingEnabled(hre);
|
|
315
|
+
await setLoggingEnabled(hre, enabled);
|
|
316
|
+
if (enabled) {
|
|
317
|
+
printLogsEnabledMessage(`${closureName ? `"${chalk2.bold(closureName)}" logs:` : "Logs:"}`);
|
|
318
|
+
}
|
|
319
|
+
if (!enabled && initiallyEnabled) {
|
|
320
|
+
printLogsBlockEnd();
|
|
321
|
+
}
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.log(chalk2.red("mock_setLoggingEnabled error"), error);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
var mock_withLogs = async (hre, closureName, closure) => {
|
|
327
|
+
const initiallyEnabled = await getLoggingEnabled(hre);
|
|
328
|
+
await setLoggingEnabled(hre, true);
|
|
329
|
+
printLogsEnabledMessage(`"${chalk2.bold(closureName)}" logs:`);
|
|
330
|
+
try {
|
|
331
|
+
await closure();
|
|
332
|
+
} finally {
|
|
333
|
+
printLogsBlockEnd();
|
|
334
|
+
if (!initiallyEnabled) {
|
|
335
|
+
await setLoggingEnabled(hre, false);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// src/index.ts
|
|
341
|
+
import { hardhat } from "@cofhe/sdk/chains";
|
|
342
|
+
import {
|
|
343
|
+
MockACLArtifact as MockACLArtifact2,
|
|
344
|
+
MockThresholdNetworkArtifact as MockThresholdNetworkArtifact2,
|
|
345
|
+
MockTaskManagerArtifact as MockTaskManagerArtifact3,
|
|
346
|
+
MockZkVerifierArtifact as MockZkVerifierArtifact2,
|
|
347
|
+
TestBedArtifact as TestBedArtifact2
|
|
348
|
+
} from "@cofhe/mock-contracts";
|
|
349
|
+
extendConfig((config, userConfig) => {
|
|
350
|
+
if (userConfig.networks && userConfig.networks.localcofhe) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
config.networks.localcofhe = {
|
|
354
|
+
gas: "auto",
|
|
355
|
+
gasMultiplier: 1.2,
|
|
356
|
+
gasPrice: "auto",
|
|
357
|
+
timeout: 1e4,
|
|
358
|
+
httpHeaders: {},
|
|
359
|
+
url: "http://127.0.0.1:42069",
|
|
360
|
+
accounts: [
|
|
361
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
|
|
362
|
+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
|
|
363
|
+
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
|
|
364
|
+
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6"
|
|
365
|
+
]
|
|
366
|
+
};
|
|
367
|
+
if (!userConfig.networks?.["eth-sepolia"]) {
|
|
368
|
+
config.networks["eth-sepolia"] = {
|
|
369
|
+
url: process.env.SEPOLIA_RPC_URL ?? "https://ethereum-sepolia.publicnode.com",
|
|
370
|
+
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
|
|
371
|
+
chainId: 11155111,
|
|
372
|
+
gas: "auto",
|
|
373
|
+
gasMultiplier: 1.2,
|
|
374
|
+
gasPrice: "auto",
|
|
375
|
+
timeout: 6e4,
|
|
376
|
+
httpHeaders: {}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
if (!userConfig.networks?.["arb-sepolia"]) {
|
|
380
|
+
config.networks["arb-sepolia"] = {
|
|
381
|
+
url: process.env.ARBITRUM_SEPOLIA_RPC_URL ?? "https://sepolia-rollup.arbitrum.io/rpc",
|
|
382
|
+
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
|
|
383
|
+
chainId: 421614,
|
|
384
|
+
gas: "auto",
|
|
385
|
+
gasMultiplier: 1.2,
|
|
386
|
+
gasPrice: "auto",
|
|
387
|
+
timeout: 6e4,
|
|
388
|
+
httpHeaders: {}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
config.cofhe = {
|
|
392
|
+
logMocks: userConfig.cofhe?.logMocks ?? false,
|
|
393
|
+
gasWarning: userConfig.cofhe?.gasWarning ?? false,
|
|
394
|
+
mocksDeployVerbosity: userConfig.cofhe?.mocksDeployVerbosity ?? "v"
|
|
395
|
+
};
|
|
396
|
+
});
|
|
397
|
+
task(TASK_COFHE_USE_FAUCET, "Fund an account from the funder").addOptionalParam("address", "Address to fund", void 0, types.string).setAction(async ({ address }, hre) => {
|
|
398
|
+
const { network } = hre;
|
|
399
|
+
const { name: networkName } = network;
|
|
400
|
+
if (networkName !== "localcofhe") {
|
|
401
|
+
console.info(chalk3.yellow(`Programmatic faucet only supported for localcofhe`));
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (!address) {
|
|
405
|
+
console.info(chalk3.red(`Failed to get address to fund`));
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
console.info(chalk3.green(`Getting funds from faucet for ${address}`));
|
|
409
|
+
try {
|
|
410
|
+
await localcofheFundAccount(hre, address);
|
|
411
|
+
} catch (e) {
|
|
412
|
+
console.info(chalk3.red(`failed to get funds from localcofhe for ${address}: ${e}`));
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
task(TASK_COFHE_MOCKS_DEPLOY, "Deploys the mock contracts on the Hardhat network").addOptionalParam("deployTestBed", "Whether to deploy the test bed", true, types.boolean).setAction(async ({ deployTestBed }, hre) => {
|
|
416
|
+
await deployMocks(hre, {
|
|
417
|
+
deployTestBed: deployTestBed ?? true,
|
|
418
|
+
gasWarning: hre.config.cofhe.gasWarning ?? true,
|
|
419
|
+
mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
task(TASK_TEST, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
423
|
+
const skipAutoDeploy = (() => {
|
|
424
|
+
const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
|
|
425
|
+
const normalized = raw.trim().toLowerCase();
|
|
426
|
+
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
427
|
+
})();
|
|
428
|
+
if (!skipAutoDeploy) {
|
|
429
|
+
await deployMocks(hre, {
|
|
430
|
+
deployTestBed: true,
|
|
431
|
+
gasWarning: hre.config.cofhe.gasWarning ?? true,
|
|
432
|
+
mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
return runSuper();
|
|
436
|
+
});
|
|
437
|
+
task(TASK_NODE, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
438
|
+
const skipAutoDeploy = (() => {
|
|
439
|
+
const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
|
|
440
|
+
const normalized = raw.trim().toLowerCase();
|
|
441
|
+
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
442
|
+
})();
|
|
443
|
+
if (!skipAutoDeploy) {
|
|
444
|
+
await deployMocks(hre, {
|
|
445
|
+
deployTestBed: true,
|
|
446
|
+
gasWarning: hre.config.cofhe.gasWarning ?? true,
|
|
447
|
+
mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
return runSuper();
|
|
451
|
+
});
|
|
452
|
+
task(TASK_COFHE_MOCKS_SET_LOG_OPS, "Set logging for the Mock CoFHE contracts").addParam("enable", "Whether to enable logging", false, types.boolean).setAction(async ({ enable }, hre) => {
|
|
453
|
+
await mock_setLoggingEnabled(hre, enable);
|
|
454
|
+
});
|
|
455
|
+
function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
456
|
+
return {
|
|
457
|
+
...mocksConfig,
|
|
458
|
+
encryptDelay: mocksConfig?.encryptDelay ?? 0
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
extendEnvironment((hre) => {
|
|
462
|
+
hre.cofhe = {
|
|
463
|
+
createConfig: async (config) => {
|
|
464
|
+
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS2);
|
|
465
|
+
const { walletClient: zkvWalletClient } = await HardhatSignerAdapter(zkvHhSigner);
|
|
466
|
+
const configWithZkvWalletClient = {
|
|
467
|
+
environment: "hardhat",
|
|
468
|
+
...config,
|
|
469
|
+
mocks: buildHardhatPluginMocksConfig(config.mocks),
|
|
470
|
+
_internal: {
|
|
471
|
+
...config._internal,
|
|
472
|
+
zkvWalletClient
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
return createCofheConfig(configWithZkvWalletClient);
|
|
476
|
+
},
|
|
477
|
+
createClient: (config) => {
|
|
478
|
+
return createCofheClient(config);
|
|
479
|
+
},
|
|
480
|
+
hardhatSignerAdapter: async (signer) => {
|
|
481
|
+
return HardhatSignerAdapter(signer);
|
|
482
|
+
},
|
|
483
|
+
connectWithHardhatSigner: async (client, signer) => {
|
|
484
|
+
const { publicClient, walletClient } = await HardhatSignerAdapter(signer);
|
|
485
|
+
return client.connect(publicClient, walletClient);
|
|
486
|
+
},
|
|
487
|
+
createClientWithBatteries: async (signer) => {
|
|
488
|
+
if (!signer) {
|
|
489
|
+
[signer] = await hre.ethers.getSigners();
|
|
490
|
+
}
|
|
491
|
+
const config = await hre.cofhe.createConfig({
|
|
492
|
+
environment: "hardhat",
|
|
493
|
+
supportedChains: [hardhat]
|
|
494
|
+
});
|
|
495
|
+
const client = hre.cofhe.createClient(config);
|
|
496
|
+
await hre.cofhe.connectWithHardhatSigner(client, signer);
|
|
497
|
+
await client.permits.createSelf({
|
|
498
|
+
issuer: signer.address
|
|
499
|
+
});
|
|
500
|
+
return client;
|
|
501
|
+
},
|
|
502
|
+
mocks: {
|
|
503
|
+
withLogs: async (closureName, closure) => {
|
|
504
|
+
return mock_withLogs(hre, closureName, closure);
|
|
505
|
+
},
|
|
506
|
+
enableLogs: async (closureName) => {
|
|
507
|
+
return mock_setLoggingEnabled(hre, true, closureName);
|
|
508
|
+
},
|
|
509
|
+
disableLogs: async () => {
|
|
510
|
+
return mock_setLoggingEnabled(hre, false);
|
|
511
|
+
},
|
|
512
|
+
deployMocks: async (options = {}) => {
|
|
513
|
+
return deployMocks(hre, { mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity, ...options });
|
|
514
|
+
},
|
|
515
|
+
getPlaintext: async (ctHash) => {
|
|
516
|
+
const [signer] = await hre.ethers.getSigners();
|
|
517
|
+
return mock_getPlaintext(signer.provider, ctHash);
|
|
518
|
+
},
|
|
519
|
+
expectPlaintext: async (ctHash, expectedValue) => {
|
|
520
|
+
const [signer] = await hre.ethers.getSigners();
|
|
521
|
+
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
522
|
+
},
|
|
523
|
+
getMockTaskManager: async () => getFixedMockContract(hre, MockTaskManagerArtifact3),
|
|
524
|
+
getMockACL: async () => {
|
|
525
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact3);
|
|
526
|
+
const aclAddress = await taskManager.acl();
|
|
527
|
+
return hre.ethers.getContractAt([...MockACLArtifact2.abi], aclAddress);
|
|
528
|
+
},
|
|
529
|
+
getMockThresholdNetwork: async () => getFixedMockContract(hre, MockThresholdNetworkArtifact2),
|
|
530
|
+
getMockZkVerifier: async () => getFixedMockContract(hre, MockZkVerifierArtifact2),
|
|
531
|
+
getTestBed: async () => getFixedMockContract(hre, TestBedArtifact2)
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
});
|
|
535
|
+
export {
|
|
536
|
+
TASK_COFHE_MOCKS_DEPLOY,
|
|
537
|
+
TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
538
|
+
TASK_COFHE_USE_FAUCET,
|
|
539
|
+
buildHardhatPluginMocksConfig,
|
|
540
|
+
deployMockContractFromArtifact,
|
|
541
|
+
deployMocks,
|
|
542
|
+
getFixedMockContract,
|
|
543
|
+
localcofheFundAccount,
|
|
544
|
+
localcofheFundWalletIfNeeded,
|
|
545
|
+
mock_expectPlaintext,
|
|
546
|
+
mock_getPlaintext,
|
|
547
|
+
mock_getPlaintextExists,
|
|
548
|
+
mock_setLoggingEnabled,
|
|
549
|
+
mock_withLogs
|
|
550
|
+
};
|
|
551
|
+
//# sourceMappingURL=index.mjs.map
|