Socket
Socket
Sign inDemoInstall

libsodium

Package Overview
Dependencies
0
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.4 to 0.7.0

10

package.json
{
"name": "libsodium",
"version": "0.5.4",
"description": "The Sodium cryptographic library compiled to pure JavaScript (raw library, no wrappers)",
"version": "0.7.0",
"description":
"The Sodium cryptographic library compiled to pure JavaScript (raw library, no wrappers)",
"main": "dist/modules/libsodium.js",

@@ -26,3 +27,3 @@ "files": ["dist/modules/libsodium.js", "package.json"],

"author": "Ahmad Ben Mrad (@BatikhSouri)",
"contributors": [ "Frank Denis (@jedisct1)" ],
"contributors": ["Frank Denis (@jedisct1)", "Ryan Lester (@buu700)"],
"license": "ISC",

@@ -32,3 +33,4 @@ "bugs": {

},
"homepage": "https://github.com/jedisct1/libsodium.js"
"homepage": "https://github.com/jedisct1/libsodium.js",
"browser": { "fs": false }
}

178

README.md

@@ -1,3 +0,1 @@

[![Make a donation to support this project](https://img.shields.io/badge/donate-PayPal-green.svg?style=flat)](https://www.libsodium.org/donate)
# libsodium.js

@@ -7,9 +5,10 @@

The [sodium](https://github.com/jedisct1/libsodium) crypto library compiled
to pure JavaScript using [Emscripten](https://github.com/kripken/emscripten),
with automatically generated wrappers to make it easy to use in web
The [sodium](https://github.com/jedisct1/libsodium) crypto library
compiled to WebAssembly and pure Javascript using
[Emscripten](https://github.com/kripken/emscripten), with
automatically generated wrappers to make it easy to use in web
applications.
The complete library weights 115 Kb (minified, gzipped) and can run in
a web browser as well as server-side.
The complete library weights 188 Kb (minified, gzipped, includes pure js +
webassembly versions) and can run in a web browser as well as server-side.

@@ -23,3 +22,2 @@ ### Compatibility

* Firefox >= 21
* Internet Explorer >= 11
* Mobile Safari on iOS >= 8.0 (older versions produce incorrect results)

@@ -32,72 +30,86 @@ * NodeJS

Ready-to-use files based on libsodium 1.0.13 can be directly copied to your
project.
???
### Usage with global definitions, for web browsers
### Usage (as a module)
Use [Bower](http://bower.io/):
```bash
$ bower install libsodium.js
```
or directly include a copy of the
[sodium.min.js](https://github.com/jedisct1/libsodium.js/tree/master/dist/browsers/combined)
file.
Load the `sodium-wrappers` module. The returned object contains a `.ready`
property: a promise that must be resolve before the sodium functions
can be used.
Alternatively, for better performance and to avoid including a local copy,
[libsodium.js is available on cdnjs](https://cdnjs.com/libraries/libsodium-wrappers).
Example:
Including the `sodium.min.js` file will add a `sodium` object to the
global namespace.
```js
const _sodium = require('libsodium-wrappers');
(async() => {
await _sodium.ready;
const sodium = _sodium;
If a `sodium` object is already present in the global namespace, and
the `sodium.onload` function is defined, this function will be called
right after the library has been loaded and initialized.
let key = sodium.crypto_secretstream_xchacha20poly1305_keygen();
```html
<script>
window.sodium = { onload: function(sodium) {
alert(sodium.to_hex(sodium.crypto_generichash(64, 'test')));
}};
</script>
...
<script src="sodium.js" async defer></script>
let res = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);
let [state_out, header] = [res.state, res.header];
let c1 = sodium.crypto_secretstream_xchacha20poly1305_push(state_out,
sodium.from_string('message 1'), null,
sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE);
let c2 = sodium.crypto_secretstream_xchacha20poly1305_push(state_out,
sodium.from_string('message 2'), null,
sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL);
let state_in = sodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key);
let r1 = sodium.crypto_secretstream_xchacha20poly1305_pull(state_in, c1);
let [m1, tag1] = [sodium.to_string(r1.message), r1.tag];
let r2 = sodium.crypto_secretstream_xchacha20poly1305_pull(state_in, c2);
let [m2, tag2] = [sodium.to_string(r2.message), r2.tag];
console.log(m1);
console.log(m2);
})();
```
As an alternative, use a module loader or Browserify as described below.
### Usage (in a web browser, via a callback)
### Usage with CommonJS/AMD/ES6 import
The `sodium.js` file includes both the core libsodium functions, as
well as the higher-level Javascript wrappers. It can be loaded
asynchronusly.
Copy the `.js` files for [libsodium and libsodium-wrappers](https://github.com/jedisct1/libsodium.js/tree/master/dist/modules)
to your project and load the `libsodium-wrappers` module.
A `sodium` object should be defined in the global namespace, with the
following properties:
Alternatively, use [yarn](https://yarnpkg.com/). The Yarn package is
called `libsodium-wrappers` and includes a dependency on the raw
`libsodium` module.
- `onload`: the function to call after the wrapper is initialized.
- `totalMemory` (optional): the maximum amount of memory that sodium can use.
The default value should be fine for most applications, unless you
need to use password hashing functions with a large amount of memory.
```shell
$ yarn add libsodium-wrappers
```
Example:
```javascript
var sodium = require('libsodium-wrappers');
console.log(sodium.to_hex(sodium.crypto_generichash(64, 'test')));
```html
<script>
window.sodium = {
onload: function (sodium) {
let h = sodium.crypto_generichash(64, sodium.from_string('test'));
console.log(sodium.to_hex(h));
}
};
</script>
<script src="sodium.js" async></script>
```
## List of wrapped algorithms and functions:
## List of wrapped APIs:
* [`crypto_aead`](https://download.libsodium.org/doc/secret-key_cryptography/aead.html) (XChaCha20-Poly1305)
* [`crypto_auth`](https://download.libsodium.org/doc/secret-key_cryptography/secret-key_authentication.html) (HMAC-SHA-512-256)
* [`crypto_box`](https://doc.libsodium.org/public-key_cryptography/authenticated_encryption.html) (X25519, XSalsa20)
* [`crypto_box_seal`](https://download.libsodium.org/libsodium/content/public-key_cryptography/sealed_boxes.html) (X25519, XSalsa20)
* [`crypto_generichash`](https://download.libsodium.org/libsodium/content/hashing/generic_hashing.html) (BLAKE2b)
* [`crypto_hash`](https://download.libsodium.org/libsodium/content/advanced/sha-2_hash_function.html) (SHA-512-256)
* [`crypto_kdf`](https://download.libsodium.org/doc/key_derivation/) (BLAKE2b)
* [`crypto_kx`](https://download.libsodium.org/doc/key_exchange/) (X25519, BLAKE2b)
* [`crypto_onetimeauth`](https://download.libsodium.org/doc/advanced/poly1305.html) (Poly1305)
* [`crypto_pwhash`](https://download.libsodium.org/libsodium/content/password_hashing/) (Argon2, Scrypt)
* [`crypto_scalarmult`](https://download.libsodium.org/libsodium/content/advanced/scalar_multiplication.html) (X25519)
* [`crypto_secretbox`](https://download.libsodium.org/libsodium/content/secret-key_cryptography/authenticated_encryption.html) (Salsa20-Poly1305)
* [`crypto_shorthash`](https://download.libsodium.org/libsodium/content/hashing/short-input_hashing.html) (SipHash, SipHash-128)
* [`crypto_sign`](https://download.libsodium.org/libsodium/content/public-key_cryptography/public-key_signatures.html) (Ed25519, Ed25519ph)
* [`crypto_stream`](https://download.libsodium.org/doc/advanced/stream_ciphers.html) (Salsa20, XSalsa20, ChaCha20, XChaCha20)
* [`crypto_aead`](https://download.libsodium.org/doc/secret-key_cryptography/aead.html)
* [`crypto_auth`](https://download.libsodium.org/doc/secret-key_cryptography/secret-key_authentication.html)
* [`crypto_box`](https://doc.libsodium.org/public-key_cryptography/authenticated_encryption.html)
* [`crypto_box_seal`](https://download.libsodium.org/libsodium/content/public-key_cryptography/sealed_boxes.html)
* [`crypto_generichash`](https://download.libsodium.org/libsodium/content/hashing/generic_hashing.html)
* [`crypto_hash`](https://download.libsodium.org/libsodium/content/advanced/sha-2_hash_function.html)
* [`crypto_kdf`](https://download.libsodium.org/doc/key_derivation/)
* [`crypto_kx`](https://download.libsodium.org/doc/key_exchange/)
* [`crypto_onetimeauth`](https://download.libsodium.org/doc/advanced/poly1305.html)
* [`crypto_pwhash`](https://download.libsodium.org/libsodium/content/password_hashing/)
* [`crypto_scalarmult`](https://download.libsodium.org/libsodium/content/advanced/scalar_multiplication.html)
* [`crypto_secretbox`](https://download.libsodium.org/libsodium/content/secret-key_cryptography/authenticated_encryption.html)
* [`crypto_secretstream`](https://download.libsodium.org/doc/secret-key_cryptography/secretstream.html)
* [`crypto_shorthash`](https://download.libsodium.org/libsodium/content/hashing/short-input_hashing.html)
* [`crypto_sign`](https://download.libsodium.org/libsodium/content/public-key_cryptography/public-key_signatures.html)
* [`crypto_stream`](https://download.libsodium.org/doc/advanced/stream_ciphers.html)
* [Ed25519->Curve25519 conversion](https://download.libsodium.org/libsodium/content/advanced/ed25519-curve25519.html)

@@ -108,4 +120,8 @@ * [`randombytes`](https://download.libsodium.org/libsodium/content/generating_random_data/)

* `from_base64()`, `to_base64()` with an optional second parameter
whose value is one of: `base64_variants.ORIGINAL`, `base64_variants.ORIGINAL_NO_PADDING`,
`base64_variants.URLSAFE` or `s.base64_variants.URLSAFE_NO_PADDING`. Default is `base64_variants.URLSAFE_NO_PADDING`.
* `from_hex()`, `to_hex()`
* `from_string()`, `to_string()`
* `pad(<buffer>, <block size>)`, `unpad(<buffer>, <block size>)`
* `memcmp()` (constant-time check for equality, returns `true` or `false`)

@@ -142,3 +158,3 @@ * `compare() (constant-time comparison. Values must have the same

order to specify what format the output should be in. Valid options
are `uint8array' (default), 'text' and 'hex'.
are `uint8array' (default), 'text', 'base64' and 'hex'.

@@ -213,10 +229,7 @@ Example (shorthash):

* autoconf
* automake
* emscripten
* binaryen
* git
* nodejs
* libtool
* make
* zopfli (`yarn global add node-zopfli`)
* uglify-es (`yarn global add uglify-es`)

@@ -227,34 +240,5 @@

### Custom build
The build available in this repository does not contain all the
functions available in the original libsodium library.
Providing that you have all the build dependencies installed, here is
how you can build libsodium.js to include the functions you need :
```shell
git clone https://github.com/jedisct1/libsodium.js
cd libsodium.js
# Get the original C version of libsodium and configure it
make libsodium/configure
# Modify the emscripten.sh
# Specifically, add the name of the missing functions and constants in the "EXPORTED_FUNCTIONS" array.
# Ensure that the name begins with an underscore and that it is between double quotes.
nano libsodium/dist-build/emscripten.sh
# Build libsodium, and then libsodium.js with your chosen functions
make
```
__NOTE:__ for each of the functions/constants you add, make sure that
the corresponding symbol files exist in the `wrapper/symbols` folder
and that the constants are listed in the `wrapper/constants.json`
file.
## Authors
Built by Ahmad Ben Mrad and Frank Denis.
Built by Ahmad Ben Mrad, Frank Denis and Ryan Lester.

@@ -261,0 +245,0 @@ ## License

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc