Skip to content

Commit

Permalink
entropyToMnemonic: enforce 128-256 size ENT
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed May 12, 2017
1 parent fd91de6 commit a0fb543
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,15 @@ function mnemonicToEntropy (mnemonic, wordlist) {
return entropyBuffer.toString('hex')
}

function entropyToMnemonic (entropy, wordlist) {
function entropyToMnemonic (entropyHex, wordlist) {
wordlist = wordlist || DEFAULT_WORDLIST
if (entropyHex.length < 256 ||
entropyHex.length > 512 ||
entropyHex.length % 8 !== 0) throw new Error('Invalid entropy')

var entropyBuffer = new Buffer(entropy, 'hex')

if (entropyBuffer.length === 0 || entropyBuffer.length > 1024 || entropyBuffer.length % 4 !== 0) {
throw new Error('Invalid entropy')
}

var entropyBits = bytesToBinary([].slice.call(entropyBuffer))
var checksum = checksumBits(entropyBuffer)
var entropy = new Buffer(entropyHex, 'hex')
var entropyBits = bytesToBinary([].slice.call(entropy))
var checksum = checksumBits(entropy)

var bits = entropyBits + checksum
var chunks = bits.match(/(.{1,11})/g)
Expand Down

0 comments on commit a0fb543

Please sign in to comment.