Skip to content

Commit

Permalink
TypeErrors for entropy length
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed May 12, 2017
1 parent 3854893 commit 126d32d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function mnemonicToEntropy (mnemonic, wordlist) {

// calculate the checksum and compare
var entropyBytes = entropy.match(/(.{1,8})/g).map(binaryToByte)
if (entropy.length % 4 !== 0) throw new TypeError(INVALID_ENTROPY)
if (entropy.length % 4 !== 0) throw new Error(INVALID_ENTROPY)
var entropyBuffer = new Buffer(entropyBytes)

var newChecksum = checksumBits(entropyBuffer)
Expand All @@ -72,11 +72,11 @@ function entropyToMnemonic (entropyHex, wordlist) {
wordlist = wordlist || DEFAULT_WORDLIST

// 128 <= ENT <= 256
if (entropyHex.length < 32) throw new Error(INVALID_ENTROPY)
if (entropyHex.length > 64) throw new Error(INVALID_ENTROPY)
if (entropyHex.length < 32) throw new TypeError(INVALID_ENTROPY)
if (entropyHex.length > 64) throw new TypeError(INVALID_ENTROPY)

// multiple of 4
if (entropyHex.length % 8 !== 0) throw new Error(INVALID_ENTROPY)
if (entropyHex.length % 8 !== 0) throw new TypeError(INVALID_ENTROPY)

var entropy = new Buffer(entropyHex, 'hex')
var entropyBits = bytesToBinary([].slice.call(entropy))
Expand Down

0 comments on commit 126d32d

Please sign in to comment.