Skip to content

Commit

Permalink
Merge branch 'email-recovery' of https://github.com/zkemail/ether-ema…
Browse files Browse the repository at this point in the history
…il-auth into email-recovery
  • Loading branch information
SoraSuegami committed Dec 14, 2024
2 parents 367b4eb + 9d736ee commit cc7b0a8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "packages/contracts/lib/forge-std"]
path = packages/contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "packages/contracts/lib/safe-singleton-deployer-sol"]
path = packages/contracts/lib/safe-singleton-deployer-sol
url = https://github.com/wilsoncusack/safe-singleton-deployer-sol
1 change: 1 addition & 0 deletions packages/contracts/lib/safe-singleton-deployer-sol
3 changes: 2 additions & 1 deletion packages/contracts/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ ds-test/=../../node_modules/ds-test/src
solady/=../../node_modules/solady/src/
accountabstraction/=../../node_modules/accountabstraction/
solidity-stringutils/=../../node_modules/solidity-stringutils/
openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/
openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/
safe-singleton-deployer/=lib/safe-singleton-deployer-sol/src/
82 changes: 54 additions & 28 deletions packages/contracts/script/DeployRecoveryController.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {SimpleWallet} from "../test/helpers/SimpleWallet.sol";
import {RecoveryController} from "../test/helpers/RecoveryController.sol";
import {Verifier} from "../src/utils/Verifier.sol";
import {Groth16Verifier} from "../src/utils/Groth16Verifier.sol";
import {ECDSAOwnedDKIMRegistry} from "../src/utils/ECDSAOwnedDKIMRegistry.sol";
import {EmailAuth} from "../src/EmailAuth.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {UserOverrideableDKIMRegistry} from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol";
import {BaseDeployScript} from "./BaseDeployScript.sol";
import {SafeSingletonDeployer} from "safe-singleton-deployer/SafeSingletonDeployer.sol";

contract Deploy is BaseDeployScript {
using ECDSA for *;
Expand All @@ -22,54 +20,82 @@ contract Deploy is BaseDeployScript {
address simpleWallet;
address recoveryController;

function deploySingleton(
uint256 deployerPrivateKey,
bytes memory creationCode,
bytes memory initData,
bytes32 salt
) private returns (address) {
return
SafeSingletonDeployer.broadcastDeploy(
deployerPrivateKey,
creationCode,
initData,
salt
);
}

function run() public override {
super.run();
vm.startBroadcast(deployerPrivateKey);
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address initialOwner = vm.envOr("INITIAL_OWNER", address(0));

// Deploy User-overrideable DKIM registry
dkim = vm.envOr("DKIM", address(0));
if (address(dkim) == address(0)) {
if (dkim == address(0)) {
address dkimSigner = vm.envAddress("DKIM_SIGNER");
if (dkimSigner == address(0)) {
console.log("DKIM_SIGNER env var not set");
return;
}
require(dkimSigner != address(0), "DKIM_SIGNER env var not set");
uint256 timeDelay = vm.envOr("DKIM_DELAY", uint256(0));
console.log("DKIM_DELAY: %s", timeDelay);

dkim = deployUserOverrideableDKIMRegistry(
initialOwner,
dkimSigner,
timeDelay
dkim = deploySingleton(
deployerPrivateKey,
type(UserOverrideableDKIMRegistry).creationCode,
abi.encode(initialOwner, dkimSigner, timeDelay),
keccak256("DKIM_REGISTRY")
);
}
console.log("UserOverrideableDKIMRegistry: %s", dkim);

// Deploy Verifier
verifier = vm.envOr("VERIFIER", address(0));
if (address(verifier) == address(0)) {
verifier = deployVerifier(initialOwner);
if (verifier == address(0)) {
verifier = deploySingleton(
deployerPrivateKey,
type(Verifier).creationCode,
abi.encode(initialOwner),
keccak256("VERIFIER")
);
}
console.log("Verifier: %s", verifier);

// Deploy EmailAuth Implementation
emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0));
if (emailAuthImpl == address(0)) {
emailAuthImpl = deployEmailAuthImplementation();
emailAuthImpl = deploySingleton(
deployerPrivateKey,
type(EmailAuth).creationCode,
"",
keccak256("EMAIL_AUTH_IMPL")
);
}
console.log("EmailAuth: %s", emailAuthImpl);

// Create RecoveryController as EmailAccountRecovery implementation
recoveryController = deployRecoveryController(
initialOwner,
address(verifier),
address(dkim),
address(emailAuthImpl)
// Create RecoveryController
recoveryController = deploySingleton(
deployerPrivateKey,
type(RecoveryController).creationCode,
abi.encode(initialOwner, verifier, dkim, emailAuthImpl),
keccak256("RECOVERY_CONTROLLER")
);
console.log("RecoveryController: %s", recoveryController);

// Deploy SimpleWallet Implementation
simpleWallet = deploySimpleWallet(
initialOwner,
address(recoveryController)
simpleWallet = deploySingleton(
deployerPrivateKey,
type(SimpleWallet).creationCode,
abi.encode(initialOwner, recoveryController),
keccak256("SIMPLE_WALLET")
);

vm.stopBroadcast();
console.log("SimpleWallet: %s", simpleWallet);
}
}

0 comments on commit cc7b0a8

Please sign in to comment.