Change seed file with a bip39 mnemonic (#207)

* Change seed file with a bip39 mnemonic

* Create helper for bip39 mnemonic

* Prod mode on lamassu-update-to-mnemonic script

* Fix standard styling issues
This commit is contained in:
Rafael Taranto 2018-11-07 15:28:40 -02:00 committed by Josh Harvey
parent 809bf5a2a9
commit d97a33565f
10 changed files with 98 additions and 34 deletions

19
lib/mnemonic-helpers.js Normal file
View file

@ -0,0 +1,19 @@
const bip39 = require('bip39')
const os = require('os')
function fromSeed (seed) {
const words = bip39.entropyToMnemonic(seed).split(' ')
let mnemonic = ''
for (let i = 0; i < words.length; i += 6) {
mnemonic += words.slice(i, i + 6).join(' ') + os.EOL
}
return mnemonic
}
function toEntropyBuffer (mnemonic) {
const hex = bip39.mnemonicToEntropy(mnemonic.split('\n').join(' ').trim())
return Buffer.from(hex.trim(), 'hex')
}
module.exports = { toEntropyBuffer, fromSeed }