This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from getwax/feature/email-recovery-circuits
Safe Email Recovery & Demo
- Loading branch information
Showing
75 changed files
with
9,938 additions
and
1,066 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"verifier": "0xEdC642bbaD91E21cCE6cd436Fdc6F040FD0fF998", | ||
"dkimRegistry": "0xC83256CCf7B94d310e49edA05077899ca036eb78", | ||
"emailAuthImpl": "0x1C76Aa365c17B40c7E944DcCdE4dC6e6D2A7b748", | ||
"simpleWalletImpl": "0xabAA8B42d053a57DeC990906ebdF3efF6844A861", | ||
"safeZkSafeZkEmailRecoveryPlugin": "0xFcfE6030952326c90fc615DDD15a3945f62AfCef" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/demos/email-recovery/src/abi/EmailAccountRecovery.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/demos/email-recovery/src/abi/SafeZkEmailRecoveryPlugin.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
packages/demos/email-recovery/src/assets/cancelRecoveryIcon.svg
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
3
packages/demos/email-recovery/src/assets/completeRecoveryIcon.svg
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.