{"name":"tweetnacl","dist-tags":{"latest":"0.14.5"},"description":"Port of TweetNaCl cryptographic library to JavaScript","readme":"TweetNaCl.js\n============\n\nPort of [TweetNaCl](http://tweetnacl.cr.yp.to) / [NaCl](http://nacl.cr.yp.to/)\nto JavaScript for modern browsers and Node.js. Public domain.\n\n[![Build Status](https://travis-ci.org/dchest/tweetnacl-js.svg?branch=master)\n](https://travis-ci.org/dchest/tweetnacl-js)\n\nDemo: \n\nDocumentation\n=============\n\n* [Overview](#overview)\n* [Audits](#audits)\n* [Installation](#installation)\n* [Examples](#examples)\n* [Usage](#usage)\n * [Public-key authenticated encryption (box)](#public-key-authenticated-encryption-box)\n * [Secret-key authenticated encryption (secretbox)](#secret-key-authenticated-encryption-secretbox)\n * [Scalar multiplication](#scalar-multiplication)\n * [Signatures](#signatures)\n * [Hashing](#hashing)\n * [Random bytes generation](#random-bytes-generation)\n * [Constant-time comparison](#constant-time-comparison)\n* [System requirements](#system-requirements)\n* [Development and testing](#development-and-testing)\n* [Benchmarks](#benchmarks)\n* [Contributors](#contributors)\n* [Who uses it](#who-uses-it)\n\n\nOverview\n--------\n\nThe primary goal of this project is to produce a translation of TweetNaCl to\nJavaScript which is as close as possible to the original C implementation, plus\na thin layer of idiomatic high-level API on top of it.\n\nThere are two versions, you can use either of them:\n\n* `nacl.js` is the port of TweetNaCl with minimum differences from the\n original + high-level API.\n\n* `nacl-fast.js` is like `nacl.js`, but with some functions replaced with\n faster versions. (Used by default when importing NPM package.)\n\n\nAudits\n------\n\nTweetNaCl.js has been audited by [Cure53](https://cure53.de/) in January-February\n2017 (audit was sponsored by [Deletype](https://deletype.com)):\n\n> The overall outcome of this audit signals a particularly positive assessment\n> for TweetNaCl-js, as the testing team was unable to find any security\n> problems in the library. It has to be noted that this is an exceptionally\n> rare result of a source code audit for any project and must be seen as a true\n> testament to a development proceeding with security at its core.\n>\n> To reiterate, the TweetNaCl-js project, the source code was found to be\n> bug-free at this point.\n>\n> [...]\n>\n> In sum, the testing team is happy to recommend the TweetNaCl-js project as\n> likely one of the safer and more secure cryptographic tools among its\n> competition.\n\n[Read full audit report](https://cure53.de/tweetnacl.pdf)\n\n\nInstallation\n------------\n\nYou can install TweetNaCl.js via a package manager:\n\n[Yarn](https://yarnpkg.com/):\n\n $ yarn add tweetnacl\n\n[NPM](https://www.npmjs.org/):\n\n $ npm install tweetnacl\n\nor [download source code](https://github.com/dchest/tweetnacl-js/releases).\n\n\nExamples\n--------\nYou can find usage examples in our [wiki](https://github.com/dchest/tweetnacl-js/wiki/Examples).\n\n\nUsage\n-----\n\nAll API functions accept and return bytes as `Uint8Array`s. If you need to\nencode or decode strings, use functions from\n or one of the more robust codec\npackages.\n\nIn Node.js v4 and later `Buffer` objects are backed by `Uint8Array`s, so you\ncan freely pass them to TweetNaCl.js functions as arguments. The returned\nobjects are still `Uint8Array`s, so if you need `Buffer`s, you'll have to\nconvert them manually; make sure to convert using copying: `Buffer.from(array)`\n(or `new Buffer(array)` in Node.js v4 or earlier), instead of sharing:\n`Buffer.from(array.buffer)` (or `new Buffer(array.buffer)` Node 4 or earlier),\nbecause some functions return subarrays of their buffers.\n\n\n### Public-key authenticated encryption (box)\n\nImplements *x25519-xsalsa20-poly1305*.\n\n#### nacl.box.keyPair()\n\nGenerates a new random key pair for box and returns it as an object with\n`publicKey` and `secretKey` members:\n\n {\n publicKey: ..., // Uint8Array with 32-byte public key\n secretKey: ... // Uint8Array with 32-byte secret key\n }\n\n\n#### nacl.box.keyPair.fromSecretKey(secretKey)\n\nReturns a key pair for box with public key corresponding to the given secret\nkey.\n\n#### nacl.box(message, nonce, theirPublicKey, mySecretKey)\n\nEncrypts and authenticates message using peer's public key, our secret key, and\nthe given nonce, which must be unique for each distinct message for a key pair.\n\nReturns an encrypted and authenticated message, which is\n`nacl.box.overheadLength` longer than the original message.\n\n#### nacl.box.open(box, nonce, theirPublicKey, mySecretKey)\n\nAuthenticates and decrypts the given box with peer's public key, our secret\nkey, and the given nonce.\n\nReturns the original message, or `null` if authentication fails.\n\n#### nacl.box.before(theirPublicKey, mySecretKey)\n\nReturns a precomputed shared key which can be used in `nacl.box.after` and\n`nacl.box.open.after`.\n\n#### nacl.box.after(message, nonce, sharedKey)\n\nSame as `nacl.box`, but uses a shared key precomputed with `nacl.box.before`.\n\n#### nacl.box.open.after(box, nonce, sharedKey)\n\nSame as `nacl.box.open`, but uses a shared key precomputed with `nacl.box.before`.\n\n#### Constants\n\n##### nacl.box.publicKeyLength = 32\n\nLength of public key in bytes.\n\n##### nacl.box.secretKeyLength = 32\n\nLength of secret key in bytes.\n\n##### nacl.box.sharedKeyLength = 32\n\nLength of precomputed shared key in bytes.\n\n##### nacl.box.nonceLength = 24\n\nLength of nonce in bytes.\n\n##### nacl.box.overheadLength = 16\n\nLength of overhead added to box compared to original message.\n\n\n### Secret-key authenticated encryption (secretbox)\n\nImplements *xsalsa20-poly1305*.\n\n#### nacl.secretbox(message, nonce, key)\n\nEncrypts and authenticates message using the key and the nonce. The nonce must\nbe unique for each distinct message for this key.\n\nReturns an encrypted and authenticated message, which is\n`nacl.secretbox.overheadLength` longer than the original message.\n\n#### nacl.secretbox.open(box, nonce, key)\n\nAuthenticates and decrypts the given secret box using the key and the nonce.\n\nReturns the original message, or `null` if authentication fails.\n\n#### Constants\n\n##### nacl.secretbox.keyLength = 32\n\nLength of key in bytes.\n\n##### nacl.secretbox.nonceLength = 24\n\nLength of nonce in bytes.\n\n##### nacl.secretbox.overheadLength = 16\n\nLength of overhead added to secret box compared to original message.\n\n\n### Scalar multiplication\n\nImplements *x25519*.\n\n#### nacl.scalarMult(n, p)\n\nMultiplies an integer `n` by a group element `p` and returns the resulting\ngroup element.\n\n#### nacl.scalarMult.base(n)\n\nMultiplies an integer `n` by a standard group element and returns the resulting\ngroup element.\n\n#### Constants\n\n##### nacl.scalarMult.scalarLength = 32\n\nLength of scalar in bytes.\n\n##### nacl.scalarMult.groupElementLength = 32\n\nLength of group element in bytes.\n\n\n### Signatures\n\nImplements [ed25519](http://ed25519.cr.yp.to).\n\n#### nacl.sign.keyPair()\n\nGenerates new random key pair for signing and returns it as an object with\n`publicKey` and `secretKey` members:\n\n {\n publicKey: ..., // Uint8Array with 32-byte public key\n secretKey: ... // Uint8Array with 64-byte secret key\n }\n\n#### nacl.sign.keyPair.fromSecretKey(secretKey)\n\nReturns a signing key pair with public key corresponding to the given\n64-byte secret key. The secret key must have been generated by\n`nacl.sign.keyPair` or `nacl.sign.keyPair.fromSeed`.\n\n#### nacl.sign.keyPair.fromSeed(seed)\n\nReturns a new signing key pair generated deterministically from a 32-byte seed.\nThe seed must contain enough entropy to be secure. This method is not\nrecommended for general use: instead, use `nacl.sign.keyPair` to generate a new\nkey pair from a random seed.\n\n#### nacl.sign(message, secretKey)\n\nSigns the message using the secret key and returns a signed message.\n\n#### nacl.sign.open(signedMessage, publicKey)\n\nVerifies the signed message and returns the message without signature.\n\nReturns `null` if verification failed.\n\n#### nacl.sign.detached(message, secretKey)\n\nSigns the message using the secret key and returns a signature.\n\n#### nacl.sign.detached.verify(message, signature, publicKey)\n\nVerifies the signature for the message and returns `true` if verification\nsucceeded or `false` if it failed.\n\n#### Constants\n\n##### nacl.sign.publicKeyLength = 32\n\nLength of signing public key in bytes.\n\n##### nacl.sign.secretKeyLength = 64\n\nLength of signing secret key in bytes.\n\n##### nacl.sign.seedLength = 32\n\nLength of seed for `nacl.sign.keyPair.fromSeed` in bytes.\n\n##### nacl.sign.signatureLength = 64\n\nLength of signature in bytes.\n\n\n### Hashing\n\nImplements *SHA-512*.\n\n#### nacl.hash(message)\n\nReturns SHA-512 hash of the message.\n\n#### Constants\n\n##### nacl.hash.hashLength = 64\n\nLength of hash in bytes.\n\n\n### Random bytes generation\n\n#### nacl.randomBytes(length)\n\nReturns a `Uint8Array` of the given length containing random bytes of\ncryptographic quality.\n\n**Implementation note**\n\nTweetNaCl.js uses the following methods to generate random bytes,\ndepending on the platform it runs on:\n\n* `window.crypto.getRandomValues` (WebCrypto standard)\n* `window.msCrypto.getRandomValues` (Internet Explorer 11)\n* `crypto.randomBytes` (Node.js)\n\nIf the platform doesn't provide a suitable PRNG, the following functions,\nwhich require random numbers, will throw exception:\n\n* `nacl.randomBytes`\n* `nacl.box.keyPair`\n* `nacl.sign.keyPair`\n\nOther functions are deterministic and will continue working.\n\nIf a platform you are targeting doesn't implement secure random number\ngenerator, but you somehow have a cryptographically-strong source of entropy\n(not `Math.random`!), and you know what you are doing, you can plug it into\nTweetNaCl.js like this:\n\n nacl.setPRNG(function(x, n) {\n // ... copy n random bytes into x ...\n });\n\nNote that `nacl.setPRNG` *completely replaces* internal random byte generator\nwith the one provided.\n\n\n### Constant-time comparison\n\n#### nacl.verify(x, y)\n\nCompares `x` and `y` in constant time and returns `true` if their lengths are\nnon-zero and equal, and their contents are equal.\n\nReturns `false` if either of the arguments has zero length, or arguments have\ndifferent lengths, or their contents differ.\n\n\nSystem requirements\n-------------------\n\nTweetNaCl.js supports modern browsers that have a cryptographically secure\npseudorandom number generator and typed arrays, including the latest versions\nof:\n\n* Chrome\n* Firefox\n* Safari (Mac, iOS)\n* Internet Explorer 11\n\nOther systems:\n\n* Node.js\n\n\nDevelopment and testing\n------------------------\n\nInstall NPM modules needed for development:\n\n $ npm install\n\nTo build minified versions:\n\n $ npm run build\n\nTests use minified version, so make sure to rebuild it every time you change\n`nacl.js` or `nacl-fast.js`.\n\n### Testing\n\nTo run tests in Node.js:\n\n $ npm run test-node\n\nBy default all tests described here work on `nacl.min.js`. To test other\nversions, set environment variable `NACL_SRC` to the file name you want to test.\nFor example, the following command will test fast minified version:\n\n $ NACL_SRC=nacl-fast.min.js npm run test-node\n\nTo run full suite of tests in Node.js, including comparing outputs of\nJavaScript port to outputs of the original C version:\n\n $ npm run test-node-all\n\nTo prepare tests for browsers:\n\n $ npm run build-test-browser\n\nand then open `test/browser/test.html` (or `test/browser/test-fast.html`) to\nrun them.\n\nTo run tests in both Node and Electron:\n\n $ npm test\n\n### Benchmarking\n\nTo run benchmarks in Node.js:\n\n $ npm run bench\n $ NACL_SRC=nacl-fast.min.js npm run bench\n\nTo run benchmarks in a browser, open `test/benchmark/bench.html` (or\n`test/benchmark/bench-fast.html`).\n\n\nBenchmarks\n----------\n\nFor reference, here are benchmarks from MacBook Pro (Retina, 13-inch, Mid 2014)\nlaptop with 2.6 GHz Intel Core i5 CPU (Intel) in Chrome 53/OS X and Xiaomi Redmi\nNote 3 smartphone with 1.8 GHz Qualcomm Snapdragon 650 64-bit CPU (ARM) in\nChrome 52/Android:\n\n| | nacl.js Intel | nacl-fast.js Intel | nacl.js ARM | nacl-fast.js ARM |\n| ------------- |:-------------:|:-------------------:|:-------------:|:-----------------:|\n| salsa20 | 1.3 MB/s | 128 MB/s | 0.4 MB/s | 43 MB/s |\n| poly1305 | 13 MB/s | 171 MB/s | 4 MB/s | 52 MB/s |\n| hash | 4 MB/s | 34 MB/s | 0.9 MB/s | 12 MB/s |\n| secretbox 1K | 1113 op/s | 57583 op/s | 334 op/s | 14227 op/s |\n| box 1K | 145 op/s | 718 op/s | 37 op/s | 368 op/s |\n| scalarMult | 171 op/s | 733 op/s | 56 op/s | 380 op/s |\n| sign | 77 op/s | 200 op/s | 20 op/s | 61 op/s |\n| sign.open | 39 op/s | 102 op/s | 11 op/s | 31 op/s |\n\n(You can run benchmarks on your devices by clicking on the links at the bottom\nof the [home page](https://tweetnacl.js.org)).\n\nIn short, with *nacl-fast.js* and 1024-byte messages you can expect to encrypt and\nauthenticate more than 57000 messages per second on a typical laptop or more than\n14000 messages per second on a $170 smartphone, sign about 200 and verify 100\nmessages per second on a laptop or 60 and 30 messages per second on a smartphone,\nper CPU core (with Web Workers you can do these operations in parallel),\nwhich is good enough for most applications.\n\n\nContributors\n------------\n\nSee AUTHORS.md file.\n\n\nThird-party libraries based on TweetNaCl.js\n-------------------------------------------\n\n* [forward-secrecy](https://github.com/alax/forward-secrecy) — Axolotl ratchet implementation\n* [nacl-stream](https://github.com/dchest/nacl-stream-js) - streaming encryption\n* [tweetnacl-auth-js](https://github.com/dchest/tweetnacl-auth-js) — implementation of [`crypto_auth`](http://nacl.cr.yp.to/auth.html)\n* [tweetnacl-sealed-box](https://github.com/whs/tweetnacl-sealed-box) — implementation of [`sealed boxes`](https://download.libsodium.org/doc/public-key_cryptography/sealed_boxes.html)\n* [chloride](https://github.com/dominictarr/chloride) - unified API for various NaCl modules\n\n\nWho uses it\n-----------\n\nSome notable users of TweetNaCl.js:\n\n* [GitHub](https://github.com)\n* [MEGA](https://github.com/meganz/webclient)\n* [Stellar](https://www.stellar.org/)\n* [miniLock](https://github.com/kaepora/miniLock)\n","versions":{"0.14.5":{"name":"tweetnacl","version":"0.14.5","description":"Port of TweetNaCl cryptographic library to JavaScript","main":"nacl-fast.js","types":"nacl.d.ts","directories":{"test":"test"},"scripts":{"build":"uglifyjs nacl.js -c -m -o nacl.min.js && uglifyjs nacl-fast.js -c -m -o nacl-fast.min.js","test-node":"tape test/*.js | faucet","test-node-all":"make -C test/c && tape test/*.js test/c/*.js | faucet","test-browser":"NACL_SRC=${NACL_SRC:='nacl.min.js'} && npm run build-test-browser && cat $NACL_SRC test/browser/_bundle.js | tape-run | faucet","build-test-browser":"browserify test/browser/init.js test/*.js | uglifyjs -c -m -o test/browser/_bundle.js 2>/dev/null && browserify test/browser/init.js test/*.quick.js | uglifyjs -c -m -o test/browser/_bundle-quick.js 2>/dev/null","test":"npm run test-node-all && npm run test-browser","bench":"node test/benchmark/bench.js","lint":"eslint nacl.js nacl-fast.js test/*.js test/benchmark/*.js"},"repository":{"type":"git","url":"git+https://github.com/dchest/tweetnacl-js.git"},"author":{"name":"TweetNaCl-js contributors"},"license":"Unlicense","bugs":{"url":"https://github.com/dchest/tweetnacl-js/issues"},"devDependencies":{"browserify":"^13.0.0","eslint":"^2.2.0","faucet":"^0.0.1","tap-browser-color":"^0.1.2","tape":"^4.4.0","tape-run":"^2.1.3","tweetnacl-util":"^0.13.3","uglify-js":"^2.6.1"},"browser":{"buffer":false,"crypto":false},"gitHead":"cce829e473b1ae299a9373b5140c713ee88f577f","_id":"tweetnacl@0.14.5","_shasum":"5ae68177f192d4456269d108afa93ff8743f4f64","_from":".","_npmVersion":"3.10.8","_nodeVersion":"7.0.0","dist":{"shasum":"5ae68177f192d4456269d108afa93ff8743f4f64","tarball":"http://localhost:4260/tweetnacl/tweetnacl-0.14.5.tgz","integrity":"sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDHhdkxfW1hN14i/xMCWfhygkl+52bR+DkNVmdARtwc6wIgPxfsfj8jgtNcMyBXTnqqri0hI2MhOcZniVHZ8VDCcFk="}]}}},"homepage":"https://tweetnacl.js.org","repository":{"type":"git","url":"git+https://github.com/dchest/tweetnacl-js.git"},"author":{"name":"TweetNaCl-js contributors"},"bugs":{"url":"https://github.com/dchest/tweetnacl-js/issues"},"license":"Unlicense","readmeFilename":"README.md"}