Skip to content

Commit

Permalink
add English wordlist and constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
weilu committed Mar 11, 2014
1 parent 4f7c5c0 commit caa9922
Show file tree
Hide file tree
Showing 3 changed files with 2,068 additions and 5 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
11 changes: 10 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -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])
})
})
Expand Down
Loading

0 comments on commit caa9922

Please sign in to comment.