# TweetNaCl.js — card for AI agents

JavaScript implementation of NaCl cryptography for Solana wallet signing.

Category: Crypto and web3 · npm package `tweetnacl` · latest version 1.0.3 (checked 2026-11-01)
Install: `npm install tweetnacl`
License: Unlicense (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## 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.

## What it is
- TweetNaCl.js is a port of TweetNaCl / NaCl to JavaScript for modern browsers and Node.js. It does secret-key authenticated encryption (`secretbox`), public-key authenticated encryption (`box`), Ed25519 signatures and SHA-512 hashing. It also has x25519 scalar multiplication, random byte generation and constant-time comparison. The site calls it a high-level crypto library "in only 7 KB (minified and gzipped)". The site and README say it is public domain. The GitHub repository lists the license as Unlicense.
- The maintainers write that the goal is a translation "as close as possible to the original C implementation", with a thin idiomatic API on top. There are two builds. `nacl.js` keeps minimum differences from the C original. `nacl-fast.js` replaces some functions with faster versions and is the default when you import the npm package. Every function takes and returns `Uint8Array` bytes.
- The README warns that this is a low-level library that "doesn't provide complete security protocols", so it fits developers who will design their own protocol around these primitives. The latest release, 1.0.3 (2020-02-10), is marked as an important bug fix: `nacl.sign` and `nacl.sign.detached` could have created incorrect signatures. The release note says this affected signing only, not verification.

## Caveats
- The README recommends WebCrypto where possible: 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.
- `box` and `secretbox` are not key-committing: One ciphertext can decrypt to valid plaintexts under two different keys. The README says this may lead to vulnerabilities where key commitment is expected.
- `nacl.sign` signatures are malleable: 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.
- `nacl.hash` allows length extension: The SHA-512 in `nacl.hash` is not resistant to length-extension attacks.
- Constant time only on paper: The operations are algorithmically constant-time. The README says JavaScript runtimes and JIT compilers make physical constant time impossible to guarantee. Secret data may also not be physically removed from memory.

## Numbers (AgentGid data)
- Gid Score: 66.9 (#556 of all tools, 4 of 155 in its category)
- Used in 14 public projects set up for AI coding agents (0.2%)
- Downloads last week: 52,131,481 (as of 2026-11-24), +38.9% over 4 weeks
- GitHub stars: 1,923 (as of 2026-11-24)
- Last push: 2025-08-15

## Often used with
Solana Web3.js 89.2%, Solana SPL Token 31.1%, bip39 29.0%, Axios 29.5%, React 57.7%, ed25519-hd-key 24.9%

## Checked alternatives (same job)
- viem: https://agentgid.com/tools/viem/agent.md
- ethers.js: https://agentgid.com/tools/ethers/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/tweetnacl/
- Homepage: https://tweetnacl.js.org
- Repository: https://github.com/dchest/tweetnacl-js
- Source: https://github.com/dchest/tweetnacl-js#readme
- Source: https://github.com/dchest/tweetnacl-js
- Source: https://github.com/dchest/tweetnacl-js/releases
- Source: https://tweetnacl.js.org

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
