Skip to content

Commit bb92bcd

Browse files
committed
chore: restructure
1 parent 54e7613 commit bb92bcd

25 files changed

+5811
-4547
lines changed

.github/workflows/e2e.yml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ jobs:
2828

2929
- name: Set Aztec version and start sandbox
3030
run: |
31-
aztec-up 0.87.2
31+
aztec-up 0.87.4
3232
aztec start --sandbox &
3333
34-
- name: Compile contracts
35-
run: script -e -c "${AZTEC_NARGO:-aztec-nargo} compile"
36-
working-directory: ./contracts
37-
3834
- name: Install dependencies
3935
working-directory: ./app
4036
run: npm install -g yarn && yarn
@@ -43,23 +39,8 @@ jobs:
4339
working-directory: ./app
4440
run: yarn playwright install --with-deps
4541

46-
- name: Deploy contracts
47-
working-directory: ./app
48-
env:
49-
PROVER_ENABLED: false
50-
run: yarn deploy-contracts
51-
52-
- name: Build app
53-
working-directory: ./app
42+
- name: Build
5443
run: yarn build
5544

5645
- name: Run tests
57-
working-directory: ./app
5846
run: yarn test
59-
60-
- uses: actions/upload-artifact@v4
61-
if: ${{ !cancelled() }}
62-
with:
63-
name: playwright-report
64-
path: app/playwright-report/
65-
retention-days: 30

.gitignore

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
contracts/target
2-
codegenCache.json
3-
41
# Logs
52
logs
63
*.log
74
npm-debug.log*
85
yarn-debug.log*
96
yarn-error.log*
107
pnpm-debug.log*
11-
lerna-debug.log*
128

139
node_modules
1410
dist
@@ -26,13 +22,19 @@ dist-ssr
2622
*.sln
2723
*.sw?
2824

29-
app/scripts/.store
30-
app/deployed-contract.json
31-
app/wallet-info.json
25+
tsconfig.tsbuildinfo
3226

27+
scripts/.store
28+
./deployed-contract.json
29+
./wallet-info.json
30+
31+
contracts/target
32+
codegenCache.json
3333

3434
# Playwright
3535
test-results/
3636
playwright-report/
3737
blob-report/
3838
playwright/.cache/
39+
40+
.env

README.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ This is an example web app that demonstrates how to interact with an Aztec contr
1010

1111
1. Install the Aztec tools from the first few steps in [Quick Start Guide](https://docs.aztec.network/developers/getting_started).
1212

13-
Please note that this project uses `0.87.2` version of Aztec SDK. If you wish to use a different version, please update the dependencies in the `app/package.json` and in `contracts/Nargo.toml` file to match your version.
13+
Please note that this project uses `latest` version of Aztec SDK. If you wish to use a different version, please update the dependencies in the `app/package.json` and in `contracts/Nargo.toml` file to match your version.
1414

15-
Alternatively, you can install `0.87.2` version of Aztec tools by running the below commands:
15+
You can install a specific version of Aztec tools by running `aztec-up 0.X.X`
1616

17-
```sh
18-
aztec-up 0.87.2
19-
aztec start --sandbox
20-
```
2117

2218
2. Compile smart contracts in `/contracts`:
2319

2420
```sh
25-
(cd contracts && ./build.sh)
21+
yarn build-contracts
2622
```
2723

2824
The build script compiles the contract and generates the artifacts.
@@ -32,19 +28,20 @@ The build script compiles the contract and generates the artifacts.
3228
Run the JS deploy script to deploy the contracts (NodeJS v20.0):
3329

3430
```sh
35-
(cd app && yarn install)
36-
(cd app && yarn deploy-contracts)
31+
yarn install
32+
yarn deploy-contracts
3733
```
3834

39-
This will deploy the contracts and save the deployment info to `app/deployed-contract.json`.
40-
The full process involves `Generating Client IVC proof`, and may take a few moments. For faster development the sandbox does not verify proofs, so this can optionally be disabled [here](#disable-client-proofs).
35+
The deploy script generates a random account and deploys the voting contract with it. It also uses the SponsoredFPC contract for fee payment. This is sufficient for testing with Sandbox, but is not suitable for production setup.
36+
37+
The script also writes the deployment info to `.env` (which our web-app reads from).
4138

42-
> Important: For a production app, you need to back up the deployment info file to a secure location as without it, you will not be able to recover the contract address.
39+
> Note that the script generates client proofs and it may take a couple of seconds. For faster development, you can disable proving by calling with `PROVER_ENABLED=false` (Sandbox accepts transactions without a valid proof).
4340
44-
4. Run the app:
41+
4. Run the app (development mode):
4542

4643
```sh
47-
(cd app && yarn dev)
44+
yarn dev
4845
```
4946

5047
### Test the app
@@ -62,7 +59,7 @@ You can now interact with the deployed contract using the web app:
6259
You can also run the E2E tests:
6360

6461
```sh
65-
(cd app && yarn test)
62+
yarn test
6663
```
6764

6865
<br />
@@ -77,8 +74,4 @@ To disable proving in the deploy script, run:
7774
PXE_PROVER=none ./deploy.sh
7875
```
7976

80-
To disable proving in the web app, you can add the following line in `app/src/embedded-wallet.ts` (uncomment the existing line):
81-
82-
```ts
83-
config.proverEnabled = false;
84-
```
77+
To disable proving in the web app, you can set `PROVER_ENABLED` to `false` in `embedded-wallet.ts` file.

app/.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/.prettierrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

app/artifacts/private_voting-EasyPrivateVoting.json

Lines changed: 68 additions & 68 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ import {
77
ContractFunctionInteraction,
88
SponsoredFeePaymentMethod,
99
type PXE,
10+
AccountWallet,
1011
} from '@aztec/aztec.js';
1112
import { SponsoredFPCContractArtifact } from '@aztec/noir-contracts.js/SponsoredFPC';
1213
import { SPONSORED_FPC_SALT } from '@aztec/constants';
1314
import { randomBytes } from '@aztec/foundation/crypto';
1415
import { getEcdsaRAccount } from '@aztec/accounts/ecdsa/lazy';
16+
import { getSchnorrAccount } from '@aztec/accounts/schnorr/lazy';
1517
import { getPXEServiceConfig } from '@aztec/pxe/config';
1618
import { createPXEService } from '@aztec/pxe/client/lazy';
17-
import { ContractArtifact, getDefaultInitializer } from '@aztec/stdlib/abi';
19+
import { type ContractArtifact, getDefaultInitializer } from '@aztec/stdlib/abi';
20+
import { getInitialTestAccounts } from '@aztec/accounts/testing';
21+
22+
const PROVER_ENABLED = true;
1823

1924
const logger = createLogger('wallet');
2025
const LocalStorageKey = 'aztec-account';
@@ -24,6 +29,7 @@ const LocalStorageKey = 'aztec-account';
2429
// This is not meant for production use
2530
export class EmbeddedWallet {
2631
private pxe!: PXE;
32+
connectedAccount: AccountWallet | null = null;
2733

2834
constructor(private nodeUrl: string) {}
2935

@@ -34,12 +40,12 @@ export class EmbeddedWallet {
3440
// Create PXE Service
3541
const config = getPXEServiceConfig();
3642
config.l1Contracts = await aztecNode.getL1ContractAddresses();
37-
// config.proverEnabled = false;
43+
config.proverEnabled = PROVER_ENABLED;
3844
this.pxe = await createPXEService(aztecNode, config);
3945

4046
// Register Sponsored FPC Contract with PXE
4147
await this.pxe.registerContract({
42-
instance: await this.getSponsoredPFCContract(),
48+
instance: await this.#getSponsoredPFCContract(),
4349
artifact: SponsoredFPCContractArtifact,
4450
});
4551

@@ -49,7 +55,7 @@ export class EmbeddedWallet {
4955
}
5056

5157
// Internal method to use the Sponsored FPC Contract for fee payment
52-
async getSponsoredPFCContract() {
58+
async #getSponsoredPFCContract() {
5359
const instance = await getContractInstanceFromDeployParams(
5460
SponsoredFPCContractArtifact,
5561
{
@@ -60,8 +66,27 @@ export class EmbeddedWallet {
6066
return instance;
6167
}
6268

69+
getConnectedAccount() {
70+
if (!this.connectedAccount) {
71+
return null;
72+
}
73+
return this.connectedAccount;
74+
}
75+
76+
async connectTestAccount(index: number) {
77+
const testAccounts = await getInitialTestAccounts();
78+
const account = testAccounts[index];
79+
const schnorrAccount = await getSchnorrAccount(this.pxe, account.secret, account.signingKey, account.salt);
80+
81+
await schnorrAccount.register();
82+
const wallet = await schnorrAccount.getWallet();
83+
84+
this.connectedAccount = wallet;
85+
return wallet;
86+
}
87+
6388
// Create a new account
64-
async createAccount() {
89+
async createAccountAndConnect() {
6590
if (!this.pxe) {
6691
throw new Error('PXE not initialized');
6792
}
@@ -81,7 +106,7 @@ export class EmbeddedWallet {
81106

82107
// Deploy the account
83108
const deployMethod = await ecdsaAccount.getDeployMethod();
84-
const sponsoredPFCContract = await this.getSponsoredPFCContract();
109+
const sponsoredPFCContract = await this.#getSponsoredPFCContract();
85110
const deployOpts = {
86111
contractAddressSalt: Fr.fromString(ecdsaAccount.salt.toString()),
87112
fee: {
@@ -93,6 +118,7 @@ export class EmbeddedWallet {
93118
skipClassRegistration: true,
94119
skipPublicDeployment: true,
95120
};
121+
96122
const provenInteraction = await deployMethod.prove(deployOpts);
97123
const receipt = await provenInteraction.send().wait({ timeout: 120 });
98124

@@ -112,10 +138,12 @@ export class EmbeddedWallet {
112138

113139
// Register the account with PXE
114140
await ecdsaAccount.register();
141+
this.connectedAccount = ecdsaWallet;
142+
115143
return ecdsaWallet;
116144
}
117145

118-
async getAccount() {
146+
async connectExistingAccount() {
119147
// Read key from local storage and create the account
120148
const account = localStorage.getItem(LocalStorageKey);
121149
if (!account) {
@@ -132,6 +160,8 @@ export class EmbeddedWallet {
132160

133161
await ecdsaAccount.register();
134162
const ecdsaWallet = await ecdsaAccount.getWallet();
163+
164+
this.connectedAccount = ecdsaWallet;
135165
return ecdsaWallet;
136166
}
137167

@@ -157,7 +187,7 @@ export class EmbeddedWallet {
157187

158188
// Send a transaction with the Sponsored FPC Contract for fee payment
159189
async sendTransaction(interaction: ContractFunctionInteraction) {
160-
const sponsoredPFCContract = await this.getSponsoredPFCContract();
190+
const sponsoredPFCContract = await this.#getSponsoredPFCContract();
161191
const provenInteraction = await interaction.prove({
162192
fee: {
163193
paymentMethod: new SponsoredFeePaymentMethod(

app/index.html

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Private Voting on Aztec</title>
7-
<link rel="stylesheet" href="./src/style.css" />
87
</head>
98

109
<body>
1110
<nav class="navbar">
1211
<div class="nav-title">Private Voting</div>
13-
<div id="account-display" class="account-display"></div>
14-
<button id="create-account" type="button" style="display: none">
15-
Create Account
16-
</button>
12+
13+
<div style="display: flex; align-items: center; gap: 1rem;">
14+
<div id="account-display" class="account-display"></div>
15+
16+
<select id="test-account-number" style="display: none">
17+
<option value="1">Account 1</option>
18+
<option value="2">Account 2</option>
19+
<option value="3">Account 3</option>
20+
</select>
21+
<button id="connect-test-account" type="button" style="display: none">
22+
Connect Test Account
23+
</button>
24+
<button id="create-account" type="button" style="display: none">
25+
Create Account
26+
</button>
27+
</div>
1728
</nav>
1829

1930
<main class="main-content">
@@ -39,7 +50,5 @@ <h4>Cast Vote</h4>
3950

4051
<div id="status-message" class="status-message"></div>
4152
</main>
42-
43-
<script type="module" src="/src/main.ts"></script>
4453
</body>
4554
</html>

0 commit comments

Comments
 (0)