Skip to content

Commit

Permalink
feat: CLI wallet initial version (#7651)
Browse files Browse the repository at this point in the history
Initial version of the CLI wallet, basically porting the old CLI
commands `create-account`, `deploy` and `send`.

Instead of specifying a private key, whenever an account is created an
alias can be given to it via the `-a` param. This will store the account
info (including secret key!) in a DB, so that the account alias can be
referenced later in the other commands.

`aztec-wallet create-account -a main`

```
New account:

Address:         0x032fc6676fea75427cffc4fafffb1ae8ec29340bc1d5814ec56c5d82fe8eec51
Public key:      0x27aaf1b4f4250d45a085524ae0e7dd4bfe62c3e7de7c3c614fd7b0fe34af21152cea6630aed6b3bddda2f2918bdd8e590e1cbcdd01a82fa95ac44dc758d6cac526ccd74bb8c11c4fc7014ed558a001583c7cf9a65c8adb2840763c325e29fc6e185acaa0f6dce3ccfec068ef090d7b450c6ad540a4e86baf204f53acab7839542bb4c2b71210b02c59bca7870d0973861a01688811acf2263f1eeefa459c240e280b949204c944e63349710c939898e739354f700cbcd427b059b558e818625325426f0ab1586937384e222000974bd917d5e498cfa7f83118096fdf176b617b2a41aeae4d6ab0d1ff9035d6295782d42a40087111aa6215cdbdd633402dd726
Private key:     0x252cef68955eee66a0f346eea4eff84d8dfca1740794436913c10c49ce1b5566
Partial address: 0x011e89c12b17cb0a602369148e82c2dd2910a7ad847cbcb818fb9bffbce02b6b
Salt:            0x0000000000000000000000000000000000000000000000000000000000000000
Init hash:       0x0673bba8f408c1bcf6faaaec4e526662871386562d8c98ff303a138599a977c1
Deployer:        0x0000000000000000000000000000000000000000000000000000000000000000

Waiting for account contract deployment...
Deploy tx hash:  2e6f063986636d3aa96c1bdc9546f96c5f40472fac2ff1031cc79186c0a87573
Deploy tx fee:   200013616
```

And then you can do:

`aztec-wallet deploy
./noir-projects/noir-contracts.js/artifacts/token_contract-Token.json
--args
0x032fc6676fea75427cffc4fafffb1ae8ec29340bc1d5814ec56c5d82fe8eec51 Test
TST 18 -a main`

The new wallet command (`aztec-wallet`) is added as part of the suite of
tools users get when doing `aztec-up`
  • Loading branch information
Thunkar authored Aug 2, 2024
1 parent bd5a26e commit 83f8d9c
Show file tree
Hide file tree
Showing 74 changed files with 673 additions and 338 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/devnet-deploys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jobs:
run: |
earthly-ci --no-output --push ./yarn-project+export-aztec-arch --DIST_TAG=${{ env.DEPLOY_TAG }}
earthly-ci --no-output --push ./yarn-project+export-aztec-arch --DIST_TAG=${{ github.sha }}
earthly-ci --no-output --push ./yarn-project+export-cli-wallet --DIST_TAG=${{ env.DEPLOY_TAG }}
earthly-ci --no-output --push ./yarn-project+export-cli-wallet-arch --DIST_TAG=${{ github.sha }}
- name: Check if mainnet fork needs deployment
id: check_fork_changes
Expand Down
2 changes: 1 addition & 1 deletion aztec-up/bin/aztec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ elif [ $# == 2 ] && [ "$1" == "start" ] && [ "$2" == "--sandbox" ]; then
trap cleanup SIGINT

get_compose -p sandbox $FILE_ARG up --force-recreate --remove-orphans
elif [ "$1" == "start" ]; then
elif [ "${1:-}" == "start" ]; then
$(dirname $0)/.aztec-run aztecprotocol/aztec "$@"
else
SKIP_PORT_ASSIGNMENT=1 $(dirname $0)/.aztec-run aztecprotocol/aztec "$@"
Expand Down
3 changes: 3 additions & 0 deletions aztec-up/bin/aztec-install
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function title() {
echo -e " ${bold}${g}aztec${r} - a collection of tools to launch subsystems and interact with the aztec network."
echo -e " ${bold}${g}aztec-nargo${r} - aztec's build of nargo, the noir compiler toolchain."
echo -e " ${bold}${g}aztec-up${r} - a tool to upgrade the aztec toolchain to the latest, or specific versions."
echo -e " ${bold}${g}aztec-wallet${r} - our minimalistic CLI wallet"
echo
read -p "Do you wish to continue? (y/n)" -n 1 -r
echo
Expand Down Expand Up @@ -105,6 +106,7 @@ if [ -z "${SKIP_PULL:-}" ]; then
info "Pulling aztec version $VERSION..."
pull_container aztec-nargo
pull_container aztec
pull_container cli-wallet
fi

# Download the Docker Compose file. Used by aztec.
Expand All @@ -123,6 +125,7 @@ install_bin .aztec-run
install_bin aztec
install_bin aztec-up
install_bin aztec-nargo
install_bin aztec-wallet

function update_path_env_var {
TARGET_DIR="${1}"
Expand Down
11 changes: 11 additions & 0 deletions aztec-up/bin/aztec-wallet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail

export SKIP_NET=1
export SKIP_PORT_ASSIGNMENT=1
export WALLET_DATA_DIRECTORY=$(dirname $0)/wallet-data
export ENV_VARS_TO_INJECT=WALLET_DATA_DIRECTORY

mkdir -p $WALLET_DATA_DIRECTORY

$(dirname $0)/.aztec-run aztecprotocol/cli-wallet $@
5 changes: 5 additions & 0 deletions barretenberg/cpp/format.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash
set -e

if [ "$(uname)" == "Darwin" ]; then
shopt -s expand_aliases
alias clang-format-16="clang-format"
fi

if [ "$1" == "staged" ]; then
echo Formatting barretenberg staged files...
for FILE in $(git diff-index --diff-filter=d --relative --cached --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$'); do
Expand Down
4 changes: 2 additions & 2 deletions build_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ aztec:
- yarn-project
multiarch: buildx

aztec-builder:
cli-wallet:
buildDir: yarn-project
projectDir: yarn-project/builder
projectDir: yarn-project/cli-wallet
dependencies:
- yarn-project
multiarch: buildx
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RUN mkdir -p $BB_WORKING_DIRECTORY $ACVM_WORKING_DIRECTORY && \
node bb-prover/dest/bb/index.js write-contract -c RootRollupArtifact -n UltraVerifier.sol || \
echo "Skipping VK generation arch=$(arch)"

RUN yarn workspaces focus @aztec/aztec @aztec/builder @aztec/cli --production && yarn cache clean
RUN yarn workspaces focus @aztec/aztec @aztec/cli-wallet --production && yarn cache clean

# TODO: Use release-please to update package.json directly, and remove this!
# It's here to ensure the image rebuilds if the commit tag changes (as the content hash won't).
Expand Down
34 changes: 20 additions & 14 deletions yarn-project/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,37 @@ rollup-verifier-contract:
RUN --entrypoint write-contract -c RootRollupArtifact -n UltraVerifier.sol
SAVE ARTIFACT /usr/src/bb /usr/src/bb

txe:
cli-base:
FROM +build
RUN yarn workspaces focus @aztec/txe --production && yarn cache clean
# Remove a bunch of stuff that we don't need that takes up space.
RUN rm -rf \
../noir-projects \
../l1-contracts \
../barretenberg/ts/src \
../barretenberg/ts/dest/node-cjs \
../barretenberg/ts/dest/browser

txe:
FROM +cli-base
RUN yarn workspaces focus @aztec/txe --production && yarn cache clean
ENTRYPOINT ["node", "--no-warnings", "/usr/src/yarn-project/txe/dest/bin/index.js"]
SAVE ARTIFACT /usr/src /usr/src

cli-wallet:
FROM +cli-base
RUN yarn workspaces focus @aztec/cli-wallet --production && yarn cache clean
ENTRYPOINT ["node", "--no-warnings", "/usr/src/yarn-project/cli-wallet/dest/bin/index.js"]
SAVE ARTIFACT /usr/src /usr/src

export-cli-wallet:
FROM +cli-wallet
ARG DIST_TAG="latest"
ARG ARCH
SAVE IMAGE --push aztecprotocol/cli-wallet:${DIST_TAG}${ARCH:+-$ARCH}

aztec-prod:
FROM +build
RUN yarn workspaces focus @aztec/aztec @aztec/builder --production && yarn cache clean
# Remove a bunch of stuff that we don't need that takes up space.
RUN rm -rf \
../noir-projects \
../l1-contracts \
../barretenberg/ts/src \
../barretenberg/ts/dest/node-cjs \
../barretenberg/ts/dest/browser \
aztec.js/dest/main.js \
end-to-end \
**/src
FROM +cli-base
RUN yarn workspaces focus @aztec/aztec --production && yarn cache clean
COPY --dir +rollup-verifier-contract/usr/src/bb /usr/src
SAVE ARTIFACT /usr/src /usr/src

Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@aztec/foundation": "workspace:^",
"@aztec/protocol-contracts": "workspace:^",
"@aztec/types": "workspace:^",
"axios": "^1.7.2",
"tslib": "^2.4.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export {
} from './utils/index.js';
export { NoteSelector } from '@aztec/foundation/abi';

export { createPXEClient } from './rpc_clients/index.js';
export { createPXEClient, createCompatibleClient } from './rpc_clients/index.js';

export { AuthWitnessProvider } from './account/index.js';

Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/rpc_clients/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './pxe_client.js';
export * from './node/index.js';
69 changes: 69 additions & 0 deletions yarn-project/aztec.js/src/rpc_clients/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { type PXE } from '@aztec/circuit-types';
import { type DebugLogger } from '@aztec/foundation/log';
import { NoRetryError } from '@aztec/foundation/retry';

import axios, { type AxiosError, type AxiosResponse } from 'axios';

import { createPXEClient } from '../pxe_client.js';

/**
* A fetch implementation using axios.
* @param host - The URL of the host.
* @param rpcMethod - The RPC method to call.
* @param body - The body of the request.
* @param useApiEndpoints - Whether to use the API endpoints or inject the method in the body.
* @param _noRetry - Whether to retry on non-server errors.
* @returns The response data.
*/
async function axiosFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean, _noRetry = true) {
let resp: AxiosResponse;
if (useApiEndpoints) {
resp = await axios
.post(`${host}/${rpcMethod}`, body, {
headers: { 'content-type': 'application/json' },
})
.catch((error: AxiosError) => {
if (error.response) {
return error.response;
}
throw error;
});
} else {
resp = await axios
.post(
host,
{ ...body, method: rpcMethod },
{
headers: { 'content-type': 'application/json' },
},
)
.catch((error: AxiosError) => {
if (error.response) {
return error.response;
}
throw error;
});
}

const isOK = resp.status >= 200 && resp.status < 300;
if (isOK) {
return resp.data;
} else if (resp.status >= 400 && resp.status < 500) {
throw new NoRetryError('(JSON-RPC PROPAGATED) ' + resp.data.error.message);
} else {
throw new Error('(JSON-RPC PROPAGATED) ' + resp.data.error.message);
}
}

/**
* Creates a PXE client with a given set of retries on non-server errors.
* Checks that PXE matches the expected version, and warns if not.
* @param rpcUrl - URL of the RPC server wrapping the PXE.
* @param _logger - Debug logger to warn version incompatibilities.
* @returns A PXE client.
*/
export function createCompatibleClient(rpcUrl: string, _logger: DebugLogger): Promise<PXE> {
// Use axios due to timeout issues with fetch when proving TXs.
const pxe = createPXEClient(rpcUrl, axiosFetch);
return Promise.resolve(pxe);
}
1 change: 0 additions & 1 deletion yarn-project/aztec.js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// import CopyWebpackPlugin from 'copy-webpack-plugin';
import { createRequire } from 'module';
import { dirname, resolve } from 'path';
import path from 'path';
import ResolveTypeScriptPlugin from 'resolve-typescript-plugin';
import { fileURLToPath } from 'url';
import webpack from 'webpack';
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@aztec/circuit-types": "workspace:^",
"@aztec/circuits.js": "workspace:^",
"@aztec/cli": "workspace:^",
"@aztec/cli-wallet": "workspace:^",
"@aztec/entrypoints": "workspace:^",
"@aztec/ethereum": "workspace:^",
"@aztec/foundation": "workspace:^",
Expand Down
6 changes: 4 additions & 2 deletions yarn-project/aztec/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { fileURLToPath } from '@aztec/aztec.js';
import { injectCommands as injectBuilderCommands } from '@aztec/builder';
import { injectCommands as injectWalletCommands } from '@aztec/cli-wallet';
import { injectCommands as injectContractCommands } from '@aztec/cli/contracts';
import { injectCommands as injectDevnetCommands } from '@aztec/cli/devnet';
import { injectCommands as injectInfrastructureCommands } from '@aztec/cli/infrastructure';
import { injectCommands as injectL1Commands } from '@aztec/cli/l1';
import { injectCommands as injectMiscCommands } from '@aztec/cli/misc';
import { injectCommands as injectPXECommands } from '@aztec/cli/pxe';
import { injectCommands as injectUtilsCommands } from '@aztec/cli/utils';
import { createConsoleLogger, createDebugLogger } from '@aztec/foundation/log';

import { Command } from 'commander';
Expand All @@ -29,8 +30,9 @@ async function main() {
program = injectInfrastructureCommands(program, userLog, debugLogger);
program = injectL1Commands(program, userLog, debugLogger);
program = injectPXECommands(program, userLog, debugLogger);
program = injectUtilsCommands(program, userLog);
program = injectMiscCommands(program, userLog);
program = injectDevnetCommands(program, userLog, debugLogger);
program = injectWalletCommands(program, userLog, debugLogger);

await program.parseAsync(process.argv);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec
import { SignerlessWallet } from '@aztec/aztec.js';
import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
import { type AztecNode } from '@aztec/circuit-types';
import { deployCanonicalAuthRegistry, deployCanonicalKeyRegistry, deployCanonicalL2GasToken } from '@aztec/cli/utils';
import { deployCanonicalAuthRegistry, deployCanonicalKeyRegistry, deployCanonicalL2GasToken } from '@aztec/cli/misc';
import {
type DeployL1Contracts,
type L1ContractArtifactsForDeployment,
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/aztec/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
{
"path": "../cli"
},
{
"path": "../cli-wallet"
},
{
"path": "../entrypoints"
},
Expand Down
1 change: 1 addition & 0 deletions yarn-project/cli-wallet/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@aztec/foundation/eslint');
6 changes: 6 additions & 0 deletions yarn-project/cli-wallet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM aztecprotocol/yarn-project AS yarn-project
ENTRYPOINT ["node", "--no-warnings", "/usr/src/yarn-project/cli-wallet/dest/bin/index.js"]

# The version has been updated in yarn-project.
# Adding COMMIT_TAG here to rebuild versioned image.
ARG COMMIT_TAG=""
2 changes: 2 additions & 0 deletions yarn-project/cli-wallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Aztec wallet Documentation

96 changes: 96 additions & 0 deletions yarn-project/cli-wallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"name": "@aztec/cli-wallet",
"version": "0.0.0",
"type": "module",
"exports": {
".": "./dest/cmds/index.js",
"./cli": "./dest/bin/index.js"
},
"typedocOptions": {
"entryPoints": [
"./src/cmds/index.ts"
],
"name": "Aztec CLI wallet",
"tsconfig": "./tsconfig.json"
},
"bin": {
"aztec-wallet": "./dest/bin/index.js"
},
"scripts": {
"start": "node --no-warnings ./dest/bin",
"start:debug": "node --inspect=0.0.0.0:9221 --no-warnings ./dest/bin",
"dev": "DEBUG='aztec:*' LOG_LEVEL=debug && node ./dest/bin",
"build": "yarn clean && tsc -b",
"build:dev": "tsc -b --watch",
"clean": "rm -rf ./dest .tsbuildinfo",
"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 ../node_modules/.bin/jest --passWithNoTests"
},
"inherits": [
"../package.common.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src",
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.tsx?$": [
"@swc/jest",
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
}
}
}
]
},
"reporters": [
[
"default",
{
"summaryThreshold": 9999
}
]
]
},
"dependencies": {
"@aztec/accounts": "workspace:^",
"@aztec/aztec.js": "workspace:^",
"@aztec/circuits.js": "workspace:^",
"@aztec/cli": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/kv-store": "workspace:^",
"commander": "^12.1.0",
"source-map-support": "^0.5.21",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/node": "^18.7.23",
"@types/source-map-support": "^0.5.10",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.5",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"files": [
"dest",
"src",
"!*.test.*"
],
"types": "./dest/index.d.ts",
"engines": {
"node": ">=18"
}
}
Loading

1 comment on commit 83f8d9c

@AztecBot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'C++ Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 83f8d9c Previous: f2a8f74 Ratio
nativeconstruct_proof_ultrahonk_power_of_2/20 5166.802439999998 ms/iter 4807.637082999989 ms/iter 1.07

This comment was automatically generated by workflow using github-action-benchmark.

CC: @ludamad @codygunton

Please sign in to comment.