From a55496b3ecbba8d6e46ccb442b93d1824989cd15 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Wed, 21 Nov 2018 18:41:15 +0700 Subject: [PATCH] Throw error on invalid bit value --- src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.js b/src/index.js index b0fd9bb..3f9af56 100644 --- a/src/index.js +++ b/src/index.js @@ -20,6 +20,10 @@ const binaryToBytes = binaryString => Buffer.from( const randomNumberBetween = (min, max) => Math.floor(parseInt(randomBytes(1).toString('hex'), 16) / 256 * (max - min + 1) + min); const dogeSeed = (bits = 128) => { + if (bits <= 0 || bits % 8 !== 0) { + throw TypeError('bits must be divisible by 8'); + } + const entropy = randomBytes(bits / 8); const words = bytesToBinary(entropy).match(/.{1,11}/g);