Browse Source

Manually create entropy for better performance

Way faster than brute forcing randomly generated seeds
pull/2/head
Luke Childs 6 years ago
parent
commit
3e80f2da23
  1. 3
      package.json
  2. 45
      src/index.js
  3. 2
      yarn.lock

3
package.json

@ -5,6 +5,7 @@
"author": "Luke Childs <lukechilds123@gmail.com>",
"license": "MIT",
"dependencies": {
"bip39": "^2.5.0"
"bip39": "^2.5.0",
"randombytes": "^2.0.6"
}
}

45
src/index.js

@ -1,13 +1,42 @@
const randomBytes = require('randombytes');
const bip39 = require('bip39');
const dogeSeed = (entropy = 128) => {
const dogeModifiers = ["so", "such", "many", "much", "very"];
while (true) {
const mnemonic = bip39.generateMnemonic(entropy).split(' ');
if(dogeModifiers.includes(mnemonic[0]) && dogeModifiers.includes(mnemonic[2]) && mnemonic[0] !== mnemonic[2]) {
return mnemonic.join(' ');
}
}
const MUCH = '10010001000';
const SUCH = '11011000011';
const VERY = '11110010111';
const bytesToBinary = buffer => buffer
.toString('hex')
.match(/.{2}/g)
.map(byte => parseInt(byte, 16).toString(2).padStart(8, '0'))
.join('');
const binaryToBytes = binaryString => Buffer.from(
binaryString
.match(/(.{1,8})/g)
.map(binary => parseInt(binary, 2))
);
const randomNumberBetween = (min, max) => Math.floor(parseInt(randomBytes(1).toString('hex'), 16) / 256 * (max - min + 1) + min);
const dogeSeed = (strength = 128) => {
const entropy = randomBytes(strength / 8);
const words = bytesToBinary(entropy).match(/.{1,11}/g);
const dogeModifiers = [
MUCH,
SUCH,
VERY
];
const index = randomNumberBetween(0, dogeModifiers.length - 1);
words[0] = dogeModifiers[index];
dogeModifiers.splice(index, 1);
words[2] = dogeModifiers[randomNumberBetween(0, dogeModifiers.length - 1)];
const dogefiedEntropy = binaryToBytes(words.join(''));
return bip39.entropyToMnemonic(dogefiedEntropy);
};
module.exports = dogeSeed;

2
yarn.lock

@ -77,7 +77,7 @@ pbkdf2@^3.0.9:
safe-buffer "^5.0.1"
sha.js "^2.4.8"
randombytes@^2.0.1:
randombytes@^2.0.1, randombytes@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.0.6.tgz#d302c522948588848a8d300c932b44c24231da80"
integrity sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==

Loading…
Cancel
Save