mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-09 13:38:03 -05:00
Add a function to change the main authorizer to Useroverridable DKIM registry. (#235)
* Add changeMainAuthorizer * Update versions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zk-email/circuits",
|
||||
"version": "6.3.0",
|
||||
"version": "6.3.1",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"publish": "yarn npm publish --access=public",
|
||||
|
||||
@@ -43,6 +43,9 @@ contract UserOverrideableDKIMRegistry is
|
||||
address indexed authorizer
|
||||
);
|
||||
|
||||
/// @notice Emitted when the main authorizer address is changed.
|
||||
event MainAuthorizerChanged(address indexed newMainAuthorizer);
|
||||
|
||||
/// @notice Main authorizer address.
|
||||
address public mainAuthorizer;
|
||||
|
||||
@@ -356,6 +359,27 @@ contract UserOverrideableDKIMRegistry is
|
||||
emit DKIMPublicKeyHashReactivated(publicKeyHash, authorizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Changes the main authorizer address.
|
||||
* @param newMainAuthorizer The address of the new main authorizer.
|
||||
* @custom:require Only the owner can change the main authorizer address.
|
||||
* @custom:require The new main authorizer address cannot be zero.
|
||||
* @custom:require The new main authorizer address cannot be the same as the current main authorizer.
|
||||
* @custom:event MainAuthorizerChanged Emitted when the main authorizer address changes.
|
||||
*/
|
||||
function changeMainAuthorizer(address newMainAuthorizer) public onlyOwner {
|
||||
require(
|
||||
newMainAuthorizer != address(0),
|
||||
"newMainAuthorizer address cannot be zero"
|
||||
);
|
||||
require(
|
||||
newMainAuthorizer != mainAuthorizer,
|
||||
"newMainAuthorizer address cannot be the same as the current mainAuthorizer"
|
||||
);
|
||||
mainAuthorizer = newMainAuthorizer;
|
||||
emit MainAuthorizerChanged(newMainAuthorizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Computes a signed message string for setting or revoking a DKIM public key hash.
|
||||
* @param prefix The operation prefix (SET: or REVOKE:).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zk-email/contracts",
|
||||
"version": "6.3.0",
|
||||
"version": "6.3.1",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "forge build",
|
||||
|
||||
@@ -590,6 +590,22 @@ contract UserOverrideableDKIMRegistryTest is Test {
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testChangeMainAuthorizer() public {
|
||||
vm.startPrank(deployer);
|
||||
vm.expectEmit();
|
||||
emit UserOverrideableDKIMRegistry.MainAuthorizerChanged(user1);
|
||||
registry.changeMainAuthorizer(user1);
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testChangeMainAuthorizerContract() public {
|
||||
vm.startPrank(deployer);
|
||||
vm.expectEmit();
|
||||
emit UserOverrideableDKIMRegistry.MainAuthorizerChanged(user1);
|
||||
registryWithContract.changeMainAuthorizer(address(user1));
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testFailIsDKIMPublicKeyHashValidByUser2() public {
|
||||
testSetDKIMPublicKeyHashByUser1();
|
||||
|
||||
@@ -1099,4 +1115,32 @@ contract UserOverrideableDKIMRegistryTest is Test {
|
||||
);
|
||||
console.log(signedMsg);
|
||||
}
|
||||
|
||||
function testExpectRevertChangeMainAuthorizerByNonOwner() public {
|
||||
vm.startPrank(mainAuthorizer);
|
||||
vm.expectRevert(
|
||||
abi.encodeWithSelector(
|
||||
OwnableUpgradeable.OwnableUnauthorizedAccount.selector,
|
||||
mainAuthorizer
|
||||
)
|
||||
);
|
||||
registry.changeMainAuthorizer(user1);
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testExpectRevertChangeMainAuthorizerIsZero() public {
|
||||
vm.startPrank(deployer);
|
||||
vm.expectRevert("newMainAuthorizer address cannot be zero");
|
||||
registry.changeMainAuthorizer(address(0));
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testExpectRevertChangeMainAuthorizerIsSame() public {
|
||||
vm.startPrank(deployer);
|
||||
vm.expectRevert(
|
||||
"newMainAuthorizer address cannot be the same as the current mainAuthorizer"
|
||||
);
|
||||
registry.changeMainAuthorizer(mainAuthorizer);
|
||||
vm.stopPrank();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zk-email/helpers",
|
||||
"version": "6.3.0",
|
||||
"version": "6.3.1",
|
||||
"license": "MIT",
|
||||
"main": "dist",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user