3 changed files with 40 additions and 10 deletions
@ -1,13 +1,42 @@ |
|||||
|
const randomBytes = require('randombytes'); |
||||
const bip39 = require('bip39'); |
const bip39 = require('bip39'); |
||||
|
|
||||
const dogeSeed = (entropy = 128) => { |
const MUCH = '10010001000'; |
||||
const dogeModifiers = ["so", "such", "many", "much", "very"]; |
const SUCH = '11011000011'; |
||||
while (true) { |
const VERY = '11110010111'; |
||||
const mnemonic = bip39.generateMnemonic(entropy).split(' '); |
|
||||
if(dogeModifiers.includes(mnemonic[0]) && dogeModifiers.includes(mnemonic[2]) && mnemonic[0] !== mnemonic[2]) { |
const bytesToBinary = buffer => buffer |
||||
return mnemonic.join(' '); |
.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; |
module.exports = dogeSeed; |
||||
|
Loading…
Reference in new issue