{"name":"libsodium-wrappers","version":"0.2.9","description":"The Sodium cryptographic library compiled to pure JavaScript (wrappers)","main":"dist/modules/libsodium-wrappers.js","files":["dist/modules/libsodium-wrappers.js"],"repository":{"type":"git","url":"git+https://github.com/jedisct1/libsodium.js.git"},"dependencies":{"libsodium":"0.2.9"},"keywords":["crypto","sodium","libsodium","nacl","chacha20","poly1305","curve25519","ed25519","blake2","siphash"],"author":{"name":"Ahmad Ben Mrad","url":"@BatikhSouri"},"contributors":[{"name":"Frank Denis","url":"@jedisct1"}],"license":"ISC","bugs":{"url":"https://github.com/jedisct1/libsodium.js/issues"},"homepage":"https://github.com/jedisct1/libsodium.js","gitHead":"f6191fe14fc170137e4b81acbd9ad47d517f5d14","_id":"libsodium-wrappers@0.2.9","scripts":{},"_shasum":"4b7fb2af23dab668ba49649494317ece57c15ff6","_from":".","_npmVersion":"2.11.0","_nodeVersion":"2.2.1","_npmUser":{"name":"jedisct1","email":"npm@pureftpd.org"},"maintainers":[{"name":"jedisct1","email":"npm@pureftpd.org"}],"dist":{"shasum":"4b7fb2af23dab668ba49649494317ece57c15ff6","tarball":"http://registry-npm.ywwl.com/libsodium-wrappers/download/libsodium-wrappers-0.2.9.tgz","integrity":"sha512-bG0bsG9Q6TNP+uYG5xffjPz2GbCDEBBFR2izmNoovA8x24n2P2bxMuu9L/yQ+GFc0J0xWydrkC5jzurs+Z/86Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnD5LjPrfChATlZbBEk3XrpvlnQkiurRy/hMPubJphjwIgO3DVkmCrppkIgxG29wEutfvON0ZxlJgQsGWUcvYKksQ="}],"size":11630,"noattachment":false,"key":"/libsodium-wrappers/-/libsodium-wrappers-0.2.9.tgz"},"directories":{},"readme":"# libsodium.js\n\n## Overview\n\nThe [sodium](https://github.com/jedisct1/libsodium) crypto library\ncompiled to WebAssembly and pure JavaScript using\n[Emscripten](https://github.com/kripken/emscripten), with\nautomatically generated wrappers to make it easy to use in web\napplications.\n\nThe complete library weighs 188 KB (minified, gzipped, includes pure JS +\nWebAssembly versions) and can run in a web browser as well as server-side.\n\n### Compatibility\n\nSupported browsers/JS engines:\n\n* Chrome >= 16\n* Edge >= 0.11\n* Firefox >= 21\n* Mobile Safari on iOS >= 8.0 (older versions produce incorrect results)\n* NodeJS\n* Bun\n* Opera >= 15\n* Safari >= 6 (older versions produce incorrect results)\n\nThis is comparable to the WebCrypto API, which is compatible with a\nsimilar number of browsers.\n\nSignatures and other Edwards25519-based operations are compatible with\n[WasmCrypto](https://github.com/jedisct1/wasm-crypto).\n\n## Installation\n\nThe [dist](https://github.com/jedisct1/libsodium.js/tree/master/dist)\ndirectory contains pre-built scripts. Copy the files from one of its\nsubdirectories to your application:\n\n- [browsers](https://github.com/jedisct1/libsodium.js/tree/master/dist/browsers)\nincludes a single-file script that can be included in web pages.\nIt contains code for commonly used functions.\n- [browsers-sumo](https://github.com/jedisct1/libsodium.js/tree/master/dist/browsers-sumo)\nis a superset of the previous script, that contains all functions,\nincluding rarely used ones and undocumented ones.\n- [modules](https://github.com/jedisct1/libsodium.js/tree/master/dist/modules)\nincludes commonly used functions, and is designed to be loaded as a module.\n`libsodium-wrappers` is the module your application should load, which\nwill in turn automatically load `libsodium` as a dependency.\n- [modules-sumo](https://github.com/jedisct1/libsodium.js/tree/master/dist/modules-sumo)\ncontains sumo variants of the previous modules.\n\nThe modules are also available on npm:\n- [libsodium-wrappers](https://www.npmjs.com/package/libsodium-wrappers)\n- [libsodium-wrappers-sumo](https://www.npmjs.com/package/libsodium-wrappers-sumo)\n\nIf you prefer Bower:\n\n```sh\nbower install libsodium.js\n```\n\n### Usage (as a module)\n\nLoad the `libsodium-wrappers` module. The returned object contains a `.ready`\nproperty: a promise that must be resolve before the sodium functions\ncan be used.\n\nExample:\n\n```js\nimport _sodium from 'libsodium-wrappers';\nawait (async() => {\n  await _sodium.ready;\n  const sodium = _sodium;\n\n  let key = sodium.crypto_secretstream_xchacha20poly1305_keygen();\n\n  let res = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);\n  let [state_out, header] = [res.state, res.header];\n  let c1 = sodium.crypto_secretstream_xchacha20poly1305_push(state_out,\n    sodium.from_string('message 1'), null,\n    sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE);\n  let c2 = sodium.crypto_secretstream_xchacha20poly1305_push(state_out,\n    sodium.from_string('message 2'), null,\n    sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL);\n\n  let state_in = sodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key);\n  let r1 = sodium.crypto_secretstream_xchacha20poly1305_pull(state_in, c1);\n  let [m1, tag1] = [sodium.to_string(r1.message), r1.tag];\n  let r2 = sodium.crypto_secretstream_xchacha20poly1305_pull(state_in, c2);\n  let [m2, tag2] = [sodium.to_string(r2.message), r2.tag];\n\n  console.log(m1);\n  console.log(m2);\n})();\n```\n\n### Usage (in a web browser, via a callback)\n\nThe `sodium.js` file includes both the core libsodium functions, as\nwell as the higher-level JavaScript wrappers. It can be loaded\nasynchronusly.\n\nA `sodium` object should be defined in the global namespace, with the\nfollowing property:\n\n- `onload`: the function to call after the wrapper is initialized.\n\nExample:\n\n```html\n<script>\n    window.sodium = {\n        onload: function (sodium) {\n            let h = sodium.crypto_generichash(64, sodium.from_string('test'));\n            console.log(sodium.to_hex(h));\n        }\n    };\n</script>\n<script src=\"sodium.js\" async></script>\n```\n\n## Additional helpers\n\n* `from_base64()`, `to_base64()` with an optional second parameter\nwhose value is one of: `base64_variants.ORIGINAL`, `base64_variants.ORIGINAL_NO_PADDING`,\n`base64_variants.URLSAFE` or `base64_variants.URLSAFE_NO_PADDING`. Default is `base64_variants.URLSAFE_NO_PADDING`.\n* `from_hex()`, `to_hex()`\n* `from_string()`, `to_string()`\n* `pad(<buffer>, <block size>)`, `unpad(<buffer>, <block size>)`\n* `memcmp()` (constant-time check for equality, returns `true` or `false`)\n* `compare()` (constant-time comparison. Values must have the same\nsize. Returns `-1`, `0` or `1`)\n* `memzero()` (applies to `Uint8Array` objects)\n* `increment()` (increments an arbitrary-long number stored as a\nlittle-endian `Uint8Array` - typically to increment nonces)\n* `add()` (adds two arbitrary-long numbers stored as little-endian\n`Uint8Array` vectors)\n* `is_zero()` (constant-time, checks `Uint8Array` objects for all zeros)\n\n## API\n\nThe API exposed by the wrappers is identical to the one of the C\nlibrary, except that buffer lengths never need to be explicitly given.\n\nBinary input buffers should be `Uint8Array` objects. However, if a string\nis given instead, the wrappers will automatically convert the string\nto an array containing a UTF-8 representation of the string.\n\nExample:\n\n```javascript\nvar key = sodium.randombytes_buf(sodium.crypto_shorthash_KEYBYTES),\n    hash1 = sodium.crypto_shorthash(new Uint8Array([1, 2, 3, 4]), key),\n    hash2 = sodium.crypto_shorthash('test', key);\n```\n\nIf the output is a unique binary buffer, it is returned as a\n`Uint8Array` object.\n\nExample (secretbox):\n\n```javascript\nlet key = sodium.from_hex('724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed');\n\nfunction encrypt_and_prepend_nonce(message) {\n    let nonce = sodium.randombytes_buf(sodium.crypto_secretbox_NONCEBYTES);\n    return nonce.concat(sodium.crypto_secretbox_easy(message, nonce, key));\n}\n\nfunction decrypt_after_extracting_nonce(nonce_and_ciphertext) {\n    if (nonce_and_ciphertext.length < sodium.crypto_secretbox_NONCEBYTES + sodium.crypto_secretbox_MACBYTES) {\n        throw \"Short message\";\n    }\n    let nonce = nonce_and_ciphertext.slice(0, sodium.crypto_secretbox_NONCEBYTES),\n        ciphertext = nonce_and_ciphertext.slice(sodium.crypto_secretbox_NONCEBYTES);\n    return sodium.crypto_secretbox_open_easy(ciphertext, nonce, key);\n}\n```\n\nIn addition, the `from_hex`, `to_hex`, `from_string`, and `to_string`\nfunctions are available to explicitly convert hexadecimal, and\narbitrary string representations from/to `Uint8Array` objects.\n\nFunctions returning more than one output buffer are returning them as\nan object. For example, the `sodium.crypto_box_keypair()` function\nreturns the following object:\n```javascript\n{ keyType: 'curve25519', privateKey: (Uint8Array), publicKey: (Uint8Array) }\n```\n\n### Standard vs Sumo version\n\nThe standard version (in the `dist/browsers` and `dist/modules`\ndirectories) contains the high-level functions, and is the recommended\none for most projects.\n\nAlternatively, the \"sumo\" version, available in the\n`dist/browsers-sumo` and `dist/modules-sumo` directories contains all\nthe symbols from the original library. This includes undocumented,\nuntested, deprecated, low-level and easy to misuse functions.\n\nThe `crypto_pwhash_*` function set is only included in the sumo version.\n\nThe sumo version is slightly larger than the standard version, reserves\nmore memory, and should be used only if you really need the extra symbols\nit provides.\n\n### Compilation\n\nIf you want to compile the files yourself, the following dependencies\nneed to be installed on your system:\n\n* Emscripten\n* binaryen\n* git\n* NodeJS\n* make\n\nRunning `make` will install the dev dependencies, clone libsodium,\nbuild it, test it, build the wrapper, and create the modules and\nminified distribution files.\n\n## Related projects\n\n* [react-native-libsodium](https://github.com/serenity-kit/react-native-libsodium): React Native bindings to Libsodium matching the libsodium-wrappers package API\n\n## Authors\n\nBuilt by Ahmad Ben Mrad, Frank Denis and Ryan Lester.\n\n## License\n\nThis wrapper is distributed under the\n[ISC License](https://en.wikipedia.org/wiki/ISC_license).\n","publish_time":1433954223805,"_cnpm_publish_time":1433954223805,"dist-tags":{"latest":"0.8.4"}}