@cofhe/mock-contracts 0.3.0 → 0.3.2
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 +17 -0
- package/contracts/MockTaskManager.sol +31 -33
- package/dist/index.d.mts +988 -1
- package/dist/index.d.ts +988 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -5
- package/src/MockTaskManager.ts +1 -1
- package/src/MockThresholdNetwork.ts +1 -1
- package/src/MockZkVerifier.ts +1 -1
- package/src/index.ts +1 -0
- package/src/typechain-types/MockACL.ts +382 -0
- package/src/typechain-types/MockTaskManager.ts +565 -0
- package/src/typechain-types/MockThresholdNetwork.ts +247 -0
- package/src/typechain-types/MockZkVerifier.ts +205 -0
- package/src/typechain-types/TestBed.ts +172 -0
- package/src/typechain-types/common.ts +92 -0
- package/src/typechain-types/index.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @cofhe/mock-contracts Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d4e86ea: Aligns with CTA encrypted variables bytes32 representation.
|
|
8
|
+
|
|
9
|
+
- **@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.
|
|
10
|
+
- **@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.
|
|
11
|
+
- **@cofhe/abi**: CTA-related types use `bytes32` (string) instead of `uint256`. Decryption and return-type helpers aligned with cofhe-contracts 0.1.0.
|
|
12
|
+
- **@cofhe/sdk**: Decryption APIs (`decryptForTx`, `decryptForView`, and related builders) now also accept `string` for ciphertext hashes (bytes32) as well as `bigint`.
|
|
13
|
+
|
|
14
|
+
## 0.3.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 370f0c7: no-op
|
|
19
|
+
|
|
3
20
|
## 0.3.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -177,6 +177,7 @@ contract MockTaskManager is ITaskManager, MockCoFHE {
|
|
|
177
177
|
owner = initialOwner;
|
|
178
178
|
initialized = true;
|
|
179
179
|
verifierSigner = address(0);
|
|
180
|
+
decryptResultSigner = address(0);
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
modifier onlyOwner() {
|
|
@@ -468,7 +469,7 @@ contract MockTaskManager is ITaskManager, MockCoFHE {
|
|
|
468
469
|
/// @notice Publish a signed decrypt result to the chain
|
|
469
470
|
/// @dev Anyone with a valid signature from the decrypt network can call this
|
|
470
471
|
function publishDecryptResult(uint256 ctHash, uint256 result, bytes calldata signature) external {
|
|
471
|
-
_verifyDecryptResult(ctHash, result, signature);
|
|
472
|
+
_verifyDecryptResult(ctHash, result, signature, true);
|
|
472
473
|
_decryptResultReady[ctHash] = true;
|
|
473
474
|
_decryptResult[ctHash] = result;
|
|
474
475
|
|
|
@@ -489,24 +490,40 @@ contract MockTaskManager is ITaskManager, MockCoFHE {
|
|
|
489
490
|
}
|
|
490
491
|
}
|
|
491
492
|
|
|
492
|
-
function
|
|
493
|
-
|
|
494
|
-
|
|
493
|
+
function verifyDecryptResult(uint256 ctHash, uint256 result, bytes calldata signature) external view returns (bool) {
|
|
494
|
+
return _verifyDecryptResult(ctHash, result, signature, true);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function verifyDecryptResultSafe(
|
|
498
|
+
uint256 ctHash,
|
|
499
|
+
uint256 result,
|
|
500
|
+
bytes calldata signature
|
|
501
|
+
) external view returns (bool) {
|
|
502
|
+
return _verifyDecryptResult(ctHash, result, signature, false);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function _verifyDecryptResult(
|
|
506
|
+
uint256 ctHash,
|
|
507
|
+
uint256 result,
|
|
508
|
+
bytes calldata signature,
|
|
509
|
+
bool shouldRevert
|
|
510
|
+
) private view returns (bool) {
|
|
511
|
+
if (decryptResultSigner == address(0)) {
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
bytes32 messageHash = keccak256(abi.encodePacked(ctHash, result));
|
|
495
516
|
(address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(messageHash, signature);
|
|
496
517
|
|
|
497
518
|
if (err != ECDSA.RecoverError.NoError || recovered == address(0)) {
|
|
498
|
-
revert InvalidSignature();
|
|
519
|
+
if (shouldRevert) revert InvalidSignature();
|
|
520
|
+
return false;
|
|
499
521
|
}
|
|
500
|
-
|
|
501
522
|
if (recovered != decryptResultSigner) {
|
|
502
|
-
revert InvalidSigner(recovered, decryptResultSigner);
|
|
523
|
+
if (shouldRevert) revert InvalidSigner(recovered, decryptResultSigner);
|
|
524
|
+
return false;
|
|
503
525
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
/// @notice Format: result (32) || enc_type (4) || chain_id (8) || ct_hash (32) = 76 bytes
|
|
507
|
-
function _computeDecryptResultHash(uint256 ctHash, uint256 result) private view returns (bytes32) {
|
|
508
|
-
uint8 encryptionType = TMCommon.getUintTypeFromHash(ctHash);
|
|
509
|
-
return keccak256(abi.encodePacked(result, uint32(encryptionType), uint64(block.chainid), bytes32(ctHash)));
|
|
526
|
+
return true;
|
|
510
527
|
}
|
|
511
528
|
|
|
512
529
|
function verifyType(uint8 ctType, uint8 desiredType) internal pure {
|
|
@@ -584,10 +601,10 @@ contract MockTaskManager is ITaskManager, MockCoFHE {
|
|
|
584
601
|
|
|
585
602
|
function extractSigner(EncryptedInput memory input, address sender) private view returns (address) {
|
|
586
603
|
bytes memory combined = abi.encodePacked(input.ctHash, input.utype, input.securityZone, sender, block.chainid);
|
|
587
|
-
|
|
588
604
|
bytes32 expectedHash = keccak256(combined);
|
|
589
605
|
|
|
590
606
|
address signer = ECDSA.recover(expectedHash, input.signature);
|
|
607
|
+
|
|
591
608
|
if (signer == address(0)) {
|
|
592
609
|
revert InvalidSignature();
|
|
593
610
|
}
|
|
@@ -656,23 +673,4 @@ contract MockTaskManager is ITaskManager, MockCoFHE {
|
|
|
656
673
|
function isPubliclyAllowed(uint256 ctHash) external view returns (bool) {
|
|
657
674
|
revert NotImplemented();
|
|
658
675
|
}
|
|
659
|
-
|
|
660
|
-
function verifyDecryptResult(uint256 ctHash, uint256 result, bytes calldata signature) external view returns (bool) {
|
|
661
|
-
// Mock implementation: verify signature using the verifier signer
|
|
662
|
-
bytes32 digest = keccak256(abi.encodePacked(result));
|
|
663
|
-
return ECDSA.recover(digest, signature) == verifierSigner;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
function verifyDecryptResultSafe(
|
|
667
|
-
uint256 ctHash,
|
|
668
|
-
uint256 result,
|
|
669
|
-
bytes calldata signature
|
|
670
|
-
) external view returns (bool) {
|
|
671
|
-
// Same as verifyDecryptResult for mock
|
|
672
|
-
try this.verifyDecryptResult(ctHash, result, signature) returns (bool valid) {
|
|
673
|
-
return valid;
|
|
674
|
-
} catch {
|
|
675
|
-
return false;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
676
|
}
|