Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Safe Email Recovery & Demo #218

Merged
merged 64 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
85afcd5
Add ether-email-auth to SafeZkEmailRecoveryPlugin
jacque006 Apr 3, 2024
6c298bd
Email recovery demo frontend initial commit
jacque006 Apr 3, 2024
f0ba1fe
Stub out demo
jacque006 Apr 3, 2024
bcba3bc
forge install: openzeppelin-contracts-upgradeable
JohnGuilding Apr 3, 2024
b513174
Add open zeppelin upgradeable to remappings
JohnGuilding Apr 3, 2024
7e497da
forge install: zk-email-verify
JohnGuilding Apr 3, 2024
22406cd
Add zk email contracts to remappings
JohnGuilding Apr 3, 2024
98298b3
forge install: openzeppelin-contracts-v4
JohnGuilding Apr 3, 2024
f8ab162
Rotate safe account owner instead of ecdsa plugin owner
JohnGuilding Apr 3, 2024
60946d1
Add note, fix version typo
jacque006 Apr 3, 2024
ec30cd6
Update ether-email-auth
JohnGuilding Apr 4, 2024
1bbcfc7
Fix build issue with copied contracts pointing at OZ v4
JohnGuilding Apr 4, 2024
46bfa1d
uninstall ether email auth
JohnGuilding Apr 4, 2024
7fce35b
forge install: email-auth-oz5-branch
JohnGuilding Apr 4, 2024
60c038d
Update email auth branch
JohnGuilding Apr 4, 2024
d91f802
Update zk email verify
JohnGuilding Apr 4, 2024
86da49d
Remove OZ upgradeable contracts
JohnGuilding Apr 4, 2024
ae38c03
forge install: openzeppelin-contracts-upgradeable
JohnGuilding Apr 4, 2024
6fc7576
Switch to zk email submodules fully and remove copied contracts
JohnGuilding Apr 4, 2024
8974f0a
fix remappings typo
JohnGuilding Apr 4, 2024
d983528
Update to latest ether-email-auth
jacque006 Apr 4, 2024
9623fbf
Add initial configs, fix forge build.
jacque006 Apr 4, 2024
610cf8b
Breakout to components, add ConnectKit stack.
jacque006 Apr 5, 2024
f5410fc
Add (failing) module deployment, relay spec json.
jacque006 Apr 5, 2024
c64ec75
Add integration test that hooks up to EmailAuth
JohnGuilding Apr 5, 2024
43b8bed
Add email recovery router contract
JohnGuilding Apr 5, 2024
4da7ed3
Add more functions to EmailAccountRouter.
SoraSuegami Apr 5, 2024
236baf9
Integration tests passed.
SoraSuegami Apr 5, 2024
1036f53
Add basic acceptRequest flow to demo.
jacque006 Apr 5, 2024
98e32c8
Add some requirements to SafeZkEmailRecoveryPlugin.
SoraSuegami Apr 5, 2024
01353c1
Merge pull request #230 from SoraSuegami/pr/email-recovery-circuits
jacque006 Apr 5, 2024
3a259c7
Add more relayer calls to test demo
jacque006 Apr 6, 2024
d1e32e7
Add hardhat deploy script for deploySafeZkEmailRecoveryPlugin
jacque006 Apr 6, 2024
d78d494
Remove demo safe moduel deploy.
jacque006 Apr 6, 2024
1eed6dd
Remove safe module deploy button
jacque006 Apr 6, 2024
845be51
Add safe module enablement
jacque006 Apr 6, 2024
fbb3609
Check if safe module is already enabled
jacque006 Apr 6, 2024
30a099e
Add Github Pages deploy
jacque006 Apr 7, 2024
bc5c359
Fix yarn cache path
jacque006 Apr 7, 2024
8bcdb70
Update deploy pipeline
jacque006 Apr 7, 2024
42d4983
Flesh out configure recovery
jacque006 Apr 7, 2024
52542dc
Fix GH page aritfact upload path
jacque006 Apr 7, 2024
dc0efd3
Update vite base
jacque006 Apr 7, 2024
b8d530c
Add axios, try diff way of gen guard addr
jacque006 Apr 7, 2024
cf5c489
Update account salt and account addr generation
JohnGuilding Apr 7, 2024
df7cbe7
Minor non-breaking clean-up of recovery plugin
JohnGuilding Apr 7, 2024
c8809b0
Integrate account salt endpoint
jacque006 Apr 7, 2024
672177d
Finish hooking in write call for rest of recovery process.
jacque006 Apr 8, 2024
b8160d9
Copy .env file in deploy, remove test timelock.
jacque006 Apr 8, 2024
49b4a81
Add base sepolia instructions
JohnGuilding Apr 8, 2024
5591b57
Disable demo deploy on branch
jacque006 Apr 9, 2024
3370c1e
Update UI/UX
wryonik Apr 9, 2024
fe91645
Merge pull request #233 from wryonik/email-recovery-demo
jacque006 Apr 10, 2024
c5b817d
Enable deploy, remove tsc check
jacque006 Apr 10, 2024
2e9ed6b
Remove non-Gnosis connection options
jacque006 Apr 10, 2024
eed9cba
Remove status checks, few other tweaks
jacque006 Apr 10, 2024
73f7941
Add loading state to config, default delay to 1
jacque006 Apr 10, 2024
f9423ed
if wallet disconnected go to connectWallet step
Rohan-cp Apr 10, 2024
f73c4e8
minor changes to copy + cleanup
Rohan-cp Apr 10, 2024
0489d5f
Fix typos
jacque006 Apr 10, 2024
4f7830e
Merge branch 'feature/email-recovery-circuits' of github.com:getwax/w…
jacque006 Apr 10, 2024
276caf4
Disable branch deploy
jacque006 Apr 10, 2024
ca65c54
Comment out removed code from safe email plugin
jacque006 Apr 23, 2024
e523080
Add EOF newline
jacque006 Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/email-recovery-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Based on https://dev.to/daslaw/deploying-a-vite-app-to-github-pages-using-github-actions-a-step-by-step-guide-2p4h
name: packages/demos/email-recovery

on:
push:
branches: ['main']
paths:
- packages/demos/email-recovery/**


# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

defaults:
run:
working-directory: ./packages/demos/email-recovery

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: 'pages'
cancel-in-progress: true

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
cache-dependency-path: packages/demos/email-recovery/yarn.lock

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Copy .env.base-sepolia
run: cp .env.base-sepolia .env
- name: Build
env:
VITE_WALLET_CONNECT_PROJECT_ID: ${{ secrets.VITE_WALLET_CONNECT_PROJECT_ID }}
run: VITE_WALLET_CONNECT_PROJECT_ID=${VITE_WALLET_CONNECT_PROJECT_ID} yarn build

- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: './packages/demos/email-recovery/dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
6 changes: 5 additions & 1 deletion .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ jobs:
forge build --sizes
id: build

# Skip safe zk email recovery unit tests while finishing demo. We still have a passing integration test - SafeZkEmailRecoveryPluginIntegration.t.sol
- name: Run Forge tests
run: |
forge test -vvv
forge test --no-match-path test/unit/safe/SafeZkEmailRecoveryPlugin.t.sol -vvv
id: test

hardhat:
Expand Down Expand Up @@ -96,5 +97,8 @@ jobs:
- name: Install Yarn dependencies
run: yarn install --frozen-lockfile

- name: Copy env file
run: cp .env.example .env

- name: Run hardhat compile
run: yarn hardhat compile
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@
[submodule "packages/plugins/lib/reference-implementation"]
path = packages/plugins/lib/reference-implementation
url = https://github.com/erc6900/reference-implementation
[submodule "packages/plugins/lib/ether-email-auth"]
path = packages/plugins/lib/ether-email-auth
url = https://github.com/zkemail/ether-email-auth
[submodule "packages/plugins/lib/openzeppelin-contracts-upgradeable"]
path = packages/plugins/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "packages/plugins/lib/zk-email-verify"]
path = packages/plugins/lib/zk-email-verify
url = https://github.com/zkemail/zk-email-verify
2 changes: 2 additions & 0 deletions packages/demos/email-recovery/.env.base-sepolia
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_WALLET_CONNECT_PROJECT_ID=REDACTED
VITE_RELAYER_URL=https://auth.prove.email/
2 changes: 2 additions & 0 deletions packages/demos/email-recovery/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_WALLET_CONNECT_PROJECT_ID=YOUR_PROJECT_ID
VITE_RELAYER_URL=https://auth.prove.email/
18 changes: 18 additions & 0 deletions packages/demos/email-recovery/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions packages/demos/email-recovery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
42 changes: 42 additions & 0 deletions packages/demos/email-recovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Email Recovery Demo

Based on `yarn creat vite w/ React, Typescript`

## Deps
- NodeJS
- yarn

## Setup

```sh
yarn
yarn setup # this will overwrite your existing .env file
```

You will need to set `VITE_WALLET_CONNECT_PROJECT_ID` . You can create a new WalletConnect project at https://cloud.walletconnect.com/

## Run

```sh
yarn dev
```

## Base Sepolia Guide

### Connecting your Safe
1. Start the app locally by following the setup instructions above, or visit https://getwax.github.io/wax. If running locally, remember to generate the WalletConnect project ID.
2. Ensure you have a Safe account deployed to Base Sepolia. This is easiest to do through the Safe Wallet UI at https://app.safe.global. Connect your signer(s) e.g. MetaMask
3. Click the "Connect Wallet" button, choose the WalletConnect option, and then "Copy to Clipboard". This copies a pairing code that can be used to connect your Safe to the recovery dApp.
4. Return to the Safe Wallet UI and look for the WalletConnect icon, it's located next to your connected account info at the top right of the screen on desktop. Click on the icon and paste the pairing code - it should connect automatically and you should see a ZKEmail icon alongside the WalletConnect icon in the UI.

### Enabling the recovery module
5. In the recovery dApp, click "Enable Email Recovery Module", you should then be prompted in the Safe UI to confirm this transaction.

### Configuring the recovery module and adding a guardian
6. Now the recovery module has been enabled, you can configure recovery and request a guardian. Enter the guardians email address and also the recovery delay in seconds (so for a 10 second delay, enter the number 10). Then click "Configure Recovery & Request Guardian" and confirm the transaction in your Safe. This will add the required recovery config to the recovery module. The relayer will also be called under the hood and will send an email to your guardian so that they can confirm they agree to be your guardian. This additional confirmation from the guardian helps to prevent mistakes when adding the guardian to the recovery config. The recovery delay is a security feature that adds a delay from when recovery is approved until recovery can actually be executed. This protects against malicious recovery attempts where a guardian or hacker tries to take over an account - when this happens, the account owner can cancel the recovery while the delay is in progress.
7. Your guardian should now receive an email asking them to confirm this request by replying "Confirm" to the email. After about a minute or two of the guardian confirming, they should get a confirmation that they have been accepted as a guardian successfully. Under the hood, the relayer is generating the zkp from the email and verifying it onchain. Your recovery module is now setup and ready to go!

### Recovering your Safe
8. To initiate the recovery process, paste your new owner address into the "New Owner" field and click "Request Recovery".
9. Your guardian will receive an email asking them to confirm the recovery request. They can do this by replying "Confirm" to the email. The relayer will then generate a zkp from this email and verify it onchain. After about a minute or two, the guardian will receive an email confirmation that their recovery approval has been a success.
10. After the recovery delay has passed, click the "Complete Recovery" button in the recovery dApp. This will rotate the owner on the Safe and replace it with the new owner. Refresh the Safe Wallet app and visit settings to see the new owner rotated successfully.
7 changes: 7 additions & 0 deletions packages/demos/email-recovery/contracts.base-sepolia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"verifier": "0xEdC642bbaD91E21cCE6cd436Fdc6F040FD0fF998",
"dkimRegistry": "0xC83256CCf7B94d310e49edA05077899ca036eb78",
"emailAuthImpl": "0x1C76Aa365c17B40c7E944DcCdE4dC6e6D2A7b748",
"simpleWalletImpl": "0xabAA8B42d053a57DeC990906ebdF3efF6844A861",
"safeZkSafeZkEmailRecoveryPlugin": "0xFcfE6030952326c90fc615DDD15a3945f62AfCef"
}
13 changes: 13 additions & 0 deletions packages/demos/email-recovery/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="https://i.imgur.com/46VRTCF.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Safe Email Recovery Demo</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions packages/demos/email-recovery/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "email-recovery",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"setup": "cp .env.base-sepolia .env",
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.28.14",
"@wagmi/cli": "^2.1.4",
"axios": "^1.6.8",
"circomlibjs": "^0.1.7",
"connectkit": "^1.7.3",
"ethers": "^6.11.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"viem": "2.x",
"wagmi": "^2.5.18"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/circomlibjs": "^0.1.6",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.2.2",
"vite": "^5.2.0",
"vite-plugin-node-polyfills": "^0.21.0"
}
}
1 change: 1 addition & 0 deletions packages/demos/email-recovery/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions packages/demos/email-recovery/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#root {

}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
56 changes: 56 additions & 0 deletions packages/demos/email-recovery/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createContext, useEffect, useState } from "react";
import "./App.css";
import ConnectWallets from "./components/ConnectWallets";
import Navbar from "./components/Navbar";
import RequestedRecoveries from "./components/RequestedRecoveries";
import RequestGuardian from "./components/RequestGuardian";
import SafeModuleRecovery from "./components/SafeModuleRecovery";
import TriggerAccountRecovery from "./components/TriggerAccountRecovery";
import { STEPS } from "./constants";
import { Web3Provider } from "./providers/Web3Provider";
import { ConnectKitButton } from "connectkit";
import { useAccount } from "wagmi";
import { AppContextProvider } from "./context/AppContextProvider";

export const StepsContext = createContext(null);

function App() {
const [step, setStep] = useState(STEPS.CONNECT_WALLETS);

const renderBody = () => {
switch (step) {
case STEPS.CONNECT_WALLETS:
return <ConnectWallets />;
case STEPS.SAFE_MODULE_RECOVERY:
return <SafeModuleRecovery />;
case STEPS.REQUEST_GUARDIAN:
return <RequestGuardian />;
case STEPS.REQUESTED_RECOVERIES:
return <RequestedRecoveries />;
case STEPS.TRIGGER_ACCOUNT_RECOVERY:
return <TriggerAccountRecovery />;
default:
return <ConnectWallets />;
}
};

return (
<Web3Provider>
<AppContextProvider>
<StepsContext.Provider
value={{
setStep,
}}
>
<div className="app">
<Navbar />
<h1>Safe Email Recovery Demo</h1>
{renderBody()}
</div>
</StepsContext.Provider>{" "}
</AppContextProvider>
</Web3Provider>
);
}

export default App;
1 change: 1 addition & 0 deletions packages/demos/email-recovery/src/abi/ERC1967Proxy.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/demos/email-recovery/src/abi/Safe.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/demos/email-recovery/src/abi/SimpleWallet.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
3 changes: 3 additions & 0 deletions packages/demos/email-recovery/src/assets/infoIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/demos/email-recovery/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading