# sodium-native

> Low level bindings for libsodium

Latest version **5.1.0** (published 2026-03-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install sodium-native
pnpm add sodium-native
yarn add sodium-native
bun add sodium-native
```

## Health

**Score 53/100 (C)** — status: stable.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; large bundle.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2026-03-06 |
| First published | 2016-11-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/sodium-native) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 17.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mafintosh, kasperisager, emilbayes |

## Links

- npm: https://www.npmjs.com/package/sodium-native
- Repository: https://github.com/holepunchto/sodium-native
- Issues: https://github.com/holepunchto/sodium-native/issues
- npm.io page: https://npm.io/package/sodium-native

## Dependencies (3)

- [bare-assert](https://npm.io/package/bare-assert.md) ^1.2.0
- [require-addon](https://npm.io/package/require-addon.md) ^1.1.0
- [which-runtime](https://npm.io/package/which-runtime.md) ^1.2.1

## Recent versions

- 5.1.0 (latest) — 2026-03-06
- 5.0.10 — 2025-11-13
- 5.0.9 — 2025-09-24
- 5.0.8 — 2025-08-25
- 5.0.7 — 2025-08-21
- 5.0.6 — 2025-06-04
- 5.0.5 — 2025-06-04
- 5.0.4 — 2025-05-21
- 5.0.3 — 2025-05-13
- 5.0.2 — 2025-05-09
- 5.0.1 — 2025-04-02
- 5.0.0 — 2025-04-01
- 4.3.3 — 2025-02-27
- 4.3.2 — 2025-02-13
- 4.3.1 — 2024-11-13
- … 71 more at https://npm.io/package/sodium-native/versions

## README

# sodium-native

Low level bindings for [libsodium](https://github.com/jedisct1/libsodium).

```
npm install sodium-native
```

The goal of this project is to be thin, stable, unopionated wrapper around libsodium.

All methods exposed are more or less a direct translation of the libsodium c-api.
This means that most data types are buffers and you have to manage allocating return values and passing them in as arguments instead of receiving them as return values.

This makes this API harder to use than other libsodium wrappers out there, but also means that you'll be able to get a lot of perf / memory improvements as you can do stuff like inline encryption / decryption, reuse buffers etc.

This also makes this library useful as a foundation for more high level crypto abstractions that you want to make.

## Usage

```js
var sodium = require('sodium-native')

var nonce = Buffer.alloc(sodium.crypto_secretbox_NONCEBYTES)
var key = sodium.sodium_malloc(sodium.crypto_secretbox_KEYBYTES) // secure buffer
var message = Buffer.from('Hello, World!')
var ciphertext = Buffer.alloc(message.length + sodium.crypto_secretbox_MACBYTES)

sodium.randombytes_buf(nonce) // insert random data into nonce
sodium.randombytes_buf(key) // insert random data into key

// encrypted message is stored in ciphertext.
sodium.crypto_secretbox_easy(ciphertext, message, nonce, key)

console.log('Encrypted message:', ciphertext)

var plainText = Buffer.alloc(ciphertext.length - sodium.crypto_secretbox_MACBYTES)

if (!sodium.crypto_secretbox_open_easy(plainText, ciphertext, nonce, key)) {
  console.log('Decryption failed!')
} else {
  console.log('Decrypted message:', plainText, '(' + plainText.toString() + ')')
}
```

## Documentation

Complete documentation may be found on the [sodium-friends website](https://sodium-friends.github.io/docs/docs/getstarted)

## License

MIT

---
_Source: https://npm.io/package/sodium-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
