@cofhe/hardhat-plugin 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # @cofhe/hardhat-plugin Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 35024b6: Remove `sdk` from function names and exported types. Rename:
8
+
9
+ - `createCofhesdkConfig` -> `createCofheConfig`
10
+ - `createCofhesdkClient` -> `createCofheClient`
11
+ - `hre.cofhesdk.*` -> `hre.cofhe.*`
12
+ - `hre.cofhesdk.createCofheConfig()` → `hre.cofhe.createConfig()`
13
+ - `hre.cofhesdk.createCofheClient()` → `hre.cofhe.createClient()`
14
+ - `hre.cofhesdk.createBatteriesIncludedCofheClient()` → `hre.cofhe.createClientWithBatteries()`
15
+
16
+ - 29c2401: implement decrypt-with-proof flows and related tests:
17
+
18
+ - Implement production `decryptForTx` backed by Threshold Network `POST /decrypt`, with explicit permit vs global-allowance selection.
19
+ - Rename mocks “Query Decrypter” -> “Threshold Network” and update SDK constants/contracts/artifacts accordingly.
20
+ - Extend mock contracts + hardhat plugin to publish & verify decryption results on-chain, and add end-to-end integration tests.
21
+
22
+ ### Patch Changes
23
+
24
+ - 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.
25
+ - Updated dependencies [35024b6]
26
+ - Updated dependencies [5467d77]
27
+ - Updated dependencies [73b1502]
28
+ - Updated dependencies [29c2401]
29
+ - Updated dependencies [650ea48]
30
+ - @cofhe/mock-contracts@0.3.0
31
+ - @cofhe/sdk@0.3.0
32
+
33
+ ## 0.2.1
34
+
35
+ ### Patch Changes
36
+
37
+ - 0000d5e: Mock contracts deployed to alternate fixed addresses to avoid collision with hardhat pre-compiles.
38
+ - Updated dependencies [409bfdf]
39
+ - Updated dependencies [ac47e2f]
40
+ - Updated dependencies [0000d5e]
41
+ - Updated dependencies [8af1b70]
42
+ - @cofhe/sdk@0.2.1
43
+ - @cofhe/mock-contracts@0.2.1
44
+
3
45
  ## 0.2.0
4
46
 
5
47
  ### Minor Changes
package/README.md CHANGED
@@ -46,7 +46,7 @@ This plugin uses [cofhe-mock-contracts](https://github.com/FhenixProtocol/cofhe-
46
46
  The mock contracts include:
47
47
 
48
48
  - MockTaskManager: Manages FHE operations and stores plaintext values
49
- - MockQueryDecrypter: Handles decryption requests
49
+ - MockThresholdNetwork: Handles decryption requests
50
50
  - MockZkVerifier: Simulates verification of encrypted inputs
51
51
  - ACL: Handles access control
52
52
 
@@ -64,6 +64,12 @@ Mock contracts are automatically deployed when using the Hardhat network:
64
64
  - Running tests: `npx hardhat test`
65
65
  - Starting a local node: `npx hardhat node`
66
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
+
67
73
  You can also manually deploy mock contracts:
68
74
 
69
75
  ```bash
package/dist/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { PublicClient, WalletClient } from 'viem';
2
2
  import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
3
- import { CofhesdkInputConfig, CofhesdkConfig, CofhesdkClient } from '@cofhe/sdk';
3
+ import { CofheInputConfig, CofheConfig, CofheClient } from '@cofhe/sdk';
4
4
  import { HardhatRuntimeEnvironment } from 'hardhat/types';
5
5
  import * as ethers from 'ethers';
6
- import { ethers as ethers$1, Contract } from 'ethers';
7
- export { MockACLArtifact, MockQueryDecrypterArtifact, MockTaskManagerArtifact, MockZkVerifierArtifact, TestBedArtifact } from '@cofhe/mock-contracts';
6
+ import { Contract, ethers as ethers$1 } from 'ethers';
8
7
  import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';
8
+ import { MockArtifact } from '@cofhe/mock-contracts';
9
9
 
10
10
  type DeployMocksArgs = {
11
11
  deployTestBed?: boolean;
@@ -14,6 +14,12 @@ type DeployMocksArgs = {
14
14
  };
15
15
  declare const deployMocks: (hre: HardhatRuntimeEnvironment, options?: DeployMocksArgs) => Promise<void>;
16
16
 
17
+ declare const TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
18
+ declare const TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
19
+ declare const TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
20
+
21
+ declare const deployMockContractFromArtifact: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
22
+ declare const getFixedMockContract: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
17
23
  declare const mock_getPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
18
24
  declare const mock_getPlaintextExists: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
19
25
  declare const mock_expectPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint, expectedValue: bigint) => Promise<void>;
@@ -43,7 +49,7 @@ declare const mock_withLogs: (hre: HardhatRuntimeEnvironment, closureName: strin
43
49
  */
44
50
  declare module 'hardhat/types/config' {
45
51
  interface HardhatUserConfig {
46
- cofhesdk?: {
52
+ cofhe?: {
47
53
  /** Whether to log mock operations (default: true) */
48
54
  logMocks?: boolean;
49
55
  /** Whether to show gas usage warnings for mock operations (default: true) */
@@ -51,7 +57,7 @@ declare module 'hardhat/types/config' {
51
57
  };
52
58
  }
53
59
  interface HardhatConfig {
54
- cofhesdk: {
60
+ cofhe: {
55
61
  /** Whether to log mock operations (default: true) */
56
62
  logMocks: boolean;
57
63
  /** Whether to show gas usage warnings for mock operations (default: true) */
@@ -66,21 +72,21 @@ declare module 'hardhat/types/config' {
66
72
  */
67
73
  declare module 'hardhat/types/runtime' {
68
74
  interface HardhatRuntimeEnvironment {
69
- cofhesdk: {
75
+ cofhe: {
70
76
  /**
71
- * Create a CoFHE SDK configuration for use with cofhesdk.createCofhesdkClient(...)
72
- * @param {CofhesdkInputConfig} config - The CoFHE SDK input configuration
73
- * @returns {CofhesdkConfig} The CoFHE SDK configuration
77
+ * Create a CoFHE configuration for use with hre.cofhe.createClient(...)
78
+ * @param {CofheInputConfig} config - The CoFHE input configuration
79
+ * @returns {CofheConfig} The CoFHE configuration
74
80
  */
75
- createCofhesdkConfig: (config: CofhesdkInputConfig) => Promise<CofhesdkConfig>;
81
+ createConfig: (config: CofheInputConfig) => Promise<CofheConfig>;
76
82
  /**
77
- * Create a CoFHE SDK client instance
78
- * @param {CofhesdkConfig} config - The CoFHE SDK configuration (use createCofhesdkConfig to create with Node.js defaults)
79
- * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance
83
+ * Create a CoFHE client instance
84
+ * @param {CofheConfig} config - The CoFHE configuration (use createCofheConfig to create with Node.js defaults)
85
+ * @returns {Promise<CofheClient>} The CoFHE client instance
80
86
  */
81
- createCofhesdkClient: (config: CofhesdkConfig) => CofhesdkClient;
87
+ createClient: (config: CofheConfig) => CofheClient;
82
88
  /**
83
- * Create viem clients from a Hardhat ethers signer, to be used with `cofhesdkClient.connect(...)`
89
+ * Create viem clients from a Hardhat ethers signer, to be used with `cofheClient.connect(...)`
84
90
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
85
91
  * @returns {Promise<{ publicClient: PublicClient; walletClient: WalletClient }>} The viem clients
86
92
  */
@@ -89,20 +95,20 @@ declare module 'hardhat/types/runtime' {
89
95
  walletClient: WalletClient;
90
96
  }>;
91
97
  /**
92
- * Connect a CoFHE SDK client with a Hardhat ethers signer
93
- * @param {CofhesdkClient} client - The CoFHE SDK client to connect
98
+ * Connect a CoFHE client with a Hardhat ethers signer
99
+ * @param {CofheClient} client - The CoFHE client to connect
94
100
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
95
101
  * @returns {Promise<void>}
96
102
  */
97
- connectWithHardhatSigner: (client: CofhesdkClient, signer: HardhatEthersSigner) => Promise<void>;
103
+ connectWithHardhatSigner: (client: CofheClient, signer: HardhatEthersSigner) => Promise<void>;
98
104
  /**
99
105
  * Create and connect to a batteries included client.
100
106
  * Also generates a self-usage a permit for the signer.
101
- * If customization is needed, use createCofhesdkClient and connectWithHardhatSigner.
107
+ * If customization is needed, use createCofheClient and connectWithHardhatSigner.
102
108
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use (optional - defaults to first signer)
103
- * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance
109
+ * @returns {Promise<CofheClient>} The CoFHE client instance
104
110
  */
105
- createBatteriesIncludedCofhesdkClient: (signer?: HardhatEthersSigner) => Promise<CofhesdkClient>;
111
+ createClientWithBatteries: (signer?: HardhatEthersSigner) => Promise<CofheClient>;
106
112
  mocks: {
107
113
  /**
108
114
  * **[MOCKS ONLY]**
@@ -114,7 +120,7 @@ declare module 'hardhat/types/runtime' {
114
120
  * Example usage:
115
121
  *
116
122
  * ```ts
117
- * await hre.cofhesdk.mocks.withLogs("counter.increment()", async () => {
123
+ * await hre.cofhe.mocks.withLogs("counter.increment()", async () => {
118
124
  * await counter.increment();
119
125
  * });
120
126
  * ```
@@ -180,10 +186,10 @@ declare module 'hardhat/types/runtime' {
180
186
  */
181
187
  getMockACL: () => Promise<Contract>;
182
188
  /**
183
- * Get the MockQueryDecrypter contract
184
- * @returns {Promise<Contract>} The MockQueryDecrypter contract
189
+ * Get the MockThresholdNetwork contract
190
+ * @returns {Promise<Contract>} The MockThresholdNetwork contract
185
191
  */
186
- getMockQueryDecrypter: () => Promise<Contract>;
192
+ getMockThresholdNetwork: () => Promise<Contract>;
187
193
  /**
188
194
  * Get the MockZkVerifier contract
189
195
  * @returns {Promise<Contract>} The MockZkVerifier contract
@@ -198,5 +204,11 @@ declare module 'hardhat/types/runtime' {
198
204
  };
199
205
  }
200
206
  }
207
+ /**
208
+ * Builds the mocks config for the hardhat plugin.
209
+ * Defaults `encryptDelay` to `0` so tests run without artificial wait times,
210
+ * unless the user has explicitly provided a value.
211
+ */
212
+ declare function buildHardhatPluginMocksConfig(mocksConfig: CofheInputConfig['mocks']): NonNullable<CofheInputConfig['mocks']>;
201
213
 
202
- export { type DeployMocksArgs, deployMocks, localcofheFundAccount, localcofheFundWalletIfNeeded, mock_expectPlaintext, mock_getPlaintext, mock_getPlaintextExists, mock_setLoggingEnabled, mock_withLogs };
214
+ export { type DeployMocksArgs, 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 };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { PublicClient, WalletClient } from 'viem';
2
2
  import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
3
- import { CofhesdkInputConfig, CofhesdkConfig, CofhesdkClient } from '@cofhe/sdk';
3
+ import { CofheInputConfig, CofheConfig, CofheClient } from '@cofhe/sdk';
4
4
  import { HardhatRuntimeEnvironment } from 'hardhat/types';
5
5
  import * as ethers from 'ethers';
6
- import { ethers as ethers$1, Contract } from 'ethers';
7
- export { MockACLArtifact, MockQueryDecrypterArtifact, MockTaskManagerArtifact, MockZkVerifierArtifact, TestBedArtifact } from '@cofhe/mock-contracts';
6
+ import { Contract, ethers as ethers$1 } from 'ethers';
8
7
  import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';
8
+ import { MockArtifact } from '@cofhe/mock-contracts';
9
9
 
10
10
  type DeployMocksArgs = {
11
11
  deployTestBed?: boolean;
@@ -14,6 +14,12 @@ type DeployMocksArgs = {
14
14
  };
15
15
  declare const deployMocks: (hre: HardhatRuntimeEnvironment, options?: DeployMocksArgs) => Promise<void>;
16
16
 
17
+ declare const TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
18
+ declare const TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
19
+ declare const TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
20
+
21
+ declare const deployMockContractFromArtifact: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
22
+ declare const getFixedMockContract: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
17
23
  declare const mock_getPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
18
24
  declare const mock_getPlaintextExists: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
19
25
  declare const mock_expectPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint, expectedValue: bigint) => Promise<void>;
@@ -43,7 +49,7 @@ declare const mock_withLogs: (hre: HardhatRuntimeEnvironment, closureName: strin
43
49
  */
44
50
  declare module 'hardhat/types/config' {
45
51
  interface HardhatUserConfig {
46
- cofhesdk?: {
52
+ cofhe?: {
47
53
  /** Whether to log mock operations (default: true) */
48
54
  logMocks?: boolean;
49
55
  /** Whether to show gas usage warnings for mock operations (default: true) */
@@ -51,7 +57,7 @@ declare module 'hardhat/types/config' {
51
57
  };
52
58
  }
53
59
  interface HardhatConfig {
54
- cofhesdk: {
60
+ cofhe: {
55
61
  /** Whether to log mock operations (default: true) */
56
62
  logMocks: boolean;
57
63
  /** Whether to show gas usage warnings for mock operations (default: true) */
@@ -66,21 +72,21 @@ declare module 'hardhat/types/config' {
66
72
  */
67
73
  declare module 'hardhat/types/runtime' {
68
74
  interface HardhatRuntimeEnvironment {
69
- cofhesdk: {
75
+ cofhe: {
70
76
  /**
71
- * Create a CoFHE SDK configuration for use with cofhesdk.createCofhesdkClient(...)
72
- * @param {CofhesdkInputConfig} config - The CoFHE SDK input configuration
73
- * @returns {CofhesdkConfig} The CoFHE SDK configuration
77
+ * Create a CoFHE configuration for use with hre.cofhe.createClient(...)
78
+ * @param {CofheInputConfig} config - The CoFHE input configuration
79
+ * @returns {CofheConfig} The CoFHE configuration
74
80
  */
75
- createCofhesdkConfig: (config: CofhesdkInputConfig) => Promise<CofhesdkConfig>;
81
+ createConfig: (config: CofheInputConfig) => Promise<CofheConfig>;
76
82
  /**
77
- * Create a CoFHE SDK client instance
78
- * @param {CofhesdkConfig} config - The CoFHE SDK configuration (use createCofhesdkConfig to create with Node.js defaults)
79
- * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance
83
+ * Create a CoFHE client instance
84
+ * @param {CofheConfig} config - The CoFHE configuration (use createCofheConfig to create with Node.js defaults)
85
+ * @returns {Promise<CofheClient>} The CoFHE client instance
80
86
  */
81
- createCofhesdkClient: (config: CofhesdkConfig) => CofhesdkClient;
87
+ createClient: (config: CofheConfig) => CofheClient;
82
88
  /**
83
- * Create viem clients from a Hardhat ethers signer, to be used with `cofhesdkClient.connect(...)`
89
+ * Create viem clients from a Hardhat ethers signer, to be used with `cofheClient.connect(...)`
84
90
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
85
91
  * @returns {Promise<{ publicClient: PublicClient; walletClient: WalletClient }>} The viem clients
86
92
  */
@@ -89,20 +95,20 @@ declare module 'hardhat/types/runtime' {
89
95
  walletClient: WalletClient;
90
96
  }>;
91
97
  /**
92
- * Connect a CoFHE SDK client with a Hardhat ethers signer
93
- * @param {CofhesdkClient} client - The CoFHE SDK client to connect
98
+ * Connect a CoFHE client with a Hardhat ethers signer
99
+ * @param {CofheClient} client - The CoFHE client to connect
94
100
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use
95
101
  * @returns {Promise<void>}
96
102
  */
97
- connectWithHardhatSigner: (client: CofhesdkClient, signer: HardhatEthersSigner) => Promise<void>;
103
+ connectWithHardhatSigner: (client: CofheClient, signer: HardhatEthersSigner) => Promise<void>;
98
104
  /**
99
105
  * Create and connect to a batteries included client.
100
106
  * Also generates a self-usage a permit for the signer.
101
- * If customization is needed, use createCofhesdkClient and connectWithHardhatSigner.
107
+ * If customization is needed, use createCofheClient and connectWithHardhatSigner.
102
108
  * @param {HardhatEthersSigner} signer - The Hardhat ethers signer to use (optional - defaults to first signer)
103
- * @returns {Promise<CofhesdkClient>} The CoFHE SDK client instance
109
+ * @returns {Promise<CofheClient>} The CoFHE client instance
104
110
  */
105
- createBatteriesIncludedCofhesdkClient: (signer?: HardhatEthersSigner) => Promise<CofhesdkClient>;
111
+ createClientWithBatteries: (signer?: HardhatEthersSigner) => Promise<CofheClient>;
106
112
  mocks: {
107
113
  /**
108
114
  * **[MOCKS ONLY]**
@@ -114,7 +120,7 @@ declare module 'hardhat/types/runtime' {
114
120
  * Example usage:
115
121
  *
116
122
  * ```ts
117
- * await hre.cofhesdk.mocks.withLogs("counter.increment()", async () => {
123
+ * await hre.cofhe.mocks.withLogs("counter.increment()", async () => {
118
124
  * await counter.increment();
119
125
  * });
120
126
  * ```
@@ -180,10 +186,10 @@ declare module 'hardhat/types/runtime' {
180
186
  */
181
187
  getMockACL: () => Promise<Contract>;
182
188
  /**
183
- * Get the MockQueryDecrypter contract
184
- * @returns {Promise<Contract>} The MockQueryDecrypter contract
189
+ * Get the MockThresholdNetwork contract
190
+ * @returns {Promise<Contract>} The MockThresholdNetwork contract
185
191
  */
186
- getMockQueryDecrypter: () => Promise<Contract>;
192
+ getMockThresholdNetwork: () => Promise<Contract>;
187
193
  /**
188
194
  * Get the MockZkVerifier contract
189
195
  * @returns {Promise<Contract>} The MockZkVerifier contract
@@ -198,5 +204,11 @@ declare module 'hardhat/types/runtime' {
198
204
  };
199
205
  }
200
206
  }
207
+ /**
208
+ * Builds the mocks config for the hardhat plugin.
209
+ * Defaults `encryptDelay` to `0` so tests run without artificial wait times,
210
+ * unless the user has explicitly provided a value.
211
+ */
212
+ declare function buildHardhatPluginMocksConfig(mocksConfig: CofheInputConfig['mocks']): NonNullable<CofheInputConfig['mocks']>;
201
213
 
202
- export { type DeployMocksArgs, deployMocks, localcofheFundAccount, localcofheFundWalletIfNeeded, mock_expectPlaintext, mock_getPlaintext, mock_getPlaintextExists, mock_setLoggingEnabled, mock_withLogs };
214
+ export { type DeployMocksArgs, 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 };