Skip to content

Commit afd7b6d

Browse files
authored
feat(aztec.js)!: Move accounts out of aztec.js into new package (AztecProtocol#3844)
Extracts account contract implementations and related classes, as well as the default base classes, to a new `@aztec/accounts` package. Updates docs to reference the new package, and includes it in the API ref. This means that all scripts that relied on using accounts from the Sandbox, creating new accounts, or using accounts already deployed, will now need to import this package. Since `accounts` is now needed along with `aztec.js` for most stuff, including web, this PR also adds a new build step for end-to-end tests to exercise web builds. Instead of building aztec.js via webpack as part of aztec.js, we create a new "web application" as part of the end-to-end tests, which includes both aztec.js and accounts, and test that. This flow should be closer to how end-users will interact with aztec.js on the web. Fixes AztecProtocol#3807
1 parent f3d37d7 commit afd7b6d

File tree

103 files changed

+773
-357
lines changed

Some content is hidden

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

103 files changed

+773
-357
lines changed

boxes/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Aztec Starter Kits
22

33
A collection of projects that act as starter kits for Aztec.
4-
These depend on aztec.js and aztec.nr, and point to the monorepos local development versions.
4+
These depend on accounts, aztec.js and aztec.nr, and point to the monorepos local development versions.
55
These projects depend on the sandbox. They're built and tested after the sandbox by docker compose files.

boxes/blank-react/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"rootDir": "./src"
3333
},
3434
"dependencies": {
35+
"@aztec/accounts": "^0.16.9",
3536
"@aztec/aztec-ui": "^0.1.14",
3637
"@aztec/aztec.js": "^0.16.9",
3738
"classnames": "^2.3.2",

boxes/blank-react/src/app/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />

boxes/blank-react/src/scripts/util.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
AccountWallet,
3-
CompleteAddress,
4-
Fr,
5-
FunctionArtifact,
6-
PXE,
7-
encodeArguments,
8-
getSandboxAccountsWallets,
9-
} from '@aztec/aztec.js';
1+
import { AccountWallet, CompleteAddress, Fr, FunctionArtifact, PXE, encodeArguments } from '@aztec/aztec.js';
2+
3+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
104

115
export function convertArgs(functionAbi: FunctionArtifact, args: any): Fr[] {
126
const untypedArgs = functionAbi.parameters.map(param => {

boxes/blank/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"rootDir": "./src"
3333
},
3434
"dependencies": {
35+
"@aztec/accounts": "^0.16.9",
3536
"@aztec/aztec.js": "^0.16.9",
3637
"serve": "^14.2.1"
3738
},

boxes/blank/src/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />

boxes/blank/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import {
1414
TxReceipt,
1515
createPXEClient,
1616
encodeArguments,
17-
getSandboxAccountsWallets,
1817
} from '@aztec/aztec.js';
1918

19+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
20+
2021
// docs:end:imports
2122

2223
export const contractArtifact: ContractArtifact = BlankContractArtifact;

boxes/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"token"
1313
],
1414
"resolutions": {
15+
"@aztec/accounts": "portal:../yarn-project/accounts",
1516
"@aztec/aztec.js": "portal:../yarn-project/aztec.js",
1617
"@aztec/circuits.js": "portal:../yarn-project/circuits.js",
1718
"@aztec/foundation": "portal:../yarn-project/foundation",

boxes/token/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"rootDir": "./src"
3333
},
3434
"dependencies": {
35+
"@aztec/accounts": "^0.16.9",
3536
"@aztec/aztec-ui": "^0.1.14",
3637
"@aztec/aztec.js": "^0.16.9",
3738
"classnames": "^2.3.2",

boxes/token/src/app/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />

boxes/token/src/scripts/util.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
AccountWallet,
3-
CompleteAddress,
4-
Fr,
5-
FunctionArtifact,
6-
PXE,
7-
encodeArguments,
8-
getSandboxAccountsWallets,
9-
} from '@aztec/aztec.js';
1+
import { AccountWallet, CompleteAddress, Fr, FunctionArtifact, PXE, encodeArguments } from '@aztec/aztec.js';
2+
3+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
104

115
function convertBasicArg(paramType: string, value: any) {
126
switch (paramType) {

boxes/token/src/tests/token.contract.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import {
1414
computeMessageSecretHash,
1515
createDebugLogger,
1616
createPXEClient,
17-
getSandboxAccountsWallets,
1817
waitForSandbox,
1918
} from '@aztec/aztec.js';
19+
20+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
21+
2022
import { afterEach, beforeAll, expect, jest } from '@jest/globals';
2123

2224
// assumes sandbox is running locally, which this script does not trigger

boxes/token/src/tests/token_simulator.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export class TokenSimulator {
66
private balancePublic: Map<AztecAddress, bigint> = new Map();
77
public totalSupply: bigint = 0n;
88

9-
constructor(protected token: TokenContract, protected logger: DebugLogger, protected accounts: AztecAddress[]) {}
9+
constructor(
10+
protected token: TokenContract,
11+
protected logger: DebugLogger,
12+
protected accounts: AztecAddress[],
13+
) {}
1014

1115
public mintPrivate(amount: bigint) {
1216
this.totalSupply += amount;

boxes/yarn.lock

+16-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ __metadata:
2929
languageName: node
3030
linkType: hard
3131

32+
"@aztec/accounts@portal:../yarn-project/accounts::locator=%40aztec%2Fboxes%40workspace%3A.":
33+
version: 0.0.0-use.local
34+
resolution: "@aztec/accounts@portal:../yarn-project/accounts::locator=%40aztec%2Fboxes%40workspace%3A."
35+
dependencies:
36+
"@aztec/aztec.js": "workspace:^"
37+
"@aztec/circuits.js": "workspace:^"
38+
"@aztec/ethereum": "workspace:^"
39+
"@aztec/foundation": "workspace:^"
40+
"@aztec/types": "workspace:^"
41+
tslib: "npm:^2.4.0"
42+
languageName: node
43+
linkType: soft
44+
3245
"@aztec/aztec-ui@npm:^0.1.14":
3346
version: 0.1.14
3447
resolution: "@aztec/aztec-ui@npm:0.1.14"
@@ -58,7 +71,6 @@ __metadata:
5871
"@aztec/types": "workspace:^"
5972
lodash.every: "npm:^4.6.0"
6073
lodash.partition: "npm:^4.6.0"
61-
lodash.zip: "npm:^4.2.0"
6274
tslib: "npm:^2.4.0"
6375
languageName: node
6476
linkType: soft
@@ -80,6 +92,7 @@ __metadata:
8092
version: 0.0.0-use.local
8193
resolution: "@aztec/box-blank-react@workspace:blank-react"
8294
dependencies:
95+
"@aztec/accounts": "npm:^0.16.9"
8396
"@aztec/aztec-ui": "npm:^0.1.14"
8497
"@aztec/aztec.js": "npm:^0.16.9"
8598
"@types/jest": "npm:^29.5.0"
@@ -130,6 +143,7 @@ __metadata:
130143
version: 0.0.0-use.local
131144
resolution: "@aztec/box-blank@workspace:blank"
132145
dependencies:
146+
"@aztec/accounts": "npm:^0.16.9"
133147
"@aztec/aztec.js": "npm:^0.16.9"
134148
"@types/jest": "npm:^29.5.0"
135149
"@types/mocha": "npm:^10.0.3"
@@ -163,6 +177,7 @@ __metadata:
163177
version: 0.0.0-use.local
164178
resolution: "@aztec/box-token@workspace:token"
165179
dependencies:
180+
"@aztec/accounts": "npm:^0.16.9"
166181
"@aztec/aztec-ui": "npm:^0.1.14"
167182
"@aztec/aztec.js": "npm:^0.16.9"
168183
"@jest/globals": "npm:^29.6.4"
@@ -9472,13 +9487,6 @@ __metadata:
94729487
languageName: node
94739488
linkType: hard
94749489

9475-
"lodash.zip@npm:^4.2.0":
9476-
version: 4.2.0
9477-
resolution: "lodash.zip@npm:4.2.0"
9478-
checksum: e596da80a6138e369998b50c78b51ed6cf984b4f239e59056aa18dca5972a213c491c511caf5888a2dec603c67265caf942099bec554a86a5c7ff1937d57f0e4
9479-
languageName: node
9480-
linkType: hard
9481-
94829490
"lodash@npm:^4.17.11, lodash@npm:^4.17.15, lodash@npm:^4.17.21":
94839491
version: 4.17.21
94849492
resolution: "lodash@npm:4.17.21"

docs/docs/dev_docs/getting_started/aztecjs-getting-started.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mkdir src
3939
3. Add necessary yarn packages (and optionally add typescript too)
4040

4141
```sh
42-
yarn add @aztec/aztec.js @aztec/noir-contracts typescript @types/node
42+
yarn add @aztec/aztec.js @aztec/accounts @aztec/noir-contracts typescript @types/node
4343
```
4444

4545
4. [Optional] If creating a typescript file, add a `tsconfig.json` file into the project root, here is an example:
@@ -88,6 +88,7 @@ yarn add @aztec/aztec.js @aztec/noir-contracts typescript @types/node
8888
"start": "yarn build && DEBUG='token' node ./dest/index.js"
8989
},
9090
"dependencies": {
91+
"@aztec/accounts": "latest",
9192
"@aztec/aztec.js": "latest",
9293
"@aztec/noir-contracts": "latest",
9394
"@types/node": "^20.6.3",

docs/docs/dev_docs/tutorials/testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Testing with Typescript
44

55
Testing is an integral part of any piece of software, and especially important for any blockchain application. In this page we will cover how to interact with your Noir contracts in a testing environment to write automated tests for your apps.
66

7-
We will be using typescript to write our tests, and rely on the [`aztec.js`](https://www.npmjs.com/package/@aztec/aztec.js) client library to interact with a local Aztec network. We will use [`jest`](https://jestjs.io/) as a testing library, though feel free to use whatever you work with. Configuring the nodejs testing framework is out of scope for this guide.
7+
We will be using typescript to write our tests, and rely on the [`aztec.js`](https://www.npmjs.com/package/@aztec/aztec.js) client library to interact with a local Aztec network, along with the [`accounts`](https://www.npmjs.com/package/@aztec/accounts) package for setting up test accounts. We will use [`jest`](https://jestjs.io/) as a testing library, though feel free to use whatever you work with. Configuring the nodejs testing framework is out of scope for this guide.
88

99
## A simple example
1010

docs/docs/dev_docs/tutorials/token_portal/setup.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Inside the `packages` directory, run
130130

131131
```bash
132132
mkdir src && cd src && yarn init -yp
133-
yarn add @aztec/aztec.js @aztec/noir-contracts @aztec/types @aztec/foundation @aztec/l1-artifacts viem "@types/node@^20.8.2"
133+
yarn add @aztec/aztec.js @aztec/accounts @aztec/noir-contracts @aztec/types @aztec/foundation @aztec/l1-artifacts viem "@types/node@^20.8.2"
134134
yarn add -D jest @jest/globals ts-jest
135135
```
136136

docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ Open `cross_chain_messaging.test.ts` and paste the initial description of the te
8787

8888
```typescript
8989
import { expect, jest} from '@jest/globals'
90-
import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, getSandboxAccountsWallets, waitForSandbox } from '@aztec/aztec.js';
90+
import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForSandbox } from '@aztec/aztec.js';
91+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
9192
import { TokenContract } from '@aztec/noir-contracts/Token';
9293
import { TokenBridgeContract } from '@aztec/noir-contracts/TokenBridge';
9394

docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ import {
8181
computeAuthWitMessageHash,
8282
createDebugLogger,
8383
createPXEClient,
84-
getSandboxAccountsWallets,
8584
waitForSandbox,
8685
} from "@aztec/aztec.js";
86+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
8787
import {
8888
Chain,
8989
HttpTransport,

docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Create a new file `src/deploy.mjs`:
5858
// src/deploy.mjs
5959
import { writeFileSync } from 'fs';
6060
import { Contract, ContractDeployer, createPXEClient, getSandboxAccountsWallets } from '@aztec/aztec.js';
61+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
6162
import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" };
6263

6364
#include_code dapp-deploy yarn-project/end-to-end/src/sample-dapp/deploy.mjs raw

docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0
4545

4646
Now that we can see the balance for each user, let's transfer tokens from one account to another. To do this, we will first need access to a `Wallet` object. This wraps access to an PXE and also provides an interface to craft and sign transactions on behalf of one of the user accounts.
4747

48-
We can initialize a wallet using one of the `getAccount` methods from `aztec.js`, along with the corresponding signing and encryption keys:
48+
We can initialize a wallet using one of the `getAccount` methods from the `accounts` package, along with the corresponding signing and encryption keys:
4949

5050
```js
51-
import { getSchnorrAccount } from "@aztec/aztec.js";
51+
import { getSchnorrAccount } from "@aztec/accounts/schnorr";
5252
const wallet = await getSchnorrAccount(
5353
client,
5454
ENCRYPTION_PRIVATE_KEY,
5555
SIGNING_PRIVATE_KEY
5656
).getWallet();
5757
```
5858

59-
For ease of use, `aztec.js` also ships with a helper `getSandboxAccountsWallets` method that returns a wallet for each of the pre-initialized accounts in the Sandbox, so you can send transactions as any of them.
59+
For ease of use, `accounts` also ships with a helper `getSandboxAccountsWallets` method that returns a wallet for each of the pre-initialized accounts in the Sandbox, so you can send transactions as any of them.
6060

6161
```js
62-
import { getSandboxAccountsWallets } from '@aztec/aztec.js';
62+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
6363
```
6464

6565
We'll use one of these wallets to initialize the `Contract` instance that represents our private token contract, so every transaction sent through it will be sent through that wallet.

docs/docs/dev_docs/tutorials/writing_dapp/project_setup.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ cd sample-dapp
2020
yarn init -yp
2121
```
2222

23-
3. Add the `aztec.js` library as a dependency:
23+
3. Add the `aztec.js` and `accounts` libraries as a dependency:
2424

2525
```sh
26-
yarn add @aztec/aztec.js
26+
yarn add @aztec/aztec.js @aztec/accounts
2727
```
2828

2929
## Next steps

docs/docs/dev_docs/wallets/writing_an_account_contract.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ For our account contract, we will take the hash of the action to authorize, requ
5959

6060
## The typescript side of things
6161

62-
Now that we have a valid account contract, we need to write the typescript glue code that will take care of formatting and authenticating transactions so they can be processed by our contract, as well as deploying the contract during account setup. This takes the form of implementing the `AccountContract` interface:
62+
Now that we have a valid account contract, we need to write the typescript glue code that will take care of formatting and authenticating transactions so they can be processed by our contract, as well as deploying the contract during account setup. This takes the form of implementing the `AccountContract` interface from `@aztec/aztec.js`:
6363

64-
#include_code account-contract-interface yarn-project/aztec.js/src/account_contract/account_contract.ts typescript
64+
#include_code account-contract-interface yarn-project/aztec.js/src/account/contract.ts typescript
6565

66-
However, if you are using the default `AccountActions` module, then you can leverage the `BaseAccountContract` class and just implement the logic for generating an auth witness that matches the one you wrote in Noir:
66+
However, if you are using the default `AccountActions` module, then you can leverage the `DefaultAccountContract` class from `@aztec/accounts` and just implement the logic for generating an auth witness that matches the one you wrote in Noir:
6767

6868
#include_code account-contract yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts typescript
6969

docs/docusaurus.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ const config = {
149149
disableSources: true,
150150
},
151151
],
152+
[
153+
"docusaurus-plugin-typedoc",
154+
{
155+
id: "apis/accounts",
156+
entryPoints: [
157+
"../yarn-project/accounts/src/defaults/index.ts",
158+
"../yarn-project/accounts/src/ecdsa/index.ts",
159+
"../yarn-project/accounts/src/schnorr/index.ts",
160+
"../yarn-project/accounts/src/single_key/index.ts",
161+
"../yarn-project/accounts/src/testing/index.ts",
162+
],
163+
tsconfig: "../yarn-project/accounts/tsconfig.json",
164+
entryPointStrategy: "resolve",
165+
out: "apis/accounts",
166+
disableSources: true,
167+
},
168+
],
152169
// ["./src/plugins/plugin-embed-code", {}],
153170
],
154171
themeConfig:

docs/sidebars.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ const sidebars = {
8181
type: "doc",
8282
id: "concepts/foundation/state_model/main",
8383
},
84-
items: [
85-
"concepts/foundation/state_model/storage_slots"
86-
]
84+
items: ["concepts/foundation/state_model/storage_slots"],
8785
},
8886
{
8987
label: "Accounts",
@@ -113,8 +111,8 @@ const sidebars = {
113111
id: "concepts/foundation/communication/public_private_calls/main",
114112
},
115113
items: [
116-
"concepts/foundation/communication/public_private_calls/slow_updates_tree"
117-
]
114+
"concepts/foundation/communication/public_private_calls/slow_updates_tree",
115+
],
118116
},
119117
"concepts/foundation/communication/cross_chain_calls",
120118
],
@@ -324,9 +322,7 @@ const sidebars = {
324322
type: "doc",
325323
id: "dev_docs/contracts/syntax/storage/main",
326324
},
327-
items: [
328-
"dev_docs/contracts/syntax/storage/storage_slots",
329-
]
325+
items: ["dev_docs/contracts/syntax/storage/storage_slots"],
330326
},
331327
"dev_docs/contracts/syntax/events",
332328
"dev_docs/contracts/syntax/functions",
@@ -361,10 +357,10 @@ const sidebars = {
361357
{
362358
label: "Common Patterns",
363359
type: "category",
364-
link: {
365-
type: "doc",
366-
id: "dev_docs/contracts/resources/common_patterns/main",
367-
},
360+
link: {
361+
type: "doc",
362+
id: "dev_docs/contracts/resources/common_patterns/main",
363+
},
368364
items: [
369365
"dev_docs/contracts/resources/common_patterns/authwit",
370366
// "dev_docs/contracts/resources/common_patterns/sending_tokens_to_user",
@@ -462,6 +458,11 @@ const sidebars = {
462458
type: "category",
463459
items: [{ dirName: "apis/aztec-js", type: "autogenerated" }],
464460
},
461+
{
462+
label: "Accounts",
463+
type: "category",
464+
items: [{ dirName: "apis/accounts", type: "autogenerated" }],
465+
},
465466
],
466467
},
467468

0 commit comments

Comments
 (0)