From 3854893382777f935ab02c879b7c6adf5bcc7727 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Fri, 12 May 2017 12:54:40 +1000 Subject: [PATCH] remove double iteration of words --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 14dbc5c..661c3ec 100644 --- a/index.js +++ b/index.js @@ -40,13 +40,12 @@ function mnemonicToEntropy (mnemonic, wordlist) { var words = unorm.nfkd(mnemonic).split(' ') if (words.length % 3 !== 0) throw new Error(INVALID_MNEMONIC) - if (words.some(function (word) { - return wordlist.indexOf(word) === -1 - })) throw new Error(INVALID_MNEMONIC) // convert word indices to 11 bit binary strings var bits = words.map(function (word) { var index = wordlist.indexOf(word) + if (index === -1) throw new Error(INVALID_MNEMONIC) + return lpad(index.toString(2), '0', 11) }).join('')