@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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @cofhe/hardhat-plugin Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.0-alpha-20260409113701
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f78beb7: Add `@cofhe/hardhat-3-plugin` and `@cofhe/foundry-plugin` packages.
|
|
8
|
+
|
|
9
|
+
**`@cofhe/hardhat-3-plugin`** — Hardhat 3 plugin with the same mock contract deployment, `network.cofhe` API, logging, and faucet task as the v2 plugin, adapted to the Hardhat 3 plugin/hook model.
|
|
10
|
+
|
|
11
|
+
**`@cofhe/foundry-plugin`** — Foundry test utilities: `CofheTest` base contract (`deployMocks`, `expectPlaintext`, `getPlaintext`) and `CofheClient` SDK mock (`connect`, `createInE*`, `decryptForTx`, `decryptForView`, permits). Usable as a git submodule or npm package, with `remappings.txt` for Hardhat 3 Solidity test compatibility.
|
|
12
|
+
|
|
13
|
+
**`mocksDeployVerbosity` config option** added to both Hardhat plugins:
|
|
14
|
+
|
|
15
|
+
- `''` — silent
|
|
16
|
+
- `'v'` — single summary line (new default)
|
|
17
|
+
- `'vv'` — full per-contract deployment logs (previous default behavior)
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [788a6e2]
|
|
22
|
+
- Updated dependencies [9a06012]
|
|
23
|
+
- Updated dependencies [503536a]
|
|
24
|
+
- @cofhe/sdk@0.0.0-alpha-20260409113701
|
|
25
|
+
- @cofhe/mock-contracts@0.0.0-alpha-20260409113701
|
|
26
|
+
|
|
27
|
+
## 0.4.0
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [e446642]
|
|
32
|
+
- @cofhe/sdk@0.4.0
|
|
33
|
+
- @cofhe/mock-contracts@0.4.0
|
|
34
|
+
|
|
35
|
+
## 0.3.2
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- d4e86ea: Aligns with CTA encrypted variables bytes32 representation.
|
|
40
|
+
|
|
41
|
+
- **@cofhe/hardhat-plugin**: `hre.cofhe.mocks.getTestBed()`, `getMockTaskManager()`, `getMockACL()`, `getMockThresholdNetwork()`, and `getMockZkVerifier()` now return typed contracts (typechain interfaces) instead of untyped `Contract`. `getPlaintext(ctHash)` and `expectPlaintext(ctHash, value)` now accept bytes32 ctHashes as `string` support cofhe-contracts 0.1.0 CTA changes.
|
|
42
|
+
- **@cofhe/mock-contracts**: Export typechain-generated contract types (`TestBed`, `MockACL`, `MockTaskManager`, `MockZkVerifier`, `MockThresholdNetwork`) for use with the hardhat plugin. Typechain is run from artifact ABIs only; factory files are not generated.
|
|
43
|
+
- **@cofhe/abi**: CTA-related types use `bytes32` (string) instead of `uint256`. Decryption and return-type helpers aligned with cofhe-contracts 0.1.0.
|
|
44
|
+
- **@cofhe/sdk**: Decryption APIs (`decryptForTx`, `decryptForView`, and related builders) now also accept `string` for ciphertext hashes (bytes32) as well as `bigint`.
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [d4e86ea]
|
|
47
|
+
- Updated dependencies [0feaf3f]
|
|
48
|
+
- @cofhe/sdk@0.3.2
|
|
49
|
+
- @cofhe/mock-contracts@0.3.2
|
|
50
|
+
|
|
51
|
+
## 0.3.1
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- 370f0c7: no-op
|
|
56
|
+
- Updated dependencies [370f0c7]
|
|
57
|
+
- @cofhe/mock-contracts@0.3.1
|
|
58
|
+
- @cofhe/sdk@0.3.1
|
|
59
|
+
|
|
60
|
+
## 0.3.0
|
|
61
|
+
|
|
62
|
+
### Minor Changes
|
|
63
|
+
|
|
64
|
+
- 35024b6: Remove `sdk` from function names and exported types. Rename:
|
|
65
|
+
|
|
66
|
+
- `createCofhesdkConfig` -> `createCofheConfig`
|
|
67
|
+
- `createCofhesdkClient` -> `createCofheClient`
|
|
68
|
+
- `hre.cofhesdk.*` -> `hre.cofhe.*`
|
|
69
|
+
- `hre.cofhesdk.createCofheConfig()` → `hre.cofhe.createConfig()`
|
|
70
|
+
- `hre.cofhesdk.createCofheClient()` → `hre.cofhe.createClient()`
|
|
71
|
+
- `hre.cofhesdk.createBatteriesIncludedCofheClient()` → `hre.cofhe.createClientWithBatteries()`
|
|
72
|
+
|
|
73
|
+
- 29c2401: implement decrypt-with-proof flows and related tests:
|
|
74
|
+
|
|
75
|
+
- Implement production `decryptForTx` backed by Threshold Network `POST /decrypt`, with explicit permit vs global-allowance selection.
|
|
76
|
+
- Rename mocks “Query Decrypter” -> “Threshold Network” and update SDK constants/contracts/artifacts accordingly.
|
|
77
|
+
- Extend mock contracts + hardhat plugin to publish & verify decryption results on-chain, and add end-to-end integration tests.
|
|
78
|
+
|
|
79
|
+
### Patch Changes
|
|
80
|
+
|
|
81
|
+
- 5467d77: Adds `config.mocks.encryptDelay: number | [number, number, number, number, number]` to allow configurable mock encryption delay. Defaults to 0 delay on hardhat to keep tests quick.
|
|
82
|
+
- Updated dependencies [35024b6]
|
|
83
|
+
- Updated dependencies [5467d77]
|
|
84
|
+
- Updated dependencies [73b1502]
|
|
85
|
+
- Updated dependencies [29c2401]
|
|
86
|
+
- Updated dependencies [650ea48]
|
|
87
|
+
- @cofhe/mock-contracts@0.3.0
|
|
88
|
+
- @cofhe/sdk@0.3.0
|
|
89
|
+
|
|
90
|
+
## 0.2.1
|
|
91
|
+
|
|
92
|
+
### Patch Changes
|
|
93
|
+
|
|
94
|
+
- 0000d5e: Mock contracts deployed to alternate fixed addresses to avoid collision with hardhat pre-compiles.
|
|
95
|
+
- Updated dependencies [409bfdf]
|
|
96
|
+
- Updated dependencies [ac47e2f]
|
|
97
|
+
- Updated dependencies [0000d5e]
|
|
98
|
+
- Updated dependencies [8af1b70]
|
|
99
|
+
- @cofhe/sdk@0.2.1
|
|
100
|
+
- @cofhe/mock-contracts@0.2.1
|
|
101
|
+
|
|
102
|
+
## 0.2.0
|
|
103
|
+
|
|
104
|
+
### Minor Changes
|
|
105
|
+
|
|
106
|
+
- 8fda09a: Removes `Promise<boolean>` return type from `client.connect(...)`, instead throws an error if the connection fails.
|
|
107
|
+
- e0caeca: Adds `environment: 'node' | 'web' | 'hardhat' | 'react'` option to config. Exposed via `client.config.enviroment`. Automatically populated appropriately within the various `createCofhesdkConfig` functions.
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- e121108: Fix ACL permission invalid issue. MockACL needs real deployment since etching doesn't call the constructor, so the EIP712 is uninitialized. Also adds additional utility functions to hardhat-plugin:
|
|
112
|
+
|
|
113
|
+
- `hre.cofhesdk.connectWithHardhatSigner(client, signer)` - Connect to client with hardhat ethers signer.
|
|
114
|
+
- `hre.cofhesdk.createBatteriesIncludedCofhesdkClient()` - Creates a batteries included client with signer connected.
|
|
115
|
+
- `hre.cofhesdk.mocks.getMockTaskManager()` - Gets deployed Mock Taskmanager
|
|
116
|
+
- `hre.cofhesdk.mocks.getMockACL()` - Gets deployed Mock ACL
|
|
117
|
+
|
|
118
|
+
- Updated dependencies [8fda09a]
|
|
119
|
+
- Updated dependencies [e121108]
|
|
120
|
+
- Updated dependencies [4057a76]
|
|
121
|
+
- Updated dependencies [dba2759]
|
|
122
|
+
- Updated dependencies [e0caeca]
|
|
123
|
+
- Updated dependencies [7c861af]
|
|
124
|
+
- Updated dependencies [2a9d6c5]
|
|
125
|
+
- @cofhe/mock-contracts@0.2.0
|
|
126
|
+
- @cofhe/sdk@0.2.0
|
|
127
|
+
|
|
128
|
+
## 0.1.1
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- a1d1323: Add repository info to package.json of public packages to fix npm publish provenance issue.
|
|
133
|
+
- d232d11: Ensure publish includes correct src and dist files
|
|
134
|
+
- b6521fb: Update publish workflow to create versioning PR upon merge with changeset.
|
|
135
|
+
- Updated dependencies [a1d1323]
|
|
136
|
+
- Updated dependencies [d232d11]
|
|
137
|
+
- Updated dependencies [b6521fb]
|
|
138
|
+
- @cofhe/mock-contracts@0.1.1
|
|
139
|
+
- @cofhe/sdk@0.1.1
|
|
140
|
+
|
|
141
|
+
## 0.1.0
|
|
142
|
+
|
|
143
|
+
### Minor Changes
|
|
144
|
+
|
|
145
|
+
- 8d41cf2: Combine existing packages into more reasonable defaults. New package layout is @cofhe/sdk (includes all the core logic for configuring and creating a @cofhe/sdk client, encrypting values, and decrypting handles), mock-contracts, hardhat-plugin, and react.
|
|
146
|
+
- a83facb: Prepare for initial release. Rename scope from `@cofhesdk` to `@cofhe` and rename `cofhesdk` package to `@cofhe/sdk`. Create `publish.yml` to publish `beta` packages on merged PR, and `latest` on changeset PR.
|
|
147
|
+
- 58e93a8: Migrate cofhe-mock-contracts and cofhe-hardhat-plugin into @cofhe/sdk.
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- Updated dependencies [cba73fd]
|
|
152
|
+
- Updated dependencies [87fc8a0]
|
|
153
|
+
- Updated dependencies [8d41cf2]
|
|
154
|
+
- Updated dependencies [738b9f5]
|
|
155
|
+
- Updated dependencies [a83facb]
|
|
156
|
+
- Updated dependencies [9a7c98e]
|
|
157
|
+
- Updated dependencies [58e93a8]
|
|
158
|
+
- Updated dependencies [fdf26d4]
|
|
159
|
+
- Updated dependencies [f5b8e25]
|
|
160
|
+
- Updated dependencies [3b135a8]
|
|
161
|
+
- Updated dependencies [5b7c43b]
|
|
162
|
+
- Updated dependencies [4bc8182]
|
|
163
|
+
- @cofhe/sdk@0.1.0
|
|
164
|
+
- @cofhe/mock-contracts@0.1.0
|
|
165
|
+
|
|
166
|
+
This changelog is maintained by Changesets and will be populated on each release.
|
|
167
|
+
|
|
168
|
+
- Do not edit this file by hand.
|
|
169
|
+
- Upcoming changes can be previewed with `pnpm changeset status --verbose`.
|
|
170
|
+
- Entries are generated when the Changesets "Version Packages" PR is created/merged.
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# CoFHE Hardhat Plugin
|
|
2
|
+
|
|
3
|
+
A Hardhat plugin for Fully Homomorphic Encryption (FHE) development with CoFHE.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install cofhe-hardhat-plugin
|
|
9
|
+
# or
|
|
10
|
+
yarn add cofhe-hardhat-plugin
|
|
11
|
+
# or
|
|
12
|
+
pnpm add cofhe-hardhat-plugin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
Add the plugin to your Hardhat config:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
// hardhat.config.js or hardhat.config.ts
|
|
21
|
+
require('cofhe-hardhat-plugin');
|
|
22
|
+
// or if using TypeScript
|
|
23
|
+
import 'cofhe-hardhat-plugin';
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
// ... other config
|
|
27
|
+
cofhe: {
|
|
28
|
+
logMocks: true, // Optional: Set to true to log mock operations
|
|
29
|
+
},
|
|
30
|
+
// Network configuration is automatically added by the plugin
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The plugin automatically adds network configurations for:
|
|
35
|
+
|
|
36
|
+
- Hardhat network with deployed mock contracts
|
|
37
|
+
- Ethereum Sepolia testnet
|
|
38
|
+
- Arbitrum Sepolia testnet
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
### Mock Contracts
|
|
43
|
+
|
|
44
|
+
This plugin uses [cofhe-mock-contracts](https://github.com/FhenixProtocol/cofhe-mock-contracts) to provide on-chain simulations of the CoFHE system. These mock contracts enable development and testing without requiring the actual off-chain FHE computation engine.
|
|
45
|
+
|
|
46
|
+
The mock contracts include:
|
|
47
|
+
|
|
48
|
+
- MockTaskManager: Manages FHE operations and stores plaintext values
|
|
49
|
+
- MockThresholdNetwork: Handles decryption requests
|
|
50
|
+
- MockZkVerifier: Simulates verification of encrypted inputs
|
|
51
|
+
- ACL: Handles access control
|
|
52
|
+
|
|
53
|
+
Key differences from the real CoFHE system:
|
|
54
|
+
|
|
55
|
+
- Operations are performed on-chain instead of off-chain
|
|
56
|
+
- Plaintext values are stored on-chain for testing and verification
|
|
57
|
+
- Decryption operations are simulated with mock delays
|
|
58
|
+
- Operations are logged using hardhat/console.sol
|
|
59
|
+
|
|
60
|
+
### Mock Contracts Deployment
|
|
61
|
+
|
|
62
|
+
Mock contracts are automatically deployed when using the Hardhat network:
|
|
63
|
+
|
|
64
|
+
- Running tests: `npx hardhat test`
|
|
65
|
+
- Starting a local node: `npx hardhat node`
|
|
66
|
+
|
|
67
|
+
To disable this automatic deployment (for example, when your tests only use external RPCs and don't need the in-process Hardhat network), set:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
COFHE_SKIP_MOCKS_DEPLOY=1
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
You can also manually deploy mock contracts:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npx hardhat deploy-mocks [--deploy-test-bed true|false] [--log-mocks true|false]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Options:
|
|
80
|
+
|
|
81
|
+
- `--deploy-test-bed`: Deploy the TestBed contract (default: true)
|
|
82
|
+
- `--log-mocks`: Log mock operations (default: true)
|
|
83
|
+
|
|
84
|
+
### Utility Functions
|
|
85
|
+
|
|
86
|
+
The plugin exports several utility functions for working with mock contracts:
|
|
87
|
+
|
|
88
|
+
#### Mock Utilities
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Get plaintext value from a ciphertext hash
|
|
92
|
+
import { mock_getPlaintext } from 'cofhe-hardhat-plugin';
|
|
93
|
+
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
94
|
+
|
|
95
|
+
// Check if a plaintext exists for a ciphertext hash
|
|
96
|
+
import { mock_getPlaintextExists } from 'cofhe-hardhat-plugin';
|
|
97
|
+
const exists = await mock_getPlaintextExists(provider, ctHash);
|
|
98
|
+
|
|
99
|
+
// Test assertion for plaintext values
|
|
100
|
+
import { mock_expectPlaintext } from 'cofhe-hardhat-plugin';
|
|
101
|
+
await mock_expectPlaintext(provider, ctHash, expectedValue);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Network Utilities
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// Get the CoFHE environment based on network name
|
|
108
|
+
import { getCofheEnvironmentFromNetwork } from 'cofhe-hardhat-plugin';
|
|
109
|
+
const environment = getCofheEnvironmentFromNetwork(networkName);
|
|
110
|
+
|
|
111
|
+
// Check if a CoFHE environment is permitted for a given network
|
|
112
|
+
import { isPermittedCofheEnvironment } from 'cofhe-hardhat-plugin';
|
|
113
|
+
const isPermitted = isPermittedCofheEnvironment(hre, environmentName);
|
|
114
|
+
|
|
115
|
+
// Initialize CoFHEjs with a Hardhat signer
|
|
116
|
+
import { cofhejs_initializeWithHardhatSigner } from 'cofhe-hardhat-plugin';
|
|
117
|
+
await cofhejs_initializeWithHardhatSigner(signer, options);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Usage in Tests
|
|
121
|
+
|
|
122
|
+
The plugin automatically deploys mock contracts when running tests:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { expect } from "chai";
|
|
126
|
+
import { mock_expectPlaintext } from "cofhe-hardhat-plugin";
|
|
127
|
+
|
|
128
|
+
describe("My FHE Contract", function() {
|
|
129
|
+
it("should store encrypted value correctly", async function() {
|
|
130
|
+
const [signer] = await ethers.getSigners();
|
|
131
|
+
const myContract = await ethers.deployContract("MyFHEContract");
|
|
132
|
+
|
|
133
|
+
// Interact with your contract
|
|
134
|
+
const tx = await myContract.storeEncrypted(123);
|
|
135
|
+
await tx.wait();
|
|
136
|
+
|
|
137
|
+
// Get the ciphertext hash from event logs
|
|
138
|
+
const ctHash = /* extract from logs */;
|
|
139
|
+
|
|
140
|
+
// Verify plaintext value (only works on hardhat network)
|
|
141
|
+
await mock_expectPlaintext(signer.provider, ctHash, 123n);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT
|
package/dist/index.d.mts
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 };
|