diff --git a/boxes/README.md b/boxes/README.md index 9efb21f2e85..a3a9e6eb7b2 100644 --- a/boxes/README.md +++ b/boxes/README.md @@ -1,5 +1,5 @@ # Aztec Starter Kits A collection of projects that act as starter kits for Aztec. -These depend on aztec.js and aztec.nr, and point to the monorepos local development versions. +These depend on accounts, aztec.js and aztec.nr, and point to the monorepos local development versions. These projects depend on the sandbox. They're built and tested after the sandbox by docker compose files. diff --git a/boxes/blank-react/package.json b/boxes/blank-react/package.json index c337fc60019..b9a9ff00dfa 100644 --- a/boxes/blank-react/package.json +++ b/boxes/blank-react/package.json @@ -32,6 +32,7 @@ "rootDir": "./src" }, "dependencies": { + "@aztec/accounts": "^0.16.9", "@aztec/aztec-ui": "^0.1.14", "@aztec/aztec.js": "^0.16.9", "classnames": "^2.3.2", diff --git a/boxes/blank-react/src/app/index.html b/boxes/blank-react/src/app/index.html index c9522dd01f9..57ece0ccf91 100644 --- a/boxes/blank-react/src/app/index.html +++ b/boxes/blank-react/src/app/index.html @@ -1,4 +1,4 @@ - + diff --git a/boxes/blank-react/src/scripts/util.ts b/boxes/blank-react/src/scripts/util.ts index cde41403d55..6aea0121265 100644 --- a/boxes/blank-react/src/scripts/util.ts +++ b/boxes/blank-react/src/scripts/util.ts @@ -1,12 +1,6 @@ -import { - AccountWallet, - CompleteAddress, - Fr, - FunctionArtifact, - PXE, - encodeArguments, - getSandboxAccountsWallets, -} from '@aztec/aztec.js'; +import { AccountWallet, CompleteAddress, Fr, FunctionArtifact, PXE, encodeArguments } from '@aztec/aztec.js'; + +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; export function convertArgs(functionAbi: FunctionArtifact, args: any): Fr[] { const untypedArgs = functionAbi.parameters.map(param => { diff --git a/boxes/blank/package.json b/boxes/blank/package.json index eea2e510cf2..f8033cdea46 100644 --- a/boxes/blank/package.json +++ b/boxes/blank/package.json @@ -32,6 +32,7 @@ "rootDir": "./src" }, "dependencies": { + "@aztec/accounts": "^0.16.9", "@aztec/aztec.js": "^0.16.9", "serve": "^14.2.1" }, diff --git a/boxes/blank/src/index.html b/boxes/blank/src/index.html index f87ccadb3bd..84f225fe8a9 100644 --- a/boxes/blank/src/index.html +++ b/boxes/blank/src/index.html @@ -1,4 +1,4 @@ - + diff --git a/boxes/blank/src/index.ts b/boxes/blank/src/index.ts index 12faf4ade68..e511f2d301b 100644 --- a/boxes/blank/src/index.ts +++ b/boxes/blank/src/index.ts @@ -14,9 +14,10 @@ import { TxReceipt, createPXEClient, encodeArguments, - getSandboxAccountsWallets, } from '@aztec/aztec.js'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; + // docs:end:imports export const contractArtifact: ContractArtifact = BlankContractArtifact; diff --git a/boxes/package.json b/boxes/package.json index 5988d68290f..daa17918ede 100644 --- a/boxes/package.json +++ b/boxes/package.json @@ -12,6 +12,7 @@ "token" ], "resolutions": { + "@aztec/accounts": "portal:../yarn-project/accounts", "@aztec/aztec.js": "portal:../yarn-project/aztec.js", "@aztec/circuits.js": "portal:../yarn-project/circuits.js", "@aztec/foundation": "portal:../yarn-project/foundation", diff --git a/boxes/token/package.json b/boxes/token/package.json index 004d953c696..133a6bb0144 100644 --- a/boxes/token/package.json +++ b/boxes/token/package.json @@ -32,6 +32,7 @@ "rootDir": "./src" }, "dependencies": { + "@aztec/accounts": "^0.16.9", "@aztec/aztec-ui": "^0.1.14", "@aztec/aztec.js": "^0.16.9", "classnames": "^2.3.2", diff --git a/boxes/token/src/app/index.html b/boxes/token/src/app/index.html index 6fedf6b23a6..a81c17f2a87 100644 --- a/boxes/token/src/app/index.html +++ b/boxes/token/src/app/index.html @@ -1,4 +1,4 @@ - + diff --git a/boxes/token/src/scripts/util.ts b/boxes/token/src/scripts/util.ts index f2aa3609e15..46f82d79ca6 100644 --- a/boxes/token/src/scripts/util.ts +++ b/boxes/token/src/scripts/util.ts @@ -1,12 +1,6 @@ -import { - AccountWallet, - CompleteAddress, - Fr, - FunctionArtifact, - PXE, - encodeArguments, - getSandboxAccountsWallets, -} from '@aztec/aztec.js'; +import { AccountWallet, CompleteAddress, Fr, FunctionArtifact, PXE, encodeArguments } from '@aztec/aztec.js'; + +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; function convertBasicArg(paramType: string, value: any) { switch (paramType) { diff --git a/boxes/token/src/tests/token.contract.test.ts b/boxes/token/src/tests/token.contract.test.ts index 2ff90186f74..f8a86b508aa 100644 --- a/boxes/token/src/tests/token.contract.test.ts +++ b/boxes/token/src/tests/token.contract.test.ts @@ -14,9 +14,11 @@ import { computeMessageSecretHash, createDebugLogger, createPXEClient, - getSandboxAccountsWallets, waitForSandbox, } from '@aztec/aztec.js'; + +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; + import { afterEach, beforeAll, expect, jest } from '@jest/globals'; // assumes sandbox is running locally, which this script does not trigger diff --git a/boxes/token/src/tests/token_simulator.ts b/boxes/token/src/tests/token_simulator.ts index c91d8554773..94f9fe887f2 100644 --- a/boxes/token/src/tests/token_simulator.ts +++ b/boxes/token/src/tests/token_simulator.ts @@ -6,7 +6,11 @@ export class TokenSimulator { private balancePublic: Map = new Map(); public totalSupply: bigint = 0n; - constructor(protected token: TokenContract, protected logger: DebugLogger, protected accounts: AztecAddress[]) {} + constructor( + protected token: TokenContract, + protected logger: DebugLogger, + protected accounts: AztecAddress[], + ) {} public mintPrivate(amount: bigint) { this.totalSupply += amount; diff --git a/boxes/yarn.lock b/boxes/yarn.lock index 62fd6f8acf2..3ef58267bdb 100644 --- a/boxes/yarn.lock +++ b/boxes/yarn.lock @@ -29,6 +29,19 @@ __metadata: languageName: node linkType: hard +"@aztec/accounts@portal:../yarn-project/accounts::locator=%40aztec%2Fboxes%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@aztec/accounts@portal:../yarn-project/accounts::locator=%40aztec%2Fboxes%40workspace%3A." + dependencies: + "@aztec/aztec.js": "workspace:^" + "@aztec/circuits.js": "workspace:^" + "@aztec/ethereum": "workspace:^" + "@aztec/foundation": "workspace:^" + "@aztec/types": "workspace:^" + tslib: "npm:^2.4.0" + languageName: node + linkType: soft + "@aztec/aztec-ui@npm:^0.1.14": version: 0.1.14 resolution: "@aztec/aztec-ui@npm:0.1.14" @@ -58,7 +71,6 @@ __metadata: "@aztec/types": "workspace:^" lodash.every: "npm:^4.6.0" lodash.partition: "npm:^4.6.0" - lodash.zip: "npm:^4.2.0" tslib: "npm:^2.4.0" languageName: node linkType: soft @@ -80,6 +92,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/box-blank-react@workspace:blank-react" dependencies: + "@aztec/accounts": "npm:^0.16.9" "@aztec/aztec-ui": "npm:^0.1.14" "@aztec/aztec.js": "npm:^0.16.9" "@types/jest": "npm:^29.5.0" @@ -130,6 +143,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/box-blank@workspace:blank" dependencies: + "@aztec/accounts": "npm:^0.16.9" "@aztec/aztec.js": "npm:^0.16.9" "@types/jest": "npm:^29.5.0" "@types/mocha": "npm:^10.0.3" @@ -163,6 +177,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/box-token@workspace:token" dependencies: + "@aztec/accounts": "npm:^0.16.9" "@aztec/aztec-ui": "npm:^0.1.14" "@aztec/aztec.js": "npm:^0.16.9" "@jest/globals": "npm:^29.6.4" @@ -9472,13 +9487,6 @@ __metadata: languageName: node linkType: hard -"lodash.zip@npm:^4.2.0": - version: 4.2.0 - resolution: "lodash.zip@npm:4.2.0" - checksum: e596da80a6138e369998b50c78b51ed6cf984b4f239e59056aa18dca5972a213c491c511caf5888a2dec603c67265caf942099bec554a86a5c7ff1937d57f0e4 - languageName: node - linkType: hard - "lodash@npm:^4.17.11, lodash@npm:^4.17.15, lodash@npm:^4.17.21": version: 4.17.21 resolution: "lodash@npm:4.17.21" diff --git a/docs/docs/dev_docs/getting_started/aztecjs-getting-started.md b/docs/docs/dev_docs/getting_started/aztecjs-getting-started.md index 1b07e71412d..db038a69592 100644 --- a/docs/docs/dev_docs/getting_started/aztecjs-getting-started.md +++ b/docs/docs/dev_docs/getting_started/aztecjs-getting-started.md @@ -39,7 +39,7 @@ mkdir src 3. Add necessary yarn packages (and optionally add typescript too) ```sh -yarn add @aztec/aztec.js @aztec/noir-contracts typescript @types/node +yarn add @aztec/aztec.js @aztec/accounts @aztec/noir-contracts typescript @types/node ``` 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 "start": "yarn build && DEBUG='token' node ./dest/index.js" }, "dependencies": { + "@aztec/accounts": "latest", "@aztec/aztec.js": "latest", "@aztec/noir-contracts": "latest", "@types/node": "^20.6.3", diff --git a/docs/docs/dev_docs/tutorials/testing.md b/docs/docs/dev_docs/tutorials/testing.md index 00d4359f419..ca2d015bd90 100644 --- a/docs/docs/dev_docs/tutorials/testing.md +++ b/docs/docs/dev_docs/tutorials/testing.md @@ -4,7 +4,7 @@ title: Testing with Typescript 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. -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. +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. ## A simple example diff --git a/docs/docs/dev_docs/tutorials/token_portal/setup.md b/docs/docs/dev_docs/tutorials/token_portal/setup.md index 23f3b514507..40541565c88 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/setup.md +++ b/docs/docs/dev_docs/tutorials/token_portal/setup.md @@ -130,7 +130,7 @@ Inside the `packages` directory, run ```bash mkdir src && cd src && yarn init -yp -yarn add @aztec/aztec.js @aztec/noir-contracts @aztec/types @aztec/foundation @aztec/l1-artifacts viem "@types/node@^20.8.2" +yarn add @aztec/aztec.js @aztec/accounts @aztec/noir-contracts @aztec/types @aztec/foundation @aztec/l1-artifacts viem "@types/node@^20.8.2" yarn add -D jest @jest/globals ts-jest ``` diff --git a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md index 0dd42374501..c3ed984126a 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md @@ -87,7 +87,8 @@ Open `cross_chain_messaging.test.ts` and paste the initial description of the te ```typescript import { expect, jest} from '@jest/globals' -import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, getSandboxAccountsWallets, waitForSandbox } from '@aztec/aztec.js'; +import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForSandbox } from '@aztec/aztec.js'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; import { TokenContract } from '@aztec/noir-contracts/Token'; import { TokenBridgeContract } from '@aztec/noir-contracts/TokenBridge'; diff --git a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md index 9ac161a01eb..6260a26a6d8 100644 --- a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md @@ -81,9 +81,9 @@ import { computeAuthWitMessageHash, createDebugLogger, createPXEClient, - getSandboxAccountsWallets, waitForSandbox, } from "@aztec/aztec.js"; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; import { Chain, HttpTransport, diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md b/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md index 1d9df9dbc87..ae8edd0e575 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md @@ -58,6 +58,7 @@ Create a new file `src/deploy.mjs`: // src/deploy.mjs import { writeFileSync } from 'fs'; import { Contract, ContractDeployer, createPXEClient, getSandboxAccountsWallets } from '@aztec/aztec.js'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" }; #include_code dapp-deploy yarn-project/end-to-end/src/sample-dapp/deploy.mjs raw diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md index effaa050802..e2f9ea026ca 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md @@ -45,10 +45,10 @@ Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0 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. -We can initialize a wallet using one of the `getAccount` methods from `aztec.js`, along with the corresponding signing and encryption keys: +We can initialize a wallet using one of the `getAccount` methods from the `accounts` package, along with the corresponding signing and encryption keys: ```js -import { getSchnorrAccount } from "@aztec/aztec.js"; +import { getSchnorrAccount } from "@aztec/accounts/schnorr"; const wallet = await getSchnorrAccount( client, ENCRYPTION_PRIVATE_KEY, @@ -56,10 +56,10 @@ const wallet = await getSchnorrAccount( ).getWallet(); ``` -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. +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. ```js -import { getSandboxAccountsWallets } from '@aztec/aztec.js'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; ``` 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. diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/project_setup.md b/docs/docs/dev_docs/tutorials/writing_dapp/project_setup.md index 1a734ff85ca..f84a2c693bb 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/project_setup.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/project_setup.md @@ -20,10 +20,10 @@ cd sample-dapp yarn init -yp ``` -3. Add the `aztec.js` library as a dependency: +3. Add the `aztec.js` and `accounts` libraries as a dependency: ```sh -yarn add @aztec/aztec.js +yarn add @aztec/aztec.js @aztec/accounts ``` ## Next steps diff --git a/docs/docs/dev_docs/wallets/writing_an_account_contract.md b/docs/docs/dev_docs/wallets/writing_an_account_contract.md index c87eb8b4973..ea4cb859c19 100644 --- a/docs/docs/dev_docs/wallets/writing_an_account_contract.md +++ b/docs/docs/dev_docs/wallets/writing_an_account_contract.md @@ -59,11 +59,11 @@ For our account contract, we will take the hash of the action to authorize, requ ## The typescript side of things -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: +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`: -#include_code account-contract-interface yarn-project/aztec.js/src/account_contract/account_contract.ts typescript +#include_code account-contract-interface yarn-project/aztec.js/src/account/contract.ts typescript -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: +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: #include_code account-contract yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts typescript diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 945bcc5ccf5..ed6e068ddb4 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -149,6 +149,23 @@ const config = { disableSources: true, }, ], + [ + "docusaurus-plugin-typedoc", + { + id: "apis/accounts", + entryPoints: [ + "../yarn-project/accounts/src/defaults/index.ts", + "../yarn-project/accounts/src/ecdsa/index.ts", + "../yarn-project/accounts/src/schnorr/index.ts", + "../yarn-project/accounts/src/single_key/index.ts", + "../yarn-project/accounts/src/testing/index.ts", + ], + tsconfig: "../yarn-project/accounts/tsconfig.json", + entryPointStrategy: "resolve", + out: "apis/accounts", + disableSources: true, + }, + ], // ["./src/plugins/plugin-embed-code", {}], ], themeConfig: diff --git a/docs/sidebars.js b/docs/sidebars.js index 4eb6dbdcac7..76794b94616 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -81,9 +81,7 @@ const sidebars = { type: "doc", id: "concepts/foundation/state_model/main", }, - items: [ - "concepts/foundation/state_model/storage_slots" - ] + items: ["concepts/foundation/state_model/storage_slots"], }, { label: "Accounts", @@ -113,8 +111,8 @@ const sidebars = { id: "concepts/foundation/communication/public_private_calls/main", }, items: [ - "concepts/foundation/communication/public_private_calls/slow_updates_tree" - ] + "concepts/foundation/communication/public_private_calls/slow_updates_tree", + ], }, "concepts/foundation/communication/cross_chain_calls", ], @@ -324,9 +322,7 @@ const sidebars = { type: "doc", id: "dev_docs/contracts/syntax/storage/main", }, - items: [ - "dev_docs/contracts/syntax/storage/storage_slots", - ] + items: ["dev_docs/contracts/syntax/storage/storage_slots"], }, "dev_docs/contracts/syntax/events", "dev_docs/contracts/syntax/functions", @@ -361,10 +357,10 @@ const sidebars = { { label: "Common Patterns", type: "category", - link: { - type: "doc", - id: "dev_docs/contracts/resources/common_patterns/main", - }, + link: { + type: "doc", + id: "dev_docs/contracts/resources/common_patterns/main", + }, items: [ "dev_docs/contracts/resources/common_patterns/authwit", // "dev_docs/contracts/resources/common_patterns/sending_tokens_to_user", @@ -462,6 +458,11 @@ const sidebars = { type: "category", items: [{ dirName: "apis/aztec-js", type: "autogenerated" }], }, + { + label: "Accounts", + type: "category", + items: [{ dirName: "apis/accounts", type: "autogenerated" }], + }, ], }, diff --git a/yarn-project/.dockerignore b/yarn-project/.dockerignore index d4f7820cd6a..24611d873ea 100644 --- a/yarn-project/.dockerignore +++ b/yarn-project/.dockerignore @@ -11,7 +11,7 @@ **/Dockerfile* **/*.tsbuildinfo -./aztec.js/src/account_contract/artifacts +./accounts/src/artifacts noir-contracts/src noir-contracts/target diff --git a/yarn-project/Dockerfile b/yarn-project/Dockerfile index 324ea28a435..54c26ede564 100644 --- a/yarn-project/Dockerfile +++ b/yarn-project/Dockerfile @@ -13,9 +13,8 @@ COPY . . RUN yarn workspace @aztec/noir-compiler build # Builds noir contracts (TODO: move this stage pre yarn-project). Generates typescript wrappers. RUN yarn workspace @aztec/noir-contracts build:contracts -# We need to build aztec.js as it needs to copy in account contracts from noir-contracts. -# TODO: Contracts should not be baked into aztec.js. -RUN yarn workspace @aztec/aztec.js build +# We need to build accounts as it needs to copy in account contracts from noir-contracts. +RUN yarn workspace @aztec/accounts build:copy-contracts RUN yarn workspace @aztec/noir-protocol-circuits noir:build RUN yarn tsc -b diff --git a/yarn-project/accounts/.eslintrc.cjs b/yarn-project/accounts/.eslintrc.cjs new file mode 100644 index 00000000000..e659927475c --- /dev/null +++ b/yarn-project/accounts/.eslintrc.cjs @@ -0,0 +1 @@ +module.exports = require('@aztec/foundation/eslint'); diff --git a/yarn-project/accounts/.gitignore b/yarn-project/accounts/.gitignore new file mode 100644 index 00000000000..7912fc48c7d --- /dev/null +++ b/yarn-project/accounts/.gitignore @@ -0,0 +1 @@ +/src/artifacts diff --git a/yarn-project/accounts/README.md b/yarn-project/accounts/README.md new file mode 100644 index 00000000000..66cee36774d --- /dev/null +++ b/yarn-project/accounts/README.md @@ -0,0 +1,38 @@ +# Accounts + +Accounts is a client library that provides implementations for some common account flavors. Use it to acquire a `Wallet` object that corresponds to an account, and use that together with `@aztec/aztec.js` to interact with the network. + +## Installing + +``` +npm install @aztec/accounts +``` + +## Account types + +- **Schnorr**: Uses an Grumpkin private key with Schnorr signatures for authentication, and a separate Grumpkin private key for encryption. Recommended for most use cases. +- **ECDSA**: Uses an ECDSA private key for authentication, and a Grumpkin private key for encryption. Recommended for building integrations with Ethereum wallets. +- **SingleKey**: Uses a single Grumpkin private key for both authentication and encryption. Recommended for testing purposes only. + +## Usage + +### Deploy a new account + +```typescript +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; +import { GrumpkinPrivateKey } from '@aztec/types'; + +const encryptionPrivateKey = GrumpkinPrivateKey.random(); +const signingPrivateKey = GrumpkinPrivateKey.random(); +const wallet = getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); +console.log(`New account deployed at ${wallet.getAddress()}`); +``` + +### Create a wallet object from an already deployed account + +```typescript +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; + +const wallet = getSchnorrWallet(pxe, encryptionPrivateKey); +console.log(`Wallet for ${wallet.getAddress()} ready`); +``` \ No newline at end of file diff --git a/yarn-project/accounts/package.json b/yarn-project/accounts/package.json new file mode 100644 index 00000000000..21c0e1d8aaa --- /dev/null +++ b/yarn-project/accounts/package.json @@ -0,0 +1,74 @@ +{ + "name": "@aztec/accounts", + "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/accounts", + "description": "Implementation of sample account contracts for Aztec Network", + "version": "0.1.0", + "type": "module", + "exports": { + "./defaults": "./dest/defaults/index.js", + "./ecdsa": "./dest/ecdsa/index.js", + "./schnorr": "./dest/schnorr/index.js", + "./single_key": "./dest/single_key/index.js", + "./testing": "./dest/testing/index.js" + }, + "typedocOptions": { + "entryPoints": [ + "./src/defaults/index.ts", + "./src/ecdsa/index.ts", + "./src/schnorr/index.ts", + "./src/single_key/index.ts", + "./src/testing/index.ts" + ], + "name": "Accounts", + "tsconfig": "./tsconfig.json" + }, + "scripts": { + "build": "yarn clean && yarn build:copy-contracts && tsc -b", + "build:copy-contracts": "mkdir -p ./src/artifacts && cp ../noir-contracts/src/SchnorrAccount.json ../noir-contracts/src/EcdsaAccount.json ../noir-contracts/src/SchnorrSingleKeyAccount.json ./src/artifacts", + "build:dev": "tsc -b --watch", + "build:ts": "tsc -b", + "clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts", + "formatting": "run -T prettier --check ./src && run -T eslint ./src", + "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src", + "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" + }, + "inherits": [ + "../package.common.json", + "./package.local.json" + ], + "jest": { + "preset": "ts-jest/presets/default-esm", + "moduleNameMapper": { + "^(\\.{1,2}/.*)\\.[cm]?js$": "$1" + }, + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", + "rootDir": "./src" + }, + "dependencies": { + "@aztec/aztec.js": "workspace:^", + "@aztec/circuits.js": "workspace:^", + "@aztec/ethereum": "workspace:^", + "@aztec/foundation": "workspace:^", + "@aztec/types": "workspace:^", + "tslib": "^2.4.0" + }, + "devDependencies": { + "@jest/globals": "^29.5.0", + "@types/jest": "^29.5.0", + "@types/node": "^18.7.23", + "jest": "^29.5.0", + "jest-mock-extended": "^3.0.3", + "ts-jest": "^29.1.0", + "ts-loader": "^9.4.4", + "ts-node": "^10.9.1", + "typescript": "^5.0.4" + }, + "files": [ + "dest", + "src", + "!*.test.*" + ], + "engines": { + "node": ">=18" + } +} diff --git a/yarn-project/accounts/package.local.json b/yarn-project/accounts/package.local.json new file mode 100644 index 00000000000..e502a0f74d0 --- /dev/null +++ b/yarn-project/accounts/package.local.json @@ -0,0 +1,9 @@ +{ + "scripts": { + "build": "yarn clean && yarn build:copy-contracts && tsc -b", + "build:copy-contracts": "mkdir -p ./src/artifacts && cp ../noir-contracts/src/SchnorrAccount.json ../noir-contracts/src/EcdsaAccount.json ../noir-contracts/src/SchnorrSingleKeyAccount.json ./src/artifacts", + "build:dev": "tsc -b --watch", + "build:ts": "tsc -b", + "clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts" + } +} diff --git a/yarn-project/aztec.js/src/account_contract/base_account_contract.ts b/yarn-project/accounts/src/defaults/account_contract.ts similarity index 70% rename from yarn-project/aztec.js/src/account_contract/base_account_contract.ts rename to yarn-project/accounts/src/defaults/account_contract.ts index 9c04fcf1d1b..3d1e67db5d9 100644 --- a/yarn-project/aztec.js/src/account_contract/base_account_contract.ts +++ b/yarn-project/accounts/src/defaults/account_contract.ts @@ -1,15 +1,14 @@ +import { AccountContract, AccountInterface, AuthWitnessProvider } from '@aztec/aztec.js/account'; import { ContractArtifact } from '@aztec/foundation/abi'; import { CompleteAddress, NodeInfo } from '@aztec/types'; -import { DefaultAccountInterface } from '../account/defaults/default_interface.js'; -import { AccountInterface, AuthWitnessProvider } from '../account/interface.js'; -import { AccountContract } from './account_contract.js'; +import { DefaultAccountInterface } from '../defaults/account_interface.js'; /** * Base class for implementing an account contract. Requires that the account uses the * default entrypoint method signature. */ -export abstract class BaseAccountContract implements AccountContract { +export abstract class DefaultAccountContract implements AccountContract { abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider; abstract getDeploymentArgs(): any[]; diff --git a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts b/yarn-project/accounts/src/defaults/account_entrypoint.ts similarity index 96% rename from yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts rename to yarn-project/accounts/src/defaults/account_entrypoint.ts index 240fb70c2ff..43db45f79eb 100644 --- a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts +++ b/yarn-project/accounts/src/defaults/account_entrypoint.ts @@ -1,9 +1,9 @@ +import { AuthWitnessProvider, EntrypointInterface } from '@aztec/aztec.js/account'; import { AztecAddress, Fr, FunctionData, TxContext } from '@aztec/circuits.js'; import { FunctionAbi, encodeArguments } from '@aztec/foundation/abi'; import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types'; -import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js'; -import { AuthWitnessProvider, EntrypointInterface } from '../interface.js'; +import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; import { buildPayload, hashPayload } from './entrypoint_payload.js'; /** diff --git a/yarn-project/aztec.js/src/account/defaults/default_interface.ts b/yarn-project/accounts/src/defaults/account_interface.ts similarity index 92% rename from yarn-project/aztec.js/src/account/defaults/default_interface.ts rename to yarn-project/accounts/src/defaults/account_interface.ts index ff981933292..d6227c6b062 100644 --- a/yarn-project/aztec.js/src/account/defaults/default_interface.ts +++ b/yarn-project/accounts/src/defaults/account_interface.ts @@ -1,8 +1,8 @@ +import { AccountInterface, AuthWitnessProvider, EntrypointInterface } from '@aztec/aztec.js/account'; import { CompleteAddress, Fr } from '@aztec/circuits.js'; import { AuthWitness, FunctionCall, NodeInfo, TxExecutionRequest } from '@aztec/types'; -import { AccountInterface, AuthWitnessProvider, EntrypointInterface } from '../interface.js'; -import { DefaultAccountEntrypoint } from './default_entrypoint.js'; +import { DefaultAccountEntrypoint } from './account_entrypoint.js'; /** * Default implementation for an account interface. Requires that the account uses the default diff --git a/yarn-project/aztec.js/src/utils/defaults.ts b/yarn-project/accounts/src/defaults/constants.ts similarity index 100% rename from yarn-project/aztec.js/src/utils/defaults.ts rename to yarn-project/accounts/src/defaults/constants.ts diff --git a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts b/yarn-project/accounts/src/defaults/entrypoint_payload.ts similarity index 100% rename from yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts rename to yarn-project/accounts/src/defaults/entrypoint_payload.ts diff --git a/yarn-project/accounts/src/defaults/index.ts b/yarn-project/accounts/src/defaults/index.ts new file mode 100644 index 00000000000..a194b8c848e --- /dev/null +++ b/yarn-project/accounts/src/defaults/index.ts @@ -0,0 +1,13 @@ +/** + * The `@aztec/accounts/defaults` export provides the base class {@link DefaultAccountContract} for implementing account contracts that use the default entrypoint payload module. + * + * Read more in {@link https://docs.aztec.network/dev_docs/wallets/writing_an_account_contract | Writing an account contract}. + * + * @packageDocumentation + */ + +export * from './entrypoint_payload.js'; +export * from './account_entrypoint.js'; +export * from './account_interface.js'; +export * from './account_contract.js'; +export * from './constants.js'; diff --git a/yarn-project/aztec.js/src/account_contract/ecdsa_account_contract.ts b/yarn-project/accounts/src/ecdsa/account_contract.ts similarity index 81% rename from yarn-project/aztec.js/src/account_contract/ecdsa_account_contract.ts rename to yarn-project/accounts/src/ecdsa/account_contract.ts index c6ce2b3b359..6c96d9cb652 100644 --- a/yarn-project/aztec.js/src/account_contract/ecdsa_account_contract.ts +++ b/yarn-project/accounts/src/ecdsa/account_contract.ts @@ -1,17 +1,17 @@ +import { AuthWitnessProvider } from '@aztec/aztec.js/account'; import { Ecdsa } from '@aztec/circuits.js/barretenberg'; import { ContractArtifact } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { AuthWitness, CompleteAddress } from '@aztec/types'; -import { AuthWitnessProvider } from '../account/interface.js'; -import EcdsaAccountContractArtifact from './artifacts/EcdsaAccount.json' assert { type: 'json' }; -import { BaseAccountContract } from './base_account_contract.js'; +import { DefaultAccountContract } from '../defaults/account_contract.js'; +import { EcdsaAccountContractArtifact } from './artifact.js'; /** * Account contract that authenticates transactions using ECDSA signatures * verified against a secp256k1 public key stored in an immutable encrypted note. */ -export class EcdsaAccountContract extends BaseAccountContract { +export class EcdsaAccountContract extends DefaultAccountContract { constructor(private signingPrivateKey: Buffer) { super(EcdsaAccountContractArtifact as ContractArtifact); } diff --git a/yarn-project/accounts/src/ecdsa/artifact.ts b/yarn-project/accounts/src/ecdsa/artifact.ts new file mode 100644 index 00000000000..05c0aae17c9 --- /dev/null +++ b/yarn-project/accounts/src/ecdsa/artifact.ts @@ -0,0 +1,5 @@ +import { ContractArtifact } from '@aztec/aztec.js'; + +import EcdsaAccountContractJson from '../artifacts/EcdsaAccount.json' assert { type: 'json' }; + +export const EcdsaAccountContractArtifact = EcdsaAccountContractJson as ContractArtifact; diff --git a/yarn-project/accounts/src/ecdsa/index.ts b/yarn-project/accounts/src/ecdsa/index.ts new file mode 100644 index 00000000000..a4a0ca92027 --- /dev/null +++ b/yarn-project/accounts/src/ecdsa/index.ts @@ -0,0 +1,42 @@ +/** + * The `@aztec/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption. + * Consider using this account type when working with integrations with Ethereum wallets. + * + * @packageDocumentation + */ +import { AccountManager, Salt } from '@aztec/aztec.js/account'; +import { AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import { AztecAddress } from '@aztec/circuits.js'; +import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types'; + +import { EcdsaAccountContract } from './account_contract.js'; + +export { EcdsaAccountContract }; +export { EcdsaAccountContractArtifact } from './artifact.js'; + +/** + * Creates an Account that relies on an ECDSA signing key for authentication. + * @param pxe - An PXE server instance. + * @param encryptionPrivateKey - Grumpkin key used for note encryption. + * @param signingPrivateKey - Secp256k1 key used for signing transactions. + * @param saltOrAddress - Deployment salt or complete address if account contract is already deployed. + */ +export function getEcdsaAccount( + pxe: PXE, + encryptionPrivateKey: GrumpkinPrivateKey, + signingPrivateKey: Buffer, + saltOrAddress?: Salt | CompleteAddress, +): AccountManager { + return new AccountManager(pxe, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), saltOrAddress); +} + +/** + * Gets a wallet for an already registered account using ECDSA signatures. + * @param pxe - An PXE server instance. + * @param address - Address for the account. + * @param signingPrivateKey - ECDSA key used for signing transactions. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export function getEcdsaWallet(pxe: PXE, address: AztecAddress, signingPrivateKey: Buffer): Promise { + return getWallet(pxe, address, new EcdsaAccountContract(signingPrivateKey)); +} diff --git a/yarn-project/aztec.js/src/account_contract/schnorr_account_contract.ts b/yarn-project/accounts/src/schnorr/account_contract.ts similarity index 81% rename from yarn-project/aztec.js/src/account_contract/schnorr_account_contract.ts rename to yarn-project/accounts/src/schnorr/account_contract.ts index 41ba89f3302..72a242310ed 100644 --- a/yarn-project/aztec.js/src/account_contract/schnorr_account_contract.ts +++ b/yarn-project/accounts/src/schnorr/account_contract.ts @@ -1,17 +1,17 @@ +import { AuthWitnessProvider } from '@aztec/aztec.js/account'; import { Schnorr } from '@aztec/circuits.js/barretenberg'; import { ContractArtifact } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types'; -import { AuthWitnessProvider } from '../account/interface.js'; -import SchnorrAccountContractArtifact from './artifacts/SchnorrAccount.json' assert { type: 'json' }; -import { BaseAccountContract } from './base_account_contract.js'; +import { DefaultAccountContract } from '../defaults/account_contract.js'; +import { SchnorrAccountContractArtifact } from './artifact.js'; /** * Account contract that authenticates transactions using Schnorr signatures * verified against a Grumpkin public key stored in an immutable encrypted note. */ -export class SchnorrAccountContract extends BaseAccountContract { +export class SchnorrAccountContract extends DefaultAccountContract { constructor(private signingPrivateKey: GrumpkinPrivateKey) { super(SchnorrAccountContractArtifact as ContractArtifact); } diff --git a/yarn-project/accounts/src/schnorr/artifact.ts b/yarn-project/accounts/src/schnorr/artifact.ts new file mode 100644 index 00000000000..672b633420e --- /dev/null +++ b/yarn-project/accounts/src/schnorr/artifact.ts @@ -0,0 +1,5 @@ +import { ContractArtifact } from '@aztec/aztec.js'; + +import SchnorrAccountContractJson from '../artifacts/SchnorrAccount.json' assert { type: 'json' }; + +export const SchnorrAccountContractArtifact = SchnorrAccountContractJson as ContractArtifact; diff --git a/yarn-project/accounts/src/schnorr/index.ts b/yarn-project/accounts/src/schnorr/index.ts new file mode 100644 index 00000000000..e61525a5eaf --- /dev/null +++ b/yarn-project/accounts/src/schnorr/index.ts @@ -0,0 +1,47 @@ +/** + * The `@aztec/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption. + * This is the suggested account contract type for most use cases within Aztec. + * + * @packageDocumentation + */ +import { AccountManager, Salt } from '@aztec/aztec.js/account'; +import { AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import { AztecAddress } from '@aztec/circuits.js'; +import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types'; + +import { SchnorrAccountContract } from './account_contract.js'; + +export { SchnorrAccountContract }; + +export { SchnorrAccountContractArtifact } from './artifact.js'; + +/** + * Creates an Account Manager that relies on a Grumpkin signing key for authentication. + * @param pxe - An PXE server instance. + * @param encryptionPrivateKey - Grumpkin key used for note encryption. + * @param signingPrivateKey - Grumpkin key used for signing transactions. + * @param saltOrAddress - Deployment salt or complete address if account contract is already deployed. + */ +export function getSchnorrAccount( + pxe: PXE, + encryptionPrivateKey: GrumpkinPrivateKey, + signingPrivateKey: GrumpkinPrivateKey, + saltOrAddress?: Salt | CompleteAddress, +): AccountManager { + return new AccountManager(pxe, encryptionPrivateKey, new SchnorrAccountContract(signingPrivateKey), saltOrAddress); +} + +/** + * Gets a wallet for an already registered account using Schnorr signatures. + * @param pxe - An PXE server instance. + * @param address - Address for the account. + * @param signingPrivateKey - Grumpkin key used for signing transactions. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export function getSchnorrWallet( + pxe: PXE, + address: AztecAddress, + signingPrivateKey: GrumpkinPrivateKey, +): Promise { + return getWallet(pxe, address, new SchnorrAccountContract(signingPrivateKey)); +} diff --git a/yarn-project/aztec.js/src/account_contract/single_key_account_contract.ts b/yarn-project/accounts/src/single_key/account_contract.ts similarity index 81% rename from yarn-project/aztec.js/src/account_contract/single_key_account_contract.ts rename to yarn-project/accounts/src/single_key/account_contract.ts index ef18fc8264d..082ec84336c 100644 --- a/yarn-project/aztec.js/src/account_contract/single_key_account_contract.ts +++ b/yarn-project/accounts/src/single_key/account_contract.ts @@ -1,19 +1,19 @@ +import { generatePublicKey } from '@aztec/aztec.js'; +import { AuthWitnessProvider } from '@aztec/aztec.js/account'; import { PartialAddress } from '@aztec/circuits.js'; import { Schnorr } from '@aztec/circuits.js/barretenberg'; import { ContractArtifact } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types'; -import { AuthWitnessProvider } from '../account/interface.js'; -import { generatePublicKey } from '../utils/index.js'; -import SchnorrSingleKeyAccountContractArtifact from './artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' }; -import { BaseAccountContract } from './base_account_contract.js'; +import { DefaultAccountContract } from '../defaults/account_contract.js'; +import { SchnorrSingleKeyAccountContractArtifact } from './artifact.js'; /** * Account contract that authenticates transactions using Schnorr signatures verified against * the note encryption key, relying on a single private key for both encryption and authentication. */ -export class SingleKeyAccountContract extends BaseAccountContract { +export class SingleKeyAccountContract extends DefaultAccountContract { constructor(private encryptionPrivateKey: GrumpkinPrivateKey) { super(SchnorrSingleKeyAccountContractArtifact as ContractArtifact); } diff --git a/yarn-project/accounts/src/single_key/artifact.ts b/yarn-project/accounts/src/single_key/artifact.ts new file mode 100644 index 00000000000..4bb139b1252 --- /dev/null +++ b/yarn-project/accounts/src/single_key/artifact.ts @@ -0,0 +1,5 @@ +import { ContractArtifact } from '@aztec/aztec.js'; + +import SchnorrSingleKeyAccountContractJson from '../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' }; + +export const SchnorrSingleKeyAccountContractArtifact = SchnorrSingleKeyAccountContractJson as ContractArtifact; diff --git a/yarn-project/accounts/src/single_key/index.ts b/yarn-project/accounts/src/single_key/index.ts new file mode 100644 index 00000000000..9b224dd7d88 --- /dev/null +++ b/yarn-project/accounts/src/single_key/index.ts @@ -0,0 +1,53 @@ +/** + * The `@aztec/accounts/single_key` export provides a testing account contract implementation that uses a single Grumpkin key for both authentication and encryption. + * It is not recommended to use this account type in production. + * + * @packageDocumentation + */ +import { AccountManager, Salt } from '@aztec/aztec.js/account'; +import { AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import { AztecAddress } from '@aztec/circuits.js'; +import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types'; + +import { SingleKeyAccountContract } from './account_contract.js'; + +export { SingleKeyAccountContract }; + +export { SchnorrSingleKeyAccountContractArtifact as SingleKeyAccountContractArtifact } from './artifact.js'; + +/** + * Creates an Account that uses the same Grumpkin key for encryption and authentication. + * @param pxe - An PXE server instance. + * @param encryptionAndSigningPrivateKey - Grumpkin key used for note encryption and signing transactions. + * @param saltOrAddress - Deployment salt or complete address if account contract is already deployed. + */ +export function getSingleKeyAccount( + pxe: PXE, + encryptionAndSigningPrivateKey: GrumpkinPrivateKey, + saltOrAddress?: Salt | CompleteAddress, +): AccountManager { + return new AccountManager( + pxe, + encryptionAndSigningPrivateKey, + new SingleKeyAccountContract(encryptionAndSigningPrivateKey), + saltOrAddress, + ); +} + +/** + * Gets a wallet for an already registered account using Schnorr signatures with a single key for encryption and authentication. + * @param pxe - An PXE server instance. + * @param address - Address for the account. + * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export function getSingleKeyWallet( + pxe: PXE, + address: AztecAddress, + signingKey: GrumpkinPrivateKey, +): Promise { + return getWallet(pxe, address, new SingleKeyAccountContract(signingKey)); +} + +export { getSingleKeyAccount as getUnsafeSchnorrAccount }; +export { getSingleKeyWallet as getUnsafeSchnorrWallet }; diff --git a/yarn-project/aztec.js/src/create_account/index.ts b/yarn-project/accounts/src/testing/create_account.ts similarity index 89% rename from yarn-project/aztec.js/src/create_account/index.ts rename to yarn-project/accounts/src/testing/create_account.ts index e4d6d169278..da3fa152ef2 100644 --- a/yarn-project/aztec.js/src/create_account/index.ts +++ b/yarn-project/accounts/src/testing/create_account.ts @@ -1,8 +1,8 @@ +import { AccountWalletWithPrivateKey } from '@aztec/aztec.js/wallet'; import { GrumpkinScalar } from '@aztec/circuits.js'; import { PXE } from '@aztec/types'; -import { getSchnorrAccount } from '../account_manager/index.js'; -import { AccountWalletWithPrivateKey } from '../wallet/account_wallet_with_private_key.js'; +import { getSchnorrAccount } from '../schnorr/index.js'; /** * Deploys and registers a new account using random private keys and returns the associated Schnorr account wallet. Useful for testing. diff --git a/yarn-project/accounts/src/testing/index.ts b/yarn-project/accounts/src/testing/index.ts new file mode 100644 index 00000000000..ba2cc4ae94d --- /dev/null +++ b/yarn-project/accounts/src/testing/index.ts @@ -0,0 +1,11 @@ +/** + * The `@aztec/accounts/testing` export provides utility methods for testing, in particular in a Sandbox environment. + * + * Use the {@link createAccount} and {@link createAccounts} methods to create new sample accounts for testing, + * or use {@link getSandboxAccountsWallets} to obtain a list of wallets for the sandbox pre-seeded accounts. + * + * @packageDocumentation + */ + +export * from './create_account.js'; +export * from './sandbox.js'; diff --git a/yarn-project/accounts/src/testing/sandbox.ts b/yarn-project/accounts/src/testing/sandbox.ts new file mode 100644 index 00000000000..9c85f383b0d --- /dev/null +++ b/yarn-project/accounts/src/testing/sandbox.ts @@ -0,0 +1,63 @@ +import { AccountWalletWithPrivateKey } from '@aztec/aztec.js/wallet'; +import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; +import { PXE } from '@aztec/types'; + +import { getSchnorrAccount } from '../schnorr/index.js'; + +export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [ + GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), + GrumpkinScalar.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'), + GrumpkinScalar.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'), +]; + +export const INITIAL_SANDBOX_SIGNING_KEYS = INITIAL_SANDBOX_ENCRYPTION_KEYS; + +export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; + +/** + * Gets a collection of wallets for the Aztec accounts that are initially stored in the sandbox. + * @param pxe - PXE instance. + * @returns A set of AccountWallet implementations for each of the initial accounts. + */ +export function getSandboxAccountsWallets(pxe: PXE): Promise { + return Promise.all( + INITIAL_SANDBOX_ENCRYPTION_KEYS.map((encryptionKey, i) => + getSchnorrAccount(pxe, encryptionKey!, INITIAL_SANDBOX_SIGNING_KEYS[i]!, INITIAL_SANDBOX_SALTS[i]).getWallet(), + ), + ); +} + +/** + * Deploys the initial set of schnorr signature accounts to the sandbox + * @param pxe - PXE instance. + * @returns The set of deployed Account objects and associated private encryption keys + */ +export async function deployInitialSandboxAccounts(pxe: PXE) { + const accounts = INITIAL_SANDBOX_ENCRYPTION_KEYS.map((privateKey, i) => { + const account = getSchnorrAccount(pxe, privateKey, INITIAL_SANDBOX_SIGNING_KEYS[i], INITIAL_SANDBOX_SALTS[i]); + return { + account, + privateKey, + }; + }); + // Attempt to get as much parallelism as possible + const deployMethods = await Promise.all( + accounts.map(async x => { + const deployMethod = await x.account.getDeployMethod(); + await deployMethod.create({ contractAddressSalt: x.account.salt }); + await deployMethod.simulate({}); + return deployMethod; + }), + ); + // Send tx together to try and get them in the same rollup + const sentTxs = deployMethods.map(dm => { + return dm.send(); + }); + await Promise.all( + sentTxs.map(async (tx, i) => { + const wallet = await accounts[i].account.getWallet(); + return tx.wait({ wallet }); + }), + ); + return accounts; +} diff --git a/yarn-project/accounts/tsconfig.dest.json b/yarn-project/accounts/tsconfig.dest.json new file mode 100644 index 00000000000..7436bb06ad8 --- /dev/null +++ b/yarn-project/accounts/tsconfig.dest.json @@ -0,0 +1,18 @@ +{ + "extends": ".", + "references": [ + { + "path": "../aztec.js/tsconfig.dest.json" + }, + { + "path": "../circuits.js/tsconfig.dest.json" + }, + { + "path": "../foundation/tsconfig.dest.json" + }, + { + "path": "../types/tsconfig.dest.json" + } + ], + "exclude": ["src/**/*.test.ts"] +} diff --git a/yarn-project/accounts/tsconfig.json b/yarn-project/accounts/tsconfig.json new file mode 100644 index 00000000000..d95dd516822 --- /dev/null +++ b/yarn-project/accounts/tsconfig.json @@ -0,0 +1,26 @@ +{ + "extends": "..", + "compilerOptions": { + "outDir": "dest", + "rootDir": "src", + "tsBuildInfoFile": ".tsbuildinfo" + }, + "references": [ + { + "path": "../aztec.js" + }, + { + "path": "../circuits.js" + }, + { + "path": "../ethereum" + }, + { + "path": "../foundation" + }, + { + "path": "../types" + } + ], + "include": ["src", "src/**/*.json"] +} diff --git a/yarn-project/aztec-node/tsconfig.json b/yarn-project/aztec-node/tsconfig.json index 3c938379585..54b15a4bc8a 100644 --- a/yarn-project/aztec-node/tsconfig.json +++ b/yarn-project/aztec-node/tsconfig.json @@ -18,6 +18,9 @@ { "path": "../foundation" }, + { + "path": "../kv-store" + }, { "path": "../l1-artifacts" }, @@ -35,9 +38,6 @@ }, { "path": "../world-state" - }, - { - "path": "../kv-store" } ], "include": ["src"] diff --git a/yarn-project/aztec-sandbox/package.json b/yarn-project/aztec-sandbox/package.json index 0739a8d9cc4..99c393a40ba 100644 --- a/yarn-project/aztec-sandbox/package.json +++ b/yarn-project/aztec-sandbox/package.json @@ -27,6 +27,7 @@ "../package.common.json" ], "dependencies": { + "@aztec/accounts": "workspace:^", "@aztec/aztec-node": "workspace:^", "@aztec/aztec.js": "workspace:^", "@aztec/circuits.js": "workspace:^", diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index 6e4de4005a5..105cfc85605 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -1,6 +1,7 @@ #!/usr/bin/env -S node --no-warnings +import { deployInitialSandboxAccounts } from '@aztec/accounts/testing'; import { createAztecNodeRpcServer, getConfigEnvVars as getNodeConfigEnvVars } from '@aztec/aztec-node'; -import { AccountManager, createAztecNodeClient, deployInitialSandboxAccounts } from '@aztec/aztec.js'; +import { AccountManager, createAztecNodeClient } from '@aztec/aztec.js'; import { NULL_KEY } from '@aztec/ethereum'; import { init } from '@aztec/foundation/crypto'; import { createStatusRouter } from '@aztec/foundation/json-rpc/server'; diff --git a/yarn-project/aztec-sandbox/src/examples/token.ts b/yarn-project/aztec-sandbox/src/examples/token.ts index a9ec1d921d6..816bae98370 100644 --- a/yarn-project/aztec-sandbox/src/examples/token.ts +++ b/yarn-project/aztec-sandbox/src/examples/token.ts @@ -1,12 +1,5 @@ -import { - AccountWallet, - Fr, - GrumpkinScalar, - Note, - computeMessageSecretHash, - createPXEClient, - getUnsafeSchnorrAccount, -} from '@aztec/aztec.js'; +import { getSingleKeyAccount } from '@aztec/accounts/single_key'; +import { AccountWallet, Fr, GrumpkinScalar, Note, computeMessageSecretHash, createPXEClient } from '@aztec/aztec.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { TokenContract } from '@aztec/noir-contracts/Token'; import { ExtendedNote } from '@aztec/types'; @@ -32,8 +25,8 @@ const TRANSFER_AMOUNT = 33n; async function main() { logger('Running token contract test on HTTP interface.'); - aliceWallet = await getUnsafeSchnorrAccount(pxe, alicePrivateKey).waitDeploy(); - bobWallet = await getUnsafeSchnorrAccount(pxe, bobPrivateKey).waitDeploy(); + aliceWallet = await getSingleKeyAccount(pxe, alicePrivateKey).waitDeploy(); + bobWallet = await getSingleKeyAccount(pxe, bobPrivateKey).waitDeploy(); const alice = aliceWallet.getCompleteAddress(); const bob = bobWallet.getCompleteAddress(); diff --git a/yarn-project/aztec-sandbox/tsconfig.json b/yarn-project/aztec-sandbox/tsconfig.json index 89a05426e77..bdceec5cca5 100644 --- a/yarn-project/aztec-sandbox/tsconfig.json +++ b/yarn-project/aztec-sandbox/tsconfig.json @@ -6,6 +6,9 @@ "tsBuildInfoFile": ".tsbuildinfo" }, "references": [ + { + "path": "../accounts" + }, { "path": "../aztec-node" }, diff --git a/yarn-project/aztec.js/README.md b/yarn-project/aztec.js/README.md index e1041cab73f..46f84df88f8 100644 --- a/yarn-project/aztec.js/README.md +++ b/yarn-project/aztec.js/README.md @@ -2,19 +2,15 @@ Aztec.js is a library that provides APIs for managing accounts and interacting with contracts on the Aztec network. It communicates with the [Private eXecution Environment (PXE)](https://docs.aztec.network/apis/pxe/interfaces/PXE) through a `PXE` implementation, allowing developers to easily register new accounts, deploy contracts, view functions, and send transactions. -## Usage +## Installing -### Create a new account +``` +npm install @aztec/aztec.js +``` -```typescript -import { getSchnorrAccount } from '@aztec/aztec.js'; -import { GrumpkinPrivateKey } from '@aztec/types'; +## Usage -const encryptionPrivateKey = GrumpkinPrivateKey.random(); -const signingPrivateKey = GrumpkinPrivateKey.random(); -const wallet = getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); -console.log(`New account deployed at ${wallet.getAddress()}`); -``` +Use the `@aztec/accounts` package in order to create and manage accounts, and acquire a `Wallet` object needed to send transactions and interact with the network. ### Deploy a contract diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index ffa14be1f1f..5a67386abfb 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -7,13 +7,15 @@ ".": "./dest/index.js", "./interfaces/pxe": "./dest/api/interfaces/pxe.js", "./abi": "./dest/api/abi.js", + "./account": "./dest/api/account.js", "./aztec_address": "./dest/api/aztec_address.js", "./eth_address": "./dest/api/eth_address.js", "./ethereum": "./dest/api/ethereum.js", "./fields": "./dest/api/fields.js", "./init": "./dest/api/init.js", "./log_id": "./dest/api/log_id.js", - "./tx_hash": "./dest/api/tx_hash.js" + "./tx_hash": "./dest/api/tx_hash.js", + "./wallet": "./dest/api/wallet.js" }, "typedocOptions": { "entryPoints": [ diff --git a/yarn-project/aztec.js/src/account_contract/account_contract.ts b/yarn-project/aztec.js/src/account/contract.ts similarity index 95% rename from yarn-project/aztec.js/src/account_contract/account_contract.ts rename to yarn-project/aztec.js/src/account/contract.ts index 0954dcc9fd3..1cb9e3c9cd5 100644 --- a/yarn-project/aztec.js/src/account_contract/account_contract.ts +++ b/yarn-project/aztec.js/src/account/contract.ts @@ -1,7 +1,7 @@ import { ContractArtifact } from '@aztec/foundation/abi'; import { CompleteAddress, NodeInfo } from '@aztec/types'; -import { AccountInterface } from '../account/interface.js'; +import { AccountInterface } from './interface.js'; // docs:start:account-contract-interface /** diff --git a/yarn-project/aztec.js/src/account/defaults/index.ts b/yarn-project/aztec.js/src/account/defaults/index.ts deleted file mode 100644 index b03671fb1bf..00000000000 --- a/yarn-project/aztec.js/src/account/defaults/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './entrypoint_payload.js'; -export * from './default_entrypoint.js'; -export * from './default_interface.js'; diff --git a/yarn-project/aztec.js/src/account/index.ts b/yarn-project/aztec.js/src/account/index.ts index a57f2fb40ba..9458fb467a5 100644 --- a/yarn-project/aztec.js/src/account/index.ts +++ b/yarn-project/aztec.js/src/account/index.ts @@ -1,30 +1,15 @@ /** - * The `account` module provides utilities for managing accounts. The most common methods to use - * are {@link getEcdsaAccount} and {@link getSchnorrAccount}, which return {@link AccountManager} instances - * using the default ECDSA or Schnorr account implementation respectively. The {@link AccountManager} class then - * allows to deploy and register a fresh account, or to obtain a `Wallet` instance out of an account already deployed. - * - * ```ts - * const encryptionPrivateKey = GrumpkinScalar.random(); - * const signingPrivateKey = GrumpkinScalar.random(); - * const wallet = getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); - * ``` - * - * For testing purposes, consider using the {@link createAccount} and {@link createAccounts} methods, - * which create, register, and deploy random accounts, and return their associated `Wallet`s. - * - * For implementing your own account contract, the recommended way is to extend from the base - * {@link BaseAccountContract} class. - * Read more in {@link https://docs.aztec.network/dev_docs/wallets/writing_an_account_contract | Writing an account contract}. + * The `account` module provides utilities for managing accounts. The {@link AccountManager} class + * allows to deploy and register a fresh account, or to obtain a `Wallet` instance out of an account + * already deployed. Use the `@aztec/accounts` package to load default account implementations that rely + * on ECDSA or Schnorr signatures. * * @packageDocumentation */ import { Fr } from '@aztec/circuits.js'; -export { CompleteAddress } from '@aztec/types'; - -export * from './defaults/index.js'; -export { AccountInterface, AuthWitnessProvider } from './interface.js'; +export { AccountContract } from './contract.js'; +export { AccountInterface, AuthWitnessProvider, EntrypointInterface } from './interface.js'; export * from './wallet.js'; /** A contract deployment salt. */ diff --git a/yarn-project/aztec.js/src/account_contract/index.ts b/yarn-project/aztec.js/src/account_contract/index.ts deleted file mode 100644 index 0e3be8aee56..00000000000 --- a/yarn-project/aztec.js/src/account_contract/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './account_contract.js'; -export * from './ecdsa_account_contract.js'; -export * from './schnorr_account_contract.js'; -export * from './single_key_account_contract.js'; -export * from './base_account_contract.js'; diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index 20de45d7ccb..59d3ed9d4c9 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -2,14 +2,9 @@ import { PublicKey, getContractDeploymentInfo } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types'; +import { AccountContract } from '../account/contract.js'; import { Salt } from '../account/index.js'; import { AccountInterface } from '../account/interface.js'; -import { - AccountContract, - EcdsaAccountContract, - SchnorrAccountContract, - SingleKeyAccountContract, -} from '../account_contract/index.js'; import { DefaultWaitOpts, DeployMethod, WaitOpts } from '../contract/index.js'; import { ContractDeployer } from '../contract_deployer/index.js'; import { generatePublicKey } from '../utils/index.js'; @@ -156,54 +151,3 @@ export class AccountManager { return completeAddress; } } - -/** - * Creates an Account that relies on an ECDSA signing key for authentication. - * @param pxe - An PXE server instance. - * @param encryptionPrivateKey - Grumpkin key used for note encryption. - * @param signingPrivateKey - Secp256k1 key used for signing transactions. - * @param saltOrAddress - Deployment salt or complete address if account contract is already deployed. - */ -export function getEcdsaAccount( - pxe: PXE, - encryptionPrivateKey: GrumpkinPrivateKey, - signingPrivateKey: Buffer, - saltOrAddress?: Salt | CompleteAddress, -): AccountManager { - return new AccountManager(pxe, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), saltOrAddress); -} - -/** - * Creates an Account that relies on a Grumpkin signing key for authentication. - * @param pxe - An PXE server instance. - * @param encryptionPrivateKey - Grumpkin key used for note encryption. - * @param signingPrivateKey - Grumpkin key used for signing transactions. - * @param saltOrAddress - Deployment salt or complete address if account contract is already deployed. - */ -export function getSchnorrAccount( - pxe: PXE, - encryptionPrivateKey: GrumpkinPrivateKey, - signingPrivateKey: GrumpkinPrivateKey, - saltOrAddress?: Salt | CompleteAddress, -): AccountManager { - return new AccountManager(pxe, encryptionPrivateKey, new SchnorrAccountContract(signingPrivateKey), saltOrAddress); -} - -/** - * Creates an Account that uses the same Grumpkin key for encryption and authentication. - * @param pxe - An PXE server instance. - * @param encryptionAndSigningPrivateKey - Grumpkin key used for note encryption and signing transactions. - * @param saltOrAddress - Deployment salt or complete address if account contract is already deployed. - */ -export function getUnsafeSchnorrAccount( - pxe: PXE, - encryptionAndSigningPrivateKey: GrumpkinPrivateKey, - saltOrAddress?: Salt | CompleteAddress, -): AccountManager { - return new AccountManager( - pxe, - encryptionAndSigningPrivateKey, - new SingleKeyAccountContract(encryptionAndSigningPrivateKey), - saltOrAddress, - ); -} diff --git a/yarn-project/aztec.js/src/api/account.ts b/yarn-project/aztec.js/src/api/account.ts new file mode 100644 index 00000000000..6192287792d --- /dev/null +++ b/yarn-project/aztec.js/src/api/account.ts @@ -0,0 +1,12 @@ +export { + AccountContract, + AccountInterface, + AuthWitnessProvider, + EntrypointInterface, + Salt, + Wallet, +} from '../account/index.js'; + +export { AccountManager } from '../account_manager/index.js'; + +export { CompleteAddress } from '@aztec/types'; diff --git a/yarn-project/aztec.js/src/api/wallet.ts b/yarn-project/aztec.js/src/api/wallet.ts new file mode 100644 index 00000000000..f9026e6a8ff --- /dev/null +++ b/yarn-project/aztec.js/src/api/wallet.ts @@ -0,0 +1 @@ +export { AccountWallet, AccountWalletWithPrivateKey, SignerlessWallet, Wallet, getWallet } from '../wallet/index.js'; diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 6ad796595e4..1f0c9dcac73 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -48,24 +48,15 @@ export { export { createPXEClient } from './pxe_client.js'; -export { CompleteAddress, AuthWitnessProvider } from './account/index.js'; +export { AuthWitnessProvider } from './account/index.js'; -export { - AccountContract, - EcdsaAccountContract, - SchnorrAccountContract, - SingleKeyAccountContract, - BaseAccountContract, -} from './account_contract/index.js'; - -export { getSchnorrAccount, AccountManager, getUnsafeSchnorrAccount } from './account_manager/index.js'; +export { AccountContract } from './account/index.js'; +export { AccountManager } from './account_manager/index.js'; -export { waitForSandbox, getSandboxAccountsWallets, deployInitialSandboxAccounts } from './sandbox/index.js'; +export { waitForSandbox } from './sandbox/index.js'; export { AccountWalletWithPrivateKey, AccountWallet, Wallet, SignerlessWallet } from './wallet/index.js'; -export { createAccount, createAccounts } from './create_account/index.js'; - // // TODO https://github.com/AztecProtocol/aztec-packages/issues/2632 --> FunctionSelector might not need to be exposed // // here once the issue is resolved. export { @@ -85,6 +76,7 @@ export { Grumpkin, Schnorr } from '@aztec/circuits.js/barretenberg'; export { AuthWitness, AztecNode, + CompleteAddress, ContractData, DeployedContract, ExtendedContractData, diff --git a/yarn-project/aztec.js/src/sandbox/index.ts b/yarn-project/aztec.js/src/sandbox/index.ts index 79f9f068b1d..bf60e94a5d7 100644 --- a/yarn-project/aztec.js/src/sandbox/index.ts +++ b/yarn-project/aztec.js/src/sandbox/index.ts @@ -1,71 +1,10 @@ -import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { sleep } from '@aztec/foundation/sleep'; import { PXE } from '@aztec/types'; -import { getSchnorrAccount } from '../account_manager/index.js'; import { createPXEClient } from '../pxe_client.js'; -import { AccountWalletWithPrivateKey } from '../wallet/index.js'; - -export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [ - GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), - GrumpkinScalar.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'), - GrumpkinScalar.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'), -]; - -export const INITIAL_SANDBOX_SIGNING_KEYS = INITIAL_SANDBOX_ENCRYPTION_KEYS; - -export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; export const { PXE_URL = 'http://localhost:8080' } = process.env; -/** - * Gets a collection of wallets for the Aztec accounts that are initially stored in the sandbox. - * @param pxe - PXE instance. - * @returns A set of AccountWallet implementations for each of the initial accounts. - */ -export function getSandboxAccountsWallets(pxe: PXE): Promise { - return Promise.all( - INITIAL_SANDBOX_ENCRYPTION_KEYS.map((encryptionKey, i) => - getSchnorrAccount(pxe, encryptionKey!, INITIAL_SANDBOX_SIGNING_KEYS[i]!, INITIAL_SANDBOX_SALTS[i]).getWallet(), - ), - ); -} - -/** - * Deploys the initial set of schnorr signature accounts to the sandbox - * @param pxe - PXE instance. - * @returns The set of deployed Account objects and associated private encryption keys - */ -export async function deployInitialSandboxAccounts(pxe: PXE) { - const accounts = INITIAL_SANDBOX_ENCRYPTION_KEYS.map((privateKey, i) => { - const account = getSchnorrAccount(pxe, privateKey, INITIAL_SANDBOX_SIGNING_KEYS[i], INITIAL_SANDBOX_SALTS[i]); - return { - account, - privateKey, - }; - }); - // Attempt to get as much parallelism as possible - const deployMethods = await Promise.all( - accounts.map(async x => { - const deployMethod = await x.account.getDeployMethod(); - await deployMethod.create({ contractAddressSalt: x.account.salt }); - await deployMethod.simulate({}); - return deployMethod; - }), - ); - // Send tx together to try and get them in the same rollup - const sentTxs = deployMethods.map(dm => { - return dm.send(); - }); - await Promise.all( - sentTxs.map(async (tx, i) => { - const wallet = await accounts[i].account.getWallet(); - return tx.wait({ wallet }); - }), - ); - return accounts; -} - /** * Function to wait until the sandbox becomes ready for use. * @param pxe - The pxe client connected to the sandbox. diff --git a/yarn-project/aztec.js/src/wallet/index.ts b/yarn-project/aztec.js/src/wallet/index.ts index a8121edaf60..dc4b55a20b1 100644 --- a/yarn-project/aztec.js/src/wallet/index.ts +++ b/yarn-project/aztec.js/src/wallet/index.ts @@ -1,28 +1,13 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { GrumpkinPrivateKey, PXE } from '@aztec/types'; +import { PXE } from '@aztec/types'; -import { AccountContract, SingleKeyAccountContract } from '../account_contract/index.js'; +import { AccountContract } from '../account/contract.js'; import { AccountWallet } from './account_wallet.js'; +export * from '../account/wallet.js'; export * from './account_wallet.js'; -export * from './signerless_wallet.js'; export * from './account_wallet_with_private_key.js'; -export * from '../account/wallet.js'; - -/** - * Gets a wallet for an already registered account using Schnorr signatures with a single key for encryption and authentication. - * @param pxe - An PXE server instance. - * @param address - Address for the account. - * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions. - * @returns A wallet for this account that can be used to interact with a contract instance. - */ -export function getUnsafeSchnorrWallet( - pxe: PXE, - address: AztecAddress, - signingKey: GrumpkinPrivateKey, -): Promise { - return getWallet(pxe, address, new SingleKeyAccountContract(signingKey)); -} +export * from './signerless_wallet.js'; /** * Gets a wallet for an already registered account. diff --git a/yarn-project/bootstrap.sh b/yarn-project/bootstrap.sh index a8837f38b74..5701cbaaaf1 100755 --- a/yarn-project/bootstrap.sh +++ b/yarn-project/bootstrap.sh @@ -34,8 +34,7 @@ yarn workspace @aztec/circuits.js remake-constants yarn workspace @aztec/noir-compiler build # Builds noir contracts (TODO: move this stage pre yarn-project). Generates typescript wrappers. yarn workspace @aztec/noir-contracts build:contracts -# TODO: Contracts should not be baked into aztec.js. -yarn workspace @aztec/aztec.js build:copy-contracts +yarn workspace @aztec/accounts build:copy-contracts # Build protocol circuits. TODO: move pre yarn-project. yarn workspace @aztec/noir-protocol-circuits noir:build diff --git a/yarn-project/cli/package.json b/yarn-project/cli/package.json index 8d686c93f8c..a030bb84aae 100644 --- a/yarn-project/cli/package.json +++ b/yarn-project/cli/package.json @@ -34,6 +34,7 @@ "rootDir": "./src" }, "dependencies": { + "@aztec/accounts": "workspace:^", "@aztec/aztec.js": "workspace:^", "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", diff --git a/yarn-project/cli/src/cmds/create_account.ts b/yarn-project/cli/src/cmds/create_account.ts index f178409c82d..a8f895a84ce 100644 --- a/yarn-project/cli/src/cmds/create_account.ts +++ b/yarn-project/cli/src/cmds/create_account.ts @@ -1,4 +1,5 @@ -import { GrumpkinScalar, getSchnorrAccount } from '@aztec/aztec.js'; +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; +import { GrumpkinScalar } from '@aztec/aztec.js'; import { Fq, Fr } from '@aztec/foundation/fields'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; diff --git a/yarn-project/cli/src/cmds/send.ts b/yarn-project/cli/src/cmds/send.ts index cb8c3bfb413..50dab7479e9 100644 --- a/yarn-project/cli/src/cmds/send.ts +++ b/yarn-project/cli/src/cmds/send.ts @@ -1,4 +1,5 @@ -import { AztecAddress, Contract, Fq, Fr, getSchnorrAccount } from '@aztec/aztec.js'; +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; +import { AztecAddress, Contract, Fq, Fr } from '@aztec/aztec.js'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { createCompatibleClient } from '../client.js'; diff --git a/yarn-project/cli/src/cmds/unbox.ts b/yarn-project/cli/src/cmds/unbox.ts index 5793de363f0..4fd0ef1d73e 100644 --- a/yarn-project/cli/src/cmds/unbox.ts +++ b/yarn-project/cli/src/cmds/unbox.ts @@ -7,6 +7,7 @@ import { dirname, resolve } from 'path'; import { fileURLToPath } from 'url'; const resolutions: { [key: string]: string } = { + '@aztec/accounts': 'portal:.aztec-packages/yarn-project/accounts', '@aztec/aztec.js': 'portal:.aztec-packages/yarn-project/aztec.js', '@aztec/circuits.js': 'portal:.aztec-packages/yarn-project/circuits.js', '@aztec/foundation': 'portal:.aztec-packages/yarn-project/foundation', diff --git a/yarn-project/cli/tsconfig.json b/yarn-project/cli/tsconfig.json index 7bd5491149a..325ed8c0edb 100644 --- a/yarn-project/cli/tsconfig.json +++ b/yarn-project/cli/tsconfig.json @@ -6,6 +6,9 @@ "tsBuildInfoFile": ".tsbuildinfo" }, "references": [ + { + "path": "../accounts" + }, { "path": "../aztec.js" }, diff --git a/yarn-project/deploy_npm.sh b/yarn-project/deploy_npm.sh index 19c58b80d6c..119aa114edc 100755 --- a/yarn-project/deploy_npm.sh +++ b/yarn-project/deploy_npm.sh @@ -83,6 +83,7 @@ deploy_package foundation deploy_package circuits.js deploy_package types deploy_package aztec.js +deploy_package accounts deploy_package l1-artifacts deploy_package ethereum deploy_package noir-compiler diff --git a/yarn-project/end-to-end/.gitignore b/yarn-project/end-to-end/.gitignore index c9bba6e4021..48645e85aab 100644 --- a/yarn-project/end-to-end/.gitignore +++ b/yarn-project/end-to-end/.gitignore @@ -1,3 +1,5 @@ addresses.json /log /data +/src/web/main.js +/src/web/main.js.LICENSE.txt \ No newline at end of file diff --git a/yarn-project/end-to-end/Dockerfile b/yarn-project/end-to-end/Dockerfile index d65eda2b13a..3e81baa6f2c 100644 --- a/yarn-project/end-to-end/Dockerfile +++ b/yarn-project/end-to-end/Dockerfile @@ -1,10 +1,9 @@ FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS builder -# Build aztec.js web. -WORKDIR /usr/src/yarn-project/aztec.js +# Build web bundle for browser tests +WORKDIR /usr/src/yarn-project/end-to-end RUN yarn build:web -WORKDIR /usr/src/yarn-project/end-to-end # Productionify. See comment in yarn-project-base/Dockerfile. RUN yarn workspaces focus --production && yarn cache clean @@ -25,9 +24,6 @@ RUN apk update && apk add --no-cache \ ENV CHROME_BIN="/usr/bin/chromium-browser" PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" COPY --from=builder /usr/src /usr/src -RUN rm /usr/src/yarn-project/end-to-end/src/web/main.js -COPY --from=builder /usr/src/yarn-project/aztec.js/dest/main.js /usr/src/yarn-project/end-to-end/src/web/main.js - WORKDIR /usr/src/yarn-project/end-to-end ENTRYPOINT ["yarn", "test"] diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index d3059c62120..18e2892cc04 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -4,8 +4,9 @@ "type": "module", "exports": "./dest/index.js", "scripts": { - "build": "yarn clean && tsc -b", + "build": "yarn clean && tsc -b && webpack", "build:dev": "tsc -b --watch", + "build:web": "webpack", "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src \"!src/web/main.js\" && run -T eslint ./src", "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src", @@ -22,6 +23,7 @@ "rootDir": "./src" }, "dependencies": { + "@aztec/accounts": "workspace:^", "@aztec/archiver": "workspace:^", "@aztec/aztec-node": "workspace:^", "@aztec/aztec-sandbox": "workspace:^", @@ -51,6 +53,8 @@ "@types/lodash.zipwith": "^4.2.7", "@types/memdown": "^3.0.3", "@types/node": "^18.7.23", + "buffer": "^6.0.3", + "crypto-browserify": "^3.12.0", "glob": "^10.3.10", "jest": "^29.5.0", "koa": "^2.14.2", @@ -63,13 +67,21 @@ "lodash.zip": "^4.2.0", "lodash.zipwith": "^4.2.0", "memdown": "^6.1.1", + "process": "^0.11.10", "puppeteer": "^21.3.4", + "resolve-typescript-plugin": "^2.0.1", + "stream-browserify": "^3.0.0", "string-argv": "^0.3.2", "ts-jest": "^29.1.0", + "ts-loader": "^9.4.4", "ts-node": "^10.9.1", "tslib": "^2.4.0", + "tty-browserify": "^0.0.1", "typescript": "^5.0.4", + "util": "^0.12.5", "viem": "^1.2.5", + "webpack": "^5.88.2", + "webpack-cli": "^5.1.4", "winston": "^3.10.0" }, "devDependencies": { diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 3a186cc178c..60d3bcbfe4a 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -1,3 +1,4 @@ +import { getUnsafeSchnorrAccount } from '@aztec/accounts/single_key'; import { AztecAddress, AztecNode, @@ -12,7 +13,6 @@ import { TxStatus, Wallet, computeMessageSecretHash, - getUnsafeSchnorrAccount, retryUntil, } from '@aztec/aztec.js'; import { ChildContract, TokenContract } from '@aztec/noir-contracts'; diff --git a/yarn-project/end-to-end/src/e2e_account_contracts.test.ts b/yarn-project/end-to-end/src/e2e_account_contracts.test.ts index 42999f59063..0c12c729419 100644 --- a/yarn-project/end-to-end/src/e2e_account_contracts.test.ts +++ b/yarn-project/end-to-end/src/e2e_account_contracts.test.ts @@ -1,14 +1,14 @@ +import { EcdsaAccountContract } from '@aztec/accounts/ecdsa'; +import { SchnorrAccountContract } from '@aztec/accounts/schnorr'; +import { SingleKeyAccountContract } from '@aztec/accounts/single_key'; import { AccountContract, AccountManager, CompleteAddress, - EcdsaAccountContract, Fr, GrumpkinPrivateKey, GrumpkinScalar, PXE, - SchnorrAccountContract, - SingleKeyAccountContract, Wallet, } from '@aztec/aztec.js'; import { ChildContract } from '@aztec/noir-contracts/Child'; diff --git a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts index b34bdb5334b..3049ef611d8 100644 --- a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts +++ b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts @@ -16,7 +16,7 @@ const pageLogger = createDebugLogger('aztec:canary_aztec.js:web:page'); * This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. * To run the test, do the following: * 1) Build the whole repository, - * 2) go to `yarn-project/aztec.js` and build the web packed package with `yarn build:web`, + * 2) go to `yarn-project/end-to-end` and build the web packed package with `yarn build:web`, * 3) start anvil: `anvil`, * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index ca254469a4d..737d5c1273d 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -1,12 +1,5 @@ -import { - AccountWallet, - AztecAddress, - DebugLogger, - PXE, - Wallet, - deployInitialSandboxAccounts, - getSandboxAccountsWallets, -} from '@aztec/aztec.js'; +import { deployInitialSandboxAccounts, getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { AccountWallet, AztecAddress, DebugLogger, PXE, Wallet } from '@aztec/aztec.js'; import { CardGameContract } from '@aztec/noir-contracts/CardGame'; import { setup } from './fixtures/utils.js'; diff --git a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts index a4e0f1ebfa7..0f23b5387d3 100644 --- a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts +++ b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts @@ -1,3 +1,5 @@ +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; import { AztecAddress, AztecNode, @@ -12,8 +14,6 @@ import { Wallet, computeMessageSecretHash, generatePublicKey, - getSandboxAccountsWallets, - getSchnorrAccount, } from '@aztec/aztec.js'; import { TokenContract } from '@aztec/noir-contracts/Token'; diff --git a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts index 40df1a54182..dd56c756b41 100644 --- a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts +++ b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts @@ -1,4 +1,6 @@ // docs:start:imports +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; import { ExtendedNote, Fr, @@ -8,8 +10,6 @@ import { computeMessageSecretHash, createDebugLogger, createPXEClient, - getSandboxAccountsWallets, - getSchnorrAccount, waitForSandbox, } from '@aztec/aztec.js'; import { TokenContract } from '@aztec/noir-contracts/Token'; diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 3ac20b8339f..9809052c3a2 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -1,3 +1,4 @@ +import { createAccounts, getSandboxAccountsWallets } from '@aztec/accounts/testing'; import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { AccountWalletWithPrivateKey, @@ -12,12 +13,10 @@ import { LogType, PXE, SentTx, - createAccounts, createAztecNodeClient, createDebugLogger, createPXEClient, deployL1Contracts, - getSandboxAccountsWallets, retryUntil, } from '@aztec/aztec.js'; import { diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 5a5d5bda30a..75154bca3ee 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -1,3 +1,4 @@ +import { createAccount, getSandboxAccountsWallets } from '@aztec/accounts/testing'; import { createSandbox } from '@aztec/aztec-sandbox'; import { AccountWallet, @@ -7,9 +8,7 @@ import { Note, PXE, computeMessageSecretHash, - createAccount, createPXEClient, - getSandboxAccountsWallets, waitForSandbox, } from '@aztec/aztec.js'; import { TestContract } from '@aztec/noir-contracts/Test'; diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index 3889fac2c48..974f0f5e7a1 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -1,8 +1,8 @@ +import { DefaultAccountContract } from '@aztec/accounts/defaults'; import { AccountManager, AuthWitness, AuthWitnessProvider, - BaseAccountContract, CompleteAddress, ExtendedNote, Fr, @@ -21,7 +21,7 @@ import { setup } from '../fixtures/utils.js'; const PRIVATE_KEY = GrumpkinScalar.fromString('0xd35d743ac0dfe3d6dbe6be8c877cb524a00ab1e3d52d7bada095dfc8894ccfa'); /** Account contract implementation that authenticates txs using Schnorr signatures. */ -class SchnorrHardcodedKeyAccountContract extends BaseAccountContract { +class SchnorrHardcodedKeyAccountContract extends DefaultAccountContract { constructor(private privateKey: GrumpkinPrivateKey = PRIVATE_KEY) { super(SchnorrHardcodedAccountContractArtifact); } diff --git a/yarn-project/end-to-end/src/sample-dapp/deploy.mjs b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs index 7b2dbeaa8c2..62c6f98ba94 100644 --- a/yarn-project/end-to-end/src/sample-dapp/deploy.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs @@ -1,4 +1,5 @@ -import { Contract, ContractDeployer, createPXEClient, getSandboxAccountsWallets } from '@aztec/aztec.js'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { Contract, createPXEClient } from '@aztec/aztec.js'; import { TokenContractArtifact } from '@aztec/noir-contracts/Token'; import { writeFileSync } from 'fs'; @@ -10,16 +11,12 @@ const { PXE_URL = 'http://localhost:8080' } = process.env; async function main() { const pxe = createPXEClient(PXE_URL); const [ownerWallet] = await getSandboxAccountsWallets(pxe); + const ownerAddress = ownerWallet.getCompleteAddress(); - const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [ownerWallet.getCompleteAddress()]) - .send() - .deployed(); - + const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [ownerAddress]).send().deployed(); console.log(`Token deployed at ${token.address.toString()}`); - const addresses = { - token: token.address.toString(), - }; + const addresses = { token: token.address.toString() }; writeFileSync('addresses.json', JSON.stringify(addresses, null, 2)); } // docs:end:dapp-deploy diff --git a/yarn-project/end-to-end/src/sample-dapp/index.mjs b/yarn-project/end-to-end/src/sample-dapp/index.mjs index de98301f581..32d67453da9 100644 --- a/yarn-project/end-to-end/src/sample-dapp/index.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/index.mjs @@ -1,12 +1,5 @@ -import { - ExtendedNote, - Fr, - L2BlockL2Logs, - Note, - computeMessageSecretHash, - createPXEClient, - getSandboxAccountsWallets, -} from '@aztec/aztec.js'; +import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { ExtendedNote, Fr, Note, computeMessageSecretHash, createPXEClient } from '@aztec/aztec.js'; import { fileURLToPath } from '@aztec/foundation/url'; import { getToken } from './contracts.mjs'; diff --git a/yarn-project/end-to-end/src/sample-dapp/index.test.mjs b/yarn-project/end-to-end/src/sample-dapp/index.test.mjs index 7441e6ba7e6..69e4fb2a9b5 100644 --- a/yarn-project/end-to-end/src/sample-dapp/index.test.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/index.test.mjs @@ -1,11 +1,10 @@ -import { createSandbox } from '@aztec/aztec-sandbox'; +import { createAccount } from '@aztec/accounts/testing'; import { Contract, ExtendedNote, Fr, Note, computeMessageSecretHash, - createAccount, createPXEClient, waitForSandbox, } from '@aztec/aztec.js'; @@ -15,7 +14,7 @@ const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:854 describe('token', () => { // docs:start:setup - let pxe, stop, owner, recipient, token; + let owner, recipient, token; beforeAll(async () => { const pxe = createPXEClient(PXE_URL); await waitForSandbox(pxe); diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index 4becaf5cd34..4b1eb21ce01 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -1,4 +1,6 @@ /* eslint-disable no-console */ +import * as AztecAccountsSingleKey from '@aztec/accounts/single_key'; +import * as AztecAccountsTesting from '@aztec/accounts/testing'; import * as AztecJs from '@aztec/aztec.js'; import { TokenContractArtifact } from '@aztec/noir-contracts/Token'; @@ -16,7 +18,7 @@ declare global { /** * The aztec.js library. */ - AztecJs: typeof AztecJs; + AztecJs: typeof AztecJs & typeof AztecAccountsSingleKey & typeof AztecAccountsTesting; } } @@ -132,10 +134,15 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL it("Gets the owner's balance", async () => { const result = await page.evaluate( async (rpcUrl, contractAddress, TokenContractArtifact) => { - const { Contract, AztecAddress, createPXEClient: createPXEClient } = window.AztecJs; + const { + Contract, + AztecAddress, + createPXEClient: createPXEClient, + getSandboxAccountsWallets, + } = window.AztecJs; const pxe = createPXEClient(rpcUrl!); const owner = (await pxe.getRegisteredAccounts())[0].address; - const [wallet] = await AztecJs.getSandboxAccountsWallets(pxe); + const [wallet] = await getSandboxAccountsWallets(pxe); const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet); const balance = await contract.methods.balance_of_private(owner).view({ from: owner }); return balance; @@ -151,11 +158,16 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL const result = await page.evaluate( async (rpcUrl, contractAddress, transferAmount, TokenContractArtifact) => { console.log(`Starting transfer tx`); - const { AztecAddress, Contract, createPXEClient: createPXEClient } = window.AztecJs; + const { + AztecAddress, + Contract, + createPXEClient: createPXEClient, + getSandboxAccountsWallets, + } = window.AztecJs; const pxe = createPXEClient(rpcUrl!); const accounts = await pxe.getRegisteredAccounts(); const receiver = accounts[1].address; - const [wallet] = await AztecJs.getSandboxAccountsWallets(pxe); + const [wallet] = await getSandboxAccountsWallets(pxe); const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet); await contract.methods.transfer(accounts[0].address, receiver, transferAmount, 0).send().wait(); console.log(`Transferred ${transferAmount} tokens to new Account`); @@ -198,7 +210,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL accounts[0].publicKey, pxe, TokenContractArtifact, - a => Contract.at(a, TokenContractArtifact, owner), + (a: AztecJs.AztecAddress) => Contract.at(a, TokenContractArtifact, owner), [owner.getCompleteAddress()], ).send(); const { contract: token, txHash } = await tx.wait(); diff --git a/yarn-project/end-to-end/src/web/main.js b/yarn-project/end-to-end/src/web/main.js deleted file mode 120000 index 53fbb99288a..00000000000 --- a/yarn-project/end-to-end/src/web/main.js +++ /dev/null @@ -1 +0,0 @@ -../../../aztec.js/dest/main.js \ No newline at end of file diff --git a/yarn-project/end-to-end/src/web/main.ts b/yarn-project/end-to-end/src/web/main.ts new file mode 100644 index 00000000000..924b01eb9d4 --- /dev/null +++ b/yarn-project/end-to-end/src/web/main.ts @@ -0,0 +1,3 @@ +export * from '@aztec/aztec.js'; +export * from '@aztec/accounts/testing'; +export * from '@aztec/accounts/single_key'; diff --git a/yarn-project/end-to-end/tsconfig.json b/yarn-project/end-to-end/tsconfig.json index c44790b98d8..b6911d791d6 100644 --- a/yarn-project/end-to-end/tsconfig.json +++ b/yarn-project/end-to-end/tsconfig.json @@ -6,6 +6,9 @@ "tsBuildInfoFile": ".tsbuildinfo" }, "references": [ + { + "path": "../accounts" + }, { "path": "../archiver" }, diff --git a/yarn-project/end-to-end/tsconfig.web.json b/yarn-project/end-to-end/tsconfig.web.json new file mode 100644 index 00000000000..94b4537fe51 --- /dev/null +++ b/yarn-project/end-to-end/tsconfig.web.json @@ -0,0 +1,12 @@ +{ + "extends": ".", + "include": ["src/web/*.ts"], + "references": [ + { + "path": "../accounts" + }, + { + "path": "../aztec.js" + } + ], +} diff --git a/yarn-project/end-to-end/webpack.config.js b/yarn-project/end-to-end/webpack.config.js new file mode 100644 index 00000000000..6fe97604e7e --- /dev/null +++ b/yarn-project/end-to-end/webpack.config.js @@ -0,0 +1,70 @@ +import { createRequire } from 'module'; +import { dirname, resolve } from 'path'; +import ResolveTypeScriptPlugin from 'resolve-typescript-plugin'; +import { fileURLToPath } from 'url'; +import webpack from 'webpack'; + +const require = createRequire(import.meta.url); + +export default { + target: 'web', + mode: 'production', + devtool: false, + entry: { + main: './src/web/main.ts', + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: [ + { + loader: 'ts-loader', + options: { + configFile: 'tsconfig.web.json', + }, + }, + ], + }, + ], + }, + output: { + path: resolve(dirname(fileURLToPath(import.meta.url)), './src/web'), + filename: 'main.js', + library: { + type: 'module', + }, + chunkFormat: 'module', + }, + experiments: { + outputModule: true, + }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: JSON.stringify('production'), + }, + }), + new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }), + ], + resolve: { + plugins: [new ResolveTypeScriptPlugin()], + alias: { + // All node specific code, wherever it's located, should be imported as below. + // Provides a clean and simple way to always strip out the node code for the web build. + './node/index.js': false, + }, + fallback: { + crypto: false, + os: false, + fs: false, + path: false, + url: false, + worker_threads: false, + buffer: require.resolve('buffer/'), + util: require.resolve('util/'), + stream: require.resolve('stream-browserify'), + tty: require.resolve('tty-browserify'), + }, + }, +}; diff --git a/yarn-project/p2p/tsconfig.json b/yarn-project/p2p/tsconfig.json index b780dee9f30..e934003361b 100644 --- a/yarn-project/p2p/tsconfig.json +++ b/yarn-project/p2p/tsconfig.json @@ -13,10 +13,10 @@ "path": "../foundation" }, { - "path": "../types" + "path": "../kv-store" }, { - "path": "../kv-store" + "path": "../types" } ], "include": ["src"] diff --git a/yarn-project/package.common.json b/yarn-project/package.common.json index 12e168ae5f0..57e7aa40182 100644 --- a/yarn-project/package.common.json +++ b/yarn-project/package.common.json @@ -11,7 +11,6 @@ "node": ">=18" }, "files": ["dest", "src", "!*.test.*"], - "types": "./dest/index.d.ts", "devDependencies": { "@jest/globals": "^29.5.0", "@types/jest": "^29.5.0", diff --git a/yarn-project/package.json b/yarn-project/package.json index 9769892147b..a9721c086a4 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -16,6 +16,7 @@ "clean": "yarn workspaces foreach -p -v run clean" }, "workspaces": [ + "accounts", "acir-simulator", "archiver", "aztec-faucet", diff --git a/yarn-project/tsconfig.json b/yarn-project/tsconfig.json index a57263c1824..b5dcf4fc843 100644 --- a/yarn-project/tsconfig.json +++ b/yarn-project/tsconfig.json @@ -18,6 +18,7 @@ "skipLibCheck": true }, "references": [ + { "path": "accounts/tsconfig.json" }, { "path": "acir-simulator/tsconfig.json" }, { "path": "archiver/tsconfig.json" }, { "path": "aztec-faucet/tsconfig.json" }, diff --git a/yarn-project/typedoc.json b/yarn-project/typedoc.json index 408f630dc80..34fd9160a1f 100644 --- a/yarn-project/typedoc.json +++ b/yarn-project/typedoc.json @@ -2,6 +2,7 @@ "cleanOutputDir": false, "entryPointStrategy": "packages", "entryPoints": [ + "accounts", "acir-simulator", "archiver", "aztec-cli", diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index fc56b14cff8..a3f9c9557f3 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -57,6 +57,28 @@ __metadata: languageName: node linkType: hard +"@aztec/accounts@workspace:^, @aztec/accounts@workspace:accounts": + version: 0.0.0-use.local + resolution: "@aztec/accounts@workspace:accounts" + dependencies: + "@aztec/aztec.js": "workspace:^" + "@aztec/circuits.js": "workspace:^" + "@aztec/ethereum": "workspace:^" + "@aztec/foundation": "workspace:^" + "@aztec/types": "workspace:^" + "@jest/globals": ^29.5.0 + "@types/jest": ^29.5.0 + "@types/node": ^18.7.23 + jest: ^29.5.0 + jest-mock-extended: ^3.0.3 + ts-jest: ^29.1.0 + ts-loader: ^9.4.4 + ts-node: ^10.9.1 + tslib: ^2.4.0 + typescript: ^5.0.4 + languageName: unknown + linkType: soft + "@aztec/acir-simulator@workspace:^, @aztec/acir-simulator@workspace:acir-simulator": version: 0.0.0-use.local resolution: "@aztec/acir-simulator@workspace:acir-simulator" @@ -178,6 +200,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/aztec-sandbox@workspace:aztec-sandbox" dependencies: + "@aztec/accounts": "workspace:^" "@aztec/aztec-node": "workspace:^" "@aztec/aztec.js": "workspace:^" "@aztec/circuits.js": "workspace:^" @@ -297,6 +320,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/cli@workspace:cli" dependencies: + "@aztec/accounts": "workspace:^" "@aztec/aztec.js": "workspace:^" "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" @@ -343,6 +367,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/end-to-end@workspace:end-to-end" dependencies: + "@aztec/accounts": "workspace:^" "@aztec/archiver": "workspace:^" "@aztec/aztec-node": "workspace:^" "@aztec/aztec-sandbox": "workspace:^" @@ -372,7 +397,9 @@ __metadata: "@types/lodash.zipwith": ^4.2.7 "@types/memdown": ^3.0.3 "@types/node": ^18.7.23 + buffer: ^6.0.3 concurrently: ^7.6.0 + crypto-browserify: ^3.12.0 glob: ^10.3.10 jest: ^29.5.0 koa: ^2.14.2 @@ -385,13 +412,21 @@ __metadata: lodash.zip: ^4.2.0 lodash.zipwith: ^4.2.0 memdown: ^6.1.1 + process: ^0.11.10 puppeteer: ^21.3.4 + resolve-typescript-plugin: ^2.0.1 + stream-browserify: ^3.0.0 string-argv: ^0.3.2 ts-jest: ^29.1.0 + ts-loader: ^9.4.4 ts-node: ^10.9.1 tslib: ^2.4.0 + tty-browserify: ^0.0.1 typescript: ^5.0.4 + util: ^0.12.5 viem: ^1.2.5 + webpack: ^5.88.2 + webpack-cli: ^5.1.4 winston: ^3.10.0 languageName: unknown linkType: soft