diff --git a/.github/workflows/test-noir-js.yml b/.github/workflows/test-noir-js.yml index 907f10f49dd..f65650e43c0 100644 --- a/.github/workflows/test-noir-js.yml +++ b/.github/workflows/test-noir-js.yml @@ -47,7 +47,10 @@ jobs: - name: Build noirc_abi run: yarn workspace @noir-lang/noirc_abi build - + + - name: Build noir_js_types + run: yarn workspace @noir-lang/types build + - name: Build barretenberg wrapper run: yarn workspace @noir-lang/backend_barretenberg build diff --git a/tooling/noir_js/src/program.ts b/tooling/noir_js/src/program.ts index 0c129aa3a72..78a7df97294 100644 --- a/tooling/noir_js/src/program.ts +++ b/tooling/noir_js/src/program.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Backend, CompiledCircuit } from '@noir-lang/types'; import { generateWitness } from './witness_generation.js'; +import initAbi from '@noir-lang/noirc_abi'; +import initACVM from '@noir-lang/acvm_js'; export class Noir { constructor( @@ -8,6 +10,15 @@ export class Noir { private backend: Backend, ) {} + async init(): Promise { + // If these are available, then we are in the + // web environment. For the node environment, this + // is a no-op. + if (typeof initAbi === 'function') { + await Promise.all([initAbi(), initACVM()]); + } + } + // Initial inputs to your program async generateFinalProof(inputs: any): Promise { const serializedWitness = await generateWitness(this.circuit, inputs); diff --git a/tooling/noir_js_backend_barretenberg/src/serialize.ts b/tooling/noir_js_backend_barretenberg/src/serialize.ts index af07913f3c6..b15931848a0 100644 --- a/tooling/noir_js_backend_barretenberg/src/serialize.ts +++ b/tooling/noir_js_backend_barretenberg/src/serialize.ts @@ -2,7 +2,7 @@ import { decompressSync as gunzip } from 'fflate'; import { base64Decode } from './base64_decode.js'; // Converts bytecode from a base64 string to a Uint8Array -export function acirToUint8Array(base64EncodedBytecode): Uint8Array { +export function acirToUint8Array(base64EncodedBytecode: string): Uint8Array { const compressedByteCode = base64Decode(base64EncodedBytecode); return gunzip(compressedByteCode); } diff --git a/tooling/noir_js_types/.gitignore b/tooling/noir_js_types/.gitignore index e69de29bb2d..7951405f85a 100644 --- a/tooling/noir_js_types/.gitignore +++ b/tooling/noir_js_types/.gitignore @@ -0,0 +1 @@ +lib \ No newline at end of file diff --git a/tooling/noir_js_types/package.json b/tooling/noir_js_types/package.json index 188b052273a..42c90010c37 100644 --- a/tooling/noir_js_types/package.json +++ b/tooling/noir_js_types/package.json @@ -3,12 +3,29 @@ "collaborators": [ "The Noir Team " ], - "version": "0.14.1", "packageManager": "yarn@3.5.1", + "version": "0.14.1", "license": "(MIT OR Apache-2.0)", "files": [ "lib", "package.json" ], - "types": "lib/types.ts" + "main": "lib/cjs/types.js", + "module": "lib/esm/types.js", + "types": "lib/esm/types.d.ts", + "scripts": { + "build:esm": "tsc", + "build:cjs": "tsc --module CommonJS --outDir lib/cjs", + "build": "yarn run build:cjs && yarn run build:esm" + }, + "exports": { + ".": { + "import": "./lib/esm/types.js", + "require": "./lib/cjs/types.js", + "types": "./lib/esm/types.d.ts" + } + }, + "devDependencies": { + "typescript": "^5.2.2" + } } diff --git a/tooling/noir_js_types/lib/types.ts b/tooling/noir_js_types/src/types.ts similarity index 100% rename from tooling/noir_js_types/lib/types.ts rename to tooling/noir_js_types/src/types.ts diff --git a/tooling/noir_js_types/tsconfig.json b/tooling/noir_js_types/tsconfig.json new file mode 100644 index 00000000000..1fe2a46abaa --- /dev/null +++ b/tooling/noir_js_types/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "declaration": true, + "module": "ESNext", + "moduleResolution": "node", + "outDir": "lib/esm", + "target": "ES2020", + "rootDir": "./src" + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules"] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 52c5915c8b4..cbaededbec8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -555,6 +555,8 @@ __metadata: "@noir-lang/types@workspace:*, @noir-lang/types@workspace:tooling/noir_js_types": version: 0.0.0-use.local resolution: "@noir-lang/types@workspace:tooling/noir_js_types" + dependencies: + typescript: ^5.2.2 languageName: unknown linkType: soft