diff --git a/.github/workflows/publish-es-packages.yml b/.github/workflows/publish-es-packages.yml index 181df8f85ad..17e50f97021 100644 --- a/.github/workflows/publish-es-packages.yml +++ b/.github/workflows/publish-es-packages.yml @@ -42,7 +42,6 @@ jobs: result/noirc_abi_wasm/web build-noir_wasm: - needs: [build-noirc_abi_wasm] runs-on: ubuntu-latest steps: - name: Checkout sources @@ -58,15 +57,12 @@ jobs: key: noir-wasm save-if: false - - name: Download noirc_abi_wasm package artifact - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: ./tooling/noirc_abi_wasm - - name: Install Yarn dependencies uses: ./.github/actions/setup + - name: Build noir_js_types + run: yarn workspace @noir-lang/types build + - name: Build noir_wasm run: yarn workspace @noir-lang/noir_wasm build diff --git a/.github/workflows/test-js-packages.yml b/.github/workflows/test-js-packages.yml index 7ebe5ced36b..a007192f6c7 100644 --- a/.github/workflows/test-js-packages.yml +++ b/.github/workflows/test-js-packages.yml @@ -47,7 +47,6 @@ jobs: retention-days: 3 build-noir-wasm: - needs: [build-noirc-abi] runs-on: ubuntu-latest timeout-minutes: 30 @@ -64,15 +63,12 @@ jobs: cache-on-failure: true save-if: ${{ github.event_name != 'merge_group' }} - - name: Download noirc_abi_wasm package artifact - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: ./tooling/noirc_abi_wasm - - name: Install Yarn dependencies uses: ./.github/actions/setup + - name: Build noir_js_types + run: yarn workspace @noir-lang/types build + - name: Build noir_wasm run: yarn workspace @noir-lang/noir_wasm build diff --git a/compiler/wasm/package.json b/compiler/wasm/package.json index 2aaf4a494df..74dfd27de3e 100644 --- a/compiler/wasm/package.json +++ b/compiler/wasm/package.json @@ -80,6 +80,7 @@ "webpack-cli": "^4.7.2" }, "dependencies": { + "@noir-lang/types": "workspace:*", "pako": "^2.1.0" } } diff --git a/compiler/wasm/src/types/noir_artifact.ts b/compiler/wasm/src/types/noir_artifact.ts index 715877e335f..350a4053a9a 100644 --- a/compiler/wasm/src/types/noir_artifact.ts +++ b/compiler/wasm/src/types/noir_artifact.ts @@ -1,4 +1,4 @@ -import { Abi, AbiType } from '@noir-lang/noirc_abi'; +import { Abi, AbiType } from '@noir-lang/types'; /** * A named type. diff --git a/tooling/noir_js_types/package.json b/tooling/noir_js_types/package.json index ef75f3d2fb3..6ec0e772f67 100644 --- a/tooling/noir_js_types/package.json +++ b/tooling/noir_js_types/package.json @@ -38,9 +38,6 @@ "types": "./lib/esm/types.d.ts" } }, - "dependencies": { - "@noir-lang/noirc_abi": "workspace:*" - }, "devDependencies": { "@types/prettier": "^3", "eslint": "^8.50.0", diff --git a/tooling/noir_js_types/src/types.ts b/tooling/noir_js_types/src/types.ts index 84148c5d855..3a62d79a807 100644 --- a/tooling/noir_js_types/src/types.ts +++ b/tooling/noir_js_types/src/types.ts @@ -1,6 +1,33 @@ -import { Abi } from '@noir-lang/noirc_abi'; +export type Field = string | number | boolean; +export type InputValue = Field | InputMap | (Field | InputMap)[]; +export type InputMap = { [key: string]: InputValue }; -export { Abi, WitnessMap } from '@noir-lang/noirc_abi'; +export type Visibility = 'public' | 'private' | 'databus'; +export type Sign = 'unsigned' | 'signed'; +export type AbiType = + | { kind: 'field' } + | { kind: 'boolean' } + | { kind: 'string'; length: number } + | { kind: 'integer'; sign: Sign; width: number } + | { kind: 'array'; length: number; type: AbiType } + | { kind: 'tuple'; fields: AbiType[] } + | { kind: 'struct'; path: string; fields: { name: string; type: AbiType }[] }; + +export type AbiParameter = { + name: string; + type: AbiType; + visibility: Visibility; +}; + +// Map from witness index to hex string value of witness. +export type WitnessMap = Map; + +export type Abi = { + parameters: AbiParameter[]; + param_witnesses: Record; + return_type: { abi_type: AbiType; visibility: Visibility } | null; + return_witnesses: number[]; +}; export interface Backend { /** diff --git a/tooling/noirc_abi_wasm/package.json b/tooling/noirc_abi_wasm/package.json index db0f6c29153..f829543b9aa 100644 --- a/tooling/noirc_abi_wasm/package.json +++ b/tooling/noirc_abi_wasm/package.json @@ -37,6 +37,9 @@ "build:nix": "nix build -L .#noirc_abi_wasm", "install:from:nix": "yarn clean && yarn build:nix && cp -rL ./result/noirc_abi_wasm/nodejs ./ && cp -rL ./result/noirc_abi_wasm/web ./" }, + "dependencies": { + "@noir-lang/types": "workspace:*" + }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", "@web/dev-server-esbuild": "^0.3.6", diff --git a/tooling/noirc_abi_wasm/src/js_witness_map.rs b/tooling/noirc_abi_wasm/src/js_witness_map.rs index fcc6e75f18c..293c5c089f8 100644 --- a/tooling/noirc_abi_wasm/src/js_witness_map.rs +++ b/tooling/noirc_abi_wasm/src/js_witness_map.rs @@ -7,12 +7,6 @@ use acvm::{ use js_sys::{JsString, Map}; use wasm_bindgen::prelude::{wasm_bindgen, JsValue}; -#[wasm_bindgen(typescript_custom_section)] -const WITNESS_MAP: &'static str = r#" -// Map from witness index to hex string value of witness. -export type WitnessMap = Map; -"#; - // WitnessMap #[wasm_bindgen] extern "C" { diff --git a/tooling/noirc_abi_wasm/src/lib.rs b/tooling/noirc_abi_wasm/src/lib.rs index 5557cc917bf..ce15f6d502e 100644 --- a/tooling/noirc_abi_wasm/src/lib.rs +++ b/tooling/noirc_abi_wasm/src/lib.rs @@ -26,9 +26,8 @@ use js_witness_map::JsWitnessMap; #[wasm_bindgen(typescript_custom_section)] const INPUT_MAP: &'static str = r#" -export type Field = string | number | boolean; -export type InputValue = Field | InputMap | (Field | InputMap)[]; -export type InputMap = { [key: string]: InputValue }; +import { Field, InputValue, InputMap, Visibility, Sign, AbiType, AbiParameter, Abi, WitnessMap } from "@noir-lang/types"; +export { Field, InputValue, InputMap, Visibility, Sign, AbiType, AbiParameter, Abi, WitnessMap } from "@noir-lang/types"; "#; #[wasm_bindgen] @@ -36,44 +35,11 @@ extern "C" { #[wasm_bindgen(extends = js_sys::Object, js_name = "InputMap", typescript_type = "InputMap")] #[derive(Clone, Debug, PartialEq, Eq)] pub type JsInputMap; -} -#[wasm_bindgen] -extern "C" { #[wasm_bindgen(extends = js_sys::Object, js_name = "InputValue", typescript_type = "InputValue")] #[derive(Clone, Debug, PartialEq, Eq)] pub type JsInputValue; -} -#[wasm_bindgen(typescript_custom_section)] -const ABI: &'static str = r#" -export type Visibility = "public" | "private" | "databus"; -export type Sign = "unsigned" | "signed"; -export type AbiType = - { kind: "field" } | - { kind: "boolean" } | - { kind: "string", length: number } | - { kind: "integer", sign: Sign, width: number } | - { kind: "array", length: number, type: AbiType } | - { kind: "tuple", fields: AbiType[] } | - { kind: "struct", path: string, fields: { name: string, type: AbiType }[] }; - -export type AbiParameter = { - name: string, - type: AbiType, - visibility: Visibility, -}; - -export type Abi = { - parameters: AbiParameter[], - param_witnesses: Record, - return_type: {abi_type: AbiType, visibility: Visibility} | null, - return_witnesses: number[], -} -"#; - -#[wasm_bindgen] -extern "C" { #[wasm_bindgen(extends = js_sys::Object, js_name = "Abi", typescript_type = "Abi")] #[derive(Clone, Debug, PartialEq, Eq)] pub type JsAbi; diff --git a/yarn.lock b/yarn.lock index 8da9bf2a5ca..c99fb68dd0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4523,6 +4523,7 @@ __metadata: "@esm-bundle/chai": ^4.3.4-fix.0 "@ltd/j-toml": ^1.38.0 "@noir-lang/noirc_abi": "workspace:*" + "@noir-lang/types": "workspace:*" "@types/adm-zip": ^0.5.0 "@types/chai": ^4 "@types/mocha": ^10.0.6 @@ -4572,6 +4573,7 @@ __metadata: resolution: "@noir-lang/noirc_abi@workspace:tooling/noirc_abi_wasm" dependencies: "@esm-bundle/chai": ^4.3.4-fix.0 + "@noir-lang/types": "workspace:*" "@web/dev-server-esbuild": ^0.3.6 "@web/test-runner": ^0.15.3 "@web/test-runner-playwright": ^0.10.0 @@ -4610,7 +4612,6 @@ __metadata: version: 0.0.0-use.local resolution: "@noir-lang/types@workspace:tooling/noir_js_types" dependencies: - "@noir-lang/noirc_abi": "workspace:*" "@types/prettier": ^3 eslint: ^8.50.0 eslint-plugin-prettier: ^5.0.0