Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #23 from braydonf/bug/jsdoc
Browse files Browse the repository at this point in the history
Added .jshintrc with various jshint updates and fixed jsdoc formatting.
  • Loading branch information
maraoz committed Apr 2, 2015
2 parents 95fd9bb + e530ff8 commit 8a64b94
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
44 changes: 44 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
"browser": true, // Standard browser globals e.g. `window`, `document`.
"camelcase": false, // Permit only camelcase for `var` and `object indexes`.
"curly": true, // Require {} for every new block or scope.
"devel": false, // Allow development statements e.g. `console.log();`.
"eqeqeq": true, // Require triple equals i.e. `===`.
"esnext": true, // Allow ES.next specific features such as `const` and `let`.
"freeze": true, // Forbid overwriting prototypes of native objects such as Array, Date and so on.
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"indent": 2, // Specify indentation spacing
"latedef": true, // Prohibit variable use before definition.
"newcap": false, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"noempty": true, // Prohibit use of empty blocks.
"nonew": true, // Prohibits the use of constructor functions for side-effects
"quotmark": "single", // Define quotes to string values.
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
"smarttabs": false, // Supress warnings about mixed tabs and spaces
"strict": true, // Require `use strict` pragma in every file.
"trailing": true, // Prohibit trailing whitespaces.
"undef": true, // Require all non-global variables be declared before they are used.
"unused": true, // Warn unused variables.

"maxparams": 4, // Maximum number of parameters for a function
"maxstatements": 15, // Maximum number of statements in a function
"maxcomplexity": 6, // Cyclomatic complexity (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
"maxdepth": 4, // Maximum depth of nested control structures
"maxlen": 120, // Maximum number of cols in a line

"predef": [ // Extra globals.
"after",
"afterEach",
"before",
"beforeEach",
"define",
"describe",
"exports",
"it",
"module",
"require"
]
}
4 changes: 2 additions & 2 deletions lib/mnemonic.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var $ = bitcore.util.preconditions;
* var xprivkey = mnemonic.toHDPrivateKey();
*
* @param {*=} data - a seed, phrase, or entropy to initialize (can be skipped)
* @param {Array[]=} wordlist - the wordlist to generate mnemonics from
* @param {Array=} wordlist - the wordlist to generate mnemonics from
* @returns {Mnemonic} A new instance of Mnemonic
* @constructor
*/
Expand Down Expand Up @@ -187,7 +187,7 @@ Mnemonic.fromSeed = function(seed, wordlist) {
};

/**
*
*
* Generates a HD Private Key from a Mnemonic.
* Optionally receive a passphrase and bitcoin network.
*
Expand Down
25 changes: 17 additions & 8 deletions lib/pbkdf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ var crypto = require("crypto");
* Copyright (c) 2014, JP Richardson Copyright (c) 2010-2011 Intalio Pte, All Rights Reserved
*/
function pbkdf2(key, salt, iterations, dkLen) {
/* jshint maxstatements: 31 */
/* jshint maxcomplexity: 9 */

var hLen = 64; //SHA512 Mac length
if (dkLen > (Math.pow(2, 32) - 1) * hLen)
throw Error("Requested key length too long");

if (typeof key != 'string' && !Buffer.isBuffer(key))
if (dkLen > (Math.pow(2, 32) - 1) * hLen) {
throw Error('Requested key length too long');
}

if (typeof key !== 'string' && !Buffer.isBuffer(key)) {
throw new TypeError('key must a string or Buffer');
if (typeof salt != 'string' && !Buffer.isBuffer(salt))
}

if (typeof salt !== 'string' && !Buffer.isBuffer(salt)) {
throw new TypeError('salt must a string or Buffer');
}

if (typeof salt == 'string') salt = new Buffer(salt);
if (typeof salt === 'string') {
salt = new Buffer(salt);
}

var DK = new Buffer(dkLen);

Expand All @@ -36,7 +45,7 @@ function pbkdf2(key, salt, iterations, dkLen) {
block1[salt.length + 3] = (i >> 0 & 0xff);

U = crypto.createHmac('sha512', key).update(block1).digest();

U.copy(T, 0, 0, hLen);

for (var j = 1; j < iterations; j++) {
Expand All @@ -48,7 +57,7 @@ function pbkdf2(key, salt, iterations, dkLen) {
}

var destPos = (i - 1) * hLen;
var len = (i == l ? r : hLen);
var len = (i === l ? r : hLen);
T.copy(DK, destPos, 0, len);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"gulp": "^3.8.10"
},
"dependencies": {
"bitcore": "^0.11.4"
"bitcore": "^0.11.6"
}
}

0 comments on commit 8a64b94

Please sign in to comment.