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

View file

@ -6,6 +6,7 @@ const configManager = require('./config-manager')
const pify = require('pify')
const fs = pify(require('fs'))
const mnemonicHelpers = require('./mnemonic-helpers')
const options = require('./options')
const ph = require('./plugin-helper')
const layer2 = require('./layer2')
@ -24,20 +25,20 @@ function httpError (msg, code) {
}
function computeSeed (masterSeed) {
return hkdf(masterSeed, 32, {salt: 'lamassu-server-salt', info: 'wallet-seed'}).toString('hex')
return hkdf(masterSeed, 32, { salt: 'lamassu-server-salt', info: 'wallet-seed' }).toString('hex')
}
function fetchWallet (settings, cryptoCode) {
return fs.readFile(options.seedPath, 'utf8')
.then(hex => {
const masterSeed = Buffer.from(hex.trim(), 'hex')
return fs.readFile(options.mnemonicPath, 'utf8')
.then(mnemonic => {
const masterSeed = mnemonicHelpers.toEntropyBuffer(mnemonic)
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).wallet
const wallet = ph.load(ph.WALLET, plugin)
const rawAccount = settings.accounts[plugin]
const account = _.set('seed', computeSeed(masterSeed), rawAccount)
if (_.isFunction(wallet.run)) wallet.run(account)
return {wallet, account}
return { wallet, account }
})
}
@ -46,7 +47,7 @@ const lastBalance = {}
function _balance (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.balance(r.account, cryptoCode))
.then(balance => ({balance, timestamp: Date.now()}))
.then(balance => ({ balance, timestamp: Date.now() }))
.then(r => {
lastBalance[cryptoCode] = r
return r
@ -103,7 +104,7 @@ function mergeStatus (a, b) {
if (!a) return b
if (!b) return a
return {status: mergeStatusMode(a.status, b.status)}
return { status: mergeStatusMode(a.status, b.status) }
}
function mergeStatusMode (a, b) {
@ -169,7 +170,7 @@ function getStatus (settings, tx, machineId) {
const status = isAuthorized ? 'authorized' : unauthorizedStatus
return {status}
return { status }
})
}