Add a function to change the main authorizer to Useroverridable DKIM registry. (#235)

* Add changeMainAuthorizer

* Update versions
This commit is contained in:
Sora Suegami
2024-10-30 18:32:55 +09:00
committed by GitHub
parent 3b3c808c61
commit 3e551fb2e5
5 changed files with 71 additions and 3 deletions

View File

@@ -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",

View File

@@ -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:).

View File

@@ -1,6 +1,6 @@
{
"name": "@zk-email/contracts",
"version": "6.3.0",
"version": "6.3.1",
"license": "MIT",
"scripts": {
"build": "forge build",

View File

@@ -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();
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@zk-email/helpers",
"version": "6.3.0",
"version": "6.3.1",
"license": "MIT",
"main": "dist",
"scripts": {