Skip to content

refactor(nitro): port the 28 specs and C++ to Nitro Modules v1 - #1108

Merged
boorad merged 11 commits into
nextfrom
refactor/1102-port-nitro-specs-v1
Nov 28, 2026
Merged

boorad merged 11 commits into
nextfrom
refactor/1102-port-nitro-specs-v1

Conversation

@boorad

@boorad boorad commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

This is the first PR into next (RNQC 2.0). It ports RNQC's 28 Nitro specs (30 HybridObjects) to Nitro Modules v1 (margelo/nitro@43e09c1, npm 1.0.0-alpha.nightly.138.g43e09c161101), regenerates them with nitrogen v1 using "environment": "bare", and ports the C++ hybrid objects to the new headers and types. Following decision 4 from #1100, stateless members become statics and stateful classes get constructors.

next was created from main at 5f9560e.

Changes

  • Dependencies: nitrogen, nitro-core and react-native-nitro-modules are pinned to the v1 nightly. The nitro-core and react-native-nitro-modules peers are optional and pinned to that exact nightly, following decision 7 from Nitro Modules v1: research breaking changes and React Native support #1100.
  • Config: nitro.json is rewritten for v1, with environment: bare and no autolinking block. package.json gains the #nitro/* imports map.
  • Specs: all 28 now use decorated declare class specs that import from nitro-core. The generated output under nitrogen/generated is fully regenerated, and the old ios/ and flat shared/c++ layout is gone.
  • JS: all 66 createHybridObject calls (65 in the package, 1 in the example) become new X() or static calls. The lazy singletons for static-only modules are removed. JS reaches the raw JSI methods (Utils.stringToBuffer/bufferToString, KeyObjectHandle.importSlhDsaRawPrivateKey) through in/typeof type guards, with no casts.
  • C++:
    • ArrayBuffer is now a value type. The ToNativeArrayBuffer helpers deep-copy with ArrayBuffer::copy and never asOwning(), so JS can't mutate bytes that native code is reading.
    • Wrap deleters and the wipe calls (cleanse, secureZero, memzero) are unchanged: 33 sites before and after.
    • dataOrEmpty() guards the OpenSSL and libsodium calls that would otherwise get a null pointer for empty buffers.
    • Promise<T> is returned by value, and async lambdas capture owned data. The DH, DSA, EC, Ed and RSA generateKeyPair lambdas now hold shared_cast self rather than bare this.
    • The raw JSI methods use an extended nested Class that overrides getHybridClass().
  • Build:
    • Bob and the example's Babel config enable the decorators parser, and the example's tsconfig resolves package imports.
    • On Android there's a v1 cpp-adapter.cpp (registerAllNatives()) and a nitro-core-config.cmake shim (from Nitro Modules v1: research breaking changes and React Native support #1100's spike).
    • The example drops react-native-mmkv. Nothing used it, and its Nitro 0.x generated code doesn't compile against v1.
    • scripts/check-nitro-v1-compile.sh is new. It runs a clang++ -std=c++20 -fsyntax-only pass over every hand-written, generated and ncrypto TU for the iOS simulator and the Android NDK.

Testing

All runs were on macOS.

  • Compile check: scripts/check-nitro-v1-compile.sh, run at f7c7ca4, passed 108/108 TUs on arm64-apple-ios16.0-simulator and 108/108 on aarch64-linux-android26. A run with SODIUM_ENABLED=1 at 4f5aa8b also passed 108/108 on both targets. As a negative control, an unported TU fails the check.
  • Android build: cd example && bun run build:android (arm64-v8a, at 4668d3a) reported BUILD SUCCESSFUL. app-debug.apk contains libQuickCrypto.so and libNitroModules.so, and llvm-nm -D --defined-only shows no exported ERR_*, EVP_*, SSL_* or OPENSSL_* symbols.
  • ncrypto deprecations: OPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3.6 scripts/check-ncrypto-openssl-deprecations.sh exited 0 at 4f5aa8b. ncrypto is unchanged in this PR.
  • JS checks:
    • bun tsc, bun lint, bun format, bun --filter="react-native-quick-crypto" prepare and bun run circular passed at 435b2de.
    • cd packages/react-native-quick-crypto && bun run test passed 19 tests in 3 suites at 435b2de.
    • bun tsc and bun lint passed again at f7c7ca4.
  • Regeneration: nitrogen v1 was rerun in a scratch copy, and the output matches the committed nitrogen/generated exactly.
  • Review: an independent local review found no correctness or memory-safety defects in the port. Its fixes are in f7c7ca4.
  • Attestation: the agentscm/local-validation gate covers PRs into main only, so it doesn't apply to this PR into next. No mobile E2E ran, so there are no screenshots.

Delivery

Merging into next delivers nothing to npm or to consumers. next is an integration branch for RNQC 2.0 (#1105).

Not verified

These gaps are deliberate. The scope split was agreed for #1102, and each item has an owner:

Closes #1102

🤖 Generated with Claude Code

Bump nitrogen, nitro-core and react-native-nitro-modules to
1.0.0-alpha.nightly.138.g43e09c161101, rewrite nitro.json for the bare
environment, add the #nitro/* imports map, port all 28 specs to
decorated declare classes (statics for stateless members, zero-arg
constructors for stateful classes), regenerate with nitrogen v1, and
replace every createHybridObject call site with `new X()` or static
calls. Configure bob and Metro babel for the decorators parser and the
example tsconfig for package imports.

Native code (cpp/, Android, iOS) is not ported in this commit and will
not compile until phases 2-4 of #1102 land. TypeScript, lint, format,
bob build and Jest pass.
…ules v1

Add scripts/check-nitro-v1-compile.sh (iOS simulator and Android NDK syntax-only
compile of the package C++ against Nitro v1). Port ToNativeArrayBuffer helpers,
KeyObjectData, HybridKeyObjectHandle (raw SLH-DSA import via an extended Class),
and the static modules Argon2, Certificate, Hkdf, Pbkdf2, Prime, Random, Scrypt,
TurboShake, RsaCipher and Utils. Stateful modules follow in Phase 3.
… Modules v1

Port HybridCipher and its subclasses, HybridCipherFactory, Hash, Hmac, Kmac,
Blake3, SignHandle, VerifyHandle and X509Certificate to the v1 ArrayBuffer
value type, no-argument HybridObject constructors, and static members for
the stateless methods. Keypair modules follow in Phase 3b.
react-native-mmkv 4.3.2 ships Nitro Modules 0.x generated code and cannot
compile against Nitro Modules v1. Nothing in the example uses it. With it
gone, the example's Android build succeeds on Nitro Modules v1.
- Capture shared_cast self in the DH, DSA, EC and RSA generateKeyPair
  async lambdas, matching Ed/ML-DSA, so a disposed or collected object
  is never written from the worker.
- Make the compile check also require every TU to report ok.
- Restore import type for KeyObjectHandle in utils/types.
- Pin the nitro-core and react-native-nitro-modules peers to the exact
  Nitro Modules v1 nightly the generated bindings target.
- Record the known next-branch breakage owned by #1101 and #1103.
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
react-native-quick-crypto Ready Ready Preview Nov 28, 2026 8:49pm UTC

Request Review

@boorad
boorad merged commit 217c9cb into next Nov 28, 2026
7 checks passed
@boorad
boorad deleted the refactor/1102-port-nitro-specs-v1 branch November 28, 2026 22:46

This branch was successfully deployed

1 active deployment
Preview — 1f2c7e06 Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant