mirror of https://github.com/status-im/bip39.git
add English wordlist and constructor
This commit is contained in:
parent
4f7c5c0c14
commit
caa9922dc8
12
index.js
12
index.js
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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])
|
||||
})
|
||||
})
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue