Feat: implement per operator settings cache
Fix: fix linter-found issues Chore: move findOperatorId to own middleware file Chore: delete old routes.js file and rename new-routes.js to routes.js Fix: PR fixes
This commit is contained in:
parent
85235eaa13
commit
558317e9f3
30 changed files with 232 additions and 860 deletions
30
lib/middlewares/operatorId.js
Normal file
30
lib/middlewares/operatorId.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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')
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
function findOperatorId (req, res, next) {
|
||||
getMnemonic().then(mnemonic => {
|
||||
return computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic))
|
||||
}).then(id => {
|
||||
res.locals.operatorId = id
|
||||
}).catch(e => console.error('Error while computing operator id\n' + e))
|
||||
next()
|
||||
}
|
||||
|
||||
module.exports = findOperatorId
|
||||
Loading…
Add table
Add a link
Reference in a new issue