TweetNaCl.js
JavaScript implementation of NaCl cryptography for Solana wallet signing.
3. Used by agents' projects
Dependency in 14 public GitHub projects set up for AI coding agents that we scanned (0.2%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What TweetNaCl.js does
TweetNaCl.js is a deliberately literal JavaScript port of the C library TweetNaCl, and its own README tells you to use the WebCrypto API where possible, since WebCrypto covers most of its primitives except XSalsa20-Poly1305 encryption.
TweetNaCl.js popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How TweetNaCl.js is used
- TweetNaCl.js is a dependency in 14 of the 6,258 public GitHub projects set up for AI coding agents that we scanned, too few to describe it from them alone. Our scan also samples projects by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750); counting those, it appears in 241 projects, and what it is used with below comes from all of them.
- The most used alternative in our scan is viem (47 projects).
- Projects that use it most often also use Solana Web3.js (89.2%), Solana SPL Token (31.1%), bip39 (29.0%).
By coding agent
Often used with
TweetNaCl.js in practice
Strengths
Cure53 audited the library in January-February 2017. The report, as quoted in the README, says the testers were unable to find any security problems. The README adds that one bug was discovered and fixed after the audit.
<code>nacl.js</code> stays close to the C source, plus the high-level API. <code>nacl-fast.js</code> swaps in faster functions and is what the npm package loads by default.
A separate script, <code>npm run test-node-all</code>, runs the full Node.js suite. That suite includes comparing the JavaScript port's outputs with the original C version. The default <code>npm run test-node</code> tests <code>nacl.min.js</code> unless <code>NACL_SRC</code> points elsewhere.
By the README's own benchmarks, <code>nacl-fast.js</code> encrypts and authenticates more than 57000 1024-byte messages per second on a typical laptop. The README also gives more than 14000 on a $170 smartphone, per CPU core.
Watch out for
The maintainers note that WebCrypto supports most of the primitives here: X25519, Ed25519 and SHA-512. The exception is XSalsa20-Poly1305 authenticated encryption. Their advice is to use WebCrypto if possible.
One ciphertext can decrypt to valid plaintexts under two different keys. The README says this may lead to vulnerabilities where key commitment is expected.
Anyone can produce a second valid signature for an already signed message without the secret key. The README warns about contexts where malleability is not expected.
Plugging in your own entropy source
nacl.setPRNG(function(x, n) {
// ... copy n random bytes into x ...
});More about TweetNaCl.js
Packages around it
- @solana/web3.js: Solana JavaScript SDK
- @solana/spl-token: Solana token program client
- axios: HTTP client
- bip39: Mnemonic seed phrases
- react: UI library
- ed25519-hd-key: Ed25519 HD key derivation
Alternatives
TweetNaCl.js This page
TypeScript interface for Ethereum with type-safe interactions.
Complete Ethereum library for building dapps, wallets and blockchain tools.
Get started
Install it.
npm install tweetnaclRules for your agent
## TweetNaCl.js
- Pass and expect `Uint8Array` everywhere. Encode or decode strings with `tweetnacl-util` or another codec package.
- To get a Node `Buffer` from a result, copy with `Buffer.from(array)`. Never use `Buffer.from(array.buffer)`, because some functions return subarrays.
- The 24-byte nonce for `nacl.box` and `nacl.secretbox` must be unique for each distinct message under the key or key pair.
- Check for `null` from `nacl.box.open`, `nacl.secretbox.open` and `nacl.sign.open`, and for `false` from `nacl.sign.detached.verify`.
- Generate signing keys with `nacl.sign.keyPair()`. The docs say `fromSeed` is not recommended for general use.
- Expect `nacl.randomBytes`, `nacl.box.keyPair` and `nacl.sign.keyPair` to throw if the platform has no suitable PRNG. Only call `nacl.setPRNG` with a cryptographically strong source, never `Math.random`. It completely replaces the internal generator.
- Prefer WebCrypto for X25519, Ed25519 and SHA-512 where available. Do not design protocols that rely on key commitment, signature uniqueness or SHA-512 resistance to length extension.