Comparing version 5.4.1 to 6.0.0
630
index.js
"use strict"; | ||
var scryptNative = require("./build/Release/scrypt"); | ||
var scryptNative = require("./build/Release/scrypt") | ||
, Crypto = require("crypto") | ||
, Os = require("os"); | ||
var checkNumberOfArguments = function(args, message, numberOfArguments) { | ||
if (message === undefined) message = "No arguments present"; | ||
if (numberOfArguments === undefined) numberOfArguments = 1; | ||
if (message === undefined) message = "No arguments present"; | ||
if (numberOfArguments === undefined) numberOfArguments = 1; | ||
if (args.length < numberOfArguments) { | ||
var error = new SyntaxError(message); | ||
throw error; | ||
} | ||
if (args.length < numberOfArguments) { | ||
var error = new SyntaxError(message); | ||
throw error; | ||
} | ||
} | ||
@@ -20,26 +22,26 @@ | ||
var checkAsyncArguments = function(args, callback_least_needed_pos, message) { | ||
checkNumberOfArguments(args); | ||
checkNumberOfArguments(args); | ||
var callback_index = (function(){ | ||
for (var i=0; i < args.length; i++) { | ||
if (typeof args[i] === "function") { | ||
return i; | ||
} | ||
} | ||
})(); | ||
var callback_index = (function(){ | ||
for (var i=0; i < args.length; i++) { | ||
if (typeof args[i] === "function") { | ||
return i; | ||
} | ||
} | ||
})(); | ||
if (callback_index === undefined) { | ||
if (typeof Promise !== "undefined") | ||
return undefined; // if promises are available, don't worry about call backs | ||
if (callback_index === undefined) { | ||
if (typeof Promise !== "undefined") | ||
return undefined; // if promises are available, don't worry about call backs | ||
var error = new SyntaxError("No callback function present, and Promises are not available"); | ||
throw error; | ||
} | ||
var error = new SyntaxError("No callback function present, and Promises are not available"); | ||
throw error; | ||
} | ||
if (callback_index < callback_least_needed_pos) { | ||
var error = new SyntaxError(message); | ||
throw error; | ||
} | ||
if (callback_index < callback_least_needed_pos) { | ||
var error = new SyntaxError(message); | ||
throw error; | ||
} | ||
return callback_index; | ||
return callback_index; | ||
} | ||
@@ -51,239 +53,197 @@ | ||
var checkScryptParametersObject = function(params) { | ||
var error = undefined; | ||
var error = undefined; | ||
if (typeof params !== "object") { | ||
var error = new TypeError("Scrypt parameters type is incorrect: It must be a JSON object"); | ||
} | ||
if (typeof params !== "object") { | ||
var error = new TypeError("Scrypt parameters type is incorrect: It must be a JSON object"); | ||
} | ||
if (!error && !params.hasOwnProperty("N")) { | ||
var error = new TypeError("Scrypt params object does not have 'N' property present"); | ||
} | ||
if (!error && !params.hasOwnProperty("N")) { | ||
var error = new TypeError("Scrypt params object does not have 'N' property present"); | ||
} | ||
if (!error && params.N !== parseInt(params.N)) { | ||
var error = new TypeError("Scrypt params object 'N' property is not an integer"); | ||
} | ||
if (!error && params.N !== parseInt(params.N)) { | ||
var error = new TypeError("Scrypt params object 'N' property is not an integer"); | ||
} | ||
if (!error && !params.hasOwnProperty("r")) { | ||
var error = new TypeError("Scrypt params object does not have 'r' property present"); | ||
} | ||
if (!error && !params.hasOwnProperty("r")) { | ||
var error = new TypeError("Scrypt params object does not have 'r' property present"); | ||
} | ||
if (!error && params.r !== parseInt(params.r)) { | ||
var error = new TypeError("Scrypt params object 'r' property is not an integer"); | ||
} | ||
if (!error && params.r !== parseInt(params.r)) { | ||
var error = new TypeError("Scrypt params object 'r' property is not an integer"); | ||
} | ||
if (!error && !params.hasOwnProperty("p")) { | ||
var error = new TypeError("Scrypt params object does not have 'p' property present"); | ||
} | ||
if (!error && !params.hasOwnProperty("p")) { | ||
var error = new TypeError("Scrypt params object does not have 'p' property present"); | ||
} | ||
if (!error && params.p !== parseInt(params.p)) { | ||
var error = new TypeError("Scrypt params object 'p' property is not an integer"); | ||
} | ||
if (!error && params.p !== parseInt(params.p)) { | ||
var error = new TypeError("Scrypt params object 'p' property is not an integer"); | ||
} | ||
if (error) { | ||
error.propertyName = "Scrypt parameters object"; | ||
error.propertyValue = params; | ||
throw error; | ||
} | ||
if (error) { | ||
error.propertyName = "Scrypt parameters object"; | ||
error.propertyValue = params; | ||
throw error; | ||
} | ||
} | ||
var processParamsArguments = function(args) { | ||
var error = undefined; | ||
var error = undefined; | ||
checkNumberOfArguments(args, "At least one argument is needed - the maxtime", 1); | ||
checkNumberOfArguments(args, "At least one argument is needed - the maxtime", 1); | ||
// Set defaults (if necessary) | ||
if (args[1] === undefined) args[1] = 0; //maxmem default to 0 | ||
if (args[2] === undefined) args[2] = 0.5; //max_memfrac default to 0.5 | ||
// Set defaults (if necessary) | ||
if (args[1] === undefined) args[1] = 0; //maxmem default to 0 | ||
if (args[2] === undefined) args[2] = 0.5; //max_memfrac default to 0.5 | ||
for(var i=0; i < Math.min(3, args.length); i++) { | ||
var propertyName = (function() { | ||
if (i === 0) return "maxtime"; | ||
if (i === 1) return "maxmem"; | ||
if (i === 2) return "max_memfrac"; | ||
})(); | ||
for(var i=0; i < Math.min(3, args.length); i++) { | ||
var propertyName = (function() { | ||
if (i === 0) return "maxtime"; | ||
if (i === 1) return "maxmem"; | ||
if (i === 2) return "max_memfrac"; | ||
})(); | ||
// All args must be of type number | ||
if (!error && typeof args[i] !== "number") { | ||
error = new TypeError(propertyName + " must be a number"); | ||
} | ||
// All args must be of type number | ||
if (!error && typeof args[i] !== "number") { | ||
error = new TypeError(propertyName + " must be a number"); | ||
} | ||
// Specific argument checks | ||
if (!error) { | ||
switch (i) { | ||
case 0: //maxtime | ||
if (args[0] <= 0) { | ||
error = new RangeError(propertyName + " must be greater than 0"); | ||
} | ||
break; | ||
// Specific argument checks | ||
if (!error) { | ||
switch (i) { | ||
case 0: //maxtime | ||
if (args[0] <= 0) { | ||
error = new RangeError(propertyName + " must be greater than 0"); | ||
} | ||
break; | ||
case 1: //maxmem | ||
if (args[1] !== parseInt(args[1], 10)) { | ||
error = new TypeError(propertyName + " must be an integer"); | ||
} | ||
case 1: //maxmem | ||
if (args[1] !== parseInt(args[1], 10)) { | ||
error = new TypeError(propertyName + " must be an integer"); | ||
} | ||
if (!error && args[1] < 0) { | ||
error = new RangeError(propertyName + " must be greater than or equal to 0") | ||
} | ||
break; | ||
if (!error && args[1] < 0) { | ||
error = new RangeError(propertyName + " must be greater than or equal to 0") | ||
} | ||
break; | ||
case 2: //max_memfrac | ||
if (args[2] < 0.0 || args[2] > 1.0) { | ||
error = new RangeError(propertyName + " must be between 0.0 and 1.0 inclusive") | ||
} | ||
break; | ||
} | ||
} | ||
case 2: //max_memfrac | ||
if (args[2] < 0.0 || args[2] > 1.0) { | ||
error = new RangeError(propertyName + " must be between 0.0 and 1.0 inclusive") | ||
} | ||
break; | ||
} | ||
} | ||
// Throw error if necessary | ||
if (error) { | ||
error.propertyName = propertyName; | ||
error.propertyValue = args[i]; | ||
throw error; | ||
} | ||
} | ||
// Throw error if necessary | ||
if (error) { | ||
error.propertyName = propertyName; | ||
error.propertyValue = args[i]; | ||
throw error; | ||
} | ||
} | ||
return args; | ||
return args; | ||
} | ||
var processKDFArguments = function(args) { | ||
checkNumberOfArguments(args, "At least two arguments are needed - the key and the Scrypt paramaters object", 2) | ||
checkNumberOfArguments(args, "At least two arguments are needed - the key and the Scrypt paramaters object", 2) | ||
// | ||
// Check key argument | ||
// | ||
if (typeof args[0] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[0] = new Buffer(args[0]); | ||
else if (!Buffer.isBuffer(args[0])) { | ||
var error = new TypeError("Key type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "key"; | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// Check resulting buffer is not empty | ||
if (!args[0].length) { | ||
var error = new Error("Input key is empty"); | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// | ||
// Check key argument | ||
// | ||
if (typeof args[0] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[0] = new Buffer(args[0]); | ||
else if (!Buffer.isBuffer(args[0])) { | ||
var error = new TypeError("Key type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "key"; | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// | ||
// Check Scrypt Parameters object | ||
// | ||
checkScryptParametersObject(args[1]) | ||
// | ||
// Check Scrypt Parameters object | ||
// | ||
checkScryptParametersObject(args[1]) | ||
return args; | ||
return args; | ||
} | ||
var processVerifyArguments = function(args) { | ||
checkNumberOfArguments(args, "At least two arguments are needed - the KDF and the key", 2); | ||
checkNumberOfArguments(args, "At least two arguments are needed - the KDF and the key", 2); | ||
// | ||
// Check KDF | ||
// | ||
if (typeof args[0] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[0] = new Buffer(args[0]); | ||
else if (!Buffer.isBuffer(args[0])) { | ||
var error = new TypeError("KDF type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "KDF"; | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// | ||
// Check KDF | ||
// | ||
if (typeof args[0] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[0] = new Buffer(args[0]); | ||
else if (!Buffer.isBuffer(args[0])) { | ||
var error = new TypeError("KDF type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "KDF"; | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// Check resulting buffer is not empty | ||
if (!args[0].length) { | ||
var error = new Error("Input KDF is empty"); | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// | ||
// Check Key | ||
// | ||
if (typeof args[1] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[1] = new Buffer(args[1]); | ||
else if (!Buffer.isBuffer(args[1])) { | ||
var error = new TypeError("Key type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "key"; | ||
error.propertyValue = args[1]; | ||
throw error; | ||
} | ||
// Check resulting buffer is not empty | ||
if (!args[0].length) { | ||
var error = new Error("Input KDF is empty"); | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// | ||
// Check Key | ||
// | ||
if (typeof args[1] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[1] = new Buffer(args[1]); | ||
else if (!Buffer.isBuffer(args[1])) { | ||
var error = new TypeError("Key type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "key"; | ||
error.propertyValue = args[1]; | ||
throw error; | ||
} | ||
// Check resulting key is not empty | ||
if (!args[1].length) { | ||
var error = new Error("Input key is empty"); | ||
error.propertyValue = args[1]; | ||
throw error; | ||
} | ||
// Check resulting key is not empty | ||
if (!args[1].length) { | ||
var error = new Error("Input key is empty"); | ||
error.propertyValue = args[1]; | ||
throw error; | ||
} | ||
return args; | ||
return args; | ||
} | ||
var processHashArguments = function(args) { | ||
checkNumberOfArguments(args, "At least four arguments are needed - the key to hash, the scrypt params object, the output length of the hash and the salt", 4); | ||
checkNumberOfArguments(args, "At least four arguments are needed - the key to hash, the scrypt params object, the output length of the hash and the salt", 4); | ||
// | ||
// Check Key | ||
// | ||
if (typeof args[0] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[0] = new Buffer(args[0]); | ||
else if (!Buffer.isBuffer(args[0])) { | ||
var error = new TypeError("Key type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "KDF"; | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// | ||
// Check Key | ||
// | ||
if (typeof args[0] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[0] = new Buffer(args[0]); | ||
else if (!Buffer.isBuffer(args[0])) { | ||
var error = new TypeError("Key type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "KDF"; | ||
error.propertyValue = args[0]; | ||
throw error; | ||
} | ||
// Check resulting key is not empty | ||
if (!args[0].length) { | ||
var error = new Error("Input key is empty"); | ||
error.propertyValue = args[1]; | ||
throw error; | ||
} | ||
// | ||
// Check Scrypt Parameters object | ||
// | ||
checkScryptParametersObject(args[1]) | ||
// | ||
// Check Scrypt Parameters object | ||
// | ||
checkScryptParametersObject(args[1]) | ||
// | ||
// Check the hash output length | ||
// | ||
if (typeof args[2] !== "number" || args[2] !== parseInt(args[2],10)) { | ||
error = new TypeError("Hash length must be an integer"); | ||
throw error; | ||
} | ||
// | ||
// Check the hash output length | ||
// | ||
if (typeof args[2] !== "number" || args[2] !== parseInt(args[2],10)) { | ||
error = new TypeError("Hash length must be an integer"); | ||
throw error; | ||
} | ||
// | ||
// Check Salt | ||
// | ||
if (typeof args[3] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[3] = new Buffer(args[3]); | ||
else if (!Buffer.isBuffer(args[3])) { | ||
var error = new TypeError("Salt type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "salt"; | ||
error.propertyValue = args[3]; | ||
throw error; | ||
} | ||
// | ||
// Check Salt | ||
// | ||
if (typeof args[3] === "string") | ||
// Convert string to buffer (if necessary) | ||
args[3] = new Buffer(args[3]); | ||
else if (!Buffer.isBuffer(args[3])) { | ||
var error = new TypeError("Salt type is incorrect: It can only be of type string or Buffer"); | ||
error.propertyName = "salt"; | ||
error.propertyValue = args[3]; | ||
throw error; | ||
} | ||
return args; | ||
return args; | ||
} | ||
@@ -295,123 +255,135 @@ | ||
var scrypt = { | ||
paramsSync: function() { | ||
var args = processParamsArguments(arguments); | ||
return scryptNative.paramsSync(args[0], args[1], args[2]); | ||
}, | ||
paramsSync: function() { | ||
var args = processParamsArguments(arguments); | ||
return scryptNative.paramsSync(args[0], args[1], args[2], Os.totalmem()); | ||
}, | ||
params: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 1, "At least one argument is needed before the callback - the maxtime"); | ||
params: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 1, "At least one argument is needed before the callback - the maxtime"); | ||
if (callback_index === undefined) { | ||
// Promise | ||
return new Promise(function(resolve, reject) { | ||
args = processParamsArguments(args); | ||
scryptNative.params(args[0], args[1], args[2], function(err, params) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(params); | ||
} | ||
}); | ||
}) | ||
} else { | ||
// Normal async with callback | ||
if (callback_index === undefined) { | ||
// Promise | ||
return new Promise(function(resolve, reject) { | ||
args = processParamsArguments(args); | ||
scryptNative.params(args[0], args[1], args[2], Os.totalmem(), function(err, params) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(params); | ||
} | ||
}); | ||
}) | ||
} else { | ||
// Normal async with callback | ||
// If not using promise (so using callback), | ||
// remove callback function from args and | ||
// put it in it's own variable. This allows | ||
// sync check to be used (DRY) | ||
var callback = args[callback_index]; | ||
delete args[callback_index]; | ||
args = processParamsArguments(args); | ||
args[3] = callback; | ||
scryptNative.params(args[0], args[1], args[2], args[3]); | ||
} | ||
}, | ||
// If not using promise (so using callback), | ||
// remove callback function from args and | ||
// put it in it's own variable. This allows | ||
// sync check to be used (DRY) | ||
var callback = args[callback_index]; | ||
delete args[callback_index]; | ||
args = processParamsArguments(args); | ||
args[3] = callback; | ||
scryptNative.params(args[0], args[1], args[2], Os.totalmem(), args[3]); | ||
} | ||
}, | ||
kdfSync: function() { | ||
var args = processKDFArguments(arguments); | ||
return scryptNative.kdfSync(args[0], args[1]); | ||
}, | ||
kdfSync: function() { | ||
var args = processKDFArguments(arguments); | ||
return scryptNative.kdfSync(args[0], args[1], Crypto.randomBytes(256)); | ||
}, | ||
kdf: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 2, "At least two arguments are needed before the call back function - the key and the Scrypt parameters object"); | ||
kdf: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 2, "At least two arguments are needed before the call back function - the key and the Scrypt parameters object") | ||
, that = this; | ||
if (callback_index === undefined) { | ||
// Promise | ||
return new Promise(function(resolve, reject) { | ||
args = processKDFArguments(args); | ||
scryptNative.kdf(args[0], args[1], function(err, kdfResult) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(kdfResult); | ||
} | ||
}) | ||
}); | ||
} else { | ||
// Normal async with callback | ||
args = processKDFArguments(arguments); | ||
scryptNative.kdf(args[0], args[1], args[2]); | ||
} | ||
}, | ||
args = processKDFArguments(args); | ||
verifyKdfSync: function() { | ||
var args = processVerifyArguments(arguments); | ||
return scryptNative.verifySync(args[0], args[1]); | ||
}, | ||
if (callback_index === undefined) { // promise | ||
return new Promise(function(resolve, reject) { | ||
verifyKdf: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 2, "At least two arguments are needed before the callback function - the KDF and the key"); | ||
// Get some async salt | ||
Crypto.randomBytes(256, function(err, salt) { | ||
if (err) reject(err); | ||
else { | ||
scryptNative.kdf(args[0], args[1], salt, function(err, kdfResult) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(kdfResult); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} else { // Normal async with callback | ||
Crypto.randomBytes(256, function(err, salt) { | ||
// Normal async with callback | ||
if (err) // Crypto.randomBytes err | ||
args[2](err); // call callback with error | ||
else | ||
scryptNative.kdf(args[0], args[1], salt, args[2]); | ||
}); | ||
} | ||
}, | ||
if (callback_index === undefined) { | ||
// Promise | ||
return new Promise(function(resolve, reject) { | ||
args = processVerifyArguments(args); | ||
scryptNative.verify(args[0], args[1], function(err, match) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(match); | ||
} | ||
}); | ||
}) | ||
} else { | ||
// Normal async with callback | ||
args = processVerifyArguments(args); | ||
scryptNative.verify(args[0], args[1], args[2]); | ||
} | ||
}, | ||
verifyKdfSync: function() { | ||
var args = processVerifyArguments(arguments); | ||
return scryptNative.verifySync(args[0], args[1]); | ||
}, | ||
hashSync: function() { | ||
var args = processHashArguments(arguments); | ||
return scryptNative.hashSync(args[0], args[1], args[2], args[3]); | ||
}, | ||
verifyKdf: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 2, "At least two arguments are needed before the callback function - the KDF and the key"); | ||
hash: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 4, "At least four arguments are needed before the callback - the key to hash, the scrypt params object, the output length of the hash and the salt"); | ||
if (callback_index === undefined) { | ||
// Promise | ||
return new Promise(function(resolve, reject) { | ||
args = processVerifyArguments(args); | ||
scryptNative.verify(args[0], args[1], function(err, match) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(match); | ||
} | ||
}); | ||
}) | ||
} else { | ||
// Normal async with callback | ||
args = processVerifyArguments(args); | ||
scryptNative.verify(args[0], args[1], args[2]); | ||
} | ||
}, | ||
if (callback_index === undefined) { | ||
//Promise | ||
return new Promise(function(resolve, reject) { | ||
args = processHashArguments(args); | ||
scryptNative.hash(args[0], args[1], args[2], args[3], function(err, hash) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(hash); | ||
} | ||
}); | ||
}); | ||
} else { | ||
// Normal async with callback | ||
args = processHashArguments(arguments); | ||
scryptNative.hash(args[0], args[1], args[2], args[3], args[4]); | ||
} | ||
} | ||
hashSync: function() { | ||
var args = processHashArguments(arguments); | ||
return scryptNative.hashSync(args[0], args[1], args[2], args[3]); | ||
}, | ||
hash: function() { | ||
var args = arguments | ||
, callback_index = checkAsyncArguments(args, 4, "At least four arguments are needed before the callback - the key to hash, the scrypt params object, the output length of the hash and the salt"); | ||
args = processHashArguments(args); | ||
if (callback_index === undefined) { | ||
//Promise | ||
return new Promise(function(resolve, reject) { | ||
scryptNative.hash(args[0], args[1], args[2], args[3], function(err, hash) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(hash); | ||
} | ||
}); | ||
}); | ||
} else { | ||
// Normal async with callback | ||
scryptNative.hash(args[0], args[1], args[2], args[3], args[4]); | ||
} | ||
} | ||
}; | ||
module.exports = scrypt; |
{ | ||
"name": "scrypt", | ||
"description": "The scrypt crypto library for NodeJS", | ||
"version": "5.4.1", | ||
"version": "6.0.0", | ||
"license": "zlib", | ||
@@ -48,4 +48,6 @@ "keywords": [ | ||
"scripts": { | ||
"preinstall": "node node-scrypt-preinstall.js", | ||
"install": "node-gyp rebuild", | ||
"test": "mocha tests/scrypt-tests.js" | ||
} | ||
} |
@@ -14,3 +14,13 @@ # Scrypt For Node | ||
## Node-Scrypt Version 5 | ||
## Node-Scrypt Version 6 | ||
Version 6 is a major new release. It is by and large compatible with version 5. | ||
* Scrypt version 1.2.0 is being used (a very recently released version of Scrypt) | ||
* Using Node's internal cryptographic libraries - for windows users, there is no need to use an external OpenSSL library anymore. | ||
* Using Node's OS module to check for freemem, meaning no need to use any system calls and therefore no external dependencies | ||
Version 6 should work much better on all platforms | ||
## Past Releases | ||
### Node-Scrypt Version 5 | ||
Version 5 is a major new release that is **not backward compatible** with any | ||
@@ -17,0 +27,0 @@ previous version. Some highlights: |
@@ -36,3 +36,3 @@ var chai = require("chai") | ||
expect(scrypt.paramsSync) | ||
.to.throw(SyntaxError) | ||
.to.throw(SyntaxError) | ||
.to.match(/^SyntaxError: At least one argument is needed - the maxtime$/); | ||
@@ -43,3 +43,3 @@ }); | ||
expect(function() { scrypt.paramsSync(-1); }) | ||
.to.throw(RangeError) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: maxtime must be greater than 0$/); | ||
@@ -49,35 +49,35 @@ }); | ||
it("Will throw a TypeError exception if maxmem is not an integer", function() { | ||
expect(function() { scrypt.paramsSync(1, 2.4); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: maxmem must be an integer$/); | ||
expect(function() { scrypt.paramsSync(1, 2.4); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: maxmem must be an integer$/); | ||
}); | ||
it("Will throw a RangeError exception if maxmem is less than 0", function() { | ||
expect(function() { scrypt.paramsSync(1, -2); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: maxmem must be greater than or equal to 0$/); | ||
expect(function() { scrypt.paramsSync(1, -2); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: maxmem must be greater than or equal to 0$/); | ||
}); | ||
it("Will throw a RangeError exception if max_memfrac is not between 0.0 and 1.0", function() { | ||
expect(function() { scrypt.paramsSync(1, 2, -0.1); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
expect(function() { scrypt.paramsSync(1, 2, -0.1); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
expect(function() { scrypt.paramsSync(1, 2, 1.1); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
expect(function() { scrypt.paramsSync(1, 2, 1.1); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
}); | ||
it("Will throw a TypeError if any arguments are not numbers", function() { | ||
var args = [1, 2, 0.9]; | ||
var args = [1, 2, 0.9]; | ||
for (var i=0; i < args.length; i++) { | ||
var temp = args[i]; | ||
args[i] = "not a number"; | ||
expect(function() { scrypt.paramsSync(args[0], args[1], args[2]); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: (maxtime|maxmem|max_memfrac) must be a number$/); | ||
for (var i=0; i < args.length; i++) { | ||
var temp = args[i]; | ||
args[i] = "not a number"; | ||
expect(function() { scrypt.paramsSync(args[0], args[1], args[2]); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: (maxtime|maxmem|max_memfrac) must be a number$/); | ||
args[i] = temp; | ||
} | ||
} | ||
}); | ||
@@ -98,3 +98,3 @@ }); | ||
it("Should return a JSON object when maxtime, maxmem and max_memfrac are defined", function() { | ||
var params = scrypt.paramsSync(1, 2, 0.5); | ||
var params = scrypt.paramsSync(1, 2, 0.5); | ||
examine(params); | ||
@@ -124,3 +124,3 @@ }); | ||
expect(scrypt.params) | ||
.to.throw(SyntaxError) | ||
.to.throw(SyntaxError) | ||
.to.match(/^SyntaxError: No arguments present$/); | ||
@@ -143,3 +143,3 @@ }); | ||
expect(function() { scrypt.params(-1, function(){}); }) | ||
.to.throw(RangeError) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: maxtime must be greater than 0$/); | ||
@@ -149,35 +149,35 @@ }); | ||
it("Will throw a TypeError exception if maxmem is not an integer", function() { | ||
expect(function() { scrypt.params(1, 2.4, function(){}); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: maxmem must be an integer$/); | ||
expect(function() { scrypt.params(1, 2.4, function(){}); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: maxmem must be an integer$/); | ||
}); | ||
it("Will throw a RangeError exception if maxmem is less than 0", function() { | ||
expect(function() { scrypt.params(1, -2, function(){}); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: maxmem must be greater than or equal to 0$/); | ||
expect(function() { scrypt.params(1, -2, function(){}); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: maxmem must be greater than or equal to 0$/); | ||
}); | ||
it("Will throw a RangeError exception if max_memfrac is not between 0.0 and 1.0", function() { | ||
expect(function() { scrypt.params(1, 2, -0.1, function(){}); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
expect(function() { scrypt.params(1, 2, -0.1, function(){}); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
expect(function() { scrypt.params(1, 2, 1.1, function(){}); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
expect(function() { scrypt.params(1, 2, 1.1, function(){}); }) | ||
.to.throw(RangeError) | ||
.to.match(/^RangeError: max_memfrac must be between 0.0 and 1.0 inclusive$/); | ||
}); | ||
it("Will throw a TypeError if any arguments are not numbers", function() { | ||
var args = [1, 2, 0.9]; | ||
var args = [1, 2, 0.9]; | ||
for (var i=0; i < args.length; i++) { | ||
var temp = args[i]; | ||
args[i] = "not a number"; | ||
expect(function() { scrypt.params(args[0], args[1], args[2], function(){}); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: (maxtime|maxmem|max_memfrac) must be a number$/); | ||
for (var i=0; i < args.length; i++) { | ||
var temp = args[i]; | ||
args[i] = "not a number"; | ||
expect(function() { scrypt.params(args[0], args[1], args[2], function(){}); }) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: (maxtime|maxmem|max_memfrac) must be a number$/); | ||
args[i] = temp; | ||
} | ||
} | ||
}); | ||
@@ -266,3 +266,3 @@ }); | ||
describe("Asyncrhonous functionality with incorrect arguments", function() { | ||
describe("Asynchronous functionality with incorrect arguments", function() { | ||
var promise = undefined; | ||
@@ -327,3 +327,3 @@ | ||
it("Will return a buffer object containing the KDF with a buffer input", function(done) { | ||
scrypt.kdf(new Buffer("password"), {N:1, r:1, p:1}).then(function(result) { | ||
scrypt.kdf(new Buffer("password"), {N:16, r:1, p:1}).then(function(result) { | ||
expect(result) | ||
@@ -381,3 +381,3 @@ .to.be.an.instanceof(Buffer); | ||
it("Will return a buffer object containing the hash with a string input", function() { | ||
var result = scrypt.hashSync("hash something", {N:1, r:1, p:1}, hash_length, "NaCl"); | ||
var result = scrypt.hashSync("hash something", {N:16, r:1, p:1}, hash_length, "NaCl"); | ||
expect(result) | ||
@@ -415,3 +415,3 @@ .to.be.an.instanceof(Buffer); | ||
it("Will throw a SyntaxError if no callback function is present", function() { | ||
expect(function() {scrypt.hash("hash something", {N:1, r:1, p:1}, 64, "NaCl");}) | ||
expect(function() {scrypt.hash("hash something", {N:16, r:1, p:1}, 64, "NaCl");}) | ||
.to.throw(SyntaxError) | ||
@@ -422,3 +422,3 @@ .to.match(/^SyntaxError: No callback function present, and Promises are not available$/); | ||
it("Will throw a TypeError if the key is not a string or a Buffer object", function() { | ||
expect(function(){scrypt.hash(1123, {N:1, r:1, p:1}, 32, "NaCl", function(){})}) | ||
expect(function(){scrypt.hash(1123, {N:16, r:1, p:1}, 32, "NaCl", function(){})}) | ||
.to.throw(TypeError) | ||
@@ -429,3 +429,3 @@ .to.match(/^TypeError: Key type is incorrect: It can only be of type string or Buffer$/); | ||
it("Will throw a TypeError if the Scrypt params object is incorrect", function() { | ||
expect(function(){scrypt.hash("hash something", {N:1, r:1}, 32, "NaCl", function(){})}) | ||
expect(function(){scrypt.hash("hash something", {N:16, r:1}, 32, "NaCl", function(){})}) | ||
.to.throw(TypeError) | ||
@@ -436,7 +436,7 @@ .to.match(/^TypeError: Scrypt params object does not have 'p' property present$/); | ||
it("Will throw a TypeError if the hash length is not an integer", function() { | ||
expect(function(){scrypt.hash("hash something", {N:1, r:1, p:1}, 32.5, new Buffer("NaCl"), function(){})}) | ||
expect(function(){scrypt.hash("hash something", {N:16, r:1, p:1}, 32.5, new Buffer("NaCl"), function(){})}) | ||
.to.throw(TypeError) | ||
.to.match(/^TypeError: Hash length must be an integer$/); | ||
expect(function(){scrypt.hash("hash something", {N:1, r:1, p:1}, "thirty-two", "NaCl", function(){})}) | ||
expect(function(){scrypt.hash("hash something", {N:16, r:1, p:1}, "thirty-two", "NaCl", function(){})}) | ||
.to.throw(TypeError) | ||
@@ -447,3 +447,3 @@ .to.match(/^TypeError: Hash length must be an integer$/); | ||
it("Will throw a TypeError if the salt is not a string or a Buffer object", function() { | ||
expect(function(){scrypt.hash("hash something", {N:1, r:1, p:1}, 32, 45, function(){})}) | ||
expect(function(){scrypt.hash("hash something", {N:16, r:1, p:1}, 32, 45, function(){})}) | ||
.to.throw(TypeError) | ||
@@ -457,11 +457,11 @@ .to.match(/^TypeError: Salt type is incorrect: It can only be of type string or Buffer$/); | ||
it("Will return a buffer object containing the hash with a string input", function(done) { | ||
scrypt.hash("hash something", {N:1, r:1, p:1}, hash_length, "NaCl", function(err, result){ | ||
scrypt.hash("hash something", {N:16, r:1, p:1}, hash_length, "NaCl", function(err, result){ | ||
expect(result) | ||
.to.be.an.instanceof(Buffer); | ||
expect(result) | ||
expect(result) | ||
.to.have.length(hash_length); | ||
expect(err) | ||
.to.not.exist; | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -474,9 +474,9 @@ }); | ||
it("Will return a buffer object containing the hash with a string input", function(done) { | ||
scrypt.hash("hash something", {N:1, r:1, p:1}, hash_length, "NaCl").then(function(result){ | ||
scrypt.hash("hash something", {N:16, r:1, p:1}, hash_length, "NaCl").then(function(result){ | ||
expect(result) | ||
.to.be.an.instanceof(Buffer); | ||
expect(result) | ||
expect(result) | ||
.to.have.length(hash_length); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -516,3 +516,3 @@ } | ||
var key = "kdf" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}); | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}); | ||
@@ -554,3 +554,3 @@ it("Will produce a boolean value", function(){ | ||
var key = "kdf" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}); | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}); | ||
@@ -583,3 +583,3 @@ expect(function() {scrypt.verifyKdf(kdf, key);}) | ||
var key = "kdf" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}); | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}); | ||
@@ -608,3 +608,3 @@ it("Will produce a boolean value", function(done){ | ||
var key = "kdf" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}); | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}); | ||
@@ -688,4 +688,4 @@ if (typeof Promise !== "undefined") { | ||
it("Will use random salt to ensure no two KDFs are the same, even if the keys are identical", function(){ | ||
var result1 = scrypt.kdfSync("password", {N:1, r:1, p:1}) | ||
, result2 = scrypt.kdfSync("password", {N:1, r:1, p:1}); | ||
var result1 = scrypt.kdfSync("password", {N:16, r:1, p:1}) | ||
, result2 = scrypt.kdfSync("password", {N:16, r:1, p:1}); | ||
@@ -698,3 +698,3 @@ expect(result1.toString("base64")) | ||
var key = "this is a key" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}) | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}) | ||
, result = scrypt.verifyKdfSync(kdf, key); | ||
@@ -709,3 +709,3 @@ | ||
var key = "this is a key" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}) | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}) | ||
, result = scrypt.verifyKdfSync(kdf, new Buffer("Another key")); | ||
@@ -721,6 +721,6 @@ | ||
it("Will use random salt to ensure no two KDFs are the same, even if the keys are identical", function(done) { | ||
scrypt.kdf("password", {N:1, r:1, p:1}, function(err, result1) { | ||
scrypt.kdf("password", {N:16, r:1, p:1}, function(err, result1) { | ||
expect(err) | ||
.to.not.exist; | ||
scrypt.kdf("password", {N:1, r:1, p:1}, function(err, result2) { | ||
scrypt.kdf("password", {N:16, r:1, p:1}, function(err, result2) { | ||
expect(err) | ||
@@ -737,3 +737,3 @@ .to.not.exist; | ||
var key = "this is a key" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}); | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}); | ||
@@ -752,3 +752,3 @@ scrypt.verifyKdf(kdf, key, function(err, result) { | ||
var key = "this is a key" | ||
, kdf = scrypt.kdfSync(key, {N:1, r:1, p:1}); | ||
, kdf = scrypt.kdfSync(key, {N:16, r:1, p:1}); | ||
@@ -771,3 +771,3 @@ scrypt.verifyKdf(kdf, "Another Key", function(err, result) { | ||
it("Will be deterministic if salts are identical", function() { | ||
var result1 = scrypt.hashSync(new Buffer("hash something"), {N:1, r:1, p:1}, hash_length, "NaCl"); | ||
var result1 = scrypt.hashSync(new Buffer("hash something"), {N:16, r:1, p:1}, hash_length, "NaCl"); | ||
expect(result1) | ||
@@ -778,3 +778,3 @@ .to.be.an.instanceof(Buffer); | ||
var result2 = scrypt.hashSync("hash something", {N:1, r:1, p:1}, hash_length, new Buffer("NaCl")); | ||
var result2 = scrypt.hashSync("hash something", {N:16, r:1, p:1}, hash_length, new Buffer("NaCl")); | ||
expect(result2) | ||
@@ -792,3 +792,3 @@ .to.be.an.instanceof(Buffer); | ||
it("Will be deterministic if salts are identical", function(done) { | ||
scrypt.hash(new Buffer("hash something"), {N:1, r:1, p:1}, hash_length, "NaCl", function(err, result1) { | ||
scrypt.hash(new Buffer("hash something"), {N:16, r:1, p:1}, hash_length, "NaCl", function(err, result1) { | ||
expect(result1) | ||
@@ -801,3 +801,3 @@ .to.be.an.instanceof(Buffer); | ||
scrypt.hash("hash something", {N:1, r:1, p:1}, hash_length, new Buffer("NaCl"), function(err, result2) { | ||
scrypt.hash("hash something", {N:16, r:1, p:1}, hash_length, new Buffer("NaCl"), function(err, result2) { | ||
expect(result2) | ||
@@ -804,0 +804,0 @@ .to.be.an.instanceof(Buffer); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
AI-detected potential security risk
Supply chain riskAI has determined that this package may contain potential security issues or vulnerabilities.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
1
100
415
140323
41
1010
1