Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8f3cc11
feat(ipc-runtime): a JSI binding, for services linked into a React Na…
charlielye Nov 19, 2026
146bcf1
feat(bb.js): a React Native build, on bb linked into the app
charlielye Nov 19, 2026
5e1c246
feat: @aztec-foundation/react-native, to run a labs PXE in a React Na…
charlielye Nov 19, 2026
607aa03
Merge remote-tracking branch 'origin/cl/kv-sqlite' into cl/react-nati…
charlielye Nov 19, 2026
48d7127
style(react-native): the Noir test in the package's style
charlielye Nov 19, 2026
54e4f1e
fix(react-native): build the ACVM and kv-sqlite packages before the p…
charlielye Nov 19, 2026
0d77cf7
Merge branch 'cl/kv-sqlite' into cl/react-native
charlielye Nov 21, 2026
5b79ecf
feat(ipc-runtime): asynchronous instances over JSI
charlielye Nov 21, 2026
8663af5
chore(labs-patches): raise the playground's main entrypoint limit to …
charlielye Nov 21, 2026
9222557
Merge cl/kv-sqlite into cl/react-native
charlielye Nov 21, 2026
ed33e5c
Merge cl/kv-sqlite into cl/react-native
charlielye Nov 21, 2026
fdb6f54
Merge cl/kv-sqlite into cl/react-native
charlielye Nov 22, 2026
603b2b2
Merge cl/kv-sqlite into cl/react-native
charlielye Nov 22, 2026
e5ba1ee
Merge branch 'cl/kv-sqlite' into cl/react-native
charlielye Nov 22, 2026
55cc04b
Merge branch 'cl/kv-sqlite' into cl/react-native
charlielye Nov 22, 2026
c4e4557
Merge branch 'cl/kv-sqlite' into cl/react-native
charlielye Nov 22, 2026
f9abe7e
Merge remote-tracking branch 'origin/cl/kv-sqlite' into cl/react-native
charlielye Nov 24, 2026
f557a81
Merge cl/kv-sqlite into cl/react-native
charlielye Nov 25, 2026
dfddbbb
Merge cl/kv-sqlite into cl/react-native
charlielye Nov 25, 2026
20eefbc
Merge cl/kv-sqlite into cl/react-native
charlielye Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fast-foundation: barretenberg bb-tests \
protocol-contracts protocol-contracts-tests \
fnd-release-tests fnd-genesis-tests \
ipc-runtime ipc-codegen-tests \
react-native-tests \
constants-codegen constants-codegen-tests \
labs-patches-tests \
claude-tests \
Expand Down Expand Up @@ -104,7 +105,7 @@ bench: bench-foundation bench-labs

# Release: everything, plus the cross builds and release tarballs. Each project's release step packages every
# platform's binaries from the cross build directories itself.
release-foundation: fast-foundation bb-cpp-release-dir ipc-runtime-cross
release-foundation: fast-foundation bb-cpp-release-dir ipc-runtime-cross react-native-mobile

release-labs: fast-labs

Expand Down Expand Up @@ -427,6 +428,25 @@ acvm-tests: acvm
kv-sqlite-tests: kv-sqlite
$(call test,$@,native-packages/kv-sqlite)

# The ACVM's static library for Android and iOS (release only), which @aztec-foundation/react-native ships.
acvm-mobile: acvm
$(call build,$@,native-packages/acvm,build_mobile)

# @aztec-foundation/react-native: the native module a React Native app links to run the client stack. Its tests run
# bb.js, bb, the ACVM, kv-sqlite and ipc-codegen's echo example from this tree under Hermes, through the module (see
# native-packages/react-native/README.md).
.PHONY: react-native react-native-tests react-native-mobile acvm-mobile
# Its node_modules portal to @aztec-labs/acvm's and kv-sqlite's generated TS packages, so those build first.
react-native: ipc-codegen acvm kv-sqlite
$(call build,$@,native-packages/react-native)

react-native-tests: react-native bb-ts
$(call test,$@,native-packages/react-native)

# The libraries the package ships (release only): bb and the ACVM for Android and iOS.
react-native-mobile: bb-cpp-cross-arm64-ios bb-cpp-cross-arm64-ios-sim bb-cpp-cross-arm64-android \
bb-cpp-cross-x86_64-android acvm-mobile

#==============================================================================
# .claude tooling
#==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/bb.js/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function build {
if ! cache_download bb.js-$hash.tar.gz; then
find . -exec touch -d "@0" {} + 2>/dev/null || true
yarn clean
parallel -v --line-buffered --tag 'denoise "yarn {}"' ::: build:esm build:cjs build:browser
parallel -v --line-buffered --tag 'denoise "yarn {}"' ::: build:esm build:cjs build:browser build:react-native
cache_upload bb.js-$hash.tar.gz dest
fi

Expand Down
7 changes: 5 additions & 2 deletions barretenberg/ts/bb.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"types": "./dest/node/index.d.ts",
"exports": {
".": {
"react-native": "./dest/react-native/index.js",
"require": "./dest/node-cjs/index.js",
"browser": "./dest/browser/index.js",
"default": "./dest/node/index.js"
Expand All @@ -23,10 +24,11 @@
],
"scripts": {
"clean": "rm -rf ./dest .tsbuildinfo .tsbuildinfo.cjs",
"build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:browser",
"build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:browser && yarn build:react-native",
"build:esm": "tsgo -b tsconfig.esm.json && chmod +x ./dest/node/bin/index.js",
"build:cjs": "tsgo -b tsconfig.cjs.json && ./scripts/cjs_postprocess.sh",
"build:browser": "tsgo -b tsconfig.browser.json && ./scripts/browser_postprocess.sh",
"build:react-native": "tsgo -b tsconfig.react-native.json && ./scripts/react_native_postprocess.sh",
"formatting": "prettier --check ./src && eslint --max-warnings 0 ./src",
"formatting:fix": "eslint --fix ./src && prettier -w ./src",
"test": "NODE_OPTIONS='--loader ts-node/esm' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests",
Expand Down Expand Up @@ -98,5 +100,6 @@
"ts-node": "^10.9.1",
"typescript": "^5.3.3",
"typescript-eslint": "^8.32.1"
}
},
"react-native": "./dest/react-native/index.js"
}
10 changes: 10 additions & 0 deletions barretenberg/ts/bb.js/scripts/react_native_postprocess.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# The React Native build: the browser build's rewrite, to the react-native directories.
DIR="./dest/react-native"

for node_dir in $(find $DIR -type d \( -name node -o -name browser \)); do
rm -rf $node_dir
done

# Replace all **/node/** imports and exports with **/react-native/**
find "$DIR" -type f -name "*.js" -exec sed -i 's/\(import\|export\)\(.*\)from\(.*\)\/node\//\1\2from\3\/react-native\//g' {} +
3 changes: 3 additions & 0 deletions barretenberg/ts/bb.js/src/backends/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export function findBbBinary(_customPath?: string): string | null {
throw new Error('findBbBinary is not available in a browser.');
}

/** The in-process backend when none is named and no process is used: bb's wasm module. */
export const IN_PROCESS_BACKEND: BackendType = BackendType.Wasm;

/**
* Create backend of specific type (no fallback)
*/
Expand Down
6 changes: 6 additions & 0 deletions barretenberg/ts/bb.js/src/backends/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export enum BackendType {
* (BarretenbergSync) or on a native thread of its own (Barretenberg). No process is spawned.
*/
Napi = 'Napi',
/**
* bb's library linked into a React Native app, through JSI (React Native only, where it is the default): an
* instance of bb of its own, on the calling thread (BarretenbergSync) or on a native thread of its own
* (Barretenberg).
*/
Jsi = 'Jsi',
}

export type BackendOptions = {
Expand Down
3 changes: 3 additions & 0 deletions barretenberg/ts/bb.js/src/backends/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const SHM_RING_SIZE = 1024 * 1024 * 4;
*/
const BB_PROCESS_LIFETIME = { unref: true };

/** The in-process backend when none is named and no process is used: bb's wasm module. */
export const IN_PROCESS_BACKEND: BackendType = BackendType.Wasm;

/**
* Create backend of specific type (no fallback). Everything here is bb's choice of options over
* @aztec-foundation/bb.js-api's backends: thread defaults, ring sizes, artifact overrides.
Expand Down
46 changes: 46 additions & 0 deletions barretenberg/ts/bb.js/src/backends/react-native/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createBackend, createBackendSync } from '@aztec-foundation/bb.js-api/react-native';
import type { IpcClientAsync, IpcClientSync } from '@aztec-foundation/ipc-runtime';

import { BackendOptions, BackendType } from '../index.js';

/** There is no bb binary in a React Native app; bb is a library linked into it. */
export function findBbBinary(_customPath?: string): string | null {
throw new Error('findBbBinary is not available in React Native.');
}

/** React Native has no WebAssembly: bb runs in-process as the library the app links, over JSI. */
export const IN_PROCESS_BACKEND: BackendType = BackendType.Jsi;

/**
* Create backend of specific type (no fallback)
*/
export async function createAsyncBackend(
type: BackendType,
_options: BackendOptions,
logger: (msg: string) => void,
): Promise<IpcClientAsync> {
switch (type) {
case BackendType.Jsi:
logger('Using the JSI backend (bb on a native thread of its own)');
return await createBackend();
default:
throw new Error(`Backend ${type} not supported in React Native (use BackendType.Jsi)`);
}
}

/**
* Create backend of specific type (no fallback)
*/
export async function createSyncBackend(
type: BackendType,
_options: BackendOptions,
logger: (msg: string) => void,
): Promise<IpcClientSync> {
switch (type) {
case BackendType.Jsi:
logger('Using the JSI backend (bb on the calling thread)');
return await createBackendSync();
default:
throw new Error(`Backend ${type} not supported in React Native (use BackendType.Jsi)`);
}
}
24 changes: 14 additions & 10 deletions barretenberg/ts/bb.js/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AsyncApi, SyncApi } from '@aztec-foundation/bb.js-api';
import type { IpcClientAsync } from '@aztec-foundation/ipc-runtime';
import { isIos } from '@aztec-foundation/ipc-runtime/wasm';

import { BackendOptions, BackendType } from '../backends/index.js';
import { createAsyncBackend, createSyncBackend } from '../backends/node/index.js';
import { IN_PROCESS_BACKEND, createAsyncBackend, createSyncBackend } from '../backends/node/index.js';
import { Crs, GrumpkinCrs } from '../crs/index.js';
import { isIos } from '../platform/node/index.js';

const DEFAULT_BB_CRS_SIZE = 2 ** 19;
const BN254_SRS_CHUNK_POINTS = 2 ** 17;
Expand Down Expand Up @@ -49,7 +49,7 @@ export class Barretenberg extends AsyncApi {
* If options.backend is set: uses that specific backend (throws if unavailable)
* If options.backend is unset: tries backends in order with fallback:
* 1. NativeUnixSocket (node, if the bb binary is available)
* 2. Wasm
* 2. Wasm (Jsi in React Native, which has no WebAssembly)
*
* Every backend runs off the calling thread: a bb process, or bb in-process on a thread of its own (a worker for
* Wasm, a native thread for Napi). For calls on the calling thread, use BarretenbergSync.
Expand All @@ -60,20 +60,24 @@ export class Barretenberg extends AsyncApi {
if (options.backend) {
// Explicit backend required - no fallback
const backend = new Barretenberg(await createAsyncBackend(options.backend, options, logger), options);
if (options.backend === BackendType.Wasm || options.backend === BackendType.Napi) {
if (
options.backend === BackendType.Wasm ||
options.backend === BackendType.Napi ||
options.backend === BackendType.Jsi
) {
await backend.initInProcess();
}
return backend;
}

if (typeof window === 'undefined') {
if (typeof window === 'undefined' && IN_PROCESS_BACKEND !== BackendType.Jsi) {
try {
return new Barretenberg(await createAsyncBackend(BackendType.NativeUnixSocket, options, logger), options);
} catch (err: any) {
logger(`Unix socket unavailable (${err.message}), falling back to WASM`);
logger(`Unix socket unavailable (${err.message}), falling back to ${IN_PROCESS_BACKEND}`);
}
}
const backend = new Barretenberg(await createAsyncBackend(BackendType.Wasm, options, logger), options);
const backend = new Barretenberg(await createAsyncBackend(IN_PROCESS_BACKEND, options, logger), options);
await backend.initInProcess();
return backend;
}
Expand Down Expand Up @@ -197,7 +201,7 @@ export class BarretenbergSync extends SyncApi {
* If options.backend is unset: tries backends in order with fallback:
* 1. Napi (node, if bb's library is installed): bb in-process, on the calling thread
* 2. NativeSharedMem (node, if the bb binary and ipc-runtime's addon are available)
* 3. Wasm
* 3. Wasm (Jsi in React Native, which has no WebAssembly)
*
* Supported backends: Wasm, Napi, NativeSharedMem
* Not supported: NativeUnixSocket (asynchronous only). Every backend runs on the calling thread.
Expand All @@ -209,7 +213,7 @@ export class BarretenbergSync extends SyncApi {
return new BarretenbergSync(await createSyncBackend(options.backend, options, logger));
}

if (typeof window === 'undefined') {
if (typeof window === 'undefined' && IN_PROCESS_BACKEND !== BackendType.Jsi) {
for (const backend of [BackendType.Napi, BackendType.NativeSharedMemory]) {
try {
return new BarretenbergSync(await createSyncBackend(backend, options, logger));
Expand All @@ -219,7 +223,7 @@ export class BarretenbergSync extends SyncApi {
}
}

return new BarretenbergSync(await createSyncBackend(BackendType.Wasm, options, logger));
return new BarretenbergSync(await createSyncBackend(IN_PROCESS_BACKEND, options, logger));
}

/**
Expand Down
Loading
Loading