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

Commit

Permalink
Merge pull request #218 from getwax/feature/email-recovery-circuits
Browse files Browse the repository at this point in the history
Safe Email Recovery & Demo
  • Loading branch information
jacque006 authored Apr 23, 2024
2 parents 29b8099 + e523080 commit a63aa91
Show file tree
Hide file tree
Showing 75 changed files with 9,938 additions and 1,066 deletions.
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

0 comments on commit a63aa91

Please sign in to comment.