scryptsy
scryptsy
is a pure JavaScript implementation of the scrypt key deriviation function that is fully compatible with Node.js and the browser (via Browserify).
Why?
Scrypt
is an integral part of many crypto currencies. It's a part of the BIP38 standard for encrypting private Bitcoin keys. It also serves as the proof-of-work system for many crypto currencies, most notably: Litecoin and Dogecoin.
Why didn't I just the predominant pure JavaScript imlementation found here? Because it's riddled with bugs, contains no tests, and is a transliteration of the Java version. i.e. it's neither Node.js optimized nor browser optimized. Required optimizations: Buffer in Node.js and type arrays in the browser.
Note
This has been optimized and usings some static typed arrays. This means that in your application in Node.js or in the browser, you'll only want to run the algorithm once during any given time.
Usage
Installation
npm install --save scryptsy
Example
var scrypt = require('scryptsy').scrypt;
var key = "pleaseletmein";
var salt = "SodiumChloride";
var data = scrypt(key, salt, 16384, 8, 1, 64);
console.log(data.toString('hex'))
Bundling for the Browser
To use in the browser, clone the repo and then download Browserify:
npm install -g browserify
run:
browserify --standalone pbdkf2 < lib/pbkdf2.js > pbdkf2.bundle.js
then include pbdkf2.bundle.js
in your <script>
tag in your html.
Testing
If you want to test the algorithm, clone the git repo. Then run npm install --development
to install all of the dependencies.
Node.js
run:
make test-node
Browser
run:
make test-browser
Resources
Credits
This code was modified from the code found here https://github.com/cheongwy/node-scrypt-js which was based on https://github.com/wg/scrypt.
License
MIT License
Copyright (c) 2014, JP Richardson Copyright (c) 2010-2011 Intalio Pte, All Rights Reserved
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.