Universal wrapper for sodium-javascript and sodium-native working in Node.js and the Browser
JavaScript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE.md
README.md
browser.js
index.js
package.json

README.md

sodium-universal

Universal wrapper for sodium-javascript and sodium-native working in Node.js and the Browser

npm install sodium-universal

sodium-native ships with prebuilds for macOS, Windows, and Linux. If for whatever reason it cannot load the native module, sodium-universal will seamlessly fall back to using the javascript version.

Usage

var sodium = require('sodium-universal')

var rnd = Buffer.allocUnsafe(12) // Cryptographically random data
sodium.randombytes_buf(rnd)

console.log(rnd.toString('hex'))

Works seamlessly with Node.js:

$ node example.js
c7dbd46a6cc84ff2e0d1285c

And the browser:

browserify example.js > bundle.js

Introduction

libsodium is a collection of cryptographic primitives, providing a low-level foundation to build higher-level cryptographic applications and protocols. It is often put in contrast to RSA based cryptography and OpenSSL, even though they all share overlapping algorithms and target slightly different audiences. Sodium is a collection of modern collection of primitives, fulfilling the same cryptographic tasks, but based on simpler and more efficient algorithms.

This library provides seamless bindings to sodium-native, which is the original C implementation of libsodium exposed as a Node native module. For the browser we expose sodium-javascript, using the package.json browser field, which is supported by most bundlers.

API

Please refer to sodium-native and sodium-javascript. Note that the two modules do not yet have feature parity, where sodium-native is the more featureful of the two.

License

MIT