Skip to content

Commit ffb1d04

Browse files
committed
Update email_based_account project
1 parent 4163a1e commit ffb1d04

51 files changed

Lines changed: 19158 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

email_based_account/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Dependencies
2+
/node_modules
3+
/**/node_modules
4+
.yarn/*
5+
!.yarn/patches
6+
!.yarn/plugins
7+
!.yarn/releases
8+
!.yarn/sdks
9+
!.yarn/versions
10+
11+
# Build outputs
12+
dist/
13+
build/
14+
target/
15+
dest/
16+
17+
# Debug logs
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
22+
# Environment variables
23+
.env
24+
.env.local
25+
.env.development.local
26+
.env.test.local
27+
.env.production.local
28+
29+
# IDE and editor files
30+
.idea/
31+
.vscode/*
32+
!.vscode/extensions.json
33+
*.swp
34+
*.swo
35+
.DS_Store
36+
37+
# Noir/Aztec specific
38+
artifacts/
39+
codegenCache.json
40+
.tsbuildinfo
41+
42+
# Testing
43+
coverage/
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
AZTEC_PORT
2+
ASSUME_PROVEN_UNTIL_BLOCK_NUMBER
3+
TEST_ACCOUNTS
4+
ENABLE_GAS
5+
API_PREFIX
6+
ETHEREUM_HOST
7+
L1_CHAIN_ID
8+
MNEMONIC
9+
ROLLUP_CONTRACT_ADDRESS
10+
REGISTRY_CONTRACT_ADDRESS
11+
INBOX_CONTRACT_ADDRESS
12+
OUTBOX_CONTRACT_ADDRESS
13+
AVAILABILITY_ORACLE_CONTRACT_ADDRESS
14+
FEE_JUICE_CONTRACT_ADDRESS
15+
FEE_JUICE_PORTAL_CONTRACT_ADDRESS
16+
ARCHIVER_URL
17+
DEPLOY_AZTEC_CONTRACTS
18+
L1_PRIVATE_KEY
19+
L2_QUEUE_SIZE
20+
WS_BLOCK_CHECK_INTERVAL_MS
21+
P2P_ENABLED
22+
P2P_BLOCK_CHECK_INTERVAL_MS
23+
P2P_PEER_CHECK_INTERVAL_MS
24+
P2P_L2_QUEUE_SIZE
25+
TCP_LISTEN_ADDR
26+
UDP_LISTEN_ADDR
27+
P2P_TCP_ANNOUNCE_ADDR
28+
P2P_UDP_ANNOUNCE_ADDR
29+
PEER_ID_PRIVATE_KEY
30+
BOOTSTRAP_NODES
31+
P2P_TX_PROTOCOL
32+
P2P_MIN_PEERS
33+
P2P_MAX_PEERS
34+
DATA_DIRECTORY
35+
TX_GOSSIP_VERSION
36+
P2P_QUERY_FOR_IP
37+
P2P_TX_POOL_KEEP_PROVEN_FOR
38+
TELEMETRY
39+
OTEL_SERVICE_NAME
40+
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
41+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
42+
NETWORK_NAME
43+
NETWORK
44+
API_KEY
45+
AZTEC_NODE_URL
46+
ARCHIVER_POLLING_INTERVAL_MS
47+
ARCHIVER_VIEM_POLLING_INTERVAL_MS
48+
ARCHIVER_MAX_LOGS
49+
SEQ_TX_POLLING_INTERVAL_MS
50+
SEQ_MAX_TX_PER_BLOCK
51+
SEQ_MIN_TX_PER_BLOCK
52+
SEQ_MIN_SECONDS_BETWEEN_BLOCKS
53+
SEQ_MAX_SECONDS_BETWEEN_BLOCKS
54+
COINBASE
55+
FEE_RECIPIENT
56+
ACVM_WORKING_DIRECTORY
57+
ACVM_BINARY_PATH
58+
SEQ_ALLOWED_SETUP_FN
59+
SEQ_ALLOWED_TEARDOWN_FN
60+
SEQ_MAX_BLOCK_SIZE_IN_BYTES
61+
ENFORCE_FEES
62+
SEQ_PUBLISHER_PRIVATE_KEY
63+
SEQ_REQUIRED_CONFIRMATIONS
64+
SEQ_PUBLISH_RETRY_INTERVAL_MS
65+
VERSION
66+
SEQ_DISABLED
67+
PROVER_DISABLED
68+
PROVER_REAL_PROOFS
69+
PROVER_AGENT_ENABLED
70+
PROVER_AGENT_POLL_INTERVAL_MS
71+
PROVER_AGENT_CONCURRENCY
72+
PROVER_JOB_TIMEOUT_MS
73+
PROVER_JOB_POLL_INTERVAL_MS
74+
PROVER_ID
75+
WS_L2_BLOCK_QUEUE_SIZE
76+
WS_PROVEN_BLOCKS_ONLY
77+
PROVER_PUBLISH_RETRY_INTERVAL_MS
78+
PROVER_PUBLISHER_PRIVATE_KEY
79+
PROVER_REQUIRED_CONFIRMATIONS
80+
PROVER_TEST_DELAY_MS
81+
TX_PROVIDER_NODE_URL
82+
TXE_PORT
83+
LOG_JSON
84+
BOT_PXE_URL
85+
BOT_PRIVATE_KEY
86+
BOT_RECIPIENT_ENCRYPTION_SECRET
87+
BOT_TOKEN_SALT
88+
BOT_TX_INTERVAL_SECONDS
89+
BOT_PRIVATE_TRANSFERS_PER_TX
90+
BOT_PUBLIC_TRANSFERS_PER_TX
91+
BOT_FEE_PAYMENT_METHOD
92+
BOT_NO_START
93+
BOT_TX_MINED_WAIT_SECONDS
94+
BOT_NO_WAIT_FOR_TRANSFERS
95+
BOT_MAX_PENDING_TXS
96+
PXE_BLOCK_POLLING_INTERVAL_MS
97+
PXE_L2_STARTING_BLOCK
98+
PXE_DATA_DIRECTORY
99+
BB_BINARY_PATH
100+
BB_WORKING_DIRECTORY
101+
BB_SKIP_CLEANUP
102+
PXE_PROVER_ENABLED
103+
BOT_FOLLOW_CHAIN
104+
BOT_FLUSH_SETUP_TRANSACTIONS
105+
VALIDATOR_PRIVATE_KEY
106+
VALIDATOR_DISABLED
107+
PROVER_NODE_DISABLE_AUTOMATIC_PROVING
108+
PROVER_NODE_MAX_PENDING_JOBS
109+
LOG_LEVEL
110+
DEBUG

email_based_account/.prompt

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Overall code structure and explanation:
2+
Project Structure:
3+
Your project is structured as a monorepo with the main application in the frontend directory. The root directory contains configuration files for the entire project, while the frontend directory has its own configuration and source files.
4+
Frontend Application:
5+
Built with React and TypeScript
6+
Uses Vite as the build tool
7+
Implements a basic wallet functionality for the Aztec Protocol
8+
Main Components:
9+
Home (frontend/src/pages/Home.tsx): The landing page with options to create an account or sign in
10+
CreateAccount (frontend/src/pages/CreateAccount.tsx): Handles the account creation process
11+
Wallet (frontend/src/pages/Wallet.tsx): Displays wallet information and balance
12+
State Management:
13+
Uses React Context (WalletContext) for managing wallet state across the application
14+
Routing:
15+
Utilizes React Router for navigation between different pages
16+
6. Styling:
17+
Uses CSS modules (styles/Common.module.css) for component-specific styles
18+
Has a global App.css file for general styling
19+
Testing:
20+
Jest is set up for unit testing
21+
SimpleTest.test.tsx contains tests for various components and functionalities
22+
Build and Configuration:
23+
Vite is used as the build tool (vite.config.ts)
24+
TypeScript configurations for both the app (tsconfig.json) and Node environment (tsconfig.node.json)
25+
ESLint for code linting (eslint.config.js)
26+
Dependencies:
27+
React and React DOM
28+
@aztec/aztec.js for Aztec Protocol integration
29+
Various development tools (TypeScript, Jest, ESLint, etc.)
30+
Key Features:
31+
Create a new Aztec account
32+
View account details (address, private key, transaction signing key)
33+
Basic wallet functionality
34+
11. Planned Features:
35+
Improved UI
36+
Token transfers
37+
Account abstraction features
38+
Fee management improvements
39+
Your project is a React-based frontend for an Aztec Protocol wallet. It's set up with modern tooling and practices, including TypeScript for type safety, Jest for testing, and Vite for fast builds. The application currently provides basic wallet functionality with plans for more advanced features in the future.
40+
The codebase is well-structured and follows React best practices, using functional components and hooks. It's set up to be easily expandable as you add more features to your wallet application.
41+
42+
43+
44+
Frontend Code Structure and Explanation:
45+
An overview of my frontend code structure and explain the main components:
46+
Entry Point (frontend/src/main.tsx):
47+
This file is the entry point of your React application. It renders the main App component into the DOM.
48+
App Component (frontend/src/App.tsx):
49+
This is your main application component. It sets up the routing using React Router and wraps the entire application with the WalletProvider for state management.
50+
Home Page (frontend/src/pages/Home.tsx):
51+
This is the landing page of your application. It provides options to create an account or sign in.
52+
Create Account Page (frontend/src/pages/CreateAccount.tsx):
53+
This page handles the account creation process. It simulates creating a new wallet and redirects to the wallet page upon completion.
54+
Wallet Page (frontend/src/pages/Wallet.tsx):
55+
This page displays the wallet information, including the address, private key, and transaction signing key.
56+
Wallet Context (frontend/src/context/WalletContext.tsx):
57+
This file sets up the React Context for managing wallet state across your application.
58+
Key Features:
59+
The application uses React Router for navigation between different pages.
60+
State management is handled through React Context (WalletContext).
61+
The app simulates wallet creation and management without actual blockchain integration yet.
62+
There's a basic UI with buttons for creating an account and signing in.
63+
The wallet view shows sensitive information (private key, transaction signing key) with a warning.
64+
Styling:
65+
The app uses CSS modules for styling (styles/Common.module.css).
66+
There's also a global App.css file for some general styling.
67+
Testing:
68+
There's a test file (SimpleTest.test.tsx) that includes tests for various components and functionalities.
69+
Build and Configuration:
70+
The project uses Vite as the build tool, configured in vite.config.ts.
71+
There are separate TypeScript configurations for the app (tsconfig.json) and Node environment (tsconfig.node.json).
72+
Dependencies:
73+
The project uses React, React Router, and various development tools like TypeScript, Jest for testing, and ESLint for linting.
74+
Overall, this frontend provides a basic structure for a wallet application, with placeholders for future functionality like actual account creation and transaction management. The code is organized in a typical React application structure, with separate files for components, context, and pages.
75+
76+
Logical flow for create account to put new account details display from wallet component to create-account component
77+
The main wallet functionality (display of address, private key, transaction signing key followed by the done button) that is now part of Wallet component,is logically a part of the create-account component. The user goes through this stage (if they dont yet have an account only. if they do then from the Home screen they click on 'Already have an account? Sign in' and go into a different flow which we dont need to consider here) when they click on 'Create Account' from the Home screen. The create-account component simulates this action and then displays the address, private key, and transaction signing key in the Wallet component. so can we just add the functionality of displaying the address, private key, and transaction signing key in the create-account component and then redirect to the wallet component? If yes, tell me how you will do it. If not, tell me what other changes need to be made. dont make any changes to the code yet till i ask you to.
78+
79+
80+
'Sign in if you have an account' story:
81+
on the home screen, on clicking 'Already have an account? Sign in', the user is redirected to the 'enter private key' screen. this screen has a form with 1 field 'Enter your private key'. once the user enters their private key which is essentially the encryptionSecretKey and another key, transaction signing key and clicks on 'Sign in', we fetch the account and wallet, when successfully done, user are redirected to the wallet component. if the credentials are not correct, show error and redirect to landing page/ component. salt=0
82+
83+
84+
implement createschnorr account functionality in the frontend. for real:
85+
As shown in @aztec.tsx there is a way to use @getSchnorrAccount.
86+
@createSchnorrAccount has the details. we start in the create-account component. we want to create the schnorr account. first create the pxe client and return it as an object. once @pxe object is available in the function to create schnorr account, then generate at random an @encryptionSecretKey and @signingSecretKey .
87+
now create new account by calling @getSchnorrAccount with the parameters we already have. get @Wallet object for the account. return an object with 3 properties: the wallet @address (User Address) , @encryptionSecretKey (Private Key) and @signingSecretKey (Transaction Signing Key) . use salt=0
88+
89+
separate creating pxe client and creating schnorr account in aztec.tsx. because pxe is used much more widely in in the lifetime of a user. user will use it to hold their private data including tokens, transactions, etc. the create schnorr account once at the beginning of their use.
90+
91+
changes to make in getting real schnorr account:
92+
1. currently address, encryptionSecretKey, signingSecretKey are returned as strings, Fr, Fq to create-account component. we need to change this to the actual object for address. account object?
93+
2. we need to make changes in create-account component to handle the new objects.
94+
3. we need to make changes in the aztec.tsx file to handle the new objects.
95+
4. we need to make changes in the wallet component to handle the new objects.
96+
what is stored in context, where walletinfo is defined. walletinfo has address as string, encryptionSecretKey as string, signingSecretKey as string, balance, transactions as its properties. does this make sense. is it what we want? why dont we retain it as the wallet object as defined by aztec.
97+
Wallet component does not need to show EncryptionSecretKey and SigningSecretKey. it only needs to show the address and balance. the transaction signing key is only needed for signing transactions, which we currently do not support. the private key is only needed for creating public key and we do not need to show that. so we can remove all these from context. we are only left with address and balance.
98+
99+
add initialization or waiting logic for pxe client in aztec.tsx.
100+
101+
deploy a token contract name, symbol, total supply. transfer some tokens to address from terminal.
102+
103+
add token feature to frontend. show token balance for hardcoded token contract. show token amount. put dummy value as 0 always for now. first log the balance quantity of tokens for token address for signed in user address.
104+
105+
email id as input in ui. hash it and use it as input in getSchnorrAccount method
106+
107+
this error - fs/promises related in github codespaces. how to fix.
108+
109+
if an account with an email is already registered, then if user uses different signing key next time, it should not create a totally new and different account. it should throw up error saying wrong signing key! else if a new account for created everytime a different signing key is used for same email, that results in terrible user experience.
110+
111+
version update of aztec to 0.57.0 is breaking smart contract tests. compiles well. but tests break. reference repo, aztec-starter on github works.

email_based_account/.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

email_based_account/Nargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "use zkemail"
3+
type = "bin"
4+
authors = ["rajesh"]
5+
compiler_version = ">=0.35.0"
6+
7+
[dependencies]
8+
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "aztec-packages-v0.57.0", directory = "noir-projects/aztec-nr/aztec" }
9+
zkemail = { tag = "v0.3.2", git = "https://github.com/zkemail/zkemail.nr", directory = "lib" }

email_based_account/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Email Based Account
2+
3+
Create an email based aztec account. That one can sign into using an email address (gmail) and a password. The user can sign transactions using the password.
4+
5+
This project uses zkemail.nr library for email verification on the user's device. The email ID and the password are kept private and do not leave the user's browser.
6+
7+
[watch the demo here](https://youtu.be/V_2vtAR1lzo)
8+
9+
How to run the project locally:
10+
1. Clone the repo (either this or the parent repo: https://github.com/rajeshb62/ab2)
11+
2. From project root (email_based_account), run:
12+
```
13+
nargo compile
14+
```
15+
3. From project root, run:
16+
```
17+
yarn install
18+
cd frontend
19+
yarn install
20+
cd ..
21+
```
22+
4. From project root (email_based_account folder), run:
23+
```
24+
yarn workspace frontend dev
25+
```
26+
5. Run tests:
27+
```
28+
# to run both noir and frontend tests
29+
yarn test
30+
# to run only frontend tests
31+
yarn test:frontend
32+
```
33+
34+
35+
## Challenge Selection
36+
Read [this article](https://aztec.network/blog/unlocking-the-future-of-privacy-exploring-identity-and-social-use-cases-in-alpha-build-2-with-100k-in-prizes) that announces Alpha Build 2 to learn more about the challenges and get ideas on what to build!
37+
38+
- [x] ZKEmail Guardian
39+
- [ ] Social Cipher
40+
41+
**Note**: You can change which challenges you've selected during the competition if you'd like. You are not bound by your choices or descriptions entered during the one week check-in.
42+
43+
## Team information
44+
45+
[Rajesh ](https://github.com/rajeshb62)
46+
47+
## Technical Approach
48+
### Questions/ approach
49+
- create an account for an email address abc@xyz.com based on .eml file:
50+
- verify header is valid using dkim signature verification
51+
- check sender is 'abc@xyz.com'
52+
- (additional check) check if subject contains a specific random string shown in UI
53+
- hash email+password into sha256 hash, and use it as encryption key in getSchnorrAccount(..) function, hash the password and use it as signing key. Show the account wallet in UI (user can sign tx from this wallet using their password)
54+
Inspirations:
55+
https://zkemail.shieldswap.org/
56+
https://docs.aztec.network/guides/developer_guides/smart_contracts/writing_contracts/authwit#usage
57+
Inspiration codebases: Loads account based on Face ID of user: loads account based on password: https://github.com/skaunov/aabch1_23
58+
59+
## Expected Outcomes
60+
A wallet app (previously created in alpha build 1 https://github.com/rajeshb62/aztec-wallet) that now is modified to use email ownership proof to create aztec account
61+
62+
## Lessons Learned (For Submission)
63+
64+
- What are the most important takeaways from your project?
65+
Creation of email based private blockchain accounts are a reality.
66+
- Are there any patterns or best practices that you've learned that would be useful for other projects?Learning about zkemail.nr library will help improve readme/ other documentation for this library.
67+
- Highlight reusable code patterns, key code snippets, and best practices - what are some of the ‘lego bricks’ you’ve built, and how could someone else best use them?
68+
69+
## Project Links (For Submission)
70+
71+
Please provide links to any relevant documentation, code, or other resources that you've used in your project.
72+
73+
## Video Demo (For Submission)
74+
75+
[![Email Based Account Demo]](https://www.youtube.com/watch?v=V_2vtAR1lzo)
76+
77+
A brief demo showing:
78+
- Email verification process
79+
- Account creation
80+
81+
- How does your project leverage Aztec's unique features? (programmable cryptography, private/public state, etc.)
82+
While not directly within scope of AB2, the wallet is being built only because
83+
1. it allows fully private state and activities, most importantly:
84+
- private transfers of stablecoins and eth
85+
- assets can stay fully private for user, as absolutely esstial for card games
86+
2. account abstraction features that make possible
87+
- user friendly encryption and signing key namely, email based hash for private key and Face ID for signing key
88+
- email ID based token transfer (???)
89+
- transaction rules like 'allow only transactions below $100 / day by email(???)'
90+
- allow session ID based transaction approval
91+
3. fee abstraction features:
92+
-allow for wallet provider to pay gas (needed for activities like card games)
93+
94+
- What is the potential real-world impact of your project?
95+
- onboard web2 users using familiar account creation and signing methods like email ID and password
96+
- ( there are other features relevant for web2 users in wallet but that are not directly within scope of AB2)
97+
98+
## Scope for future research, improvements and problems to solve
99+
- emails and aliases need to be studied. The goal is one email ID one aztec account (users have multiple aliases for one email ID, how does that work and how to handle that? Users can own domain name and have emails sent from and to all email ids using that domain name (a@joshcrites.com, b@joshcrites.com) be operated from the same inbox (??). there is lot of scope to better understand the email protocol)
100+
- current implementation has users sending emails to an inbox controlled by the developer. It defeats the purpose of user privacy. It needs a better solution (user sending verification email to themselves for the verification step???)
101+
- zkemail seems to support a limited number of domains currently. The app itself only supports emails sent from icloud.com and that too emails of a small size.
102+
- Replace password with touch/face ID for better UX and security

0 commit comments

Comments
 (0)