diff --git a/bin/hkdf b/bin/hkdf index b5c33284..eb700684 100755 --- a/bin/hkdf +++ b/bin/hkdf @@ -2,7 +2,7 @@ 'use strict' -const HKDF = require('node-hkdf-sync') +const hkdf = require('futoin-hkdf') const label = process.argv[2] const masterSeedHex = process.argv[3].trim() @@ -14,5 +14,4 @@ if (process.argv.length !== 4) { } const masterSeed = new Buffer(masterSeedHex, 'hex') -const hkdf = new HKDF('sha256', 'lamassu-server-salt', masterSeed) -console.log(hkdf.derive(label, 32).toString('hex')) +console.log(hkdf(masterSeed, 32, {salt: 'lamassu-server-salt', info: label}).toString('hex')) diff --git a/lib/coinatmradar/coinatmradar.js b/lib/coinatmradar/coinatmradar.js index 19e72850..1fac60e4 100644 --- a/lib/coinatmradar/coinatmradar.js +++ b/lib/coinatmradar/coinatmradar.js @@ -1,5 +1,9 @@ const axios = require('axios') const _ = require('lodash/fp') +const hkdf = require('futoin-hkdf') + +const pify = require('pify') +const fs = pify(require('fs')) const db = require('../db') const configManager = require('../config-manager') @@ -125,9 +129,9 @@ function sendRadar (data) { function mapRecord (info) { const timestamp = new Date().toISOString() - return getMachines(info) - .then(machines => ({ - operatorId: options.operatorId, + return Promise.all([getMachines(info), fs.readFile(options.seedPath, 'utf8')]) + .then(([machines, hex]) => ({ + operatorId: computeOperatorId(Buffer.from(hex.trim(), 'hex')), operator: { name: null, phone: null, @@ -147,3 +151,7 @@ function update (info) { .then(sendRadar) .catch(err => logger.error(err)) } + +function computeOperatorId (masterSeed) { + return hkdf(masterSeed, 32, {salt: 'lamassu-server-salt', info: 'operator-id'}).toString('hex') +} diff --git a/lib/wallet.js b/lib/wallet.js index dbd04fbc..879373c2 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -1,6 +1,6 @@ const _ = require('lodash/fp') const mem = require('mem') -const HKDF = require('node-hkdf-sync') +const hkdf = require('futoin-hkdf') const configManager = require('./config-manager') const pify = require('pify') @@ -24,8 +24,7 @@ function httpError (msg, code) { } function computeSeed (masterSeed) { - const hkdf = new HKDF('sha256', 'lamassu-server-salt', masterSeed) - return hkdf.derive('wallet-seed', 32) + return hkdf(masterSeed, 32, {salt: 'lamassu-server-salt', info: 'wallet-seed'}).toString('hex') } function fetchWallet (settings, cryptoCode) { diff --git a/package.json b/package.json index ce94feca..dbda0f18 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "express-limiter": "^1.6.0", "express-rate-limit": "^2.9.0", "express-ws": "^3.0.0", + "futoin-hkdf": "^1.0.2", "got": "^7.1.0", "helmet": "^3.8.1", "inquirer": "^5.2.0", @@ -42,7 +43,6 @@ "morgan": "^1.8.2", "nano-markdown": "^1.2.0", "ndjson": "^1.5.0", - "node-hkdf-sync": "^1.0.0", "numeral": "^2.0.3", "p-each-series": "^1.0.0", "pg-native": "^2.2.0",