@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { PublicClient, WalletClient } from 'viem';
|
|
2
|
+
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
|
|
3
|
+
import { CofheInputConfig, CofheConfig, CofheClient } from '@cofhe/sdk';
|
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
|
|
5
|
+
import { MockArtifact, MockTaskManager, MockACL, MockThresholdNetwork, MockZkVerifier, TestBed } from '@cofhe/mock-contracts';
|
|
6
|
+
import * as ethers from 'ethers';
|
|
7
|
+
import { Contract, ethers as ethers$1 } from 'ethers';
|
|
8
|
+
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Controls deploy-mocks console output.
|
|
12
|
+
* - `''` — silent, no output
|
|
13
|
+
* - `'v'` — single summary line (default)
|
|
14
|
+
* - `'vv'` — full per-contract deployment logs
|
|
15
|
+
*/
|
|
16
|
+
type LogMocksDeploy = '' | 'v' | 'vv';
|
|
17
|
+
type DeployMocksArgs = {
|
|
18
|
+
deployTestBed?: boolean;
|
|
19
|
+
gasWarning?: boolean;
|
|
20
|
+
mocksDeployVerbosity?: LogMocksDeploy;
|
|
21
|
+
};
|
|
22
|
+
declare const deployMocks: (hre: HardhatRuntimeEnvironment, options?: DeployMocksArgs) => Promise<void>;
|
|
23
|
+
|
|
24
|
+
declare const TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
25
|
+
declare const TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
26
|
+
declare const TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
|
|
27
|
+
|
|
28
|
+
declare const deployMockContractFromArtifact: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
|
|
29
|
+
declare const getFixedMockContract: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
|
|
30
|
+
declare const mock_getPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint | string) => Promise<any>;
|
|
31
|
+
declare const mock_getPlaintextExists: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint | string) => Promise<any>;
|
|
32
|
+
declare const mock_expectPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint | string, expectedValue: bigint) => Promise<void>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sends funds to the specified address
|
|
36
|
+
* @param hre Hardhat Runtime Environment
|
|
37
|
+
* @param toAddress Address to send funds to
|
|
38
|
+
* @param amount Amount to send in ETH (default: 10)
|
|
39
|
+
* @returns Transaction receipt or null if failed
|
|
40
|
+
*/
|
|
41
|
+
declare function localcofheFundAccount(hre: HardhatRuntimeEnvironment, toAddress: string, amount?: string): Promise<ethers.TransactionReceipt | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Checks a wallet's balance and funds it if below 1 ETH
|
|
44
|
+
* @param hre Hardhat Runtime Environment
|
|
45
|
+
* @param walletAddress Address of the wallet to check and potentially fund
|
|
46
|
+
* @returns Promise that resolves when the funding operation completes (if needed)
|
|
47
|
+
*/
|
|
48
|
+
declare function localcofheFundWalletIfNeeded(hre: HardhatRuntimeEnvironment, walletAddress: string): Promise<void>;
|
|
49
|
+
|
|
50
|
+
declare const mock_setLoggingEnabled: (hre: HardhatRuntimeEnvironment, enabled: boolean, closureName?: string) => Promise<void>;
|
|
51
|
+
declare const mock_withLogs: (hre: HardhatRuntimeEnvironment, closureName: string, closure: () => Promise<void>) => Promise<void>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Configuration interface for the CoFHE Hardhat plugin.
|
|
55
|
+
* Allows users to configure mock logging and gas warning settings.
|
|
56
|
+
*/
|
|
57
|
+
declare module 'hardhat/types/config' {
|
|
58
|
+
interface HardhatUserConfig {
|
|
59
|
+
cofhe?: {
|
|
60
|
+
/** Whether to log mock operations (default: true) */
|
|
61
|
+
logMocks?: boolean;
|
|
62
|
+
/** Whether to show gas usage warnings for mock operations (default: true) */
|
|
63
|
+
gasWarning?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Controls deploy-mocks console output.
|
|
66
|
+
* - `''` — silent, no output
|
|
67
|
+
* - `'v'` — single summary line (default)
|
|
68
|
+
* - `'vv'` — full per-contract deployment logs
|
|
69
|
+
*/
|
|
70
|
+
mocksDeployVerbosity?: LogMocksDeploy;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
interface HardhatConfig {
|
|
74
|
+
cofhe: {
|
|
75
|
+
/** Whether to log mock operations (default: true) */
|
|
76
|
+
logMocks: boolean;
|
|
77
|
+
/** Whether to show gas usage warnings for mock operations (default: true) */
|
|
78
|
+
gasWarning: boolean;
|
|
79
|
+
mocksDeployVerbosity: LogMocksDeploy;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Runtime environment extensions for the CoFHE Hardhat plugin.
|
|
86
|
+
* Provides access to CoFHE initialization, environment checks, and mock utilities.
|
|
87
|
+
*/
|
|
88
|
+
declare module 'hardhat/types/runtime' {
|
|
89
|
+
interface HardhatRuntimeEnvironment {
|
|
90
|
+
cofhe: {
|
|
91
|
+
/**
|
|
92
|
+
* Create a CoFHE configuration for use with hre.cofhe.createClient(...)
|
|
93
|
+
* @param {CofheInputConfig} config - The CoFHE input configuration
|
|
94
|
+
* @returns {CofheConfig} The CoFHE configuration
|
|
95
|
+
*/
|
|
96
|
+
createConfig: (config: CofheInputConfig) => Promise<CofheConfig>;
|
|
97
|
+
/**
|
|
98
|
+
* Create a CoFHE client instance
|
|
99
|
+
* @param {CofheConfig} config - The CoFHE configuration (use createCofheConfig to create with Node.js defaults)
|
|
100
|
+
* @returns {Promise<CofheClient>} The CoFHE client instance
|
|
101
|
+
*/
|
|
102
|
+
createClient: (config: CofheConfig) => CofheClient;
|
|
103
|
+
/**
|
|
104
|
+
* Create viem clients from a Hardhat ethers signer, to be used with `cofheClient.connect(...)`
|
|
105
|
+
* @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
|
|
106
|
+
* @returns {Promise<{ publicClient: PublicClient; walletClient: WalletClient }>} The viem clients
|
|
107
|
+
*/
|
|
108
|
+
hardhatSignerAdapter: (signer: HardhatEthersSigner) => Promise<{
|
|
109
|
+
publicClient: PublicClient;
|
|
110
|
+
walletClient: WalletClient;
|
|
111
|
+
}>;
|
|
112
|
+
/**
|
|
113
|
+
* Connect a CoFHE client with a Hardhat ethers signer
|
|
114
|
+
* @param {CofheClient} client - The CoFHE client to connect
|
|
115
|
+
* @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
|
|
116
|
+
* @returns {Promise<void>}
|
|
117
|
+
*/
|
|
118
|
+
connectWithHardhatSigner: (client: CofheClient, signer: HardhatEthersSigner) => Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Create and connect to a batteries included client.
|
|
121
|
+
* Also generates a self-usage a permit for the signer.
|
|
122
|
+
* If customization is needed, use createCofheClient and connectWithHardhatSigner.
|
|
123
|
+
* @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use (optional - defaults to first signer)
|
|
124
|
+
* @returns {Promise<CofheClient>} The CoFHE client instance
|
|
125
|
+
*/
|
|
126
|
+
createClientWithBatteries: (signer?: HardhatEthersSigner) => Promise<CofheClient>;
|
|
127
|
+
mocks: {
|
|
128
|
+
/**
|
|
129
|
+
* **[MOCKS ONLY]**
|
|
130
|
+
*
|
|
131
|
+
* Execute a block of code with cofhe mock contracts logging enabled.
|
|
132
|
+
*
|
|
133
|
+
* _(If logging only a function, we recommend passing the function name as the closureName (ex "counter.increment()"))_
|
|
134
|
+
*
|
|
135
|
+
* Example usage:
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* await hre.cofhe.mocks.withLogs("counter.increment()", async () => {
|
|
139
|
+
* await counter.increment();
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* Expected output:
|
|
144
|
+
* ```
|
|
145
|
+
* ┌──────────────────┬──────────────────────────────────────────────────
|
|
146
|
+
* │ [COFHE-MOCKS] │ "counter.increment()" logs:
|
|
147
|
+
* ├──────────────────┴──────────────────────────────────────────────────
|
|
148
|
+
* ├ FHE.add | euint32(4473..3424)[0] + euint32(1157..3648)[1] => euint32(1106..1872)[1]
|
|
149
|
+
* ├ FHE.allowThis | euint32(1106..1872)[1] -> 0x663f..6602
|
|
150
|
+
* ├ FHE.allow | euint32(1106..1872)[1] -> 0x3c44..93bc
|
|
151
|
+
* └─────────────────────────────────────────────────────────────────────
|
|
152
|
+
* ```
|
|
153
|
+
* @param {string} closureName - Name of the code block to log within
|
|
154
|
+
* @param {() => Promise<void>} closure - The async function to execute
|
|
155
|
+
*/
|
|
156
|
+
withLogs: (closureName: string, closure: () => Promise<void>) => Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* **[MOCKS ONLY]**
|
|
159
|
+
*
|
|
160
|
+
* Enable logging from cofhe mock contracts
|
|
161
|
+
* @param {string} closureName - Optional name of the code block to enable logging for
|
|
162
|
+
*/
|
|
163
|
+
enableLogs: (closureName?: string) => Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* **[MOCKS ONLY]**
|
|
166
|
+
*
|
|
167
|
+
* Disable logging from cofhe mock contracts
|
|
168
|
+
*/
|
|
169
|
+
disableLogs: () => Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* **[MOCKS ONLY]**
|
|
172
|
+
*
|
|
173
|
+
* Deploy the cofhe mock contracts (normally this is done automatically)
|
|
174
|
+
* @param {DeployMocksArgs} options - Deployment options
|
|
175
|
+
*/
|
|
176
|
+
deployMocks: (options?: DeployMocksArgs) => Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* **[MOCKS ONLY]**
|
|
179
|
+
*
|
|
180
|
+
* Get the plaintext value for a ciphertext hash
|
|
181
|
+
* @param {bigint | string} ctHash - The ciphertext hash to look up
|
|
182
|
+
* @returns {Promise<bigint>} The plaintext value
|
|
183
|
+
*/
|
|
184
|
+
getPlaintext: (ctHash: bigint | string) => Promise<bigint>;
|
|
185
|
+
/**
|
|
186
|
+
* **[MOCKS ONLY]**
|
|
187
|
+
*
|
|
188
|
+
* Assert that a ciphertext hash represents an expected plaintext value
|
|
189
|
+
* @param {bigint | string} ctHash - The ciphertext hash to check
|
|
190
|
+
* @param {bigint} expectedValue - The expected plaintext value
|
|
191
|
+
*/
|
|
192
|
+
expectPlaintext: (ctHash: bigint | string, expectedValue: bigint) => Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Get the MockTaskManager contract (typed via typechain)
|
|
195
|
+
* @returns {Promise<MockTaskManager>} The MockTaskManager contract
|
|
196
|
+
*/
|
|
197
|
+
getMockTaskManager: () => Promise<MockTaskManager>;
|
|
198
|
+
/**
|
|
199
|
+
* Get the MockACL contract (typed via typechain)
|
|
200
|
+
* @returns {Promise<MockACL>} The MockACL contract
|
|
201
|
+
*/
|
|
202
|
+
getMockACL: () => Promise<MockACL>;
|
|
203
|
+
/**
|
|
204
|
+
* Get the MockThresholdNetwork contract (typed via typechain)
|
|
205
|
+
* @returns {Promise<MockThresholdNetwork>} The MockThresholdNetwork contract
|
|
206
|
+
*/
|
|
207
|
+
getMockThresholdNetwork: () => Promise<MockThresholdNetwork>;
|
|
208
|
+
/**
|
|
209
|
+
* Get the MockZkVerifier contract (typed via typechain)
|
|
210
|
+
* @returns {Promise<MockZkVerifier>} The MockZkVerifier contract
|
|
211
|
+
*/
|
|
212
|
+
getMockZkVerifier: () => Promise<MockZkVerifier>;
|
|
213
|
+
/**
|
|
214
|
+
* Get the TestBed contract (typed via typechain)
|
|
215
|
+
* @returns {Promise<TestBed>} The TestBed contract
|
|
216
|
+
*/
|
|
217
|
+
getTestBed: () => Promise<TestBed>;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Builds the mocks config for the hardhat plugin.
|
|
224
|
+
* Defaults `encryptDelay` to `0` so tests run without artificial wait times,
|
|
225
|
+
* unless the user has explicitly provided a value.
|
|
226
|
+
*/
|
|
227
|
+
declare function buildHardhatPluginMocksConfig(mocksConfig: CofheInputConfig['mocks']): NonNullable<CofheInputConfig['mocks']>;
|
|
228
|
+
|
|
229
|
+
export { type DeployMocksArgs, type LogMocksDeploy, TASK_COFHE_MOCKS_DEPLOY, TASK_COFHE_MOCKS_SET_LOG_OPS, TASK_COFHE_USE_FAUCET, buildHardhatPluginMocksConfig, deployMockContractFromArtifact, deployMocks, getFixedMockContract, localcofheFundAccount, localcofheFundWalletIfNeeded, mock_expectPlaintext, mock_getPlaintext, mock_getPlaintextExists, mock_setLoggingEnabled, mock_withLogs };
|