feat: create db table and store operator id
This commit is contained in:
parent
86e9204a28
commit
9b28c6a3f1
4 changed files with 77 additions and 38 deletions
|
|
@ -1,34 +1,15 @@
|
|||
const pify = require('pify')
|
||||
const fs = pify(require('fs'))
|
||||
const hkdf = require('futoin-hkdf')
|
||||
|
||||
const state = require('./state')
|
||||
const mnemonicHelpers = require('../mnemonic-helpers')
|
||||
const options = require('../options')
|
||||
const logger = require('../logger')
|
||||
|
||||
function computeOperatorId (masterSeed) {
|
||||
return hkdf(masterSeed, 16, { salt: 'lamassu-server-salt', info: 'operator-id' }).toString('hex')
|
||||
}
|
||||
|
||||
function getMnemonic () {
|
||||
if (state.mnemonic) return Promise.resolve(state.mnemonic)
|
||||
return fs.readFile(options.mnemonicPath, 'utf8').then(mnemonic => {
|
||||
state.mnemonic = mnemonic
|
||||
return mnemonic
|
||||
})
|
||||
}
|
||||
const { getOperatorId } = require('../operator')
|
||||
|
||||
function findOperatorId (req, res, next) {
|
||||
return getMnemonic().then(mnemonic => {
|
||||
return computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic))
|
||||
}).then(id => {
|
||||
res.locals.operatorId = id
|
||||
return next()
|
||||
}).catch(e => {
|
||||
logger.error('Error while computing operator id\n' + e)
|
||||
next(e)
|
||||
})
|
||||
return getOperatorId()
|
||||
.then(({ id }) => {
|
||||
res.locals.operatorId = id
|
||||
return next()
|
||||
})
|
||||
.catch(e => {
|
||||
console.error('Error while computing operator id\n' + e)
|
||||
next(e)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = findOperatorId
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue