-
Notifications
You must be signed in to change notification settings - Fork 0
Initiator control #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,30 +2,58 @@ | |
| pragma solidity ^0.8.17; | ||
|
|
||
| import {IModule} from "./interfaces/IModule.sol"; | ||
| import {IEmailRecoveryModule} from "@zk-email/email-recovery/src/interfaces/IEmailRecoveryModule.sol"; | ||
| import {IEmailRecoveryModule} from "@zk-email/email-recovery-clave/src/interfaces/IEmailRecoveryModule.sol"; | ||
| import {IClaveAccount} from "./interfaces/IClave.sol"; | ||
| import {Errors} from "./libraries/Errors.sol"; | ||
| import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; | ||
| import {EmailRecoveryManagerZkSync} from "@zk-email/email-recovery/src/EmailRecoveryManagerZkSync.sol"; | ||
| import {GuardianManager} from "@zk-email/email-recovery/src/GuardianManager.sol"; | ||
| import {EmailRecoveryManagerZkSync} from "@zk-email/email-recovery-clave/src/EmailRecoveryManagerZkSync.sol"; | ||
| import {EmailRecoveryManager} from "@zk-email/email-recovery-clave/src/EmailRecoveryManager.sol"; | ||
| import {GuardianManager} from "@zk-email/email-recovery-clave/src/GuardianManager.sol"; | ||
| import {EmailAccountRecovery} from "@zk-email/ether-email-auth-contracts/src/EmailAccountRecovery.sol"; | ||
|
|
||
| contract EmailRecoveryModule is | ||
| EmailRecoveryManagerZkSync, | ||
| IModule, | ||
| IEmailRecoveryModule | ||
| { | ||
| /** | ||
| * Deployment timestamp | ||
| */ | ||
| uint256 public immutable deploymentTimestamp; | ||
|
|
||
| /** | ||
| * Account address to isInited | ||
| */ | ||
| mapping(address account => bool) internal inited; | ||
|
|
||
| /** | ||
| * Account address to initiate transactions | ||
| */ | ||
| mapping(address account => bool isInitiator) internal transactionInitiators; | ||
|
|
||
| /** | ||
| * @notice Emitted when a recovery is executed | ||
| * @param account address - Recovered account | ||
| * @param newOwner bytes - New owner of the account | ||
| */ | ||
| event RecoveryExecuted(address indexed account, bytes newOwner); | ||
|
|
||
| /** | ||
| * @notice Modifier to check if the caller is an initiator | ||
| */ | ||
| modifier isInitiator() { | ||
| bool isOpenToAll = transactionInitiators[address(0)] || | ||
| block.timestamp >= deploymentTimestamp + 6 * 30 days; | ||
|
|
||
| if (!isOpenToAll) { | ||
| require( | ||
| transactionInitiators[msg.sender], | ||
| "Only allowed accounts can call this function" | ||
| ); | ||
| } | ||
| _; | ||
| } | ||
|
|
||
| /** | ||
| * @notice Initializes the EmailRecoveryModule contract | ||
| * @param _verifier Address of the verifier contract | ||
|
|
@@ -57,7 +85,9 @@ contract EmailRecoveryModule is | |
| _factoryAddr, | ||
| _proxyBytecodeHash | ||
| ) | ||
| {} | ||
| { | ||
| deploymentTimestamp = block.timestamp; | ||
| } | ||
|
|
||
| /** | ||
| * @notice Initializes the recovery module for the calling account using the provided configuration data. | ||
|
|
@@ -113,6 +143,17 @@ contract EmailRecoveryModule is | |
| emit Disabled(msg.sender); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Sets the transaction initiator status for an account | ||
| * @dev Can only be called by the kill switch authorizer | ||
| */ | ||
| function setTransactionInitiator( | ||
| address account, | ||
| bool canInitiate | ||
| ) external onlyOwner { | ||
| transactionInitiators[account] = canInitiate; | ||
| } | ||
|
|
||
| function canStartRecoveryRequest( | ||
| address account | ||
| ) external view returns (bool) { | ||
|
|
@@ -134,6 +175,55 @@ contract EmailRecoveryModule is | |
| interfaceId == type(IERC165).interfaceId; | ||
| } | ||
|
|
||
| /** | ||
| * @notice Accepts a guardian for the specified account. This is the second core function | ||
| * that must be called during the end-to-end recovery flow | ||
| * @dev Called once per guardian added. Although this adds an extra step to recovery, this | ||
| * acceptance flow is an important security feature to ensure that no typos are made when adding | ||
| * a guardian, and that the guardian is in control of the specified email address. Called as | ||
| * part of handleAcceptance in EmailAccountRecovery | ||
| * @param guardian The address of the guardian to be accepted | ||
| * @param templateIdx The index of the template used for acceptance | ||
| * @param commandParams An array of bytes containing the command parameters | ||
| * @param nullifier The unique identifier for an email (unused in this implementation) | ||
| */ | ||
| function acceptGuardian( | ||
| address guardian, | ||
| uint256 templateIdx, | ||
| bytes[] memory commandParams, | ||
| bytes32 nullifier | ||
| ) | ||
| internal | ||
| override(EmailAccountRecovery, EmailRecoveryManager) | ||
| onlyWhenActive | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a reason |
||
| isInitiator | ||
| { | ||
| super.acceptGuardian(guardian, templateIdx, commandParams, nullifier); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Processes a recovery request for a given account. This is the third core function | ||
| * that must be called during the end-to-end recovery flow | ||
| * @dev Called once per guardian until the threshold is reached | ||
| * @param guardian The address of the guardian initiating/voting on the recovery request | ||
| * @param templateIdx The index of the template used for the recovery request | ||
| * @param commandParams An array of bytes containing the command parameters | ||
| * @param nullifier The unique identifier for an email (unused in this implementation) | ||
| */ | ||
| function processRecovery( | ||
| address guardian, | ||
| uint256 templateIdx, | ||
| bytes[] memory commandParams, | ||
| bytes32 nullifier | ||
| ) | ||
| internal | ||
| override(EmailAccountRecovery, EmailRecoveryManager) | ||
| onlyWhenActive | ||
| isInitiator | ||
| { | ||
| super.processRecovery(guardian, templateIdx, commandParams, nullifier); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Recovers the ownership or control of the given account by setting a new owner or validator. | ||
| * @dev | ||
|
|
@@ -145,6 +235,7 @@ contract EmailRecoveryModule is | |
| * @param account The address of the account for which the recovery is being executed. | ||
| * @param newOwner The new owner of the account | ||
| */ | ||
|
|
||
| function recover( | ||
| address account, | ||
| bytes calldata newOwner | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.