From 47490fa6d19f94c46c9780d6a81b78c31fecc514 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Tue, 5 Dec 2023 21:58:41 +0000 Subject: [PATCH 1/8] initial --- aztec-up/.gitignore | 3 ++ aztec-up/README.md | 30 +++++++++++ aztec-up/bin/.aztec-run | 81 ++++++++++++++++++++++++++++ aztec-up/bin/aztec | 4 ++ aztec-up/bin/aztec-cli | 12 +++++ aztec-up/bin/aztec-nargo | 4 ++ aztec-up/bin/aztec-start | 9 ++++ aztec-up/bin/aztec-up | 94 +++++++++++++++++++++++++++++++++ aztec-up/bin/docker-compose.yml | 34 ++++++++++++ aztec-up/deploy.sh | 23 ++++++++ aztec-up/terraform/main.tf | 83 +++++++++++++++++++++++++++++ 11 files changed, 377 insertions(+) create mode 100644 aztec-up/.gitignore create mode 100644 aztec-up/README.md create mode 100755 aztec-up/bin/.aztec-run create mode 100755 aztec-up/bin/aztec create mode 100755 aztec-up/bin/aztec-cli create mode 100755 aztec-up/bin/aztec-nargo create mode 100755 aztec-up/bin/aztec-start create mode 100755 aztec-up/bin/aztec-up create mode 100644 aztec-up/bin/docker-compose.yml create mode 100755 aztec-up/deploy.sh create mode 100644 aztec-up/terraform/main.tf diff --git a/aztec-up/.gitignore b/aztec-up/.gitignore new file mode 100644 index 000000000000..5fd438ece3e8 --- /dev/null +++ b/aztec-up/.gitignore @@ -0,0 +1,3 @@ +.terraform +.terraform* +.DS_Store \ No newline at end of file diff --git a/aztec-up/README.md b/aztec-up/README.md new file mode 100644 index 000000000000..c326d638081f --- /dev/null +++ b/aztec-up/README.md @@ -0,0 +1,30 @@ +# The Aztec Installation Script + +``` +bash -c "$(curl https://up.aztec.network)" +``` + +That is all. + +This will install into `~/.aztec/bin` a collection of scripts to help running aztec containers, and will update +a users `PATH` variable in their shell startup script so they can be found. + +- `aztec` - The infrastructure container. +- `aztec-cli` - A command line tool for interacting with infrastructure. +- `aztec-nargo` - A build of `nargo` from `noir` that is guaranteed to be version aligned. Provides compiler, lsp and more. + +Run any of these commands to get more help. + +To upgrade, re-run the install script as above. To install a specific version you can e.g. + +``` +VERSION=master bash -c "$(curl https://up.aztec.network)" +``` + +This will install the container built from master branch. + +``` +VERSION=v1.2.3 bash -c "$(curl https://up.aztec.network)" +``` + +This will install tagged release version 1.2.3. diff --git a/aztec-up/bin/.aztec-run b/aztec-up/bin/.aztec-run new file mode 100755 index 000000000000..1ad06ed2c9d9 --- /dev/null +++ b/aztec-up/bin/.aztec-run @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +# The script starts a Docker container passing any commands and arguments to the command running inside the container. + +set -euo pipefail + +IMAGE=${1:-} +shift + +if [ -z "$IMAGE" ]; then + echo "Provide a container image in IMAGE." +fi + +VERSION=${VERSION:-"latest"} + +# Any host bindings we might send to the container. +DOCKER_HOST="" + +# Volumes to pass to the container. +DOCKER_VOLUME="" + +if ! command -v docker &> /dev/null; then + echo "No docker found." + exit 1 +fi + +# Set up host.docker.internal alias on Linux, just like it is on mac. +UNAME=$(uname -s) +if [ "$UNAME" == "Linux" ]; then + DOCKER_HOST="$DOCKER_HOST --add-host host.docker.internal:host-gateway" +fi + +# Build a list of mount points +function add_mount() { + DIR="${1:-}" + + # Grab its dirname if its a file. + if [ -f "$DIR" ]; then + DIR=$(dirname "$DIR") + fi + + if [ ! -d "$DIR" ]; then + return + fi + + # Check if it's already been added. + REALDIR=$(realpath $DIR) + if [[ "$DOCKER_VOLUME" =~ "$REALDIR:" ]]; then + return + fi + + DOCKER_VOLUME="$DOCKER_VOLUME -v $REALDIR:$REALDIR" +} + +# Always mount the CWD into the container. +add_mount "$PWD" + +# Check if it's either a filename or a directory that exists outside the CWD. +# If it is then mount inside the container. +# NOTE: This won't work with assignement-style flags, e.g. --outdir=/foo +for (( i=1; i <= "$#"; i++ )); do + arg_value=${!i} + if [[ -f "$arg_value" || -d "$arg_value" && $(realpath $arg_value) != ${PWD}* ]]; then + add_mount "$arg_value" + fi +done + +DOCKER_ENV="" +for env in ${ENV_VARS_TO_INJECT:-}; do + DOCKER_ENV+="-e $env:${!env} " +done + +DOCKER_VOLUME="$DOCKER_VOLUME -v cache:/cache" + +docker run \ + --rm \ + --user $(id -u):$(id -g) \ + --workdir "$PWD" \ + $DOCKER_HOST \ + $DOCKER_ENV \ + $DOCKER_VOLUME \ + $IMAGE:$VERSION $@ diff --git a/aztec-up/bin/aztec b/aztec-up/bin/aztec new file mode 100755 index 000000000000..30ef8a66fabe --- /dev/null +++ b/aztec-up/bin/aztec @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euo pipefail + +$(dirname $0)/.aztec-run aztecprotocol/aztec-sandbox $@ \ No newline at end of file diff --git a/aztec-up/bin/aztec-cli b/aztec-up/bin/aztec-cli new file mode 100755 index 000000000000..e3acd66f1639 --- /dev/null +++ b/aztec-up/bin/aztec-cli @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# TODO: Make compile command always be wasm. Or put nargo in container. Or probe. +# TODO: Make unbox fail if trying to unbox outside of the cwd. +set -euo pipefail + +export ENV_VARS_TO_INJECT="PXE_URL PRIVATE_KEY DEBUG" +export PXE_URL=${PXE_URL:-"http://host.docker.internal:8080"} + +# Replace 'localhost' with 'host.docker.internal' in PXE_URL +export PXE_URL=${PXE_URL//localhost/host.docker.internal} + +$(dirname $0)/.aztec-run aztecprotocol/cli $@ \ No newline at end of file diff --git a/aztec-up/bin/aztec-nargo b/aztec-up/bin/aztec-nargo new file mode 100755 index 000000000000..5fdee793d7dc --- /dev/null +++ b/aztec-up/bin/aztec-nargo @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euo pipefail + +$(dirname $0)/.aztec-run aztecprotocol/noir $@ \ No newline at end of file diff --git a/aztec-up/bin/aztec-start b/aztec-up/bin/aztec-start new file mode 100755 index 000000000000..2a6af09063fc --- /dev/null +++ b/aztec-up/bin/aztec-start @@ -0,0 +1,9 @@ +#!/bin/bash +set -euo pipefail + +CMD="docker compose" + +# Fallback on docker-compose. +[ $CMD &>/dev/null ] || CMD="docker-compose" + +$CMD -f ~/.aztec/bin/docker-compose.yml up \ No newline at end of file diff --git a/aztec-up/bin/aztec-up b/aztec-up/bin/aztec-up new file mode 100755 index 000000000000..2c913d88ede5 --- /dev/null +++ b/aztec-up/bin/aztec-up @@ -0,0 +1,94 @@ +#!/bin/bash +set -euo pipefail + +# Define version if specified, otherwise set to "latest". +VERSION=${VERSION:-"latest"} + +# Check if Docker is available. +if ! command -v docker &>/dev/null; then + echo "Docker is not installed. Please install Docker and try again." + exit 1 +fi + +# Check if Docker is running. +if ! docker info &>/dev/null; then + echo "Docker is not running. Please start Docker and try again." + exit 1 +fi + +if ! docker compose &>/dev/null && ! command -v docker-compose &>/dev/null; then + echo "Install docker-compose, or a version of docker that supports 'docker compose' command." + exit 1 +fi + +# Create a "hidden" `$HOME/.aztec` dir, so as not to clutter the user's cwd. +AZTEC_PATH=$HOME/.aztec +BIN_PATH=$AZTEC_PATH/bin +rm -f $BIN_PATH/* && mkdir -p $BIN_PATH + +# Download containers from dockerhub. Tag them as latest. +function pull_container { + docker pull aztecprotocol/$1:$VERSION + + # If not latest, retag to be latest so it runs from scripts. + if [ $VERSION != "latest" ]; then + docker tag aztecprotocol/$1:$VERSION aztecprotocol/$1:latest + fi +} + +echo "Pulling aztec version $VERSION.." +pull_container aztec-sandbox +pull_container cli +pull_container noir + +# Download the Docker Compose file. Used by aztec-start. +curl -fsSL http://install.aztec.network/docker-compose.yml -o $BIN_PATH/docker-compose.yml + +function install_bin { + curl -fsSL http://install.aztec.network/$1 -o $BIN_PATH/$1 + chmod +x $BIN_PATH/$1 +} + +echo "Installing scripts in $BIN_PATH..." +install_bin aztec +install_bin aztec-cli +install_bin aztec-start +install_bin aztec-up +install_bin aztec-nargo + +function update_path_env_var { + TARGET_DIR="${1}" + # Check if the target directory is in the user's PATH. + if [[ ":$PATH:" != *":$TARGET_DIR:"* ]]; then + # Determine the user's shell. + SHELL_PROFILE="" + case $SHELL in + */bash) + SHELL_PROFILE="$HOME/.bashrc" + ;; + */zsh) + SHELL_PROFILE="$HOME/.zshrc" + ;; + # Add other shells as needed + *) + echo "Unsupported shell: $SHELL" + return + ;; + esac + # Inform the user about the change and ask for confirmation + echo "The directory $TARGET_DIR is not in your PATH." + echo "We'd like to add it to your $SHELL_PROFILE to make the binary accessible." + read -p "Do you want to proceed? (y/n) " -n 1 -r + echo # Move to a new line + if [[ $REPLY =~ ^[Yy]$ ]]; then + # Add the target directory to the user's PATH in their profile + echo "export PATH=\$PATH:$TARGET_DIR" >> "$SHELL_PROFILE" + echo "Updated PATH in $SHELL_PROFILE" + echo "Reload $SHELL_PROFILE to use the binary." + else + echo "Skipped updating PATH. You might need to add $TARGET_DIR to your PATH manually to use the binary." + fi + fi +} + +update_path_env_var $BIN_PATH/bin \ No newline at end of file diff --git a/aztec-up/bin/docker-compose.yml b/aztec-up/bin/docker-compose.yml new file mode 100644 index 000000000000..735466e39047 --- /dev/null +++ b/aztec-up/bin/docker-compose.yml @@ -0,0 +1,34 @@ +version: '3' +services: + ethereum: + image: ghcr.io/foundry-rs/foundry@sha256:29ba6e34379e79c342ec02d437beb7929c9e254261e8032b17e187be71a2609f + entrypoint: > + sh -c ' + if [ -n "$FORK_BLOCK_NUMBER" ] && [ -n "$FORK_URL" ]; then + exec anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent --fork-url "$FORK_URL" --fork-block-number "$FORK_BLOCK_NUMBER" + elif [ -n "$FORK_URL" ]; then + exec anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent --fork-url "$FORK_URL" + else + exec anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent + fi' + ports: + - '${SANDBOX_ANVIL_PORT:-8545}:8545' + + aztec: + image: 'aztecprotocol/aztec-sandbox' + ports: + - '${SANDBOX_AZTEC_NODE_PORT:-8079}:8079' + - '${SANDBOX_PXE_PORT:-8080}:8080' + environment: + DEBUG: # Loaded from the user shell if explicitly set + HOST_WORKDIR: '${PWD}' # Loaded from the user shell to show log files absolute path in host + ETHEREUM_HOST: http://ethereum:8545 + CHAIN_ID: 31337 + ARCHIVER_POLLING_INTERVAL_MS: 50 + P2P_BLOCK_CHECK_INTERVAL_MS: 50 + SEQ_TX_POLLING_INTERVAL_MS: 50 + WS_BLOCK_CHECK_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 + ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 + volumes: + - ./log:/usr/src/yarn-project/aztec-sandbox/log:rw diff --git a/aztec-up/deploy.sh b/aztec-up/deploy.sh new file mode 100755 index 000000000000..14f89b8e8db3 --- /dev/null +++ b/aztec-up/deploy.sh @@ -0,0 +1,23 @@ +set -e + +BRANCH=$1 + +export TF_VAR_BRANCH=$BRANCH + +# Downloads and installs `terraform` if it's not installed. +if [ ! -f /usr/local/bin/terraform ]; then + cd $HOME + TERRAFORM_VERSION=1.5.2 + curl -sSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip + sudo apt install -y unzip + unzip terraform.zip + sudo mv terraform /usr/local/bin/ + rm terraform.zip + cd - +fi + +echo "Initializing terraform" +terraform init -input=false -backend-config="key=aztec-sandbox-website/$BRANCH" + +echo "Applying terraform config" +terraform apply -input=false -auto-approve \ No newline at end of file diff --git a/aztec-up/terraform/main.tf b/aztec-up/terraform/main.tf new file mode 100644 index 000000000000..d6da5a366a28 --- /dev/null +++ b/aztec-up/terraform/main.tf @@ -0,0 +1,83 @@ +terraform { + backend "s3" { + bucket = "aztec-terraform" + region = "eu-west-2" + key = "aztec-up" + } + required_providers { + aws = { + source = "hashicorp/aws" + version = "3.74.2" + } + } +} + +# Define provider and region +provider "aws" { + region = "eu-west-2" +} + +data "terraform_remote_state" "aztec2_iac" { + backend = "s3" + config = { + bucket = "aztec-terraform" + key = "aztec2/iac" + region = "eu-west-2" + } +} + +# Create the website S3 bucket +resource "aws_s3_bucket" "install_bucket" { + bucket = "install.aztec.network" + website { + index_document = "aztec-up" + } +} + +resource "aws_s3_bucket_public_access_block" "install_bucket_public_access" { + bucket = aws_s3_bucket.install_bucket.id + + block_public_acls = false + ignore_public_acls = false + block_public_policy = false + restrict_public_buckets = false +} + +resource "aws_s3_bucket_policy" "install_bucket_policy" { + bucket = aws_s3_bucket.install_bucket.id + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Effect = "Allow" + Principal = "*" + Action = "s3:GetObject" + Resource = "arn:aws:s3:::${aws_s3_bucket.install_bucket.id}/*" + } + ] + }) +} + +# Upload files to s3 bucket if changes were detected +resource "null_resource" "upload_public_directory" { + triggers = { + always_run = "${timestamp()}" + } + + provisioner "local-exec" { + command = "aws s3 sync ../bin s3://${aws_s3_bucket.install_bucket.id}/" + } +} + +resource "aws_route53_record" "subdomain_record" { + zone_id = data.terraform_remote_state.aztec2_iac.outputs.aws_route53_zone_id + name = "install.aztec.network" + type = "A" + + alias { + name = "${aws_s3_bucket.install_bucket.website_endpoint}" + zone_id = "${aws_s3_bucket.install_bucket.hosted_zone_id}" + evaluate_target_health = false + } +} From bd17f287abe0f41d4b69e171f54fda1e11ed3ab9 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Wed, 6 Dec 2023 23:54:19 +0000 Subject: [PATCH 2/8] wip --- aztec-up/bin/.aztec-run | 45 ++++++++++++------ aztec-up/bin/aztec-cli | 3 -- aztec-up/bin/aztec-start | 9 ---- aztec-up/bin/aztec-up | 93 +------------------------------------- aztec-up/terraform/main.tf | 15 ++++-- 5 files changed, 43 insertions(+), 122 deletions(-) delete mode 100755 aztec-up/bin/aztec-start diff --git a/aztec-up/bin/.aztec-run b/aztec-up/bin/.aztec-run index 1ad06ed2c9d9..8621f54f210e 100755 --- a/aztec-up/bin/.aztec-run +++ b/aztec-up/bin/.aztec-run @@ -1,19 +1,16 @@ #!/usr/bin/env bash # The script starts a Docker container passing any commands and arguments to the command running inside the container. - +# It handles mounting paths into the container. +# It handles networking comms back to the host. set -euo pipefail IMAGE=${1:-} shift -if [ -z "$IMAGE" ]; then - echo "Provide a container image in IMAGE." -fi - VERSION=${VERSION:-"latest"} # Any host bindings we might send to the container. -DOCKER_HOST="" +DOCKER_HOST_BINDS="" # Volumes to pass to the container. DOCKER_VOLUME="" @@ -23,10 +20,21 @@ if ! command -v docker &> /dev/null; then exit 1 fi +# Colors. +yellow="\033[33m" +reset="\033[0m" + # Set up host.docker.internal alias on Linux, just like it is on mac. UNAME=$(uname -s) if [ "$UNAME" == "Linux" ]; then - DOCKER_HOST="$DOCKER_HOST --add-host host.docker.internal:host-gateway" + if docker info 2>/dev/null | grep -q rootless; then + # We're in rootless docker. Probe for the host ip and use that. + ip=$(hostname -I | head | tr -d ' ') + echo -e "${yellow}WARNING: Running within rootless docker. Using $ip as host ip. Ensure listening services are listening on this interface.${reset}" + DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:$ip" + else + DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:host-gateway" + fi fi # Build a list of mount points @@ -54,19 +62,27 @@ function add_mount() { # Always mount the CWD into the container. add_mount "$PWD" +# Substitute any references to localhost with our host gateway. +args=("$@") +for i in "${!args[@]}"; do + args[$i]=${args[$i]//localhost/host.docker.internal} +done + # Check if it's either a filename or a directory that exists outside the CWD. # If it is then mount inside the container. # NOTE: This won't work with assignement-style flags, e.g. --outdir=/foo -for (( i=1; i <= "$#"; i++ )); do - arg_value=${!i} - if [[ -f "$arg_value" || -d "$arg_value" && $(realpath $arg_value) != ${PWD}* ]]; then - add_mount "$arg_value" +for arg in "${args[@]}"; do + if [[ -f "$arg" || -d "$arg" && $(realpath $arg) != ${PWD}* ]]; then + add_mount "$arg" fi done DOCKER_ENV="" for env in ${ENV_VARS_TO_INJECT:-}; do - DOCKER_ENV+="-e $env:${!env} " + # First substitute any reference to localhost with our host gateway. + env=${env//localhost/host.docker.internal} + # Inject into container. + DOCKER_ENV+="-e $env:${!env:-} " done DOCKER_VOLUME="$DOCKER_VOLUME -v cache:/cache" @@ -75,7 +91,8 @@ docker run \ --rm \ --user $(id -u):$(id -g) \ --workdir "$PWD" \ - $DOCKER_HOST \ + --net host \ + $DOCKER_HOST_BINDS \ $DOCKER_ENV \ $DOCKER_VOLUME \ - $IMAGE:$VERSION $@ + $IMAGE:$VERSION ${args[@]} diff --git a/aztec-up/bin/aztec-cli b/aztec-up/bin/aztec-cli index e3acd66f1639..7d8b75f41469 100755 --- a/aztec-up/bin/aztec-cli +++ b/aztec-up/bin/aztec-cli @@ -6,7 +6,4 @@ set -euo pipefail export ENV_VARS_TO_INJECT="PXE_URL PRIVATE_KEY DEBUG" export PXE_URL=${PXE_URL:-"http://host.docker.internal:8080"} -# Replace 'localhost' with 'host.docker.internal' in PXE_URL -export PXE_URL=${PXE_URL//localhost/host.docker.internal} - $(dirname $0)/.aztec-run aztecprotocol/cli $@ \ No newline at end of file diff --git a/aztec-up/bin/aztec-start b/aztec-up/bin/aztec-start deleted file mode 100755 index 2a6af09063fc..000000000000 --- a/aztec-up/bin/aztec-start +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -euo pipefail - -CMD="docker compose" - -# Fallback on docker-compose. -[ $CMD &>/dev/null ] || CMD="docker-compose" - -$CMD -f ~/.aztec/bin/docker-compose.yml up \ No newline at end of file diff --git a/aztec-up/bin/aztec-up b/aztec-up/bin/aztec-up index 2c913d88ede5..d3b88660090d 100755 --- a/aztec-up/bin/aztec-up +++ b/aztec-up/bin/aztec-up @@ -1,94 +1,5 @@ #!/bin/bash set -euo pipefail -# Define version if specified, otherwise set to "latest". -VERSION=${VERSION:-"latest"} - -# Check if Docker is available. -if ! command -v docker &>/dev/null; then - echo "Docker is not installed. Please install Docker and try again." - exit 1 -fi - -# Check if Docker is running. -if ! docker info &>/dev/null; then - echo "Docker is not running. Please start Docker and try again." - exit 1 -fi - -if ! docker compose &>/dev/null && ! command -v docker-compose &>/dev/null; then - echo "Install docker-compose, or a version of docker that supports 'docker compose' command." - exit 1 -fi - -# Create a "hidden" `$HOME/.aztec` dir, so as not to clutter the user's cwd. -AZTEC_PATH=$HOME/.aztec -BIN_PATH=$AZTEC_PATH/bin -rm -f $BIN_PATH/* && mkdir -p $BIN_PATH - -# Download containers from dockerhub. Tag them as latest. -function pull_container { - docker pull aztecprotocol/$1:$VERSION - - # If not latest, retag to be latest so it runs from scripts. - if [ $VERSION != "latest" ]; then - docker tag aztecprotocol/$1:$VERSION aztecprotocol/$1:latest - fi -} - -echo "Pulling aztec version $VERSION.." -pull_container aztec-sandbox -pull_container cli -pull_container noir - -# Download the Docker Compose file. Used by aztec-start. -curl -fsSL http://install.aztec.network/docker-compose.yml -o $BIN_PATH/docker-compose.yml - -function install_bin { - curl -fsSL http://install.aztec.network/$1 -o $BIN_PATH/$1 - chmod +x $BIN_PATH/$1 -} - -echo "Installing scripts in $BIN_PATH..." -install_bin aztec -install_bin aztec-cli -install_bin aztec-start -install_bin aztec-up -install_bin aztec-nargo - -function update_path_env_var { - TARGET_DIR="${1}" - # Check if the target directory is in the user's PATH. - if [[ ":$PATH:" != *":$TARGET_DIR:"* ]]; then - # Determine the user's shell. - SHELL_PROFILE="" - case $SHELL in - */bash) - SHELL_PROFILE="$HOME/.bashrc" - ;; - */zsh) - SHELL_PROFILE="$HOME/.zshrc" - ;; - # Add other shells as needed - *) - echo "Unsupported shell: $SHELL" - return - ;; - esac - # Inform the user about the change and ask for confirmation - echo "The directory $TARGET_DIR is not in your PATH." - echo "We'd like to add it to your $SHELL_PROFILE to make the binary accessible." - read -p "Do you want to proceed? (y/n) " -n 1 -r - echo # Move to a new line - if [[ $REPLY =~ ^[Yy]$ ]]; then - # Add the target directory to the user's PATH in their profile - echo "export PATH=\$PATH:$TARGET_DIR" >> "$SHELL_PROFILE" - echo "Updated PATH in $SHELL_PROFILE" - echo "Reload $SHELL_PROFILE to use the binary." - else - echo "Skipped updating PATH. You might need to add $TARGET_DIR to your PATH manually to use the binary." - fi - fi -} - -update_path_env_var $BIN_PATH/bin \ No newline at end of file +export SKIP_TITLE=1 +bash -i <(curl -s http://install.aztec.network) \ No newline at end of file diff --git a/aztec-up/terraform/main.tf b/aztec-up/terraform/main.tf index d6da5a366a28..2465082e3fa4 100644 --- a/aztec-up/terraform/main.tf +++ b/aztec-up/terraform/main.tf @@ -7,7 +7,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "3.74.2" + version = "5.29.0" } } } @@ -29,8 +29,13 @@ data "terraform_remote_state" "aztec2_iac" { # Create the website S3 bucket resource "aws_s3_bucket" "install_bucket" { bucket = "install.aztec.network" - website { - index_document = "aztec-up" +} + +resource "aws_s3_bucket_website_configuration" "website_bucket" { + bucket = aws_s3_bucket.install_bucket.id + + index_document { + suffix = "aztec-install" } } @@ -76,8 +81,8 @@ resource "aws_route53_record" "subdomain_record" { type = "A" alias { - name = "${aws_s3_bucket.install_bucket.website_endpoint}" + name = "${aws_s3_bucket_website_configuration.website_bucket.website_domain}" zone_id = "${aws_s3_bucket.install_bucket.hosted_zone_id}" - evaluate_target_health = false + evaluate_target_health = true } } From 4d522b48a89ecf32362b9df66af9b4049ec41f9a Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 7 Dec 2023 00:06:42 +0000 Subject: [PATCH 3/8] wip --- aztec-up/bin/aztec-install | 152 +++++++++++++++++++++++++++++++++++++ aztec-up/bin/aztec-sandbox | 9 +++ 2 files changed, 161 insertions(+) create mode 100755 aztec-up/bin/aztec-install create mode 100755 aztec-up/bin/aztec-sandbox diff --git a/aztec-up/bin/aztec-install b/aztec-up/bin/aztec-install new file mode 100755 index 000000000000..e7760cfff8d0 --- /dev/null +++ b/aztec-up/bin/aztec-install @@ -0,0 +1,152 @@ +#!/bin/bash +set -euo pipefail + +# Colors +g="\033[32m" # Green +y="\033[33m" # Yellow +b="\033[34m" # Blue +p="\033[35m" # Purple +r="\033[0m" # Reset +bold="\033[1m" + +# Function to replace characters and add color +function print_colored() { + local b=$'\033[34m' # Blue + local y=$'\033[33m' # Yellow + local r=$'\033[0m' # Reset + echo "$1" | sed -E "s/(█+)/${b}\1${y}/g" +} + +function title() { + # Print each line with colors + print_colored " █████╗ ███████╗████████╗███████╗ ██████╗" + print_colored "██╔══██╗╚══███╔╝╚══██╔══╝██╔════╝██╔════╝" + print_colored "███████║ ███╔╝ ██║ █████╗ ██║" + print_colored "██╔══██║ ███╔╝ ██║ ██╔══╝ ██║" + print_colored "██║ ██║███████╗ ██║ ███████╗╚██████╗" + print_colored "╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝ ╚═════╝" + echo -e "${r}" + echo -e "Welcome to the ${bold}${b}Aztec${r} installer! Your journey into blockchain privacy begins... ${bold}${p}now${r}." + echo -e "We presently leverage docker to simplify releases of our complex project. Please ensure it's installed." + echo + echo -e "This will install the following scripts and update your PATH if necessary:" + echo -e " ${bold}${g}aztec${r} - launches various infrastructure subsystems (sequencer, prover, pxe, etc)." + echo -e " ${bold}${g}aztec-cli${r} - a command line tool for interfacing and experimenting with infrastructure." + echo -e " ${bold}${g}aztec-nargo${r} - aztec's build of nargo, the noir compiler toolchain." + echo -e " ${bold}${g}aztec-sandbox${r} - a wrapper around docker-compose that launches services needed for sandbox testing." + echo -e " ${bold}${g}aztec-up${r} - a tool to upgrade the aztec toolchain to the latest, or specific versions." + echo + read -p "Do you wish to continue? (y/n)" -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 0 + fi +} + +AZTEC_PATH=$HOME/.aztec +BIN_PATH=$AZTEC_PATH/bin + +# Define version if specified, otherwise set to "latest". +VERSION=${VERSION:-"latest"} +INSTALL_HOST=install.aztec.network.s3-website.eu-west-2.amazonaws.com + +[ -z "${SKIP_TITLE:-}" ] && title + +# Check if Docker is available. +if ! command -v docker &>/dev/null; then + echo "Docker is not installed. Please install Docker and try again." + exit 1 +fi + +# Check if Docker is running. +if ! docker info &>/dev/null; then + echo "Docker is not running. Please start Docker and try again." + exit 1 +fi + +if ! docker compose &>/dev/null && ! command -v docker-compose &>/dev/null; then + echo "WARNING: 'docker compose' command not supported and docker-compose not found." + echo "You can continue installation, but aztec-start will not work." + echo "If you want to use it, upgrade docker, or install docker-compose." + exit 1 + read -p "Add it to $SHELL_PROFILE to make the aztec binaries accessible? (y/n)" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + # Add the target directory to the user's PATH in their profile. + echo "export PATH=\$PATH:$TARGET_DIR" >> "$SHELL_PROFILE" + echo "Updated PATH. Starting fresh shell..." + $SHELL + else + echo "Skipped updating PATH. You might need to add $TARGET_DIR to your PATH manually to use the binary." + fi +fi + +# Create a "hidden" `$HOME/.aztec` dir, so as not to clutter the user's cwd. +rm -f $BIN_PATH/* && mkdir -p $BIN_PATH + +# Download containers from dockerhub. Tag them as latest. +function pull_container { + docker pull aztecprotocol/$1:$VERSION + + # If not latest, retag to be latest so it runs from scripts. + if [ $VERSION != "latest" ]; then + docker tag aztecprotocol/$1:$VERSION aztecprotocol/$1:latest + fi +} + +echo "Pulling aztec version $VERSION.." +pull_container aztec-sandbox +pull_container cli +pull_container noir + +# Download the Docker Compose file. Used by aztec-start. +curl -fsSL http://$INSTALL_HOST/docker-compose.yml -o $BIN_PATH/docker-compose.yml + +function install_bin { + curl -fsSL http://$INSTALL_HOST/$1 -o $BIN_PATH/$1 + chmod +x $BIN_PATH/$1 +} + +echo "Installing scripts in $BIN_PATH..." +install_bin .aztec-run +install_bin aztec +install_bin aztec-cli +install_bin aztec-start +install_bin aztec-up +install_bin aztec-nargo + +function update_path_env_var { + TARGET_DIR="${1}" + # Check if the target directory is in the user's PATH. + if [[ ":$PATH:" != *":$TARGET_DIR:"* ]]; then + # Determine the user's shell. + SHELL_PROFILE="" + case $SHELL in + */bash) + SHELL_PROFILE="$HOME/.bashrc" + ;; + */zsh) + SHELL_PROFILE="$HOME/.zshrc" + ;; + # Add other shells as needed + *) + echo "Unsupported shell: $SHELL" + return + ;; + esac + # Inform the user about the change and ask for confirmation + echo "The directory $TARGET_DIR is not in your PATH." + read -p "Add it to $SHELL_PROFILE to make the aztec binaries accessible? (y/n)" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + # Add the target directory to the user's PATH in their profile. + echo "export PATH=\$PATH:$TARGET_DIR" >> "$SHELL_PROFILE" + echo "Updated PATH. Starting fresh shell..." + $SHELL + else + echo "Skipped updating PATH. You might need to add $TARGET_DIR to your PATH manually to use the binary." + fi + fi +} + +update_path_env_var $BIN_PATH \ No newline at end of file diff --git a/aztec-up/bin/aztec-sandbox b/aztec-up/bin/aztec-sandbox new file mode 100755 index 000000000000..2a6af09063fc --- /dev/null +++ b/aztec-up/bin/aztec-sandbox @@ -0,0 +1,9 @@ +#!/bin/bash +set -euo pipefail + +CMD="docker compose" + +# Fallback on docker-compose. +[ $CMD &>/dev/null ] || CMD="docker-compose" + +$CMD -f ~/.aztec/bin/docker-compose.yml up \ No newline at end of file From 7e296fcc9aa9df38b51f6b0520380c345adf7e33 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 7 Dec 2023 00:18:31 +0000 Subject: [PATCH 4/8] wip --- aztec-up/bin/aztec-install | 44 ++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/aztec-up/bin/aztec-install b/aztec-up/bin/aztec-install index e7760cfff8d0..49ad7de7af82 100755 --- a/aztec-up/bin/aztec-install +++ b/aztec-up/bin/aztec-install @@ -18,7 +18,7 @@ function print_colored() { } function title() { - # Print each line with colors + echo print_colored " █████╗ ███████╗████████╗███████╗ ██████╗" print_colored "██╔══██╗╚══███╔╝╚══██╔══╝██╔════╝██╔════╝" print_colored "███████║ ███╔╝ ██║ █████╗ ██║" @@ -43,6 +43,14 @@ function title() { fi } +function info { + echo -e "${g}$1${r}" +} + +function warn { + echo -e "${y}$1${r}" +} + AZTEC_PATH=$HOME/.aztec BIN_PATH=$AZTEC_PATH/bin @@ -54,31 +62,19 @@ INSTALL_HOST=install.aztec.network.s3-website.eu-west-2.amazonaws.com # Check if Docker is available. if ! command -v docker &>/dev/null; then - echo "Docker is not installed. Please install Docker and try again." + warn "Docker is not installed. Please install Docker and try again." exit 1 fi # Check if Docker is running. if ! docker info &>/dev/null; then - echo "Docker is not running. Please start Docker and try again." + warn "Docker is not running. Please start Docker and try again." exit 1 fi if ! docker compose &>/dev/null && ! command -v docker-compose &>/dev/null; then - echo "WARNING: 'docker compose' command not supported and docker-compose not found." - echo "You can continue installation, but aztec-start will not work." - echo "If you want to use it, upgrade docker, or install docker-compose." - exit 1 - read -p "Add it to $SHELL_PROFILE to make the aztec binaries accessible? (y/n)" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - # Add the target directory to the user's PATH in their profile. - echo "export PATH=\$PATH:$TARGET_DIR" >> "$SHELL_PROFILE" - echo "Updated PATH. Starting fresh shell..." - $SHELL - else - echo "Skipped updating PATH. You might need to add $TARGET_DIR to your PATH manually to use the binary." - fi + warn "WARNING: 'docker compose' not supported and docker-compose not found." + warn "Continuing installation, but aztec-start will not work." fi # Create a "hidden" `$HOME/.aztec` dir, so as not to clutter the user's cwd. @@ -94,7 +90,7 @@ function pull_container { fi } -echo "Pulling aztec version $VERSION.." +info "Pulling aztec version $VERSION..." pull_container aztec-sandbox pull_container cli pull_container noir @@ -107,7 +103,7 @@ function install_bin { chmod +x $BIN_PATH/$1 } -echo "Installing scripts in $BIN_PATH..." +info "Installing scripts in $BIN_PATH..." install_bin .aztec-run install_bin aztec install_bin aztec-cli @@ -135,18 +131,20 @@ function update_path_env_var { ;; esac # Inform the user about the change and ask for confirmation - echo "The directory $TARGET_DIR is not in your PATH." + warn "The directory $TARGET_DIR is not in your PATH." read -p "Add it to $SHELL_PROFILE to make the aztec binaries accessible? (y/n)" -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then # Add the target directory to the user's PATH in their profile. echo "export PATH=\$PATH:$TARGET_DIR" >> "$SHELL_PROFILE" - echo "Updated PATH. Starting fresh shell..." + info "Done! Starting fresh shell..." $SHELL else - echo "Skipped updating PATH. You might need to add $TARGET_DIR to your PATH manually to use the binary." + warn "Skipped updating PATH. You might need to add $TARGET_DIR to your PATH manually to use the binary." fi fi } -update_path_env_var $BIN_PATH \ No newline at end of file +update_path_env_var $BIN_PATH + +info "Done!" \ No newline at end of file From e1062a233ecdf4a0d6f41d98a985daeb1637970f Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 7 Dec 2023 16:26:11 +0000 Subject: [PATCH 5/8] wip --- aztec-up/bin/.aztec-run | 7 ++++--- aztec-up/bin/aztec-install | 8 +++++--- aztec-up/bin/aztec-sandbox | 8 +++++--- yarn-project/aztec-sandbox/src/bin/index.ts | 14 +++++++++++++- yarn-project/cli/src/index.ts | 16 ++++++++++++++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/aztec-up/bin/.aztec-run b/aztec-up/bin/.aztec-run index 8621f54f210e..c338bede2e12 100755 --- a/aztec-up/bin/.aztec-run +++ b/aztec-up/bin/.aztec-run @@ -71,7 +71,8 @@ done # Check if it's either a filename or a directory that exists outside the CWD. # If it is then mount inside the container. # NOTE: This won't work with assignement-style flags, e.g. --outdir=/foo -for arg in "${args[@]}"; do +for i in "${!args[@]}"; do + arg=${args[$i]} if [[ -f "$arg" || -d "$arg" && $(realpath $arg) != ${PWD}* ]]; then add_mount "$arg" fi @@ -88,11 +89,11 @@ done DOCKER_VOLUME="$DOCKER_VOLUME -v cache:/cache" docker run \ + -ti \ --rm \ --user $(id -u):$(id -g) \ --workdir "$PWD" \ - --net host \ $DOCKER_HOST_BINDS \ $DOCKER_ENV \ $DOCKER_VOLUME \ - $IMAGE:$VERSION ${args[@]} + $IMAGE:$VERSION ${args[@]:-} diff --git a/aztec-up/bin/aztec-install b/aztec-up/bin/aztec-install index 49ad7de7af82..653e80e9886b 100755 --- a/aztec-up/bin/aztec-install +++ b/aztec-up/bin/aztec-install @@ -27,7 +27,8 @@ function title() { print_colored "╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝ ╚═════╝" echo -e "${r}" echo -e "Welcome to the ${bold}${b}Aztec${r} installer! Your journey into blockchain privacy begins... ${bold}${p}now${r}." - echo -e "We presently leverage docker to simplify releases of our complex project. Please ensure it's installed." + echo -e "We presently leverage docker to simplify releases of our complex project." + echo -e "Please ensure it's installed for your platform: https://docs.docker.com/engine/install" echo echo -e "This will install the following scripts and update your PATH if necessary:" echo -e " ${bold}${g}aztec${r} - launches various infrastructure subsystems (sequencer, prover, pxe, etc)." @@ -74,7 +75,7 @@ fi if ! docker compose &>/dev/null && ! command -v docker-compose &>/dev/null; then warn "WARNING: 'docker compose' not supported and docker-compose not found." - warn "Continuing installation, but aztec-start will not work." + warn "Continuing installation, but aztec-sandbox will not work." fi # Create a "hidden" `$HOME/.aztec` dir, so as not to clutter the user's cwd. @@ -101,13 +102,14 @@ curl -fsSL http://$INSTALL_HOST/docker-compose.yml -o $BIN_PATH/docker-compose.y function install_bin { curl -fsSL http://$INSTALL_HOST/$1 -o $BIN_PATH/$1 chmod +x $BIN_PATH/$1 + echo "Installed: $BIN_PATH/$1" } info "Installing scripts in $BIN_PATH..." install_bin .aztec-run install_bin aztec install_bin aztec-cli -install_bin aztec-start +install_bin aztec-sandbox install_bin aztec-up install_bin aztec-nargo diff --git a/aztec-up/bin/aztec-sandbox b/aztec-up/bin/aztec-sandbox index 2a6af09063fc..ccbe97470456 100755 --- a/aztec-up/bin/aztec-sandbox +++ b/aztec-up/bin/aztec-sandbox @@ -1,9 +1,11 @@ #!/bin/bash set -euo pipefail -CMD="docker compose" +# Change working dir, so relative volume mounts are in the right place. +cd ~/.aztec -# Fallback on docker-compose. -[ $CMD &>/dev/null ] || CMD="docker-compose" +# Favour 'docker compose', falling back on docker-compose. +CMD="docker compose" +$CMD &>/dev/null || CMD="docker-compose" $CMD -f ~/.aztec/bin/docker-compose.yml up \ No newline at end of file diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index 85e8ac2e6aed..aa3acb3ce65b 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -9,6 +9,7 @@ import { NoirCommit } from '@aztec/noir-compiler/versions'; import { BootstrapNode, getP2PConfigEnvVars } from '@aztec/p2p'; import { GrumpkinScalar, PXEService, createPXERpcServer } from '@aztec/pxe'; +import { resolve as dnsResolve } from 'dns'; import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; import { mnemonicToAccount } from 'viem/accounts'; @@ -28,8 +29,19 @@ enum SandboxMode { P2PBootstrap = 'p2p-bootstrap', } +/** + * If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat + * localhost as being host.docker.internal. + */ +function getLocalhost() { + return new Promise(resolve => + dnsResolve('host.docker.internal', err => (err ? resolve('localhost') : resolve('host.docker.internal'))), + ); +} + +const LOCALHOST = await getLocalhost(); const { - AZTEC_NODE_URL = 'http://localhost:8079', + AZTEC_NODE_URL = `http://${LOCALHOST}:8079`, AZTEC_NODE_PORT = 8079, PXE_PORT = 8080, MODE = 'sandbox', diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index 6f44a6ca8b31..27a7275880f3 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -4,6 +4,7 @@ import { fileURLToPath } from '@aztec/foundation/url'; import { addNoirCompilerCommanderActions } from '@aztec/noir-compiler/cli'; import { Command, Option } from 'commander'; +import { resolve as dnsResolve } from 'dns'; import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; @@ -23,7 +24,18 @@ import { parseTxHash, } from './utils.js'; -const { ETHEREUM_HOST = 'http://localhost:8545', PRIVATE_KEY, API_KEY } = process.env; +/** + * If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat + * localhost as being host.docker.internal. + */ +function getLocalhost() { + return new Promise(resolve => + dnsResolve('host.docker.internal', err => (err ? resolve('localhost') : resolve('host.docker.internal'))), + ); +} + +const LOCALHOST = await getLocalhost(); +const { ETHEREUM_HOST = `http://${LOCALHOST}:8545`, PRIVATE_KEY, API_KEY } = process.env; /** * Returns commander program that defines the CLI. @@ -42,7 +54,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { const pxeOption = new Option('-u, --rpc-url ', 'URL of the PXE') .env('PXE_URL') - .default('http://localhost:8080') + .default(`http://${LOCALHOST}:8080`) .makeOptionMandatory(true); const createPrivateKeyOption = (description: string, mandatory: boolean) => From 3f6b2e176a78a5c6d82d85db445824b236f40005 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 8 Dec 2023 11:23:50 +0000 Subject: [PATCH 6/8] Top level init bb.js, but better scoped imports to not incur cost too early. --- barretenberg/ts/src/barretenberg/index.ts | 6 +- yarn-project/aztec.js/src/api/init.ts | 11 +- yarn-project/aztec.js/src/index.ts | 9 +- .../barretenberg/crypto/aes128/index.test.ts | 5 +- .../crypto/grumpkin/index.test.ts | 4 +- yarn-project/cli/src/cmds/add_note.ts | 2 +- yarn-project/cli/src/index.ts | 5 +- yarn-project/cli/src/parse_args.ts | 248 ++++++++++++++++++ yarn-project/cli/src/test/utils.test.ts | 3 +- yarn-project/cli/src/utils.ts | 234 +---------------- yarn-project/foundation/src/abi/abi_coder.ts | 2 +- yarn-project/foundation/src/abi/decoder.ts | 4 +- yarn-project/foundation/src/abi/encoder.ts | 4 +- .../foundation/src/abi/function_selector.ts | 8 +- yarn-project/foundation/src/abi/utils.ts | 2 +- .../foundation/src/eth-address/index.ts | 3 +- yarn-project/foundation/src/fields/fields.ts | 2 +- yarn-project/types/src/tx/tx_hash.ts | 5 +- 18 files changed, 293 insertions(+), 264 deletions(-) create mode 100644 yarn-project/cli/src/parse_args.ts diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 6019b24e88fa..3210c48ee860 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -65,7 +65,7 @@ export class BarretenbergSync extends BarretenbergApiSync { static getSingleton() { if (!barretenbergSyncSingleton) { - throw new Error('Initialise first via initSingleton().'); + throw new Error('First call BarretenbergSync.initSingleton() on @aztec/bb.js module.'); } return barretenbergSyncSingleton; } @@ -75,8 +75,8 @@ export class BarretenbergSync extends BarretenbergApiSync { } } -// If we're loading this module in a test environment, just init the singleton immediately for convienience. -if (process.env.NODE_ENV === 'test') { +// If we're in ESM environment, use top level await. CJS users need to call it manually. +if (typeof __filename === 'undefined') { // Need to ignore for cjs build. // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore diff --git a/yarn-project/aztec.js/src/api/init.ts b/yarn-project/aztec.js/src/api/init.ts index 2b5203c9d0b0..9654b9c80427 100644 --- a/yarn-project/aztec.js/src/api/init.ts +++ b/yarn-project/aztec.js/src/api/init.ts @@ -1 +1,10 @@ -export { init as initAztecJs } from '@aztec/foundation/crypto'; +import { init } from '@aztec/foundation/crypto'; + +/** + * This should only be needed to be called in CJS environments that don't have top level await. + * Initializes any asynchronous subsystems required to use the library. + * At time of writing, this is just our foundation crypto lib. + */ +export async function initAztecJs() { + await init(); +} diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index c7c1bcc8f4ef..1638f69a0859 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -16,6 +16,8 @@ * import { AztecAddress } from '@aztec/aztec.js/aztec_address'; * import { EthAddress } from '@aztec/aztec.js/eth_address'; * ``` + * + * TODO: Ultimately reimplement this mega exporter by mega exporting a granular api (then deprecate it). */ export { WaitOpts, @@ -124,7 +126,7 @@ export { fileURLToPath } from '@aztec/foundation/url'; export { sleep } from '@aztec/foundation/sleep'; export { elapsed } from '@aztec/foundation/timer'; export { retry, retryUntil } from '@aztec/foundation/retry'; -export { sha256, init } from '@aztec/foundation/crypto'; +export { sha256 } from '@aztec/foundation/crypto'; export { to2Fields, toBigInt } from '@aztec/foundation/serialize'; export { toBigIntBE } from '@aztec/foundation/bigint-buffer'; export { makeFetch } from '@aztec/foundation/json-rpc/client'; @@ -135,3 +137,8 @@ export { DeployL1Contracts, L1ContractArtifactsForDeployment, } from '@aztec/ethereum'; + +// Start of section that exports public api via granular api. +// Here you *can* do `export *` as the granular api defacto exports things explicitly. +// This entire index file will be deprecated at some point after we're satisfied. +export * from './api/init.js'; diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/aes128/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/aes128/index.test.ts index df34d06d3058..9b8afc328e2c 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/aes128/index.test.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/aes128/index.test.ts @@ -1,5 +1,3 @@ -import { init } from '@aztec/foundation/crypto'; - import { createCipheriv, createDecipheriv, randomBytes } from 'crypto'; import { Aes128 } from './index.js'; @@ -7,8 +5,7 @@ import { Aes128 } from './index.js'; describe('aes128', () => { let aes128!: Aes128; - beforeAll(async () => { - await init(); + beforeAll(() => { aes128 = new Aes128(); }); diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.test.ts index 671c019291b0..154ab39075fb 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.test.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.test.ts @@ -1,4 +1,3 @@ -import { init } from '@aztec/foundation/crypto'; import { createDebugLogger } from '@aztec/foundation/log'; import { GrumpkinScalar, Point } from '../../../index.js'; @@ -9,8 +8,7 @@ const debug = createDebugLogger('bb:grumpkin_test'); describe('grumpkin', () => { let grumpkin!: Grumpkin; - beforeAll(async () => { - await init(); + beforeAll(() => { grumpkin = new Grumpkin(); }); diff --git a/yarn-project/cli/src/cmds/add_note.ts b/yarn-project/cli/src/cmds/add_note.ts index 643400343709..33ad5a52f80a 100644 --- a/yarn-project/cli/src/cmds/add_note.ts +++ b/yarn-project/cli/src/cmds/add_note.ts @@ -3,7 +3,7 @@ import { DebugLogger } from '@aztec/foundation/log'; import { ExtendedNote, Note, TxHash } from '@aztec/types'; import { createCompatibleClient } from '../client.js'; -import { parseFields } from '../utils.js'; +import { parseFields } from '../parse_args.js'; /** * diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index 27a7275880f3..08fd0c44b5ec 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -1,4 +1,3 @@ -import { initAztecJs } from '@aztec/aztec.js/init'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; import { addNoirCompilerCommanderActions } from '@aztec/noir-compiler/cli'; @@ -22,7 +21,7 @@ import { parsePublicKey, parseSaltFromHexString, parseTxHash, -} from './utils.js'; +} from './parse_args.js'; /** * If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat @@ -63,8 +62,6 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { .argParser(parsePrivateKey) .makeOptionMandatory(mandatory); - program.hook('preAction', initAztecJs); - program .command('deploy-l1-contracts') .description('Deploys all necessary Ethereum contracts for Aztec.') diff --git a/yarn-project/cli/src/parse_args.ts b/yarn-project/cli/src/parse_args.ts new file mode 100644 index 000000000000..e2641005cd27 --- /dev/null +++ b/yarn-project/cli/src/parse_args.ts @@ -0,0 +1,248 @@ +import { FunctionSelector } from '@aztec/aztec.js/abi'; +import { AztecAddress } from '@aztec/aztec.js/aztec_address'; +import { EthAddress } from '@aztec/aztec.js/eth_address'; +import { Fr, GrumpkinScalar, Point } from '@aztec/aztec.js/fields'; +import { LogId } from '@aztec/aztec.js/log_id'; +import { TxHash } from '@aztec/aztec.js/tx_hash'; + +import { InvalidArgumentError } from 'commander'; + +/** + * Removes the leading 0x from a hex string. If no leading 0x is found the string is returned unchanged. + * @param hex - A hex string + * @returns A new string with leading 0x removed + */ +const stripLeadingHex = (hex: string) => { + if (hex.length > 2 && hex.startsWith('0x')) { + return hex.substring(2); + } + return hex; +}; + +/** + * Parses a hex encoded string to an Fr integer to be used as salt + * @param str - Hex encoded string + * @returns A integer to be used as salt + */ +export function parseSaltFromHexString(str: string): Fr { + const hex = stripLeadingHex(str); + + // ensure it's a hex string + if (!hex.match(/^[0-9a-f]+$/i)) { + throw new InvalidArgumentError('Invalid hex string'); + } + + // pad it so that we may read it as a buffer. + // Buffer needs _exactly_ two hex characters per byte + const padded = hex.length % 2 === 1 ? '0' + hex : hex; + + // finally, turn it into an integer + return Fr.fromBuffer(Buffer.from(padded, 'hex')); +} + +/** + * Parses an AztecAddress from a string. + * @param address - A serialized Aztec address + * @returns An Aztec address + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parseAztecAddress(address: string): AztecAddress { + try { + return AztecAddress.fromString(address); + } catch { + throw new InvalidArgumentError(`Invalid address: ${address}`); + } +} + +/** + * Parses an Ethereum address from a string. + * @param address - A serialized Ethereum address + * @returns An Ethereum address + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parseEthereumAddress(address: string): EthAddress { + try { + return EthAddress.fromString(address); + } catch { + throw new InvalidArgumentError(`Invalid address: ${address}`); + } +} + +/** + * Parses an AztecAddress from a string. + * @param address - A serialized Aztec address + * @returns An Aztec address + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parseOptionalAztecAddress(address: string): AztecAddress | undefined { + if (!address) { + return undefined; + } + return parseAztecAddress(address); +} + +/** + * Parses an optional log ID string into a LogId object. + * + * @param logId - The log ID string to parse. + * @returns The parsed LogId object, or undefined if the log ID is missing or empty. + */ +export function parseOptionalLogId(logId: string): LogId | undefined { + if (!logId) { + return undefined; + } + return LogId.fromString(logId); +} + +/** + * Parses a selector from a string. + * @param selector - A serialized selector. + * @returns A selector. + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parseOptionalSelector(selector: string): FunctionSelector | undefined { + if (!selector) { + return undefined; + } + try { + return FunctionSelector.fromString(selector); + } catch { + throw new InvalidArgumentError(`Invalid selector: ${selector}`); + } +} + +/** + * Parses a string into an integer or returns undefined if the input is falsy. + * + * @param value - The string to parse into an integer. + * @returns The parsed integer, or undefined if the input string is falsy. + * @throws If the input is not a valid integer. + */ +export function parseOptionalInteger(value: string): number | undefined { + if (!value) { + return undefined; + } + const parsed = Number(value); + if (!Number.isInteger(parsed)) { + throw new InvalidArgumentError('Invalid integer.'); + } + return parsed; +} + +/** + * Parses a TxHash from a string. + * @param txHash - A transaction hash + * @returns A TxHash instance + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parseTxHash(txHash: string): TxHash { + try { + return TxHash.fromString(txHash); + } catch { + throw new InvalidArgumentError(`Invalid transaction hash: ${txHash}`); + } +} + +/** + * Parses an optional TxHash from a string. + * Calls parseTxHash internally. + * @param txHash - A transaction hash + * @returns A TxHash instance, or undefined if the input string is falsy. + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parseOptionalTxHash(txHash: string): TxHash | undefined { + if (!txHash) { + return undefined; + } + return parseTxHash(txHash); +} + +/** + * Parses a public key from a string. + * @param publicKey - A public key + * @returns A Point instance + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parsePublicKey(publicKey: string): Point { + try { + return Point.fromString(publicKey); + } catch (err) { + throw new InvalidArgumentError(`Invalid public key: ${publicKey}`); + } +} + +/** + * Parses a partial address from a string. + * @param address - A partial address + * @returns A Fr instance + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parsePartialAddress(address: string): Fr { + try { + return Fr.fromString(address); + } catch (err) { + throw new InvalidArgumentError(`Invalid partial address: ${address}`); + } +} + +/** + * Parses a private key from a string. + * @param privateKey - A string + * @returns A private key + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parsePrivateKey(privateKey: string): GrumpkinScalar { + try { + const value = GrumpkinScalar.fromString(privateKey); + // most likely a badly formatted key was passed + if (value.isZero()) { + throw new Error('Private key must not be zero'); + } + + return value; + } catch (err) { + throw new InvalidArgumentError(`Invalid private key: ${privateKey}`); + } +} + +/** + * Parses a field from a string. + * @param field - A string representing the field. + * @returns A field. + * @throws InvalidArgumentError if the input string is not valid. + */ +export function parseField(field: string): Fr { + try { + const isHex = field.startsWith('0x') || field.match(new RegExp(`^[0-9a-f]{${Fr.SIZE_IN_BYTES * 2}}$`, 'i')); + if (isHex) { + return Fr.fromString(field); + } + + if (['true', 'false'].includes(field)) { + return new Fr(field === 'true'); + } + + const isNumber = +field || field === '0'; + if (isNumber) { + return new Fr(BigInt(field)); + } + + const isBigInt = field.endsWith('n'); + if (isBigInt) { + return new Fr(BigInt(field.replace(/n$/, ''))); + } + + return new Fr(BigInt(field)); + } catch (err) { + throw new InvalidArgumentError(`Invalid field: ${field}`); + } +} + +/** + * Parses an array of strings to Frs. + * @param fields - An array of strings representing the fields. + * @returns An array of Frs. + */ +export function parseFields(fields: string[]): Fr[] { + return fields.map(parseField); +} diff --git a/yarn-project/cli/src/test/utils.test.ts b/yarn-project/cli/src/test/utils.test.ts index e465138083b2..d0c9ff1b7ef8 100644 --- a/yarn-project/cli/src/test/utils.test.ts +++ b/yarn-project/cli/src/test/utils.test.ts @@ -5,7 +5,8 @@ import { InvalidArgumentError } from 'commander'; import { MockProxy, mock } from 'jest-mock-extended'; import { encodeArgs } from '../encoding.js'; -import { getTxSender, parseSaltFromHexString, stripLeadingHex } from '../utils.js'; +import { parseSaltFromHexString } from '../parse_args.js'; +import { getTxSender, stripLeadingHex } from '../utils.js'; import { mockContractArtifact } from './mocks.js'; describe('CLI Utils', () => { diff --git a/yarn-project/cli/src/utils.ts b/yarn-project/cli/src/utils.ts index ed8dd3cc0179..40867e8fbb09 100644 --- a/yarn-project/cli/src/utils.ts +++ b/yarn-project/cli/src/utils.ts @@ -1,11 +1,7 @@ -import { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/aztec.js/abi'; +import { type ContractArtifact, type FunctionArtifact } from '@aztec/aztec.js/abi'; import { AztecAddress } from '@aztec/aztec.js/aztec_address'; -import { EthAddress } from '@aztec/aztec.js/eth_address'; import { type L1ContractArtifactsForDeployment } from '@aztec/aztec.js/ethereum'; -import { Fr, GrumpkinScalar, Point } from '@aztec/aztec.js/fields'; import { type PXE } from '@aztec/aztec.js/interfaces/pxe'; -import { LogId } from '@aztec/aztec.js/log_id'; -import { TxHash } from '@aztec/aztec.js/tx_hash'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { CommanderError, InvalidArgumentError } from 'commander'; @@ -182,234 +178,6 @@ export const stripLeadingHex = (hex: string) => { return hex; }; -/** - * Parses a hex encoded string to an Fr integer to be used as salt - * @param str - Hex encoded string - * @returns A integer to be used as salt - */ -export function parseSaltFromHexString(str: string): Fr { - const hex = stripLeadingHex(str); - - // ensure it's a hex string - if (!hex.match(/^[0-9a-f]+$/i)) { - throw new InvalidArgumentError('Invalid hex string'); - } - - // pad it so that we may read it as a buffer. - // Buffer needs _exactly_ two hex characters per byte - const padded = hex.length % 2 === 1 ? '0' + hex : hex; - - // finally, turn it into an integer - return Fr.fromBuffer(Buffer.from(padded, 'hex')); -} - -/** - * Parses an AztecAddress from a string. - * @param address - A serialized Aztec address - * @returns An Aztec address - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parseAztecAddress(address: string): AztecAddress { - try { - return AztecAddress.fromString(address); - } catch { - throw new InvalidArgumentError(`Invalid address: ${address}`); - } -} - -/** - * Parses an Ethereum address from a string. - * @param address - A serialized Ethereum address - * @returns An Ethereum address - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parseEthereumAddress(address: string): EthAddress { - try { - return EthAddress.fromString(address); - } catch { - throw new InvalidArgumentError(`Invalid address: ${address}`); - } -} - -/** - * Parses an AztecAddress from a string. - * @param address - A serialized Aztec address - * @returns An Aztec address - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parseOptionalAztecAddress(address: string): AztecAddress | undefined { - if (!address) { - return undefined; - } - return parseAztecAddress(address); -} - -/** - * Parses an optional log ID string into a LogId object. - * - * @param logId - The log ID string to parse. - * @returns The parsed LogId object, or undefined if the log ID is missing or empty. - */ -export function parseOptionalLogId(logId: string): LogId | undefined { - if (!logId) { - return undefined; - } - return LogId.fromString(logId); -} - -/** - * Parses a selector from a string. - * @param selector - A serialized selector. - * @returns A selector. - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parseOptionalSelector(selector: string): FunctionSelector | undefined { - if (!selector) { - return undefined; - } - try { - return FunctionSelector.fromString(selector); - } catch { - throw new InvalidArgumentError(`Invalid selector: ${selector}`); - } -} - -/** - * Parses a string into an integer or returns undefined if the input is falsy. - * - * @param value - The string to parse into an integer. - * @returns The parsed integer, or undefined if the input string is falsy. - * @throws If the input is not a valid integer. - */ -export function parseOptionalInteger(value: string): number | undefined { - if (!value) { - return undefined; - } - const parsed = Number(value); - if (!Number.isInteger(parsed)) { - throw new InvalidArgumentError('Invalid integer.'); - } - return parsed; -} - -/** - * Parses a TxHash from a string. - * @param txHash - A transaction hash - * @returns A TxHash instance - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parseTxHash(txHash: string): TxHash { - try { - return TxHash.fromString(txHash); - } catch { - throw new InvalidArgumentError(`Invalid transaction hash: ${txHash}`); - } -} - -/** - * Parses an optional TxHash from a string. - * Calls parseTxHash internally. - * @param txHash - A transaction hash - * @returns A TxHash instance, or undefined if the input string is falsy. - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parseOptionalTxHash(txHash: string): TxHash | undefined { - if (!txHash) { - return undefined; - } - return parseTxHash(txHash); -} - -/** - * Parses a public key from a string. - * @param publicKey - A public key - * @returns A Point instance - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parsePublicKey(publicKey: string): Point { - try { - return Point.fromString(publicKey); - } catch (err) { - throw new InvalidArgumentError(`Invalid public key: ${publicKey}`); - } -} - -/** - * Parses a partial address from a string. - * @param address - A partial address - * @returns A Fr instance - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parsePartialAddress(address: string): Fr { - try { - return Fr.fromString(address); - } catch (err) { - throw new InvalidArgumentError(`Invalid partial address: ${address}`); - } -} - -/** - * Parses a private key from a string. - * @param privateKey - A string - * @returns A private key - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parsePrivateKey(privateKey: string): GrumpkinScalar { - try { - const value = GrumpkinScalar.fromString(privateKey); - // most likely a badly formatted key was passed - if (value.isZero()) { - throw new Error('Private key must not be zero'); - } - - return value; - } catch (err) { - throw new InvalidArgumentError(`Invalid private key: ${privateKey}`); - } -} - -/** - * Parses a field from a string. - * @param field - A string representing the field. - * @returns A field. - * @throws InvalidArgumentError if the input string is not valid. - */ -export function parseField(field: string): Fr { - try { - const isHex = field.startsWith('0x') || field.match(new RegExp(`^[0-9a-f]{${Fr.SIZE_IN_BYTES * 2}}$`, 'i')); - if (isHex) { - return Fr.fromString(field); - } - - if (['true', 'false'].includes(field)) { - return new Fr(field === 'true'); - } - - const isNumber = +field || field === '0'; - if (isNumber) { - return new Fr(BigInt(field)); - } - - const isBigInt = field.endsWith('n'); - if (isBigInt) { - return new Fr(BigInt(field.replace(/n$/, ''))); - } - - return new Fr(BigInt(field)); - } catch (err) { - throw new InvalidArgumentError(`Invalid field: ${field}`); - } -} - -/** - * Parses an array of strings to Frs. - * @param fields - An array of strings representing the fields. - * @returns An array of Frs. - */ -export function parseFields(fields: string[]): Fr[] { - return fields.map(parseField); -} - /** * Updates a file in place atomically. * @param filePath - Path to file diff --git a/yarn-project/foundation/src/abi/abi_coder.ts b/yarn-project/foundation/src/abi/abi_coder.ts index 6971b423757c..a702e65153a5 100644 --- a/yarn-project/foundation/src/abi/abi_coder.ts +++ b/yarn-project/foundation/src/abi/abi_coder.ts @@ -1,4 +1,4 @@ -import { ABIType } from '@aztec/foundation/abi'; +import { type ABIType } from './abi.js'; /** * Get the size of an ABI type in field elements. diff --git a/yarn-project/foundation/src/abi/decoder.ts b/yarn-project/foundation/src/abi/decoder.ts index 9ea69388f76f..cd37ba361e57 100644 --- a/yarn-project/foundation/src/abi/decoder.ts +++ b/yarn-project/foundation/src/abi/decoder.ts @@ -1,5 +1,5 @@ -import { ABIParameter, ABIType, ABIVariable, FunctionArtifact } from '@aztec/foundation/abi'; -import { Fr } from '@aztec/foundation/fields'; +import { Fr } from '../fields/index.js'; +import { ABIParameter, type ABIType, ABIVariable, FunctionArtifact } from './abi.js'; /** * The type of our decoded ABI. diff --git a/yarn-project/foundation/src/abi/encoder.ts b/yarn-project/foundation/src/abi/encoder.ts index 2e4b1844060d..a4db8e24230a 100644 --- a/yarn-project/foundation/src/abi/encoder.ts +++ b/yarn-project/foundation/src/abi/encoder.ts @@ -1,6 +1,6 @@ -import { ABIType, FunctionAbi, isAddressStruct } from '@aztec/foundation/abi'; - import { Fr } from '../fields/index.js'; +import { ABIType, FunctionAbi } from './abi.js'; +import { isAddressStruct } from './utils.js'; /** * Encodes arguments for a function call. diff --git a/yarn-project/foundation/src/abi/function_selector.ts b/yarn-project/foundation/src/abi/function_selector.ts index b898519d53e6..c5def2ac834c 100644 --- a/yarn-project/foundation/src/abi/function_selector.ts +++ b/yarn-project/foundation/src/abi/function_selector.ts @@ -1,9 +1,11 @@ -import { ABIParameter, decodeFunctionSignature } from '@aztec/foundation/abi'; import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer'; -import { keccak } from '@aztec/foundation/crypto'; -import { Fr } from '@aztec/foundation/fields'; import { BufferReader } from '@aztec/foundation/serialize'; +import { keccak } from '../crypto/keccak/index.js'; +import { Fr } from '../fields/index.js'; +import { ABIParameter } from './abi.js'; +import { decodeFunctionSignature } from './decoder.js'; + /** * A function selector is the first 4 bytes of the hash of a function signature. */ diff --git a/yarn-project/foundation/src/abi/utils.ts b/yarn-project/foundation/src/abi/utils.ts index b2ee62d2dd54..d7d15a4d94ac 100644 --- a/yarn-project/foundation/src/abi/utils.ts +++ b/yarn-project/foundation/src/abi/utils.ts @@ -1,4 +1,4 @@ -import { ABIType } from './abi.js'; +import { type ABIType } from './abi.js'; /** * Returns whether the ABI type is an Aztec or Ethereum Address defined in Aztec.nr. diff --git a/yarn-project/foundation/src/eth-address/index.ts b/yarn-project/foundation/src/eth-address/index.ts index 2571f09790c2..76587ecab263 100644 --- a/yarn-project/foundation/src/eth-address/index.ts +++ b/yarn-project/foundation/src/eth-address/index.ts @@ -1,4 +1,5 @@ -import { keccak256String, randomBytes } from '../crypto/index.js'; +import { keccak256String } from '../crypto/keccak/index.js'; +import { randomBytes } from '../crypto/random/index.js'; import { Fr } from '../fields/index.js'; import { BufferReader } from '../serialize/index.js'; diff --git a/yarn-project/foundation/src/fields/fields.ts b/yarn-project/foundation/src/fields/fields.ts index 591b57f6892d..90600643cfe5 100644 --- a/yarn-project/foundation/src/fields/fields.ts +++ b/yarn-project/foundation/src/fields/fields.ts @@ -1,5 +1,5 @@ import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js'; -import { randomBytes } from '../crypto/index.js'; +import { randomBytes } from '../crypto/random/index.js'; import { BufferReader } from '../serialize/buffer_reader.js'; const ZERO_BUFFER = Buffer.alloc(32); diff --git a/yarn-project/types/src/tx/tx_hash.ts b/yarn-project/types/src/tx/tx_hash.ts index 138aa6dbe0fd..00003456ee38 100644 --- a/yarn-project/types/src/tx/tx_hash.ts +++ b/yarn-project/types/src/tx/tx_hash.ts @@ -1,4 +1,3 @@ -import { assertMemberLength } from '@aztec/circuits.js'; import { deserializeBigInt, serializeBigInt } from '@aztec/foundation/serialize'; /** @@ -21,7 +20,9 @@ export class TxHash { */ public buffer: Buffer, ) { - assertMemberLength(this, 'buffer', TxHash.SIZE); + if (buffer.length !== TxHash.SIZE) { + throw new Error(`Expected buffer to have length ${TxHash.SIZE} but was ${buffer.length}`); + } } /** From 42d542e32075b6c0054eee6a4550f1b48768c1e2 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 8 Dec 2023 19:31:21 +0000 Subject: [PATCH 7/8] fix maybe --- yarn-project/end-to-end/src/shared/browser.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index 9c7cfdfc1545..72b064bc9030 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -84,9 +84,8 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL }); it('Loads Aztec.js in the browser', async () => { - const generatePublicKeyExists = await page.evaluate(async () => { - const { generatePublicKey, init } = window.AztecJs; - await init(); + const generatePublicKeyExists = await page.evaluate(() => { + const { generatePublicKey } = window.AztecJs; return typeof generatePublicKey === 'function'; }); expect(generatePublicKeyExists).toBe(true); From c64d476ba871c2ea95b81bb02f518816ce60bf70 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Sat, 9 Dec 2023 09:00:02 +0000 Subject: [PATCH 8/8] maybe fix --- barretenberg/ts/scripts/cjs_postprocess.sh | 2 ++ barretenberg/ts/src/barretenberg/index.ts | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/barretenberg/ts/scripts/cjs_postprocess.sh b/barretenberg/ts/scripts/cjs_postprocess.sh index ccfcfc2d8a20..8a805bcdd440 100755 --- a/barretenberg/ts/scripts/cjs_postprocess.sh +++ b/barretenberg/ts/scripts/cjs_postprocess.sh @@ -11,4 +11,6 @@ DIR="./dest/node-cjs" for FILE in $(find "$DIR" -name "*.js"); do # Use sed to replace 'import.meta.url' with '""' sed -i.bak 's/import\.meta\.url/""/g' "$FILE" && rm "$FILE.bak" + # Use sed to remove any lines postfixed // POSTPROCESS ESM ONLY + sed -i.bak '/\/\/ POSTPROCESS ESM ONLY$/d' "$FILE" && rm "$FILE.bak" done \ No newline at end of file diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 3210c48ee860..6b00a9b752a1 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -76,9 +76,7 @@ export class BarretenbergSync extends BarretenbergApiSync { } // If we're in ESM environment, use top level await. CJS users need to call it manually. -if (typeof __filename === 'undefined') { - // Need to ignore for cjs build. - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - await BarretenbergSync.initSingleton(); -} +// Need to ignore for cjs build. +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +await BarretenbergSync.initSingleton(); // POSTPROCESS ESM ONLY