Skip to content

Commit 35b0bd6

Browse files
committed
Document ZKEmailSigner and ZKEmailUtils
1 parent 27dcc0d commit 35b0bd6

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// contracts/MyAccountZKEmail.sol
2+
// SPDX-License-Identifier: MIT
3+
4+
pragma solidity ^0.8.20;
5+
6+
import {Account} from "../../../account/Account.sol";
7+
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
8+
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
9+
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
10+
import {ERC7739} from "../../../utils/cryptography/ERC7739.sol";
11+
import {ERC7821} from "../../../account/extensions/ERC7821.sol";
12+
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
13+
import {SignerZKEmail} from "../../../utils/cryptography/SignerZKEmail.sol";
14+
import {IDKIMRegistry} from "@zk-email/contracts/DKIMRegistry.sol";
15+
import {IVerifier} from "@zk-email/email-tx-builder/interfaces/IVerifier.sol";
16+
17+
contract MyAccountZKEmail is Account, SignerZKEmail, ERC7739, ERC7821, ERC721Holder, ERC1155Holder, Initializable {
18+
constructor() EIP712("MyAccountZKEmail", "1") {}
19+
20+
function initialize(
21+
bytes32 accountSalt_,
22+
IDKIMRegistry registry_,
23+
IVerifier verifier_,
24+
uint256 templateId_
25+
) public initializer {
26+
_setAccountSalt(accountSalt_);
27+
_setDKIMRegistry(registry_);
28+
_setVerifier(verifier_);
29+
_setCommandTemplate(templateId_);
30+
}
31+
32+
/// @dev Allows the entry point as an authorized executor.
33+
function _erc7821AuthorizedExecutor(
34+
address caller,
35+
bytes32 mode,
36+
bytes calldata executionData
37+
) internal view virtual override returns (bool) {
38+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
39+
}
40+
}

docs/modules/ROOT/pages/account-abstraction.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ Similarly, some government and corporate public key infrastructures use RSA for
5656
include::api:example$account/MyAccountRSA.sol[]
5757
----
5858

59+
For email-based authentication, the library provides xref:api:utils.adoc#SignerZKEmail[`SignerZKEmail`], which enables secure authentication through email messages using zero-knowledge proofs. This implementation leverages DKIM signatures from a trusted registry and a verifier contract to ensure email authenticity without revealing sensitive information.
60+
61+
The validation process involves several key components:
62+
63+
* A https://docs.zk.email/architecture/dkim-verification[DKIMRegistry] (DomainKeys Identified Mail) verification mechanism to ensure the email was sent from a valid domain
64+
* A https://docs.zk.email/email-tx-builder/architecture/command-templates[command template] validation mechanism to ensure the email command matches the expected format and parameters
65+
* A https://docs.zk.email/architecture/zk-proofs#how-zk-email-uses-zero-knowledge-proofs[zero-knowledge proof] verification mechanism to ensure the email was actually sent and received without revealing its contents
66+
67+
To use this signer, developers must set up several components during initialization:
68+
69+
* **accountSalt**: A unique identifier derived from the user's email address and account code. This is used for:
70+
* User Identification: Links the email address to a specific Ethereum address securely and deterministically
71+
* Security: Provides a unique identifier that cannot be easily guessed or brute-forced
72+
* Deterministic Address Generation: Enables the creation of deterministic addresses based on email addresses
73+
* **DKIMRegistry**: An instance of the DKIM registry contract for domain verification
74+
* **verifier**: An instance of the Verifier contract for zero-knowledge proof validation
75+
* **commandTemplate**: The template ID of the sign hash command, defining the expected format
76+
77+
[source,solidity]
78+
----
79+
include::api:example$account/MyAccountZKEmail.sol[]
80+
----
81+
82+
WARNING: Leaving any of the required components uninitialized may leave the account unusable since no proper authentication mechanism would be associated with it.
83+
5984
== Account Factory
6085

6186
The first time a user sends an user operation, the account will be created deterministically (i.e. its code and address can be predicted) using the the `initCode` field in the UserOperation. This field contains both the address of a smart contract (the factory) and the data required to call it and deploy the smart account.

0 commit comments

Comments
 (0)