Skip to content

Commit a6b66de

Browse files
authored
feat: pxeless playground + embedded wallet (#17030)
First iteration of the PXEless playground. In order to restore full functionality, it makes use of an `EmbeddedWallet` which besides implementing the `Wallet` interface allows for the creation of accounts from the app. The databases have been separated into two, a `PlaygroundDB` which contains purely application data and a `WalletDB` that stores accounts and other misc artifacts related to wallet operation. The `Wallet` interface has been extended with account retrieval, and contract registration an updating has been simplified into a single method.
2 parents 2a4e00c + a000e4b commit a6b66de

File tree

71 files changed

+1491
-1343
lines changed

Some content is hidden

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

71 files changed

+1491
-1343
lines changed

boxes/boxes/vanilla/app/embedded-wallet.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ export class EmbeddedWallet extends BaseWallet {
5959
return account;
6060
}
6161

62+
getAccounts() {
63+
return Promise.resolve(
64+
Array.from(this.accounts.values()).map((acc) => ({
65+
alias: '',
66+
item: acc.getAddress(),
67+
}))
68+
);
69+
}
70+
6271
static async initialize(nodeUrl: string) {
6372
// Create Aztec Node Client
6473
const aztecNode = await createAztecNodeClient(nodeUrl);
@@ -235,7 +244,7 @@ export class EmbeddedWallet extends BaseWallet {
235244
const StubAccountContractArtifact = await getStubAccountContractArtifact();
236245
const instance = await getContractInstanceFromInstantiationParams(
237246
StubAccountContractArtifact,
238-
{}
247+
{ salt: Fr.random() }
239248
);
240249
return {
241250
account: stubAccount,

boxes/boxes/vanilla/app/main.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ document.addEventListener('DOMContentLoaded', async () => {
5454
constructorArgs: [AztecAddress.fromString(deployerAddress)],
5555
}
5656
);
57-
await wallet.registerContract({
58-
artifact: PrivateVotingContract.artifact,
59-
instance,
60-
});
57+
await wallet.registerContract(instance, PrivateVotingContract.artifact);
6158

6259
// Get existing account
6360
displayStatusMessage('Checking for existing account...');

boxes/boxes/vanilla/scripts/deploy.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ async function deployContract(wallet: Wallet, deployer: AztecAddress) {
128128
},
129129
});
130130
await provenInteraction.send().wait({ timeout: 120 });
131-
await wallet.registerContract({
132-
instance: contract,
133-
artifact: PrivateVotingContract.artifact,
134-
});
131+
await wallet.registerContract(contract, PrivateVotingContract.artifact);
135132

136133
return {
137134
contractAddress: contract.address.toString(),
@@ -166,10 +163,10 @@ async function createAccountAndDeployContract() {
166163
const wallet = new TestWallet(pxe);
167164

168165
// Register the SponsoredFPC contract (for sponsored fee payments)
169-
await wallet.registerContract({
170-
instance: await getSponsoredPFCContract(),
171-
artifact: SponsoredFPCContractArtifact,
172-
});
166+
await wallet.registerContract(
167+
await getSponsoredPFCContract(),
168+
SponsoredFPCContractArtifact
169+
);
173170

174171
// Create a new account
175172
const accountAddress = await createAccount(wallet);

playground/.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 120,
5+
"arrowParens": "avoid"
6+
}

playground/README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
Initial version of an "everything app" that can be used to test and benchmark Aztec.
44

5-
* PXE in the browser with client proofs
6-
* Connect to local sandbox or any network (scoped data)
7-
* Lazy loading of most assets (think contract artifacts) and WASM (bb still loads at start due to top-level await, but in parallel as it is separated from the main index,js)
8-
* Bundled by vite, 1MB compressed
9-
* Drop any contract artifact, interpret its ABI, simulate and send
10-
* Acts as a barebones wallet, managing auth scopes and separating accounts
11-
* Stores artifacts, accounts and all that's required to pick up where you left off without having to redeploy everything (indexeddb)
12-
* Supports basic aliasing of addresses
13-
* Allows loading an artifact, provide the address and go (instead of having to deploy it)
14-
* Add senders/contact management
15-
* Authwits
16-
17-
Missing:
18-
19-
* Benchmarking window where simulation/proving stats are displayed
5+
- Embedded wallet with PXE in the browser and client proofs
6+
- Connect to local sandbox or any network (scoped data)
7+
- Lazy loading of most assets (think contract artifacts) and WASM
8+
- Bundled by vite, 1.6MB compressed
9+
- Drop any contract artifact, interpret its ABI, simulate and send
10+
- Stores artifacts, accounts and all that's required to pick up where you left off without having to redeploy everything (indexeddb)
11+
- Supports aliasing of addresses, senders, contracts, etc
12+
- Allows loading an artifact, provide the address and go (instead of having to deploy it)
13+
- Add senders/contact management
14+
- Authwits
15+
- Benchmarking window where simulation/proving stats are displayed
2016

2117
## To run
2218

@@ -31,4 +27,4 @@ Production:
3127
```
3228
yarn build
3329
yarn preview
34-
``````
30+
```

playground/eslint.config.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import tseslint from 'typescript-eslint'
1+
import js from '@eslint/js';
2+
import eslintConfigPrettier from 'eslint-config-prettier/flat';
3+
import globals from 'globals';
4+
import reactHooks from 'eslint-plugin-react-hooks';
5+
import reactRefresh from 'eslint-plugin-react-refresh';
6+
import tseslint from 'typescript-eslint';
67

78
export default tseslint.config(
89
{ ignores: ['dist'] },
910
{
10-
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
extends: [js.configs.recommended, ...tseslint.configs.recommended, eslintConfigPrettier],
1112
files: ['**/*.{ts,tsx}'],
1213
languageOptions: {
1314
ecmaVersion: 2025,
@@ -19,10 +20,7 @@ export default tseslint.config(
1920
},
2021
rules: {
2122
...reactHooks.configs.recommended.rules,
22-
'react-refresh/only-export-components': [
23-
'warn',
24-
{ allowConstantExport: true },
25-
],
23+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
2624
},
2725
},
28-
)
26+
);

playground/index.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
<!-- Matomo -->
1010
<script>
11-
var _paq = window._paq = window._paq || [];
11+
var _paq = (window._paq = window._paq || []);
1212
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
1313
_paq.push(['trackPageView']);
1414
_paq.push(['enableLinkTracking']);
15-
(function() {
16-
var u="https://azteclabs.matomo.cloud/";
17-
_paq.push(['setTrackerUrl', u+'matomo.php']);
15+
(function () {
16+
var u = 'https://azteclabs.matomo.cloud/';
17+
_paq.push(['setTrackerUrl', u + 'matomo.php']);
1818
_paq.push(['setSiteId', '10']);
19-
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
20-
g.async=true; g.src='https://cdn.matomo.cloud/azteclabs.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s);
19+
var d = document,
20+
g = d.createElement('script'),
21+
s = d.getElementsByTagName('script')[0];
22+
g.async = true;
23+
g.src = 'https://cdn.matomo.cloud/azteclabs.matomo.cloud/matomo.js';
24+
s.parentNode.insertBefore(g, s);
2125
})();
2226
</script>
2327
<!-- End Matomo Code -->

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
1515
"test": "playwright test"
1616
},
17-
"prettier": "@aztec/foundation/prettier",
1817
"dependencies": {
1918
"@aztec/accounts": "link:../yarn-project/accounts",
2019
"@aztec/aztec.js": "link:../yarn-project/aztec.js",
@@ -51,6 +50,7 @@
5150
"@types/react-dom": "^19.0.3",
5251
"@vitejs/plugin-react-swc": "^3.7.2",
5352
"eslint": "^9.26.0",
53+
"eslint-config-prettier": "^10.1.8",
5454
"eslint-plugin-react-hooks": "^5.1.0",
5555
"eslint-plugin-react-refresh": "^0.4.18",
5656
"globals": "^15.14.0",

playground/src/App.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import Home from './components/home/Home';
66

77
function App() {
88
return (
9-
<NotificationsProvider slotProps={{
10-
snackbar: {
11-
anchorOrigin: { vertical: 'top', horizontal: 'right' },
12-
autoHideDuration: 5000,
13-
}
14-
}}>
9+
<NotificationsProvider
10+
slotProps={{
11+
snackbar: {
12+
anchorOrigin: { vertical: 'top', horizontal: 'right' },
13+
autoHideDuration: 5000,
14+
},
15+
}}
16+
>
1517
<ThemeProvider theme={theme}>
1618
<Global styles={globalStyle}></Global>
1719
<Home />

playground/src/aztecContext.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { AztecAddress, type AztecNode, type ContractArtifact, type Wallet } from '@aztec/aztec.js';
2+
3+
import { createContext } from 'react';
4+
import { type UserTx } from './utils/txs';
5+
import type { Network } from './utils/networks';
6+
import { PlaygroundDB } from './utils/storage';
7+
import { type Log } from './utils/web_logger';
8+
9+
export const AztecContext = createContext<{
10+
network: Network;
11+
node: AztecNode;
12+
wallet: Wallet | null;
13+
playgroundDB: PlaygroundDB;
14+
from: AztecAddress;
15+
currentContractAddress: AztecAddress;
16+
currentTx: UserTx;
17+
showContractInterface: boolean;
18+
currentContractArtifact: ContractArtifact;
19+
defaultContractCreationParams: Record<string, unknown>;
20+
pendingTxUpdateCounter: number;
21+
isNetworkCongested: boolean;
22+
logs: Log[];
23+
totalLogCount: number;
24+
logsOpen: boolean;
25+
embeddedWalletSelected: boolean;
26+
setIsEmbeddedWalletSelected: (selected: boolean) => void;
27+
setLogsOpen: (open: boolean) => void;
28+
setLogs: (logs: Log[]) => void;
29+
setTotalLogCount: (count: number) => void;
30+
setShowContractInterface: (showContractInterface: boolean) => void;
31+
setNode: (node: AztecNode) => void;
32+
setWallet: (wallet: Wallet) => void;
33+
setPlaygroundDB: (playgroundDB: PlaygroundDB) => void;
34+
setFrom: (address: AztecAddress) => void;
35+
setNetwork: (network: Network) => void;
36+
setCurrentTx: (currentTx: UserTx) => void;
37+
setCurrentContractArtifact: (currentContract: ContractArtifact) => void;
38+
setCurrentContractAddress: (currentContractAddress: AztecAddress) => void;
39+
setDefaultContractCreationParams: (defaultContractCreationParams: Record<string, unknown>) => void;
40+
setPendingTxUpdateCounter: (pendingTxUpdateCounter: number) => void;
41+
setIsNetworkCongested: (isNetworkCongested: boolean) => void;
42+
}>({
43+
network: null,
44+
node: null,
45+
wallet: null,
46+
playgroundDB: null,
47+
from: null,
48+
currentContractArtifact: null,
49+
currentContractAddress: null,
50+
currentTx: null,
51+
showContractInterface: false,
52+
defaultContractCreationParams: {},
53+
pendingTxUpdateCounter: 0,
54+
isNetworkCongested: false,
55+
totalLogCount: 0,
56+
logs: [],
57+
logsOpen: false,
58+
embeddedWalletSelected: false,
59+
setIsEmbeddedWalletSelected: () => {},
60+
setLogsOpen: () => {},
61+
setLogs: () => {},
62+
setTotalLogCount: () => {},
63+
setShowContractInterface: () => {},
64+
setWallet: () => {},
65+
setNode: () => {},
66+
setPlaygroundDB: () => {},
67+
setFrom: () => {},
68+
setNetwork: () => {},
69+
setCurrentTx: () => {},
70+
setCurrentContractArtifact: () => {},
71+
setCurrentContractAddress: () => {},
72+
setDefaultContractCreationParams: () => {},
73+
setPendingTxUpdateCounter: () => {},
74+
setIsNetworkCongested: () => {},
75+
});

0 commit comments

Comments
 (0)