Getting Started
The following steps are for developers to implement account recovery using ether-email-auth. Note that this is the workflow for custom smart contracts -- if your wallet is 7579 compatible, you can simply install our 7579 module directly.
Prerequisites
First, install foundry by running the following command:
Then, install the specific version of foundry by running the following command: Note: The latest version of foundry fails some tests.
Clone the repository
At the moment, please use the feat/docs-updates branch.
Set up
Move to the packages/contracts
directory and run the following command.
Also, build the contract by running the following command.
SimpleWallet
As an example, we show how to implement the email-based account recovery into a simple wallet contract in SimpleWallet.sol. First, copy-paste SimpleWallet.sol to [the expected filepath of SimpleWallet.sol in the reader's working directory].
This implementation inherits OwnableUpgradeable.
changeOwner(address newOwner)
This function is implemented to change the owner of this wallet. When the account recovery is executed, the recovery controller calls this function. Regarding the recovery controller, see the following section.
RecoveryController
Implement the following implementation of RecoveryController. RecoveryController.sol
The Recovery Controller inherits from EmailAccountRecovery and is used to define custom guardians and email templates. The implementation address of EmailAuth is set in the Recovery Controller, and the actual email template verification is performed by EmailAuth.
Inheritance
The Controller account must inherit EmailAccountRecovery.sol.
GuardianStatus
Implement the status of the Guardian to execute Account Recovery.
Each address is initialized to NONE. If the guardian requests to accept the account recovery, the status is set to REQUESTED. If the guardian accepts the account recovery, the status is set to ACCEPTED.
Mapping
Implement the following mapping.
acceptanceSubjectTemplates()
Define the subject of the email when the guardian requests.
recoverySubjectTemplates()
Define the subject of the email when the recovery is executed.
extractRecoveredAccountFromAcceptanceSubject(bytes[] memory subjectParams, uint templateIdx)
Implement a method to return the account address to be recovered from AcceptanceSubject. The account address to be recovered is stored in templates[0][4]
in the implementation of acceptanceSubjectTemplates
. In this subject template, the variable {ethAddr}
is first defined in templates[0][4]
. Therefore, subjectParams[0]
contains this value.
extractRecoveredAccountFromRecoverySubject(bytes[] memory subjectParams, uint templateIdx)
Implement a method to return the account address to be recovered from RecoverySubject. The account address to be recovered is stored in templates[0][6]
in the implementation of recoverySubjectTemplates
. This is the first element of subjectParams
, so return subjectParams[0]
.
acceptGuardian(address guardian, uint templateIdx, bytes[] memory subjectParams, bytes32)
Implement a method to accept the guardian. If AcceptanceSubject is used, the account address to be recovered is stored in subjectParams[0]
. isRecovering
is defined in the contract, it's a mapping that stores whether the account address is being recovered. At this stage, this address must not be in isRecovering
. Next, check if the guardian is in the REQUESTED
status. Finally, change the status of the guardian to ACCEPTED
.
processRecovery(address guardian, uint templateIdx, bytes[] memory subjectParams, bytes32)
Implement a method to execute recovery. RecoverySubjectTemplate has already been defined in the implementation of recoverySubjectTemplates
. When this RecoverySubjectTemplate is used, the new signer is stored in subjectParams[1]
. subjectParams[0]
is the account address to be recovered. Check if this address is not in isRecovering
. Next, check if the guardian is in the ACCEPTED
status. Finally, set isRecovering
to true and update newSignerCandidateOfAccount
and currentTimelockOfAccount
.
completeRecovery(address account, bytes memory recoveryCalldata)
Implement a method to complete recovery. Check if the given account address account is being recovered and the timelock for account is not expired. Finally, set isRecovering
to false and update newSignerCandidateOfAccount
and currentTimelockOfAccount
. This change only changes the state of the account in the Recovery Controller. Then, call SimpleWallet.changeOwner
to change the actual owner to the new signer.
Deploy to Base Sepolia
First, set the environment variables. You should set the following environment variables to .env Your PRIVATE_KEY
needs some gas fees to deploy.
Then, set the following environment variables to .env
Then Open DeployRecoveryController.s.sol and change the following variables. Because this script are using create2 feature, you'll deploy the contracts with the same address if you use the same salt.
After that, deploy the contract by running the following command.
That's all for the contracts side.
Relayer API
Developers can use the relayers and probers we have provided. To send a request, see the API endpoints on the following page.
Last updated