add English wordlist and constructor

This commit is contained in:
Wei Lu 2014-03-11 12:38:09 +08:00
parent 4f7c5c0c14
commit caa9922dc8
3 changed files with 2068 additions and 5 deletions

View File

@ -1,10 +1,14 @@
Crypto = require('crypto-js')
var Crypto = require('crypto-js')
var Wordlists = require('require-json-tree')('./wordlists')
module.exports = {
mnemonicToSeed: mnemonicToSeed
module.exports = BIP39
function BIP39(language){
language = language || 'en'
this.wordlist = Wordlists[language]
}
function mnemonicToSeed(mnemonic, password){
BIP39.prototype.mnemonicToSeed = function(mnemonic, password){
var options = {iterations: 2048, hasher: Crypto.algo.SHA512, keySize: 512/32}
return Crypto.PBKDF2(mnemonic, salt(password), options).toString(Crypto.enc.Hex)
}

View File

@ -1,10 +1,19 @@
var vectors = require('./vectors.json').english
var bip39 = require('../index.js')
var BIP39 = require('../index.js')
var wordlist = require('../Wordlists/en.json')
var assert = require('assert')
describe('constructor', function(){
it('defaults language to english', function(){
var bip39 = new BIP39()
assert.deepEqual(bip39.wordlist, wordlist)
})
})
describe('mnemonicToSeed', function(){
vectors.forEach(function(v, i){
it('works for tests vector ' + i, function(){
var bip39 = new BIP39()
assert.equal(bip39.mnemonicToSeed(v[1], 'TREZOR'), v[2])
})
})

2050
wordlists/en.json Normal file

File diff suppressed because it is too large Load Diff