-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
noirc_abi_wasm
crate for ABI encoding in JS (#1945)
Co-authored-by: Koby <kobyhall@proton.me> Co-authored-by: kevaundray <kevtheappdev@gmail.com> Co-authored-by: Koby Hall <102518238+kobyhallx@users.noreply.github.com>
- Loading branch information
1 parent
cf38618
commit 669e0da
Showing
31 changed files
with
7,048 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Setup | ||
|
||
inputs: | ||
working-directory: | ||
default: ./ | ||
required: false | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Install node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.15 | ||
- name: Cache | ||
uses: actions/cache@v3 | ||
id: cache | ||
with: | ||
path: "**/node_modules" | ||
key: yarn-v1-${{ hashFiles('**/yarn.lock') }} | ||
- name: Install | ||
run: | | ||
cd ${{ inputs.working-directory }} | ||
yarn --immutable | ||
shell: bash | ||
if: steps.cache.outputs.cache-hit != 'true' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
name: ABI Wasm test | ||
|
||
on: | ||
pull_request: | ||
merge_group: | ||
|
||
# This will cancel previous runs when a branch or PR is updated | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
noirc-abi-wasm-build: | ||
runs-on: ubuntu-latest | ||
env: | ||
CACHED_PATH: /tmp/nix-cache | ||
|
||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- uses: cachix/install-nix-action@v20 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-23.05 | ||
github_access_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Restore nix store cache | ||
uses: actions/cache/restore@v3 | ||
id: cache | ||
with: | ||
path: ${{ env.CACHED_PATH }} | ||
key: ${{ runner.os }}-flake-abi-wasm-${{ hashFiles('*.lock') }} | ||
|
||
# Based on https://github.com/marigold-dev/deku/blob/b5016f0cf4bf6ac48db9111b70dd7fb49b969dfd/.github/workflows/build.yml#L26 | ||
- name: Copy cache into nix store | ||
if: steps.cache.outputs.cache-hit == 'true' | ||
# We don't check the signature because we're the one that created the cache | ||
run: | | ||
for narinfo in ${{ env.CACHED_PATH }}/*.narinfo; do | ||
path=$(head -n 1 "$narinfo" | awk '{print $2}') | ||
nix copy --no-check-sigs --from "file://${{ env.CACHED_PATH }}" "$path" | ||
done | ||
- name: Build noirc_abi_wasm | ||
run: | | ||
nix build -L .#noirc_abi_wasm | ||
- name: Export cache from nix store | ||
if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} | ||
run: | | ||
nix copy --to "file://${{ env.CACHED_PATH }}?compression=zstd¶llel-compression=true" .#noirc-abi-wasm-cargo-artifacts | ||
- uses: actions/cache/save@v3 | ||
# Don't create cache entries for the merge queue. | ||
if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} | ||
with: | ||
path: ${{ env.CACHED_PATH }} | ||
key: ${{ steps.cache.outputs.cache-primary-key }} | ||
|
||
- name: Dereference symlink | ||
run: echo "UPLOAD_PATH=$(readlink -f result)" >> $GITHUB_ENV | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: noirc_abi_wasm | ||
path: ${{ env.UPLOAD_PATH }} | ||
retention-days: 10 | ||
|
||
noirc-abi-wasm-test-node: | ||
needs: [noirc-abi-wasm-build] | ||
name: Node.js Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: noirc_abi_wasm | ||
path: ./result | ||
|
||
- name: Set up test environment | ||
uses: ./.github/actions/setup | ||
with: | ||
working-directory: ./crates/noirc_abi_wasm | ||
|
||
- name: Run node tests | ||
working-directory: ./crates/noirc_abi_wasm | ||
run: yarn test | ||
|
||
noirc-abi-wasm-test-browser: | ||
needs: [noirc-abi-wasm-build] | ||
name: Browser Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: noirc_abi_wasm | ||
path: ./result | ||
|
||
- name: Set up test environment | ||
uses: ./.github/actions/setup | ||
with: | ||
working-directory: ./crates/noirc_abi_wasm | ||
|
||
- name: Install playwright deps | ||
working-directory: ./crates/noirc_abi_wasm | ||
run: | | ||
npx playwright install | ||
npx playwright install-deps | ||
- name: Run browser tests | ||
working-directory: ./crates/noirc_abi_wasm | ||
run: yarn test:browser |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
root: true, | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["@typescript-eslint", "prettier"], | ||
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], | ||
rules: { | ||
"comma-spacing": ["error", { before: false, after: true }], | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": [ | ||
"warn", // or "error" | ||
{ | ||
argsIgnorePattern: "^_", | ||
varsIgnorePattern: "^_", | ||
caughtErrorsIgnorePattern: "^_", | ||
}, | ||
], | ||
"prettier/prettier": "error", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Yarn | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extension": ["ts"], | ||
"spec": "test/node/**/*.test.ts", | ||
"require": "ts-node/register" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
yarnPath: .yarn/releases/yarn-3.5.1.cjs | ||
|
||
nodeLinker: node-modules |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "noirc_abi_wasm" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
acvm.workspace = true | ||
noirc_abi.workspace = true | ||
iter-extended.workspace = true | ||
wasm-bindgen.workspace = true | ||
serde.workspace = true | ||
|
||
console_error_panic_hook = "0.1.7" | ||
gloo-utils = { version = "0.1", features = ["serde"] } | ||
|
||
js-sys = "0.3.62" | ||
|
||
# This is an unused dependency, we are adding it | ||
# so that we can enable the js feature in getrandom. | ||
getrandom = { version = "*", features = ["js"] } | ||
|
||
[build-dependencies] | ||
build-data = "0.1.3" | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.36" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Noir Lang ABI JavaScript Package | ||
|
||
This JavaScript package enables users to ABI encode inputs to a Noir program, i.e. generating an initial witness. | ||
|
||
## Building from source | ||
|
||
Outside of the [noir repo](https://github.com/noir-lang/noir), this package can be built using the command below: | ||
|
||
```bash | ||
nix build -L github:noir-lang/noir/master#abi_wasm | ||
``` | ||
|
||
If you are within the noir repo and would like to build local changes, you can use: | ||
|
||
```bash | ||
nix build -L #abi_wasm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const GIT_COMMIT: &&str = &"GIT_COMMIT"; | ||
|
||
fn main() { | ||
// Only use build_data if the environment variable isn't set | ||
// The environment variable is always set when working via Nix | ||
if std::env::var(GIT_COMMIT).is_err() { | ||
build_data::set_GIT_COMMIT(); | ||
build_data::set_GIT_DIRTY(); | ||
build_data::no_debug_rebuilds(); | ||
} | ||
|
||
build_data::set_SOURCE_TIMESTAMP(); | ||
build_data::no_debug_rebuilds(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
|
||
function require_command { | ||
if ! command -v "$1" >/dev/null 2>&1; then | ||
echo "Error: $1 is required but not installed." >&2 | ||
exit 1 | ||
fi | ||
} | ||
function check_installed { | ||
if ! command -v "$1" >/dev/null 2>&1; then | ||
echo "$1 is not installed. Please install it." >&2 | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
function run_or_fail { | ||
"$@" | ||
local status=$? | ||
if [ $status -ne 0 ]; then | ||
echo "Command '$*' failed with exit code $status" >&2 | ||
exit $status | ||
fi | ||
} | ||
|
||
require_command toml2json | ||
require_command jq | ||
require_command cargo | ||
require_command wasm-bindgen | ||
require_command wasm-opt | ||
|
||
self_path=$(dirname "$(readlink -f "$0")") | ||
export pname=$(toml2json < ${self_path}/Cargo.toml | jq -r .package.name) | ||
export CARGO_TARGET_DIR=$self_path/target | ||
|
||
rm -rf $self_path/outputs >/dev/null 2>&1 | ||
rm -rf $self_path/result >/dev/null 2>&1 | ||
|
||
if [ -v out ]; then | ||
echo "Will install package to $out (defined outside installPhase.sh script)" | ||
else | ||
out="$self_path/outputs/out" | ||
echo "Will install package to $out" | ||
fi | ||
|
||
run_or_fail ${self_path}/buildPhaseCargoCommand.sh release | ||
run_or_fail ${self_path}/installPhase.sh | ||
|
||
ln -s $out $self_path/result |
Oops, something went wrong.