Module A-19·11 min read

When V8 hits its ceiling — zero-copy Buffer handoff via napi-rs, and WASI sandboxing for deterministic cryptographic operations.

JJS
Written by Jatin Jain Saraf · Senior Software Engineer

Module 18 — Crossing the Boundary: Rust, N-API, and WASI for Cryptographic Throughput

What this module covers: At 50,000 transactions/second, every transaction requires elliptic curve signature verification (secp256k1 for Ethereum/Bitcoin, ed25519 for Supra/Solana). V8's JavaScript implementation of these algorithms cannot reach the throughput that a Rust native addon can achieve. This module covers N-API — the stable C ABI that connects Node.js to native code — and how to use napi-rs to write Rust addons that pass multi-megabyte Buffer payloads across the JavaScript/native boundary without copying, maintaining the zero-allocation principles from Module 5. WASI provides a sandboxed alternative for deterministic computation that does not require compilation per platform.


When V8 Hits Its Ceiling

JavaScript's secp256k1 implementation (via elliptic or @noble/secp256k1) processes ~10,000–25,000 verifications/second on a single thread. A Rust implementation of the same algorithm (via the secp256k1 crate) processes ~200,000–500,000 verifications/second. The difference: Rust compiles to optimized machine code with SIMD instructions, no GC pauses, and no JIT compilation overhead.

javascript

The 25× throughput difference is not marginal — it changes whether you need 1 server or 5.


N-API: The Stable Node.js Native Addon Interface

N-API (Node-API) is a stable C ABI for creating native addons that work across Node.js versions without recompilation. It replaced the older NAN (Native Abstractions for Node.js) which broke on every major Node.js version.

N-API guarantees: an addon compiled for Node.js 18 runs on Node.js 22 without recompilation. The ABI is stable.

napi-rs vs Neon: Two Ways to Bridge Rust to N-API

napi-rs (used throughout this module) is one of two mainstream frameworks for writing N-API addons in Rust. The other is Neon. Both sit on top of the same underlying N-API C ABI and solve the same core problem — safely converting Rust types (structs, Vec<T>, String, integers) into JavaScript values and back without hand-rolling raw N-API pointer calls. The practical differences are mostly about ergonomics and defaults: napi-rs leans on procedural macros (#[napi], #[napi(object)]) to generate TypeScript type definitions alongside the compiled binary and has first-class ThreadsafeFunction support for async callbacks; Neon has historically emphasized a more manual, explicit binding style and its own async task abstraction. For a new blockchain indexer addon, either is a reasonable choice — this module standardizes on napi-rs for its TypeScript generation and batch-call ergonomics, which matter once you're verifying thousands of transactions per call.

napi-rs: Rust Bindings for N-API

toml
rust
bash

Using the Addon in Node.js

javascript

Zero-Copy: The Key Principle

Sign in to keep reading

The rest of this module is free — sign in with Google to unlock it and track your progress.

Sign in & Register

Discussion

0

Join the discussion

Loading comments...

© 2026 Jatin Jain Saraf (JJS). All rights reserved.