├── .gitignore ├── LICENSE ├── README.md ├── bun.lockb ├── circuit ├── Nargo.toml ├── src │ └── main.nr └── target │ └── circuit.json ├── index.html ├── index.js ├── package.json └── vite.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .vscode 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 noir-lang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tiny NoirJS app 2 | 3 | This repo contains the full code from [this](https://noir-lang.org/docs/tutorials/noirjs_app) Noir docs page. 4 | 5 | ## Noir project 6 | 7 | Uses `nargo` version 0.31.0. 8 | 9 | Recompile with 10 | 11 | ```bash 12 | nargo compile 13 | ``` 14 | 15 | ## Vite project 16 | 17 | ```bash 18 | cd vite-project 19 | ``` 20 | 21 | Install dependencies with 22 | 23 | ```bash 24 | npm install 25 | ``` 26 | 27 | Run app with: 28 | 29 | ```bash 30 | npm run dev 31 | ``` 32 | -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noir-lang/tiny-noirjs-app/6ce5b3cb0539e456c73291dd35b8ea6bde1b3bce/bun.lockb -------------------------------------------------------------------------------- /circuit/Nargo.toml: -------------------------------------------------------------------------------- 1 | 2 | [package] 3 | name = "circuit" 4 | type = "bin" 5 | -------------------------------------------------------------------------------- /circuit/src/main.nr: -------------------------------------------------------------------------------- 1 | 2 | fn main(age: u8) { 3 | assert(age >= 18); 4 | } 5 | -------------------------------------------------------------------------------- /circuit/target/circuit.json: -------------------------------------------------------------------------------- 1 | {"noir_version":"0.31.0+540bef3597bd3e5775c83ec2ee3c0d4463084b4c","hash":4220416898248580058,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"},{"name":"y","type":{"kind":"field"},"visibility":"public"}],"return_type":null,"error_types":{}},"bytecode":"H4sIAAAAAAAA/7VUSQ7DIAyEhKa99ic2SzC3fqWo5P8vqBopUCHCLWYkZIQlMx4vUhxQ+7mJM+ZsX9kaWK1NXic0+AYdIjmwLq6EhI7cR5MxiSz5EIOHgNYk3FwwGxyoY8E1oGTkNfHxgqKj7OgpGz3hGpCTt2zqfuLPRXqUEPOAuIq5+UfkrfhrBGJg0yrB27Sq4Vnfe0P4f7xnu3R8BY/9TPn+ZRa4bNd685a/VOVfKi6SnwvW+fYm/9nR5wcPIDK6OgYAAA==","debug_symbols":"lZBBCoMwFETvMussaqsUcpVS5KtRAuFHTBQkeHd/FA+Q5Zt5m5mEwXTr1FoefYD+JTjfU7SehRJeVxRm4kwh0hKh60bB8ADdVIfCaJ2R7Hv8Faoy/V2mf8r0ukQX2Gix1DmTh+du5f75QTDu892IewI=","file_map":{"47":{"source":"fn main(x: Field, y: pub Field) {\n assert(x != y);\n}\n\n#[test]\nfn test_main() {\n main(1, 2);\n\n // Uncomment to make test fail\n // main(1, 1);\n}\n","path":"/home/josh/Documents/tiny-noirjs-app/circuit/src/main.nr"}},"names":["main"]} -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 |

Noir app

21 |
22 | 23 | 24 |
25 |
26 |

Logs

27 |

Proof

28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { compile, createFileManager } from "@noir-lang/noir_wasm"; 2 | import { UltraHonkBackend } from "@aztec/bb.js"; 3 | import { Noir } from "@noir-lang/noir_js"; 4 | import initNoirC from "@noir-lang/noirc_abi"; 5 | import initACVM from "@noir-lang/acvm_js"; 6 | import acvm from "@noir-lang/acvm_js/web/acvm_js_bg.wasm?url"; 7 | import noirc from "@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm?url"; 8 | await Promise.all([initACVM(fetch(acvm)), initNoirC(fetch(noirc))]); 9 | 10 | import main from "./circuit/src/main.nr?url"; 11 | import nargoToml from "./circuit/Nargo.toml?url"; 12 | 13 | export async function getCircuit() { 14 | const fm = createFileManager("/"); 15 | const { body } = await fetch(main); 16 | const { body: nargoTomlBody } = await fetch(nargoToml); 17 | 18 | fm.writeFile("./src/main.nr", body); 19 | fm.writeFile("./Nargo.toml", nargoTomlBody); 20 | return await compile(fm); 21 | } 22 | const show = (id, content) => { 23 | const container = document.getElementById(id); 24 | container.appendChild(document.createTextNode(content)); 25 | container.appendChild(document.createElement("br")); 26 | }; 27 | 28 | document.getElementById("submit").addEventListener("click", async () => { 29 | try { 30 | // noir goes here 31 | const { program } = await getCircuit(); 32 | const noir = new Noir(program); 33 | const backend = new UltraHonkBackend(program.bytecode); 34 | const age = document.getElementById("age").value; 35 | show("logs", "Generating witness... ⏳"); 36 | const { witness } = await noir.execute({ age }); 37 | show("logs", "Generated witness... ✅"); 38 | show("logs", "Generating proof... ⏳"); 39 | const proof = await backend.generateProof(witness); 40 | show("logs", "Generated proof... ✅"); 41 | show("results", proof.proof); 42 | show("logs", "Verifying proof... ⌛"); 43 | const isValid = await backend.verifyProof(proof); 44 | show("logs", `Proof is ${isValid ? "valid" : "invalid"}... ✅`); 45 | } catch (err) { 46 | console.error(err); 47 | show("logs", "Oh 💔"); 48 | } 49 | }); 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { "dependencies": { "@aztec/bb.js": "0.63.1", "@noir-lang/noir_js": "1.0.0-beta.0", "@noir-lang/noir_wasm": "1.0.0-beta.0" } } -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | export default { optimizeDeps: { esbuildOptions: { target: "esnext" } } }; 2 | --------------------------------------------------------------------------------