libsodium-wrappers provides a JavaScript/TypeScript binding for the highly regarded Sodium cryptographic library, compiled to WebAssembly with a pure JavaScript fallback. It is currently stable at version 0.8.3, wrapping libsodium 1.0.22. The package offers comprehensive, high-performance cryptographic operations for both web browsers (Chrome, Firefox, Edge, Safari, Mobile Safari) and server-side environments like Node.js and Bun. It comes in two variants: a standard version with commonly used functions and a 'sumo' version that includes the full, exhaustive libsodium API. Since version 0.8.1, the library automatically includes TypeScript definitions, simplifying development in typed environments. Users must `await sodium.ready` to ensure the underlying cryptographic engine is fully initialized before using any functions or constants. The library maintains a regular release cadence to incorporate upstream libsodium updates and address issues.
npm install libsodium-wrappersVerified import paths — ran on the pinned version, not inferred.
This example demonstrates end-to-end secret stream encryption and decryption using libsodium-wrappers, showcasing key generation, message pushing with tags, and message pulling.
Always `await sodium.ready;` before using any cryptographic functions or constants from the default `sodium` export.
Always use `import sodium from 'libsodium-wrappers'; await sodium.ready;` and then access functions as `sodium.crypto_...`. Only helper utilities like `from_string`, `to_hex`, and `ready` itself can be named imports.
Ensure target environments meet the minimum compatibility requirements (Mobile Safari >= 8.0, Safari >= 6, Chrome >= 16, Firefox >= 21, Edge >= 0.11, NodeJS, Bun, Opera >= 15).
For most projects, `libsodium-wrappers` is recommended. Only use `libsodium-wrappers-sumo` if you explicitly require functions not present in the standard version, and understand the implications of using advanced/low-level primitives.
Upgrade to `libsodium-wrappers` version 0.7.16 or newer for full ESM compatibility. Ensure your build system is configured to handle `.mjs` extensions if direct file paths are being used.
Ensure `await sodium.ready;` is executed before any calls to `sodium`'s cryptographic methods.
Verify the package is installed (`npm install libsodium-wrappers`). Check import paths, especially when mixing CommonJS and ESM. For bundler issues, review configuration (e.g., Next.js with Turbopack might need specific handling for WASM modules).
When testing, ensure Jest (or similar) is correctly configured for ESM and/or browser-like environments. You might need to mock the library or configure Jest's `moduleNameMapper` or `transformIgnorePatterns` to handle it correctly. Some users have found solutions by ensuring proper WebAssembly loading in their test runner.
No dependency data recorded yet.