Merge pull request #10 from dcousens/pbkdf2

index: use pbkdf2-compat instead of cryptojs
This commit is contained in:
Wei Lu 2014-09-22 20:14:58 +08:00
commit 913e26211a
2 changed files with 10 additions and 6 deletions

View File

@ -1,12 +1,15 @@
var assert = require('assert') var assert = require('assert')
var CryptoJS = require('crypto-js')
var crypto = require('crypto') var crypto = require('crypto')
var pbkdf2 = require('pbkdf2-compat')
var DEFAULT_WORDLIST = require('./wordlists/en.json') var DEFAULT_WORDLIST = require('./wordlists/en.json')
function mnemonicToSeed(mnemonic, password) {
return pbkdf2(mnemonic, salt(password), 2048, 64, 'sha512')
}
function mnemonicToSeedHex(mnemonic, password) { function mnemonicToSeedHex(mnemonic, password) {
var options = { iterations: 2048, hasher: CryptoJS.algo.SHA512, keySize: 512/32 } return mnemonicToSeed(mnemonic, password).toString('hex')
return CryptoJS.PBKDF2(mnemonic, salt(password), options).toString(CryptoJS.enc.Hex)
} }
function mnemonicToEntropy(mnemonic, wordlist) { function mnemonicToEntropy(mnemonic, wordlist) {
@ -113,6 +116,7 @@ function lpad(str, padString, length) {
} }
module.exports = { module.exports = {
mnemonicToSeed: mnemonicToSeed,
mnemonicToSeedHex: mnemonicToSeedHex, mnemonicToSeedHex: mnemonicToSeedHex,
mnemonicToEntropy: mnemonicToEntropy, mnemonicToEntropy: mnemonicToEntropy,
entropyToMnemonic: entropyToMnemonic, entropyToMnemonic: entropyToMnemonic,

View File

@ -21,11 +21,11 @@
}, },
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"crypto-js": "^3.1.2-2", "pbkdf2-compat": "^1.0.1"
"sinon": "^1.10.3"
}, },
"devDependencies": { "devDependencies": {
"browserify": "^5.9.1", "browserify": "^5.9.1",
"mocha": "^1.17.1" "mocha": "^1.17.1",
"sinon": "^1.10.3"
} }
} }