mirror of
https://github.com/status-im/bip39.git
synced 2025-02-21 08:48:25 +00:00
index: avoid overwrite, use words variable
This commit is contained in:
parent
3552491505
commit
1f6915bd01
11
index.js
11
index.js
@ -37,20 +37,19 @@ BIP39.prototype.generateMnemonic = function(strength) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BIP39.prototype.validate = function(mnemonic) {
|
BIP39.prototype.validate = function(mnemonic) {
|
||||||
mnemonic = mnemonic.split(' ')
|
var words = mnemonic.split(' ')
|
||||||
|
|
||||||
if (mnemonic.length % 3 !== 0) return false
|
if (words.length % 3 !== 0) return false
|
||||||
|
|
||||||
var wordlist = this.wordlist
|
var wordlist = this.wordlist
|
||||||
|
var belongToList = words.every(function(word) {
|
||||||
var belongToList = mnemonic.every(function(word) {
|
|
||||||
return wordlist.indexOf(word) > -1
|
return wordlist.indexOf(word) > -1
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!belongToList) return false
|
if (!belongToList) return false
|
||||||
|
|
||||||
var bits = mnemonic.map(function(m) {
|
var bits = words.map(function(word) {
|
||||||
var id = wordlist.indexOf(m)
|
var id = wordlist.indexOf(word)
|
||||||
return lpad(id.toString(2), '0', 11)
|
return lpad(id.toString(2), '0', 11)
|
||||||
}).join('')
|
}).join('')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user