From 57c029a8214c49fd2637ea0dd05e0d6849c526b0 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Mon, 22 Oct 2018 16:29:24 -0300 Subject: [PATCH 01/11] Change size of operatorId (#190) Server was expecting 32 characters and the code was generating 64. --- lib/coinatmradar/coinatmradar.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/coinatmradar/coinatmradar.js b/lib/coinatmradar/coinatmradar.js index 7474ae7f..fa023029 100644 --- a/lib/coinatmradar/coinatmradar.js +++ b/lib/coinatmradar/coinatmradar.js @@ -16,21 +16,19 @@ const MAX_CONTENT_LENGTH = 2000 // How long a machine can be down before it's considered offline const STALE_INTERVAL = '2 minutes' -module.exports = {update, mapRecord} +module.exports = { update, mapRecord } function mapCoin (info, deviceId, cryptoCode) { const config = info.config - const rates = info.rates[cryptoCode] || {cashIn: null, cashOut: null} + const rates = info.rates[cryptoCode] || { cashIn: null, cashOut: null } const cryptoConfig = configManager.scoped(cryptoCode, deviceId, config) const unscoped = configManager.unscoped(config) const showRates = unscoped.coinAtmRadarShowRates const cashInFee = showRates ? cryptoConfig.cashInCommission / 100 : null const cashOutFee = showRates ? cryptoConfig.cashOutCommission / 100 : null - const cashInRate = showRates ? _.invoke('cashIn.toNumber', rates) : null + const cashInRate = showRates ? _.invoke('cashIn.toNumber', rates) : null const cashOutRate = showRates ? _.invoke('cashOut.toNumber', rates) : null - - return { cryptoCode, @@ -155,5 +153,5 @@ function update (info) { } function computeOperatorId (masterSeed) { - return hkdf(masterSeed, 32, {salt: 'lamassu-server-salt', info: 'operator-id'}).toString('hex') + return hkdf(masterSeed, 16, { salt: 'lamassu-server-salt', info: 'operator-id' }).toString('hex') } From a35cb5c78d7e44c2ca636a08299f7e22c013cbb7 Mon Sep 17 00:00:00 2001 From: Fabio Cigliano Date: Tue, 23 Oct 2018 20:02:17 +1300 Subject: [PATCH 02/11] Renamed staging branch to release (#192) --- bin/lamassu-update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/lamassu-update b/bin/lamassu-update index 69cd396e..2e1fd6c2 100755 --- a/bin/lamassu-update +++ b/bin/lamassu-update @@ -44,8 +44,8 @@ n lts >> ${LOG_FILE} 2>&1 decho "version installed $(node -v)" export NPM_BIN=$(npm -g bin) -decho "updating lamassu-server" -npm -g install lamassu/lamassu-server#master --unsafe-perm >> ${LOG_FILE} 2>&1 +decho "updating lamassu-server#release" +npm -g install lamassu/lamassu-server#release --unsafe-perm >> ${LOG_FILE} 2>&1 decho "rebuilding npm deps" cd $(npm root -g)/lamassu-server/ >> ${LOG_FILE} 2>&1 From bd75194526e18c68785d7b4934fa2a93e4d27f72 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 1 Nov 2018 18:07:47 -0300 Subject: [PATCH 03/11] Fix exception on clock skew (#202) * Fix exception on clock skew * Return device name instead of db object --- lib/pairing.js | 9 +-------- lib/routes.js | 6 +++--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/pairing.js b/lib/pairing.js index bc2d4ccc..6fc8599d 100644 --- a/lib/pairing.js +++ b/lib/pairing.js @@ -74,14 +74,7 @@ function isPaired (deviceId) { const sql = 'select device_id, name from devices where device_id=$1 and paired=TRUE' return db.oneOrNone(sql, [deviceId]) - .then(row => { - const deviceName = row.name - const isDevicePaired = row && row.device_id === deviceId - return { - deviceName: deviceName, - isDevicePaired: isDevicePaired - } - }) + .then(row => row && row.device_id === deviceId ? row.name : false) } module.exports = {pair, unpair, authorizeCaDownload, isPaired} diff --git a/lib/routes.js b/lib/routes.js index 10c7af87..8deafe3f 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -311,10 +311,10 @@ function authorize (req, res, next) { const deviceId = req.deviceId return pairing.isPaired(deviceId) - .then(r => { - if (r.isDevicePaired) { + .then(deviceName => { + if (deviceName) { req.deviceId = deviceId - req.deviceName = r.deviceName + req.deviceName = deviceName return next() } From 65e2bf6a631bfb77f4faa4c701f47f7b0a815ae4 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Fri, 2 Nov 2018 16:29:55 -0300 Subject: [PATCH 04/11] Change HKDF return type from string to arrayBuffer (#204) --- lib/wallet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wallet.js b/lib/wallet.js index 879373c2..28649361 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -24,7 +24,7 @@ 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'}) } function fetchWallet (settings, cryptoCode) { From cc68e70f58f0561c28348774230862cfa2eebc55 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Mon, 5 Nov 2018 10:55:03 -0200 Subject: [PATCH 05/11] Sidebar fix for firefox (#205) --- public/styles.css | 1 + 1 file changed, 1 insertion(+) diff --git a/public/styles.css b/public/styles.css index 290cc50e..376ae9d2 100644 --- a/public/styles.css +++ b/public/styles.css @@ -21,6 +21,7 @@ p { .lamassuAdminMain { display: flex; + height: 100%; margin-bottom: 40px; } From 0ec647f2b21c2795b9e11245a4a466d217fb1faa Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Tue, 20 Nov 2018 21:14:54 -0200 Subject: [PATCH 06/11] Pin node version to 8 --- bin/lamassu-update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/lamassu-update b/bin/lamassu-update index 2e1fd6c2..9b770460 100755 --- a/bin/lamassu-update +++ b/bin/lamassu-update @@ -40,7 +40,7 @@ fi decho "updating node" npm install n -g >> ${LOG_FILE} 2>&1 -n lts >> ${LOG_FILE} 2>&1 +n 8 >> ${LOG_FILE} 2>&1 decho "version installed $(node -v)" export NPM_BIN=$(npm -g bin) From dc1ed523572ff21a873aca45ee4f72c33272c45a Mon Sep 17 00:00:00 2001 From: Fabio Cigliano Date: Fri, 23 Nov 2018 05:04:41 +1300 Subject: [PATCH 07/11] lamassu-migrate-config to update ls basepath (#216) * lamassu-migrate-config to update ls basepath * documentation added * constrain to a particular set of options --- lib/migrate-options.js | 53 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/migrate-options.js b/lib/migrate-options.js index 82374cea..043cfe58 100644 --- a/lib/migrate-options.js +++ b/lib/migrate-options.js @@ -1,9 +1,18 @@ const _ = require('lodash/fp') const fs = require('fs') const makeDir = require('make-dir') +const path = require('path') const load = require('./options-loader') +// current path of lamassu-server project +const currentBasePath = path.dirname(__dirname) +// get path as array of path components +const paths = _.wrap(_.split, path.sep) +// find the index of the lamassu-server directory +// /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => 3 +const indexOfLs = _.flow(paths, _.wrap(_.indexOf, 'lamassu-server')) + module.exports = {run, mapKeyValuesDeep} function mapKeyValuesDeep (cb, obj, key) { @@ -26,6 +35,36 @@ async function run () { // check if there are new options to add let result = _.mergeAll([defaultOpts, currentOpts]) + + // get all the options + // that ends with "Path" suffix + console.log(`Detected lamassu-server basepath: ${currentBasePath}`) + _.map(optionName => { + const currentPath = _.get(optionName, result) + + // process only keys that contains + // lamassu-server dir in its path + const i = indexOfLs(currentPath) + if (i === -1) { + return + } + + // workout the relative path + // /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => certs/Lamassu_OP.pem + const rPath = _.drop(i + 1, paths(currentPath)) + + // prepend the current lamassu-server path + // certs/Lamassu_OP.pem => /usr/local/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem + const newPath = _.join(path.sep, _.concat([currentBasePath], rPath)) + + // update this option + // if the value has changed + if (!_.isEqual(currentPath, newPath)) { + console.log(`Migrating option ${optionName} to new path ${newPath}`) + result[optionName] = newPath + } + }, ['seedPath', 'caPath', 'certPath', 'keyPath', 'lamassuCaPath']) + const shouldMigrate = !_.isEqual(result, currentOpts) || _.has('lamassuServerPath', result) // write the resulting lamassu.json @@ -33,8 +72,18 @@ async function run () { // remove old lamassuServerPath config result = _.omit('lamassuServerPath', result) - const newOpts = _.pick(_.difference(_.keys(result), _.keys(currentOpts)), result) - console.log('Adding options', newOpts) + // find keys for which values + // have been changed + const differentValue = _.wrap(_.filter, key => !_.isEqual(result[key], currentOpts[key])) + + // output affected options + const newOpts = _.pick(_.union( + // find change keys + differentValue(_.keys(result)), + // find new opts + _.difference(_.keys(result), _.keys(currentOpts)) + ), result) + console.log('Updating options', newOpts) // store new lamassu.json file fs.writeFileSync(options.path, JSON.stringify(result, null, ' ')) From cdfc84a96a08cb6617e941a51e890914a3960c0b Mon Sep 17 00:00:00 2001 From: Fabio Cigliano Date: Fri, 23 Nov 2018 11:16:00 +1300 Subject: [PATCH 08/11] migrate-options unit test added --- lib/migrate-options.js | 61 +++++++++++++++++++++--------------- test/unit/migrate-options.js | 31 +++++++++++++++++- 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/lib/migrate-options.js b/lib/migrate-options.js index 043cfe58..994be05b 100644 --- a/lib/migrate-options.js +++ b/lib/migrate-options.js @@ -13,7 +13,7 @@ const paths = _.wrap(_.split, path.sep) // /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => 3 const indexOfLs = _.flow(paths, _.wrap(_.indexOf, 'lamassu-server')) -module.exports = {run, mapKeyValuesDeep} +module.exports = {run, mapKeyValuesDeep, updateOptionBasepath} function mapKeyValuesDeep (cb, obj, key) { if (_.isArray(obj)) { @@ -25,6 +25,32 @@ function mapKeyValuesDeep (cb, obj, key) { } } +function updateOptionBasepath (result, optionName) { + const currentPath = _.get(optionName, result) + + // process only keys that contains + // lamassu-server dir in its path + const i = indexOfLs(currentPath) + if (i === -1) { + return + } + + // workout the relative path + // /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => certs/Lamassu_OP.pem + const rPath = _.drop(i + 1, paths(currentPath)) + + // prepend the current lamassu-server path + // certs/Lamassu_OP.pem => /usr/local/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem + const newPath = _.join(path.sep, _.concat([currentBasePath], rPath)) + + // update this option + // if the value has changed + if (!_.isEqual(currentPath, newPath)) { + console.log(`Migrating option ${optionName} to new path ${newPath}`) + result[optionName] = newPath + } +} + async function run () { // load defaults const defaultOpts = require('../lamassu-default') @@ -39,31 +65,14 @@ async function run () { // get all the options // that ends with "Path" suffix console.log(`Detected lamassu-server basepath: ${currentBasePath}`) - _.map(optionName => { - const currentPath = _.get(optionName, result) - - // process only keys that contains - // lamassu-server dir in its path - const i = indexOfLs(currentPath) - if (i === -1) { - return - } - - // workout the relative path - // /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => certs/Lamassu_OP.pem - const rPath = _.drop(i + 1, paths(currentPath)) - - // prepend the current lamassu-server path - // certs/Lamassu_OP.pem => /usr/local/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem - const newPath = _.join(path.sep, _.concat([currentBasePath], rPath)) - - // update this option - // if the value has changed - if (!_.isEqual(currentPath, newPath)) { - console.log(`Migrating option ${optionName} to new path ${newPath}`) - result[optionName] = newPath - } - }, ['seedPath', 'caPath', 'certPath', 'keyPath', 'lamassuCaPath']) + _.each(_.wrap(updateOptionBasepath, result), + [ + 'seedPath', + 'caPath', + 'certPath', + 'keyPath', + 'lamassuCaPath' + ]) const shouldMigrate = !_.isEqual(result, currentOpts) || _.has('lamassuServerPath', result) diff --git a/test/unit/migrate-options.js b/test/unit/migrate-options.js index 396da464..10ae126e 100644 --- a/test/unit/migrate-options.js +++ b/test/unit/migrate-options.js @@ -1,7 +1,10 @@ import test from 'ava' import _ from 'lodash/fp' +import path from 'path' -import {mapKeyValuesDeep} from '../../lib/migrate-options' +import {mapKeyValuesDeep, updateOptionBasepath} from '../../lib/migrate-options' + +const currentBasePath = path.dirname(path.dirname(__dirname)) test('mapKeyValuesDeep', t => { const test = { @@ -33,3 +36,29 @@ test('mapKeyValuesDeep', t => { t.deepEqual(result, expected) }) + +test('updateOptionBasepath', t => { + const test = { + someBooleanOption: true, + someStringOption: 'my-custom-option', + customExternalPath: '/usr/lib/node_modules/ava', + seedPath: '/etc/lamassu/seeds/seed.txt', + caPath: '/usr/lib/node_modules/lamassu-server/certs/Lamassu_OP_Root_CA.pem' + } + const expected = { + someBooleanOption: true, + someStringOption: 'my-custom-option', + customExternalPath: '/usr/lib/node_modules/ava', + seedPath: '/etc/lamassu/seeds/seed.txt', + caPath: path.join(currentBasePath, 'certs/Lamassu_OP_Root_CA.pem') + } + + let result = _.clone(test) + + _.each( + _.wrap(updateOptionBasepath, result), + _.keys(test) + ) + + t.deepEqual(result, expected) +}) From d253c4fa006a89092d01c3a67ed6b92e4953e859 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Mon, 3 Dec 2018 13:10:05 -0200 Subject: [PATCH 09/11] Dev script to recreate seeds file from mnemonic --- dev/recreate-seeds.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 dev/recreate-seeds.js diff --git a/dev/recreate-seeds.js b/dev/recreate-seeds.js new file mode 100644 index 00000000..7ed801c6 --- /dev/null +++ b/dev/recreate-seeds.js @@ -0,0 +1,26 @@ +#!/usr/bin/env node + +'use strict' + +const fs = require('fs') +const path = require('path') +const os = require('os') +const bip39 = require('bip39') +const options = require('../lib/options-loader')() + +if (options.opts.mnemonicPath && !options.opts.seedPath) { + const mnemonic = fs.readFileSync(options.opts.mnemonicPath, 'utf8') + const seed = bip39.mnemonicToEntropy(mnemonic.split('\n').join(' ').trim()).toString('hex') + + options.opts.seedPath = path.resolve(os.homedir(), '.lamassu', 'seeds', 'seed.txt') + + if (!fs.existsSync(path.dirname(options.opts.seedPath))) { + fs.mkdirSync(path.dirname(options.opts.seedPath)) + } + + if (!fs.existsSync(options.opts.seedPath)) { + fs.writeFileSync(options.opts.seedPath, seed, 'utf8') + } + + fs.writeFileSync(options.path, JSON.stringify(options.opts, null, '\t'), 'utf8') +} From 16a4239b862fa2c6a96b240a226163b69fc03ea1 Mon Sep 17 00:00:00 2001 From: Neal Conner Date: Sun, 9 Dec 2018 14:00:35 -0500 Subject: [PATCH 10/11] Update ZEC, BCH, ETH node versions --- lib/blockchain/common.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/blockchain/common.js b/lib/blockchain/common.js index bde996f6..fce05ef7 100644 --- a/lib/blockchain/common.js +++ b/lib/blockchain/common.js @@ -25,12 +25,12 @@ const BINARIES = { dir: 'bitcoin-0.16.3/bin' }, ETH: { - url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.8.15-89451f7c.tar.gz', - dir: 'geth-linux-amd64-1.8.15-89451f7c' + url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.8.19-dae82f09.tar.gz', + dir: 'geth-linux-amd64-1.8.19-dae82f09' }, ZEC: { - url: 'https://z.cash/downloads/zcash-2.0.0-linux64.tar.gz', - dir: 'zcash-2.0.0/bin' + url: 'https://z.cash/downloads/zcash-2.0.2-linux64.tar.gz', + dir: 'zcash-2.0.2/bin' }, DASH: { url: 'https://github.com/dashpay/dash/releases/download/v0.12.3.3/dashcore-0.12.3.3-x86_64-linux-gnu.tar.gz', @@ -41,8 +41,8 @@ const BINARIES = { dir: 'litecoin-0.16.3/bin' }, BCH: { - url: 'https://download.bitcoinabc.org/0.18.2/linux/bitcoin-abc-0.18.2-x86_64-linux-gnu.tar.gz', - dir: 'bitcoin-abc-0.18.2/bin', + url: 'https://download.bitcoinabc.org/0.18.5/linux/bitcoin-abc-0.18.5-x86_64-linux-gnu.tar.gz', + dir: 'bitcoin-abc-0.18.5/bin', files: [['bitcoind', 'bitcoincashd'], ['bitcoin-cli', 'bitcoincash-cli']] } } From b9f9c6faccf1a3f64d28467ff63eb511250f5a63 Mon Sep 17 00:00:00 2001 From: Neal Conner Date: Sun, 9 Dec 2018 15:01:49 -0500 Subject: [PATCH 11/11] Caution against mock-ticker use --- lib/admin/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/admin/config.js b/lib/admin/config.js index bb50b1f5..8cd222a9 100644 --- a/lib/admin/config.js +++ b/lib/admin/config.js @@ -173,7 +173,7 @@ function fetchData () { {code: 'bitstamp', display: 'Bitstamp', class: 'ticker', cryptos: ['BTC', 'ETH', 'LTC', 'BCH']}, {code: 'coinbase', display: 'Coinbase', class: 'ticker', cryptos: ['BTC', 'ETH', 'LTC', 'BCH']}, {code: 'quadrigacx', display: 'QuadrigaCX', class: 'ticker', cryptos: ['BTC', 'ETH', 'LTC', 'BCH']}, - {code: 'mock-ticker', display: 'Mock ticker', class: 'ticker', cryptos: ALL_CRYPTOS}, + {code: 'mock-ticker', display: 'Mock (Caution!)', class: 'ticker', cryptos: ALL_CRYPTOS}, {code: 'bitcoind', display: 'bitcoind', class: 'wallet', cryptos: ['BTC']}, {code: 'no-layer2', display: 'No Layer 2', class: 'layer2', cryptos: ALL_CRYPTOS}, {code: 'infura', display: 'Infura', class: 'wallet', cryptos: ['ETH']},