Skip to content

Commit 6716ad1

Browse files
Amxxernestognw
authored andcommitted
Add ERC7913SignatureVerifierZKEmail
1 parent 7e32eff commit 6716ad1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.20;
4+
5+
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
6+
7+
import {IDKIMRegistry} from "@zk-email/contracts/DKIMRegistry.sol";
8+
import {IVerifier} from "@zk-email/email-tx-builder/interfaces/IVerifier.sol";
9+
import {EmailAuthMsg} from "@zk-email/email-tx-builder/interfaces/IEmailTypes.sol";
10+
import {IERC7913SignatureVerifier} from "../../interfaces/IERC7913.sol";
11+
import {ZKEmailUtils} from "./ZKEmailUtils.sol";
12+
13+
/**
14+
* @dev ERC-7913 signature verifier that support ZKEmail accounts.
15+
*/
16+
contract ERC7913SignatureVerifierZKEmail is IERC7913SignatureVerifier {
17+
using ZKEmailUtils for EmailAuthMsg;
18+
19+
IVerifier public immutable verifier;
20+
uint256 public immutable commandTemplate;
21+
22+
constructor(IVerifier _verifier, uint256 _commandTemplate) {
23+
verifier = _verifier;
24+
commandTemplate = _commandTemplate;
25+
}
26+
27+
/// @inheritdoc IERC7913SignatureVerifier
28+
function verify(bytes calldata key, bytes32 hash, bytes calldata signature) public view virtual returns (bytes4) {
29+
(IDKIMRegistry registry, bytes32 accountSalt) = abi.decode(key, (IDKIMRegistry, bytes32));
30+
EmailAuthMsg memory emailAuthMsg = abi.decode(signature, (EmailAuthMsg));
31+
if (
32+
bytes32(emailAuthMsg.commandParams[0]) == hash &&
33+
emailAuthMsg.templateId == commandTemplate &&
34+
emailAuthMsg.proof.accountSalt == accountSalt
35+
) {
36+
(bool verified, ) = emailAuthMsg.isValidZKEmail(registry, verifier);
37+
if (verified) {
38+
return IERC7913SignatureVerifier.verify.selector;
39+
}
40+
}
41+
return 0xffffffff;
42+
}
43+
}

0 commit comments

Comments
 (0)