Skip to content

Commit

Permalink
chore(docs): Rearrange NoirJS section (#3260)
Browse files Browse the repository at this point in the history
  • Loading branch information
Savio-Sou authored and guipublic committed Oct 27, 2023
1 parent 36508c2 commit 5874a87
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
10 changes: 6 additions & 4 deletions docs/docs/language_concepts/01_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,21 @@ See [Lambdas](./08_lambdas.md) for more details.
Attributes are metadata that can be applied to a function, using the following syntax: `#[attribute(value)]`.

Supported attributes include:

- **builtin**: the function is implemented by the compiler, for efficiency purposes.
- **deprecated**: mark the function as *deprecated*. Calling the function will generate a warning: `warning: use of deprecated function`
- **deprecated**: mark the function as _deprecated_. Calling the function will generate a warning: `warning: use of deprecated function`
- **field**: Used to enable conditional compilation of code depending on the field size. See below for more details
- **oracle**: mark the function as *oracle*; meaning it is an external unconstrained function, implemented in noir_js. See [Unconstrained](./05_unconstrained.md) and [Noir js](../noir_js/noir_js.md) for more details.
- **oracle**: mark the function as _oracle_; meaning it is an external unconstrained function, implemented in noir_js. See [Unconstrained](./05_unconstrained.md) and [NoirJS](../noir_js/noir_js.md) for more details.
- **test**: mark the function as unit tests. See [Tests](../nargo/02_testing.md) for more details

### Field Attribute

The field attribute defines which field the function is compatible for. The function is conditionally compiled, under the condition that the field attribute matches the Noir native field.
The field can be defined implicitly, by using the name of the elliptic curve usually associated to it - for instance bn254, bls12_381 - or explicitly by using the field (prime) order, in decimal or hexadecimal form.
As a result, it is possible to define multiple versions of a function with each version specialized for a different field attribute. This can be useful when a function requires different parameters depending on the underlying elliptic curve.


Example: we define the function `foo()` three times below. Once for the default Noir bn254 curve, once for the field $\mathbb F_{23}$, which will normally never be used by Noir, and once again for the bls12_381 curve.

```rust
#[field(bn254)]
fn foo() -> u32 {
Expand All @@ -184,4 +186,4 @@ fn foo() -> u32 {
}
```

If the field name is not known to Noir, it will discard the function. Field names are case insensitive.
If the field name is not known to Noir, it will discard the function. Field names are case insensitive.
4 changes: 2 additions & 2 deletions docs/docs/noir_js/getting_started/01_tiny_noir_app.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Full Stack Noir App
title: End-to-end
description: Learn how to setup a new app that uses Noir to generate and verify zero-knowledge SNARK proofs in a typescript or javascript environment
keywords: [how to, guide, javascript, typescript, noir, barretenberg, zero-knowledge, proofs]
---

Noir JS works both on the browser and on the server, and works for both ESM and CJS module systems. In this page, we will learn how can we write a simple test and a simple web app to verify the standard Noir example.
NoirJS works both on the browser and on the server, and works for both ESM and CJS module systems. In this page, we will learn how can we write a simple test and a simple web app to verify the standard Noir example.

## Before we start

Expand Down
34 changes: 24 additions & 10 deletions docs/docs/noir_js/noir_js.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
---
title: Noir JS
description: Learn how to use noir js to use Noir in a Typescript or Javascript environment
title: NoirJS
description: Interact with Noir in Typescript or Javascript
keywords: [Noir project, javascript, typescript, node.js, browser, react]
---

Noir JS are a set of typescript libraries that make it easy to use Noir on your dapp, webapp, node.js server, website, etc.
NoirJS is a TypeScript library that make it easy to use Noir on your dapp, webapp, Node.js server, website, etc.

It is composed of two major elements:
A typical workflow would be composed of two major elements:

- Noir
- Backend proving system
- NoirJS
- Proving backend of choice's JavaScript package

<!-- TODO add "and noir_wasm" to the end once it's ready -->

Your only concern should be to write Noir. Noir.js will work out-of-the box and abstract all the components, such as the ACVM and others.
To install NoirJS, install Node.js if you have not already and run this in your JavaScript project:

## Barretenberg
```bash
npm i @noir-lang/noir_js
```

Since Noir is backend agnostic, you can instantiate `noir_js` without any backend (i.e. to execute a function). But for proving, you should instantiate it with any of the supported backends through their own `js` interface.
## Proving backend

Aztec Labs maintains the `barretenberg` backend. You can use it to instantiate your `Noir` class.
Since Noir is backend agnostic, you can instantiate NoirJS without any backend (i.e. to execute a function). But for proving, you would have to instantiate NoirJS with any of the supported backends through their own `js` interface.

### Barretenberg

Aztec Labs maintains the `barretenberg` proving backend, which you can instantiate and make use of alongside NoirJS. It is also the default proving backend installed and used with Nargo, the Noir CLI tool.

To install its JavaScript library, run this in your project:

```bash
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.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constructor(acirCircuit, (numberOfThreads = 1));

| 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](02_noirjs.md) |
| `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
Expand Down
10 changes: 5 additions & 5 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,29 @@ const sidebars = {
},
{
type: 'category',
label: 'Noir JS',
label: 'NoirJS',
link: {
type: 'doc',
id: 'noir_js/noir_js',
},
items: [
{
type: 'category',
label: 'Reference',
label: 'Guides',
items: [
{
type: 'autogenerated',
dirName: 'noir_js/reference',
dirName: 'noir_js/getting_started',
},
],
},
{
type: 'category',
label: 'Guides',
label: 'Reference',
items: [
{
type: 'autogenerated',
dirName: 'noir_js/getting_started',
dirName: 'noir_js/reference',
},
],
},
Expand Down

0 comments on commit 5874a87

Please sign in to comment.