-
Notifications
You must be signed in to change notification settings - Fork 36
Add initial Next.js project structure for Noir UH Starter #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6ef908c
Add initial Next.js project structure for Noir UH Starter
critesjosh 3625c7a
test nextjs
critesjosh d376266
rename folder
critesjosh 02ab29a
fix dir name
critesjosh 2a10072
fix port
critesjosh 4dba31c
add api
critesjosh 0e0f7f2
update path, test
critesjosh 86cc458
Merge branch 'master' into jc/web-starter-nextjs
critesjosh 05d956e
Fix nextjs ci tests complete (#75)
critesjosh 82d67b3
Add issue creation step for nightly workflow failures in Playwright CI
critesjosh 29adbc7
working
critesjosh c1a220b
chore: cleanup next config
saleel 8706812
chore: add config comments
saleel dc4bdfa
chore: add crsPath option
saleel ace6fcb
update nextjs version
critesjosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| node_modules/ | ||
| .next/ | ||
| dist/ | ||
| .env* | ||
| yarn.lock | ||
| npm-debug.log* | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Introduction | ||
|
|
||
| A simple Noir circuit with browser proving with bb.js | ||
| This is a Next.js version, similar to the vite and webpack examples. | ||
|
|
||
| Tested with Noir 1.0.0-beta.6, bb 0.84.0, and Next.js 14. | ||
|
|
||
| ## Setup | ||
|
|
||
| ```bash | ||
| (cd ../../circuits && ./build.sh) | ||
| yarn | ||
| ``` | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| yarn dev | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| background: #f8f8f8; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .container, main { | ||
| max-width: 600px; | ||
| margin: 40px auto; | ||
| background: #fff; | ||
| border-radius: 8px; | ||
| box-shadow: 0 2px 8px rgba(0,0,0,0.08); | ||
| padding: 32px; | ||
| } | ||
|
|
||
| h1 { | ||
| font-size: 2rem; | ||
| margin-bottom: 1.5rem; | ||
| } | ||
|
|
||
| button { | ||
| padding: 0.5rem 1.5rem; | ||
| font-size: 1rem; | ||
| border-radius: 4px; | ||
| border: none; | ||
| background: #0070f3; | ||
| color: #fff; | ||
| cursor: pointer; | ||
| margin-bottom: 1rem; | ||
| } | ||
|
|
||
| button:disabled { | ||
| background: #aaa; | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| #result { | ||
| background: #f4f4f4; | ||
| border-radius: 4px; | ||
| padding: 1rem; | ||
| min-height: 2rem; | ||
| margin-top: 1rem; | ||
| font-family: monospace; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import './globals.css'; | ||
| import type { ReactNode } from 'react'; | ||
|
|
||
| export default function RootLayout({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <html lang="en"> | ||
| <body> | ||
| {children} | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import ProofComponent from './proof-component'; | ||
|
|
||
| export default function HomePage() { | ||
| return ( | ||
| <main className="container"> | ||
| <h1>Noir UH Starter (Next.js)</h1> | ||
| <ProofComponent /> | ||
| </main> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| "use client"; | ||
| import { useState } from "react"; | ||
| import { UltraHonkBackend } from "@aztec/bb.js"; | ||
| import circuit from "../../../circuits/target/noir_uh_starter.json"; | ||
| import { Noir } from "@noir-lang/noir_js"; | ||
|
|
||
| export default function ProofComponent() { | ||
| const [result, setResult] = useState(""); | ||
| const [loading, setLoading] = useState(false); | ||
|
|
||
| async function generateProof() { | ||
| setLoading(true); | ||
| setResult((prev) => prev + "Generating proof...\n\n"); | ||
| try { | ||
| const noir = new Noir(circuit as any); | ||
| const honk = new UltraHonkBackend((circuit as any).bytecode, { | ||
| threads: 8, | ||
| }); | ||
| const inputs = { x: 3, y: 3 }; | ||
| const { witness } = await noir.execute(inputs); | ||
| const { proof, publicInputs } = await honk.generateProof(witness); | ||
| setResult((prev) => prev + "Proof: " + proof + "\n\n"); | ||
| setResult((prev) => prev + "Public inputs: " + publicInputs + "\n\n"); | ||
| const verified = await honk.verifyProof({ proof, publicInputs }); | ||
| setResult((prev) => prev + "Verified: " + verified + "\n\n"); | ||
|
|
||
| // Send proof to server for server-side verification | ||
| setResult((prev) => prev + "Verifying on server...\n\n"); | ||
| const response = await fetch("/api/verify", { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ proof, publicInputs }), | ||
| }); | ||
| const serverResult = await response.json(); | ||
| setResult( | ||
| (prev) => prev + "Server verified: " + serverResult.verified + "\n\n" | ||
| ); | ||
| } catch (error) { | ||
| setResult((prev) => prev + "Error: " + error + "\n\n"); | ||
| } | ||
| setLoading(false); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <button id="generateProofBtn" onClick={generateProof} disabled={loading}> | ||
| {loading ? "Generating..." : "Generate Proof"} | ||
| </button> | ||
| <div style={{ whiteSpace: "pre-wrap" }} id="result"> | ||
| {result} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| /// <reference types="next/navigation-types/compat/navigation" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
|
|
||
| /** @type {import('next').NextConfig} */ | ||
| const nextConfig = { | ||
| experimental: { | ||
| outputFileTracingIncludes: { | ||
| '/api/verify': [ | ||
| './node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/**/*', | ||
| './node_modules/@aztec/bb.js/dest/node/barretenberg_wasm/barretenberg_wasm_thread/factory/node/thread.worker.js' | ||
| ], | ||
| }, | ||
| }, | ||
| webpack: (config) => { | ||
| config.experiments = { | ||
| asyncWebAssembly: true, | ||
| syncWebAssembly: true, | ||
| layers: true, | ||
| }; | ||
| return config; | ||
| }, | ||
| // async headers() { | ||
| // return [ | ||
| // { | ||
| // // Exclude all oauth-callback paths | ||
| // source: '/((?!oauth-callback).*)', | ||
| // headers: [ | ||
| // { | ||
| // key: 'Cross-Origin-Embedder-Policy', | ||
| // value: 'require-corp', | ||
| // }, | ||
| // { | ||
| // key: 'Cross-Origin-Opener-Policy', | ||
| // value: 'same-origin', | ||
| // }, | ||
| // ], | ||
| // }, | ||
| // { | ||
| // // Special case for iOS devices - disable COOP/COEP | ||
| // source: '/((?!oauth-callback).*)', | ||
| // headers: [ | ||
| // { | ||
| // key: 'Cross-Origin-Embedder-Policy', | ||
| // value: 'unsafe-none', | ||
| // }, | ||
| // { | ||
| // key: 'Cross-Origin-Opener-Policy', | ||
| // value: 'unsafe-none', | ||
| // }, | ||
| // ], | ||
| // // Only apply these headers for iOS devices | ||
| // has: [ | ||
| // { | ||
| // type: 'header', | ||
| // key: 'user-agent', | ||
| // value: '(.*iPhone|iPad|iPod.*)', | ||
| // }, | ||
| // ], | ||
| // }, | ||
| // ]; | ||
| // }, | ||
| }; | ||
|
|
||
| export default nextConfig; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "nextjs-noir", | ||
| "type": "module", | ||
| "dependencies": { | ||
| "@aztec/bb.js": "0.84.0", | ||
| "@noir-lang/noir_js": "1.0.0-beta.6", | ||
| "next": "14.2.3", | ||
| "react": "18.2.0", | ||
| "react-dom": "18.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.53.0", | ||
| "@types/node": "^22.10.1", | ||
| "@types/react": "^18.2.62", | ||
| "@types/react-dom": "^18.2.19", | ||
| "typescript": "^5.8.3" }, | ||
| "scripts": { | ||
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "next start", | ||
| "test:e2e": "playwright test" | ||
| }, | ||
| "packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import type { NextApiRequest, NextApiResponse } from 'next'; | ||
| import { UltraHonkBackend } from '@aztec/bb.js'; | ||
| import { promises as fs } from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| // Load circuit data at module level (outside the handler) | ||
| let circuit: any = null; | ||
| let honk: UltraHonkBackend | null = null; | ||
|
|
||
| async function initializeCircuit() { | ||
| if (!circuit) { | ||
| const circuitPath = path.resolve(process.cwd(), '../../circuits/target/noir_uh_starter.json'); | ||
| const circuitData = await fs.readFile(circuitPath, 'utf-8'); | ||
| circuit = JSON.parse(circuitData); | ||
| honk = new UltraHonkBackend(circuit.bytecode, { threads: 8 }); | ||
| } | ||
| } | ||
|
|
||
| export default async function handler( | ||
| req: NextApiRequest, | ||
| res: NextApiResponse | ||
| ) { | ||
| if (req.method !== 'POST') { | ||
| res.setHeader('Allow', ['POST']); | ||
| return res.status(405).end(`Method ${req.method} Not Allowed`); | ||
| } | ||
|
|
||
| try { | ||
| // Initialize circuit if not already done | ||
| await initializeCircuit(); | ||
|
|
||
| const { proof, publicInputs } = req.body; | ||
|
|
||
| if (!proof || !publicInputs) { | ||
| return res.status(400).json({ | ||
| error: 'Missing proof or publicInputs', | ||
| verified: false | ||
| }); | ||
| } | ||
|
|
||
| if (!honk) { | ||
| throw new Error('Backend not initialized'); | ||
| } | ||
|
|
||
| // Convert proof to Uint8Array if it's not already | ||
| let proofArray: Uint8Array; | ||
| if (proof instanceof Uint8Array) { | ||
| proofArray = proof; | ||
| } else if (Array.isArray(proof)) { | ||
| proofArray = new Uint8Array(proof); | ||
| } else if (typeof proof === 'object' && proof !== null) { | ||
| // Handle serialized Uint8Array (object with numeric keys) | ||
| const values = Object.values(proof) as number[]; | ||
| proofArray = new Uint8Array(values); | ||
| } else { | ||
| throw new Error('Invalid proof format'); | ||
| } | ||
|
|
||
| const publicInputsArray = Array.isArray(publicInputs) ? publicInputs : [publicInputs]; | ||
|
|
||
| const verified = await honk.verifyProof({ | ||
| proof: proofArray, | ||
| publicInputs: publicInputsArray | ||
| }); | ||
|
|
||
| return res.status(200).json({ | ||
| verified, | ||
| message: verified ? 'Proof verified successfully' : 'Proof verification failed' | ||
| }); | ||
| } catch (error) { | ||
| console.error('Server-side verification error:', error); | ||
| return res.status(500).json({ | ||
| error: String(error), | ||
| verified: false | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // playwright.config.js | ||
| // @ts-check | ||
| /** @type {import('@playwright/test').PlaywrightTestConfig} */ | ||
| const config = { | ||
| webServer: { | ||
| command: 'yarn dev', | ||
| port: 3000, | ||
| timeout: 120 * 1000, | ||
| reuseExistingServer: !process.env.CI, | ||
| }, | ||
| use: { | ||
| baseURL: 'http://localhost:3000', | ||
| headless: true, | ||
| }, | ||
| projects: [ | ||
| { name: 'chromium', use: { browserName: 'chromium' } }, | ||
| { name: 'firefox', use: { browserName: 'firefox' } }, | ||
| { name: 'webkit', use: { browserName: 'webkit' } }, | ||
| ], | ||
| }; | ||
|
|
||
| module.exports = config; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.