Skip to content

Commit

Permalink
chore: add init method to Noir class for web (noir-lang#2920)
Browse files Browse the repository at this point in the history
Co-authored-by: Koby Hall <102518238+kobyhallx@users.noreply.github.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
4 people authored and Sakapoi committed Oct 19, 2023
1 parent c7a1107 commit 3845d3c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test-noir-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions tooling/noir_js/src/program.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
/* 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(
private circuit: CompiledCircuit,
private backend: Backend,
) {}

async init(): Promise<void> {
// 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<Uint8Array> {
const serializedWitness = await generateWitness(this.circuit, inputs);
Expand Down
2 changes: 1 addition & 1 deletion tooling/noir_js_backend_barretenberg/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions tooling/noir_js_types/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
21 changes: 19 additions & 2 deletions tooling/noir_js_types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@
"collaborators": [
"The Noir Team <team@noir-lang.org>"
],
"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"
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions tooling/noir_js_types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"declaration": true,
"module": "ESNext",
"moduleResolution": "node",
"outDir": "lib/esm",
"target": "ES2020",
"rootDir": "./src"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3845d3c

Please sign in to comment.