diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index cdebb2b8bcc..11c2bd89a8d 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -62,11 +62,37 @@ jobs: with: node-version: '18' + - name: Install wasm-bindgen-cli + uses: taiki-e/install-action@v2 + with: + tool: wasm-bindgen-cli@0.2.86 + + - name: Install wasm-opt + run: | + npm i wasm-opt -g + - name: Install dependencies run: yarn - + + - name: Build acvm_js + run: yarn workspace @noir-lang/acvm_js build + + - 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 + + - name: Run noir_js + run: | + yarn workspace @noir-lang/noir_js build + - name: Build docs - run: yarn workspace docs build + run: + yarn workspace docs build - name: Remove pre-releases working-directory: docs diff --git a/docs/.gitignore b/docs/.gitignore index c034d49ebde..e76d8caf6bc 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -7,6 +7,7 @@ # Generated files .docusaurus .cache-loader +/docs/noir_js/reference/ # Misc .DS_Store diff --git a/docs/docs/noir_js/noir_js.md b/docs/docs/noir_js/noir_js.md index 23ea550e156..f895b22eaf8 100644 --- a/docs/docs/noir_js/noir_js.md +++ b/docs/docs/noir_js/noir_js.md @@ -33,4 +33,4 @@ To install its JavaScript library, run this in your project: npm i @noir-lang/backend_barretenberg ``` -For more details on how to instantiate and use the libraries, refer to the [Full Noir App Guide](./getting_started/01_tiny_noir_app.md) and [Reference](./reference/01_noirjs.md) sections. +For more details on how to instantiate and use the libraries, refer to the [Full Noir App Guide](./getting_started/01_tiny_noir_app.md) and [Reference](./reference/noir_js/classes/Noir.md) sections. diff --git a/docs/docs/noir_js/reference/01_noirjs.md b/docs/docs/noir_js/reference/01_noirjs.md deleted file mode 100644 index 0d6d5abbbff..00000000000 --- a/docs/docs/noir_js/reference/01_noirjs.md +++ /dev/null @@ -1,147 +0,0 @@ ---- -title: Noir -description: Reference to noir_js library and the Noir class -keywords: [Noir project, javascript, typescript, node.js, browser, react, class, reference] ---- - -## Table of Contents - -- [constructor](#constructor) -- [init](#init) -- [generateFinalProof](#generatefinalproof) -- [verifyFinalProof](#verifyfinalproof) - -## `constructor` - -The `constructor` is a method used to create and initialize objects created within the `Noir` class. In the `Noir` class constructor, you need to pass two parameters: `circuit` and `backend`. - -### Syntax - -```js -constructor(circuit, backend); -``` - -### Parameters - -| Parameter | Type | Description | -| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `circuit` | Object | A circuit represented in a `json` format, containing the ABI and bytecode. Typically obtained by running [`nargo compile`](../../nargo/01_commands.md) | -| `backend` | Object | A backend instance, before initialization. | - -### Usage - -```js -const noir = new Noir(circuit, backend); -``` - -## `init` - -This async method should be called after class instantiation. It will run processes on the ACVM, instantiate your backend, etc. - -### Syntax - -```js -async init() -``` - -### Parameters - -This method takes no parameters - -### Usage - -```js -await noirInstance.init(); -``` - -## `execute` - -This async method allows to execute a circuit to get its witness and return value. [`generateFinalProof`](#generatefinalproof) calls it for you, but you can call it directly (i.e. to feed directly to a backend, or to get the return value). - -You can optionally provide a foreignCallHandler, to handle functions that should run outside of the prover (e.g. `std::println`) - -### Syntax - -```js -async execute(inputs, foreignCallHandler) -``` - -### Parameters - -| Parameter | Type | Description | -| --------- | ------ | ------------------------------------------------ | -| `inputs` | Object | An object containing the inputs to your circuit. | -| `foreignCallHandler` (optional) | Function | A function handling the foreign call from your circuit | - -### Returns - -| Return value | Type | Description | -| ------------ | --------------------- | --------------------------------------------------- | -| `witness` | Promise | The witness | -| `returnValue` | Promise | The return value | - -### Usage - -```js -const { witness, returnValue } = await noir.execute(inputs) -const { witness, returnValue } = await noir.execute(inputs, (name, args) => console.log(`Received foreign call ${name} with arguments ${args}`)) -``` - -## `generateFinalProof` - -This async method generates a witness and a proof given an object as input. - -### Syntax - -```js -async generateFinalproof(input) -``` - -### Parameters - -| Parameter | Type | Description | -| --------- | ------ | ------------------------------------------------ | -| `input` | Object | An object containing the inputs to your circuit. | - -### Returns - -| Return value | Type | Description | -| ------------ | --------------------- | --------------------------------------------------- | -| `proof` | Promise | An array with the byte representation of the proof. | - -### Usage - -```js -// consider the Standard Noir Example given with nargo init -const input = { x: 1, y: 2 }; -noirInstance.generateProof(input); -``` - -## `verifyFinalProof` - -This async method instantiates the verification key and verifies your proof. - -### Syntax - -```js -async verifyFinalProof(proof) -``` - -### Parameters - -| Parameter | Type | Description | -| --------- | ---------- | --------------------------------------------------------------------------------------------- | -| `proof` | Uint8Array | The Uint8Array representation of your proof, usually obtained by calling `generateFinalProof` | - -### Returns - -| Return value | Type | Description | -| ------------ | ------------------ | -------------------------------------------- | -| `verified` | Promise | A boolean for whether the proof was verified | - -### Usage - -```js -const proof = noirInstance.generateProof(input); -noirInstance.verifyFinalProof(proof); -``` diff --git a/docs/docs/noir_js/reference/02_bb_backend.md b/docs/docs/noir_js/reference/02_bb_backend.md deleted file mode 100644 index 21c2ff32b57..00000000000 --- a/docs/docs/noir_js/reference/02_bb_backend.md +++ /dev/null @@ -1,272 +0,0 @@ ---- -title: BarretenbergBackend -description: Reference documentation for the barretenberg_backend library and the BarretenbergBackend class -keywords: - [ - BarretenbergBackend, - Barretenberg, - javascript, - typescript, - node.js, - browser, - class, - reference, - noir_js, - ] ---- - -## Table of Contents - -- [constructor](#constructor) -- [generateFinalProof](#generatefinalproof) -- [generateIntermediateProof](#generateintermediateproof) -- [generateProof](#generateproof) -- [generateIntermediateProofArtifacts](#generateintermediateproofartifacts) -- [verifyFinalProof](#verifyfinalproof) -- [verifyIntermediateProof](#verifyintermediateproof) -- [verifyProof](#verifyproof) -- [destroy](#destroy) - -## `constructor` - -The `constructor` is a method used to create and initialize objects created within the `BarretenbergBackend` class. In this class, you should pass at least one argument for the `circuit`. - -### Syntax - -```js -constructor(acirCircuit, (numberOfThreads = 1)); -``` - -### Parameters - -| Parameter | Type | Description | -| ----------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `acirCircuit` | Object | A circuit represented in a `json` format, containing the ABI and bytecode Tipically obtained by running [`nargo compile`](../../nargo/01_commands.md). This is the same circuit expected to be passed to [the Noir class](01_noirjs.md) | -| `numberOfThreads` | Number (optional) | The number of threads to be used by the backend. Defaults to 1. | - -### Usage - -```js -const backend = new BarretenbergBackend(acirCircuit); -``` - -## `generateFinalProof` - -An async wrapper around the [generateProof](#generateproof) method that passes a `false` flag. Usually called by the Noir class. - -### Syntax - -```js -async generateFinalProof(decompressedWitness) -``` - -### Parameters - -| Parameter | Type | Description | -| --------------------- | ------ | -------------------------------------------------------- | -| `decompressedWitness` | Object | The decompressed witness for generating the final proof. | - -### Returns - -| Return value | Type | Description | -| ------------ | -------------------- | --------------------------------------------------------- | -| `proof` | Promise | An array with the byte representation of the final proof. | - -### Usage - -```js -const finalProof = await backend.generateFinalProof(decompressedWitness); -``` - -## `generateIntermediateProof` - -An async wrapper around the [generateProof](#generateproof) method that passes a `true` flag. It's not currently being used by the Noir class, but developers can call this method directly to use Noir's recursive features. - -### Syntax - -```js -async generateIntermediateProof(witness) -``` - -### Parameters - -| Parameter | Type | Description | -| --------- | ------ | -------------------------------------------------- | -| `witness` | Object | The witness for generating the intermediate proof. | - -### Returns - -| Return value | Type | Description | -| ------------ | -------------------- | --------------------------------------------------------------- | -| `proof` | Promise | An array with the byte representation of the intermediate proof | - -### Usage - -```js -const intermediateProof = await backend.generateIntermediateProof(witness); -``` - -## `generateProof` - -This async method generates a proof. Takes the witness generated by ACVM, and a boolean that evaluates to `true` when the proof _is_ meant to be verified in another circuit. Not currently used by the Noir class. - -### Syntax - -```js -async generateProof(decompressedWitness, makeEasyToVerifyInCircuit) -``` - -### Parameters - -| Parameter | Type | Description | -| --------------------------- | ------- | ---------------------------------------------------------------------------------------------- | -| `decompressedWitness` | Object | The decompressed witness for generating the proof. | -| `makeEasyToVerifyInCircuit` | Boolean | A flag indicating whether to generate proof components for easy verification within a circuit. | - -### Returns - -| Return value | Type | Description | -| ------------ | -------------------- | -------------------------------------------------- | -| `proof` | Promise | An array with the byte representation of the proof | - -### Usage - -```js -const proof = await backend.generateProof(decompressedWitness, makeEasyToVerifyInCircuit); -``` - -## `generateIntermediateProofArtifacts` - -This async method returns the artifacts needed to verify the intermediate proof in another circuit. It's not currently being used by the Noir class, but developers can call this method directly to use Noir's recursive features. - -### Syntax - -```js -async generateIntermediateProofArtifacts(proof, numOfPublicInputs = 0) -``` - -### Parameters - -| Parameter | Type | Description | -| ------------------- | ----------------- | ---------------------------------------------------------------- | -| `proof` | Object | The proof object. | -| `numOfPublicInputs` | Number (optional) | The number of public inputs in the inner proof, defaulting to 0. | - -### Returns - -| Return value | Type | Description | -| --------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `proofAsFields` | string[] | An array of strings with the hexadecimal representation of the [Fields](../../language_concepts/data_types/00_fields.md) that make up a proof | -| `vkAsFields` | string[] | An array of strings with the hexadecimal representation of the [Fields](../../language_concepts/data_types/00_fields.md) that make up the verification key | -| `vkHash` | string | A pedersen hash of the verification key | - -### Usage - -```js -const artifacts = await backend.generateIntermediateProofArtifacts(proof, numOfPublicInputs); -``` - -## `verifyFinalProof` - -An async wrapper around [verifyProof](#verifyproof) that sets the `false` flag. Usually called by the Noir class. - -### Syntax - -```js -async verifyFinalProof(proof) -``` - -### Parameters - -| Parameter | Type | Description | -| --------- | ------ | --------------------------- | -| `proof` | Object | The proof object to verify. | - -### Returns - -| Return value | Type | Description | -| ------------ | ------------------ | -------------------------------------------- | -| `verified` | Promise | A boolean for whether the proof was verified | - -### Usage - -```js -const isValidFinal = await backend.verifyFinalProof(proof); -``` - -## `verifyIntermediateProof` - -An async wrapper around [verifyProof](#verifyproof) that sets the `true` flag. It's not currently being used by the Noir class, but developers can call this method directly to use Noir's recursive features. - -### Syntax - -```js -async verifyIntermediateProof(proof) -``` - -### Parameters - -| Parameter | Type | Description | -| --------- | ------ | ---------------------------------------- | -| `proof` | Object | The intermediate proof object to verify. | - -### Returns - -| Return value | Type | Description | -| ------------ | ------------------ | -------------------------------------------- | -| `verified` | Promise | A boolean for whether the proof was verified | - -### Usage - -```js -const isValidIntermediate = await backend.verifyIntermediateProof(proof); -``` - -## `verifyProof` - -This async method verifies a proof. Takes the proof, and a boolean that evaluates to `true` when the proof is intermediate. - -### Syntax - -```js -async verifyProof(proof, makeEasyToVerifyInCircuit) -``` - -### Parameters - -| Parameter | Type | Description | -| --------------------------- | ------- | ------------------------------------------------------------ | -| `proof` | Object | The proof object to verify | -| `makeEasyToVerifyInCircuit` | Boolean | A flag indicating whether the proof is intermediate or final | - -### Returns - -| Parameter | Type | Description | -| ---------- | ------------------ | -------------------------------------------- | -| `verified` | Promise\ | A boolean for whether the proof was verified | - -### Usage - -```js -const isValid = await backend.verifyProof(proof, makeEasyToVerifyInCircuit); -``` - -## `destroy` - -This method destroys the resources allocated in the [instantiate](#instantiate) method. Noir doesn't currently call this method, but it's highly recommended that developers do so in order to save resources. - -### Syntax - -```js -async destroy() -``` - -### Parameters - -This method takes no parameters. - -### Usage - -```js -await backend.destroy(); -``` diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 5128a99b000..8f62df3d0e9 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -146,6 +146,70 @@ const config = { indexName: 'noir-lang', }, }, + plugins: [ + [ + 'docusaurus-plugin-typedoc', + { + id: 'noir_js', + entryPoints: ['../tooling/noir_js/src/index.ts'], + tsconfig: '../tooling/noir_js/tsconfig.json', + entryPointStrategy: 'resolve', + out: 'docs/noir_js/reference/noir_js', + plugin: ['typedoc-plugin-markdown'], + name: 'Noir JS', + disableSources: true, + excludePrivate: true, + + sidebar: { + filteredIds: ['noir_js/reference/noir_js/index'], + }, + readme: 'none', + hidePageHeader: true, + hideBreadcrumbs: true, + hideInPageTOC: true, + useCodeBlocks: true, + typeDeclarationFormat: 'table', + propertiesFormat: 'table', + parametersFormat: 'table', + enumMembersFormat: 'table', + indexFormat: 'table', + outputFileStrategy: 'members', + memberPageTitle: '{name}', + membersWithOwnFile: ['Interface', 'Class', 'TypeAlias', 'Function'], + }, + ], + [ + 'docusaurus-plugin-typedoc', + { + id: 'noir_js_backend_barretenberg', + entryPoints: ['../tooling/noir_js_backend_barretenberg/src/index.ts'], + tsconfig: '../tooling/noir_js_backend_barretenberg/tsconfig.json', + entryPointStrategy: 'resolve', + out: 'docs/noir_js/reference/backend_barretenberg', + plugin: ['typedoc-plugin-markdown'], + name: 'Backend Barretenberg', + disableSources: true, + excludePrivate: true, + + sidebar: { + filteredIds: ['noir_js/reference/backend_barretenberg/index'], + }, + readme: 'none', + hidePageHeader: true, + hideBreadcrumbs: true, + hideInPageTOC: true, + useCodeBlocks: true, + typeDeclarationFormat: 'table', + propertiesFormat: 'table', + parametersFormat: 'table', + enumMembersFormat: 'table', + indexFormat: 'table', + outputFileStrategy: 'members', + memberPageTitle: '{name}', + membersWithOwnFile: ['Interface', 'Class', 'TypeAlias'], + }, + ], + ], }; module.exports = config; diff --git a/docs/package.json b/docs/package.json index 3d71493c0ff..09f8d718b56 100644 --- a/docs/package.json +++ b/docs/package.json @@ -15,12 +15,18 @@ "@mdx-js/react": "^1.6.22", "axios": "^1.4.0", "clsx": "^1.2.1", + "docusaurus-plugin-typedoc": "1.0.0-next.18", "hast-util-is-element": "^1.1.0", "prism-react-renderer": "^1.3.5", "react": "^17.0.2", "react-dom": "^17.0.2", "rehype-katex": "^5.0.0", - "remark-math": "^3.0.1" + "remark-math": "^3.0.1", + "typedoc": "^0.25.0", + "typedoc-plugin-frontmatter": "^0.0.2", + "typedoc-plugin-markdown": "4.0.0-next.25", + "typedoc-plugin-merge-modules": "^5.1.0", + "typescript": "^5.2.2" }, "devDependencies": { "@docusaurus/module-type-aliases": "^2.4.0" diff --git a/docs/sidebars.js b/docs/sidebars.js index 8fddb677a58..3fd391cf09c 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -119,8 +119,22 @@ const sidebars = { label: 'Reference', items: [ { - type: 'autogenerated', - dirName: 'noir_js/reference', + type: 'category', + label: 'Noir JS', + link: { + type: 'doc', + id: 'noir_js/reference/noir_js/index', + }, + items: require('./docs/noir_js/reference/noir_js/typedoc-sidebar.cjs'), + }, + { + type: 'category', + label: 'Backend Barretenberg', + link: { + type: 'doc', + id: 'noir_js/reference/backend_barretenberg/index', + }, + items: require('./docs/noir_js/reference/backend_barretenberg/typedoc-sidebar.cjs'), }, ], }, diff --git a/tooling/noir_js/src/index.ts b/tooling/noir_js/src/index.ts index 35a3e716b6b..5e700a5b583 100644 --- a/tooling/noir_js/src/index.ts +++ b/tooling/noir_js/src/index.ts @@ -1,6 +1,6 @@ import * as acvm from '@noir-lang/acvm_js'; import * as abi from '@noir-lang/noirc_abi'; -export { acvm, abi }; +import { CompiledCircuit, ProofData } from '@noir-lang/types'; export { ecdsa_secp256r1_verify, @@ -11,6 +11,13 @@ export { xor, and, } from '@noir-lang/acvm_js'; + export { WitnessMap, ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@noir-lang/acvm_js'; export { Noir } from './program.js'; + +/** @ignore */ +export { acvm, abi }; + +// type exports for typedoc +export { CompiledCircuit, ProofData }; diff --git a/tooling/noir_js/src/program.ts b/tooling/noir_js/src/program.ts index cfd7a715dfe..711413bbc84 100644 --- a/tooling/noir_js/src/program.ts +++ b/tooling/noir_js/src/program.ts @@ -10,6 +10,7 @@ export class Noir { private backend?: Backend, ) {} + /** @ignore */ async init(): Promise { // If these are available, then we are in the // web environment. For the node environment, this @@ -19,6 +20,17 @@ export class Noir { } } + /** + * + * @description + * Destroys the underlying backend instance. + * + * @example + * ```typescript + * await noir.destroy(); + * ``` + * + */ async destroy(): Promise { await this.backend?.destroy(); } @@ -29,6 +41,15 @@ export class Noir { } // Initial inputs to your program + /** + * @description + * Allows to execute a circuit to get its witness and return value. + * + * @example + * ```typescript + * async execute(inputs) + * ``` + */ async execute( inputs: InputMap, foreignCallHandler?: ForeignCallHandler, @@ -39,12 +60,34 @@ export class Noir { return { witness: compressWitness(witness), returnValue }; } - // Initial inputs to your program + /** + * + * @description + * Generates a witness and a proof given an object as input. + * + * @example + * ```typescript + * async generateFinalproof(input) + * ``` + * + */ async generateFinalProof(inputs: InputMap): Promise { const { witness } = await this.execute(inputs); return this.getBackend().generateFinalProof(witness); } + /** + * + * @description + * Instantiates the verification key and verifies a proof. + * + * + * @example + * ```typescript + * async verifyFinalProof(proof) + * ``` + * + */ async verifyFinalProof(proofData: ProofData): Promise { return this.getBackend().verifyFinalProof(proofData); } diff --git a/tooling/noir_js/tsconfig.json b/tooling/noir_js/tsconfig.json index 1e0fdea09c7..0dbc5204556 100644 --- a/tooling/noir_js/tsconfig.json +++ b/tooling/noir_js/tsconfig.json @@ -2,7 +2,6 @@ "compilerOptions": { "target": "esnext", "declaration": true, - "emitDeclarationOnly": false, "module": "ESNext", "moduleResolution": "node", "outDir": "./lib", @@ -12,5 +11,10 @@ "noImplicitAny": false, }, "include": ["src/**/*.ts"], - "exclude": ["node_modules"] -} \ No newline at end of file + "exclude": ["node_modules"], + "references": [ + { + "path": "../noir_js_types" + }, + ] +} diff --git a/tooling/noir_js_backend_barretenberg/src/index.ts b/tooling/noir_js_backend_barretenberg/src/index.ts index 11c56a7384d..2e5a44ae8d2 100644 --- a/tooling/noir_js_backend_barretenberg/src/index.ts +++ b/tooling/noir_js_backend_barretenberg/src/index.ts @@ -25,6 +25,7 @@ export class BarretenbergBackend implements Backend { this.acirUncompressedBytecode = acirToUint8Array(acirBytecodeBase64); } + /** @ignore */ async instantiate(): Promise { if (!this.api) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -63,11 +64,20 @@ export class BarretenbergBackend implements Backend { // We set `makeEasyToVerifyInCircuit` to true, which will tell the backend to // generate the proof using components that will make the proof // easier to verify in a circuit. + + /** + * + * @example + * ```typescript + * const intermediateProof = await backend.generateIntermediateProof(witness); + * ``` + */ async generateIntermediateProof(witness: Uint8Array): Promise { const makeEasyToVerifyInCircuit = true; return this.generateProof(witness, makeEasyToVerifyInCircuit); } + /** @ignore */ async generateProof(compressedWitness: Uint8Array, makeEasyToVerifyInCircuit: boolean): Promise { await this.instantiate(); const proofWithPublicInputs = await this.api.acirCreateProof( @@ -103,6 +113,14 @@ export class BarretenbergBackend implements Backend { // method. // // The number of public inputs denotes how many public inputs are in the inner proof. + + /** + * + * @example + * ```typescript + * const artifacts = await backend.generateIntermediateProofArtifacts(proof, numOfPublicInputs); + * ``` + */ async generateIntermediateProofArtifacts( proofData: ProofData, numOfPublicInputs = 0, @@ -136,12 +154,20 @@ export class BarretenbergBackend implements Backend { return verified; } + /** + * + * @example + * ```typescript + * const isValidIntermediate = await backend.verifyIntermediateProof(proof); + * ``` + */ async verifyIntermediateProof(proofData: ProofData): Promise { const proof = reconstructProofWithPublicInputs(proofData); const makeEasyToVerifyInCircuit = true; return this.verifyProof(proof, makeEasyToVerifyInCircuit); } + /** @ignore */ async verifyProof(proof: Uint8Array, makeEasyToVerifyInCircuit: boolean): Promise { await this.instantiate(); await this.api.acirInitVerificationKey(this.acirComposer); @@ -178,3 +204,6 @@ function flattenUint8Arrays(arrays: Uint8Array[]): Uint8Array { return result; } + +// typedoc exports +export { Backend, BackendOptions, CompiledCircuit, ProofData }; diff --git a/tooling/noir_js_backend_barretenberg/src/types.ts b/tooling/noir_js_backend_barretenberg/src/types.ts index b88a942d986..041e36fdf91 100644 --- a/tooling/noir_js_backend_barretenberg/src/types.ts +++ b/tooling/noir_js_backend_barretenberg/src/types.ts @@ -1,3 +1,8 @@ +/** + * @description + * An options object, currently only used to specify the number of threads to use. + */ export type BackendOptions = { + /** @description Number of threads */ threads: number; }; diff --git a/tooling/noir_js_backend_barretenberg/tsconfig.json b/tooling/noir_js_backend_barretenberg/tsconfig.json index 393fa38f583..1e28c044bba 100644 --- a/tooling/noir_js_backend_barretenberg/tsconfig.json +++ b/tooling/noir_js_backend_barretenberg/tsconfig.json @@ -12,5 +12,10 @@ "noImplicitAny": false, }, "include": ["src/**/*.ts"], - "exclude": ["node_modules"] + "exclude": ["node_modules"], + "references": [ + { + "path": "../noir_js_types" + } + ] } diff --git a/tooling/noir_js_types/.gitignore b/tooling/noir_js_types/.gitignore index 7951405f85a..e92523b6247 100644 --- a/tooling/noir_js_types/.gitignore +++ b/tooling/noir_js_types/.gitignore @@ -1 +1,3 @@ -lib \ No newline at end of file +lib + +*.tsbuildinfo diff --git a/tooling/noir_js_types/src/types.ts b/tooling/noir_js_types/src/types.ts index f534ec9a920..5ed6b1721e9 100644 --- a/tooling/noir_js_types/src/types.ts +++ b/tooling/noir_js_types/src/types.ts @@ -1,25 +1,60 @@ import { Abi } from '@noir-lang/noirc_abi'; export interface Backend { - // Generate an outer proof. This is the proof for the circuit which will verify - // inner proofs and or can be seen as the proof created for regular circuits. + /** + * @description Generates a final proof (not meant to be verified in another circuit) */ generateFinalProof(decompressedWitness: Uint8Array): Promise; - // Generates an inner proof. This is the proof that will be verified - // in another circuit. + /** + * @description Generates an intermediate proof (meant to be verified in another circuit) */ generateIntermediateProof(decompressedWitness: Uint8Array): Promise; + /** + * + * @description Retrieves the artifacts from a proof in the Field format + */ + generateIntermediateProofArtifacts( + proofData: ProofData, + numOfPublicInputs: number, + ): Promise<{ + /** @description An array of Fields containing the proof */ + proofAsFields: string[]; + /** @description An array of Fields containing the verification key */ + vkAsFields: string[]; + /** @description A Field containing the verification key hash */ + vkHash: string; + }>; + + /** + * @description Verifies a final proof */ verifyFinalProof(proofData: ProofData): Promise; + + /** @description Verifies an intermediate proof */ verifyIntermediateProof(proofData: ProofData): Promise; + + /** + * @description Destroys the backend */ destroy(): Promise; } +/** + * @description + * The representation of a proof + * */ export type ProofData = { + /** @description Public inputs of a proof */ publicInputs: Uint8Array[]; + /** @description An byte array representing the proof */ proof: Uint8Array; }; +/** + * @description + * The representation of a compiled circuit + * */ export type CompiledCircuit = { + /** @description The bytecode of the circuit */ bytecode: string; + /** @description ABI representation of the circuit */ abi: Abi; }; diff --git a/tooling/noir_js_types/tsconfig.json b/tooling/noir_js_types/tsconfig.json index 1fe2a46abaa..0d5441cc5a2 100644 --- a/tooling/noir_js_types/tsconfig.json +++ b/tooling/noir_js_types/tsconfig.json @@ -1,12 +1,13 @@ { "compilerOptions": { + "composite": true, "declaration": true, "module": "ESNext", "moduleResolution": "node", "outDir": "lib/esm", "target": "ES2020", - "rootDir": "./src" + "rootDir": "./src", }, "include": ["src/**/*.ts"], "exclude": ["node_modules"] -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index f423ba8b384..87713e1f915 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2281,7 +2281,7 @@ __metadata: languageName: node linkType: hard -"@docusaurus/types@npm:2.4.3": +"@docusaurus/types@npm:2.4.3, @docusaurus/types@npm:^2.4.1": version: 2.4.3 resolution: "@docusaurus/types@npm:2.4.3" dependencies: @@ -5915,6 +5915,13 @@ __metadata: languageName: node linkType: hard +"ansi-sequence-parser@npm:^1.1.0": + version: 1.1.1 + resolution: "ansi-sequence-parser@npm:1.1.1" + checksum: ead5b15c596e8e85ca02951a844366c6776769dcc9fd1bd3a0db11bb21364554822c6a439877fb599e7e1ffa0b5f039f1e5501423950457f3dcb2f480c30b188 + languageName: node + linkType: hard + "ansi-styles@npm:^3.2.1": version: 3.2.1 resolution: "ansi-styles@npm:3.2.1" @@ -8285,12 +8292,18 @@ __metadata: "@mdx-js/react": ^1.6.22 axios: ^1.4.0 clsx: ^1.2.1 + docusaurus-plugin-typedoc: 1.0.0-next.18 hast-util-is-element: ^1.1.0 prism-react-renderer: ^1.3.5 react: ^17.0.2 react-dom: ^17.0.2 rehype-katex: ^5.0.0 remark-math: ^3.0.1 + typedoc: ^0.25.0 + typedoc-plugin-frontmatter: ^0.0.2 + typedoc-plugin-markdown: 4.0.0-next.25 + typedoc-plugin-merge-modules: ^5.1.0 + typescript: ^5.2.2 languageName: unknown linkType: soft @@ -8303,6 +8316,17 @@ __metadata: languageName: node linkType: hard +"docusaurus-plugin-typedoc@npm:1.0.0-next.18": + version: 1.0.0-next.18 + resolution: "docusaurus-plugin-typedoc@npm:1.0.0-next.18" + dependencies: + "@docusaurus/types": ^2.4.1 + peerDependencies: + typedoc-plugin-markdown: ">=4.0.0-next.24" + checksum: a501e3bd1cc5b33d215a1b71b018a34d4aa5bd98f39580ab114a127d3f555078443d6b690119c0adb17fb8867ba4131382ad5d14dbaa7919715020cdfaf6b9c4 + languageName: node + linkType: hard + "dom-converter@npm:^0.2.0": version: 0.2.0 resolution: "dom-converter@npm:0.2.0" @@ -11459,6 +11483,13 @@ __metadata: languageName: node linkType: hard +"jsonc-parser@npm:^3.2.0": + version: 3.2.0 + resolution: "jsonc-parser@npm:3.2.0" + checksum: 946dd9a5f326b745aa326d48a7257e3f4a4b62c5e98ec8e49fa2bdd8d96cef7e6febf1399f5c7016114fd1f68a1c62c6138826d5d90bc650448e3cf0951c53c7 + languageName: node + linkType: hard + "jsonfile@npm:^2.1.0": version: 2.4.0 resolution: "jsonfile@npm:2.4.0" @@ -12140,6 +12171,15 @@ __metadata: languageName: node linkType: hard +"marked@npm:^4.3.0": + version: 4.3.0 + resolution: "marked@npm:4.3.0" + bin: + marked: bin/marked.js + checksum: 0db6817893952c3ec710eb9ceafb8468bf5ae38cb0f92b7b083baa13d70b19774674be04db5b817681fa7c5c6a088f61300815e4dd75a59696f4716ad69f6260 + languageName: node + linkType: hard + "marky@npm:^1.2.2": version: 1.2.5 resolution: "marky@npm:1.2.5" @@ -12425,7 +12465,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:^9.0.1": +"minimatch@npm:^9.0.1, minimatch@npm:^9.0.3": version: 9.0.3 resolution: "minimatch@npm:9.0.3" dependencies: @@ -15471,6 +15511,18 @@ __metadata: languageName: node linkType: hard +"shiki@npm:^0.14.1": + version: 0.14.5 + resolution: "shiki@npm:0.14.5" + dependencies: + ansi-sequence-parser: ^1.1.0 + jsonc-parser: ^3.2.0 + vscode-oniguruma: ^1.7.0 + vscode-textmate: ^8.0.0 + checksum: 41d847817cfc9bb6d8bf190316896698d250303656546446659cc02caed8dcc171b10cd113bb5da82425b51d0032e87aafcdc36c3dd61dadc123170b438da736 + languageName: node + linkType: hard + "side-channel@npm:^1.0.4": version: 1.0.4 resolution: "side-channel@npm:1.0.4" @@ -16511,6 +16563,49 @@ __metadata: languageName: node linkType: hard +"typedoc-plugin-frontmatter@npm:^0.0.2": + version: 0.0.2 + resolution: "typedoc-plugin-frontmatter@npm:0.0.2" + dependencies: + yaml: ^2.2.2 + checksum: 44cbdb82e3fd8f4eb89cdf54783b5b07b03a57edc7bda85a48280edba73f401a2f5439cbba97426dd79e9584c410244af5dd20d5d7281c27d67d61675fa7aaef + languageName: node + linkType: hard + +"typedoc-plugin-markdown@npm:4.0.0-next.25": + version: 4.0.0-next.25 + resolution: "typedoc-plugin-markdown@npm:4.0.0-next.25" + peerDependencies: + typedoc: ">=0.25.0" + checksum: 284e2ce44446faf8db5fc54dfa84e7cd819cfc60bbed12ffb781cb24a166ba6b3a220c542990a3eb14aefff33f1d7c8322378297551f55476155cf532fbbb807 + languageName: node + linkType: hard + +"typedoc-plugin-merge-modules@npm:^5.1.0": + version: 5.1.0 + resolution: "typedoc-plugin-merge-modules@npm:5.1.0" + peerDependencies: + typedoc: 0.24.x || 0.25.x + checksum: f01d825a1c6b73c29faaf515e76076931b16bcc5762c8e9b56d18a7eca6d450bd3691012e96bc3a09ce05f29aef90744e93e187171c561ef0a3c2c1fe116803f + languageName: node + linkType: hard + +"typedoc@npm:^0.25.0": + version: 0.25.2 + resolution: "typedoc@npm:0.25.2" + dependencies: + lunr: ^2.3.9 + marked: ^4.3.0 + minimatch: ^9.0.3 + shiki: ^0.14.1 + peerDependencies: + typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x + bin: + typedoc: bin/typedoc + checksum: 5b6e24bae7498bb542aaba495378ed5a3e13c76eb04a1ae95b506f76bda4d517847101fb05a7eab3f6b79357d1e2ac6f4747d39792395329b72e463f7effda65 + languageName: node + linkType: hard + "typescript@npm:4.9.4": version: 4.9.4 resolution: "typescript@npm:4.9.4" @@ -17054,6 +17149,20 @@ __metadata: languageName: node linkType: hard +"vscode-oniguruma@npm:^1.7.0": + version: 1.7.0 + resolution: "vscode-oniguruma@npm:1.7.0" + checksum: 53519d91d90593e6fb080260892e87d447e9b200c4964d766772b5053f5699066539d92100f77f1302c91e8fc5d9c772fbe40fe4c90f3d411a96d5a9b1e63f42 + languageName: node + linkType: hard + +"vscode-textmate@npm:^8.0.0": + version: 8.0.0 + resolution: "vscode-textmate@npm:8.0.0" + checksum: 127780dfea89559d70b8326df6ec344cfd701312dd7f3f591a718693812b7852c30b6715e3cfc8b3200a4e2515b4c96f0843c0eacc0a3020969b5de262c2a4bb + languageName: node + linkType: hard + "wait-on@npm:^6.0.1": version: 6.0.1 resolution: "wait-on@npm:6.0.1" @@ -17595,6 +17704,13 @@ __metadata: languageName: node linkType: hard +"yaml@npm:^2.2.2": + version: 2.3.3 + resolution: "yaml@npm:2.3.3" + checksum: cdfd132e7e0259f948929efe8835923df05c013c273c02bb7a2de9b46ac3af53c2778a35b32c7c0f877cc355dc9340ed564018c0242bfbb1278c2a3e53a0e99e + languageName: node + linkType: hard + "yargs-parser@npm:20.2.4": version: 20.2.4 resolution: "yargs-parser@npm:20.2.4"