Merge pull request #1604 from RafaelTaranto/fix/ln-and-deprecate-some-libs

Fix/ln and deprecate some libs
This commit is contained in:
Rafael Taranto 2023-10-05 23:06:49 +01:00 committed by GitHub
commit 0daa17a1cd
12 changed files with 4296 additions and 11628 deletions

View file

@ -1,5 +0,0 @@
#!/usr/bin/env node
const adminServer = require('../lib/admin/admin-server')
adminServer.run()

View file

@ -1,32 +0,0 @@
#!/usr/bin/env node
require('../lib/environment-helper')
const login = require('../lib/admin/login')
const name = process.argv[2]
const domain = process.env.HOSTNAME
if (!domain) {
console.error('No hostname configured in the environment')
process.exit(1)
}
if (!name) {
console.log('Usage: lamassu-register <username>')
process.exit(2)
}
login.generateOTP(name)
.then(otp => {
if (domain === 'localhost') {
console.log(`https://${domain}:8070?otp=${otp}`)
} else {
console.log(`https://${domain}?otp=${otp}`)
}
process.exit(0)
})
.catch(err => {
console.log('Error: %s', err)
process.exit(3)
})

View file

@ -11,9 +11,9 @@ const argv = require('minimist')(process.argv.slice(2))
const got = require('got') const got = require('got')
const morgan = require('morgan') const morgan = require('morgan')
const helmet = require('helmet') const helmet = require('helmet')
const WebSocket = require('ws') // const WebSocket = require('ws')
const http = require('http') const http = require('http')
const SocketIo = require('socket.io') // const SocketIo = require('socket.io')
const makeDir = require('make-dir') const makeDir = require('make-dir')
const _ = require('lodash/fp') const _ = require('lodash/fp')

View file

@ -3,7 +3,6 @@ const pgp = require('pg-promise')()
const db = require('../db') const db = require('../db')
const E = require('../error') const E = require('../error')
const socket = require('../socket-client')
const logger = require('../logger') const logger = require('../logger')
const helper = require('./cash-out-helper') const helper = require('./cash-out-helper')
@ -83,7 +82,7 @@ function preProcess (t, oldTx, newTx, pi) {
if (hasError || hasDispenseOccurred) { if (hasError || hasDispenseOccurred) {
return cashOutActions.logDispense(t, updatedTx) return cashOutActions.logDispense(t, updatedTx)
.then(updateCassettes(t, updatedTx)) .then(it => updateCassettes(t, updatedTx).then(() => it) )
.then((t) => { .then((t) => {
pi.notifyOperator(updatedTx, { isRedemption: true }) pi.notifyOperator(updatedTx, { isRedemption: true })
.catch((err) => logger.error('Failure sending transaction notification', err)) .catch((err) => logger.error('Failure sending transaction notification', err))
@ -134,7 +133,6 @@ function updateCassettes (t, tx) {
values.push(tx.deviceId) values.push(tx.deviceId)
return t.one(sql, values) return t.one(sql, values)
.then(r => socket.emit(_.assign(r, {op: 'cassetteUpdate', deviceId: tx.deviceId})))
} }
function wasJustAuthorized (oldTx, newTx, isZeroConf) { function wasJustAuthorized (oldTx, newTx, isZeroConf) {

View file

@ -57,7 +57,7 @@ const reflect = p => p.then(value => ({ value, status: 'fulfilled' }), error =>
function getFunding () { function getFunding () {
return settingsLoader.loadLatest().then(settings => { return settingsLoader.loadLatest().then(settings => {
const cryptoCodes = _.filter(code => coinUtils.getExternalCryptoCode(code) === code, configManager.getAllCryptoCurrencies(settings.config)) const cryptoCodes = configManager.getAllCryptoCurrencies(settings.config)
const fiatCode = configManager.getGlobalLocale(settings.config).fiatCurrency const fiatCode = configManager.getGlobalLocale(settings.config).fiatCurrency
const pareCoins = c => _.includes(c.cryptoCode, cryptoCodes) const pareCoins = c => _.includes(c.cryptoCode, cryptoCodes)
const cryptoCurrencies = coinUtils.cryptoCurrencies() const cryptoCurrencies = coinUtils.cryptoCurrencies()

View file

@ -140,8 +140,9 @@ const buildTransactionMessage = (tx, rec, highValueTx, machineName, customer) =>
}, highValueTx] }, highValueTx]
} }
function formatCurrency (num, code) { function formatCurrency (num = 0, code) {
return numeral(num).format('0,0.00') + ' ' + code const formattedNumber = Number(num).toLocaleString(undefined, {maximumFractionDigits:2, minimumFractionDigits:2})
return `${formattedNumber} ${code}`
} }
function formatAge (age, settings) { function formatAge (age, settings) {

View file

@ -28,16 +28,15 @@ const ALL = {
} }
function buildMarket (fiatCode, cryptoCode, serviceName) { function buildMarket (fiatCode, cryptoCode, serviceName) {
const externalCryptoCode = coinUtils.getExternalCryptoCode(cryptoCode) if (!_.includes(cryptoCode, ALL[serviceName].CRYPTO)) {
if (!_.includes(externalCryptoCode, ALL[serviceName].CRYPTO)) { throw new Error('Unsupported crypto: ' + cryptoCode)
throw new Error('Unsupported crypto: ' + externalCryptoCode)
} }
const fiatSupported = ALL[serviceName].FIAT const fiatSupported = ALL[serviceName].FIAT
if (fiatSupported !== 'ALL_CURRENCIES' && !_.includes(fiatCode, fiatSupported)) { if (fiatSupported !== 'ALL_CURRENCIES' && !_.includes(fiatCode, fiatSupported)) {
logger.info('Building a market for an unsupported fiat. Defaulting to EUR market') logger.info('Building a market for an unsupported fiat. Defaulting to EUR market')
return cryptoCode + '/' + 'EUR' return cryptoCode + '/' + 'EUR'
} }
return externalCryptoCode + '/' + fiatCode return cryptoCode + '/' + fiatCode
} }
function verifyFiatSupport (fiatCode, serviceName) { function verifyFiatSupport (fiatCode, serviceName) {

View file

@ -1,6 +1,6 @@
const _ = require('lodash/fp') const _ = require('lodash/fp')
const BitGo = require('bitgo') const { BitGoAPI } = require('@bitgo/sdk-api')
const { toLegacyAddress, toCashAddress } = require('bchaddrjs') const { toLegacyAddress, toCashAddress } = require('bchaddrjs')
const BN = require('../../../bn') const BN = require('../../../bn')
@ -11,19 +11,29 @@ const pjson = require('../../../../package.json')
const userAgent = 'Lamassu-Server/' + pjson.version const userAgent = 'Lamassu-Server/' + pjson.version
const NAME = 'BitGo' const NAME = 'BitGo'
const SUPPORTED_COINS = ['BTC', 'ZEC', 'LTC', 'BCH', 'DASH']
const BITGO_MODULES = {
BCH: require('@bitgo/sdk-coin-bch'),
BTC: require('@bitgo/sdk-coin-btc'),
DASH: require('@bitgo/sdk-coin-dash'),
LTC: require('@bitgo/sdk-coin-ltc'),
ZEC: require('@bitgo/sdk-coin-zec'),
}
const SUPPORTED_COINS = _.keys(BITGO_MODULES)
const BCH_CODES = ['BCH', 'TBCH'] const BCH_CODES = ['BCH', 'TBCH']
function buildBitgo (account) { const getWallet = (account, cryptoCode) => {
const accessToken = account.token.trim()
const env = account.environment === 'test' ? 'test' : 'prod' const env = account.environment === 'test' ? 'test' : 'prod'
return new BitGo.BitGo({ accessToken: account.token.trim(), env, userAgent: userAgent }) const walletId = account[`${cryptoCode}WalletId`]
}
function getWallet (account, cryptoCode) { const bitgo = new BitGoAPI({ accessToken, env, userAgent })
const bitgo = buildBitgo(account) BITGO_MODULES[cryptoCode].register(bitgo)
const coin = account.environment === 'test' ? `t${cryptoCode.toLowerCase()}` : cryptoCode.toLowerCase()
return bitgo.coin(coin).wallets().get({ id: account[`${cryptoCode}WalletId`] }) cryptoCode = cryptoCode.toLowerCase()
const coin = env === 'test' ? `t${cryptoCode}` : cryptoCode
return bitgo.coin(coin).wallets().get({ id: walletId })
} }
function checkCryptoCode (cryptoCode) { function checkCryptoCode (cryptoCode) {

View file

@ -142,7 +142,7 @@ function sendFundsLN (walletId, invoice, token) {
function sendCoins (account, tx, settings, operatorId) { function sendCoins (account, tx, settings, operatorId) {
const { toAddress, cryptoAtoms, cryptoCode } = tx const { toAddress, cryptoAtoms, cryptoCode } = tx
const externalCryptoCode = coinUtils.getExternalCryptoCode(cryptoCode) const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => getGaloyAccount(account.apiKey)) .then(() => getGaloyAccount(account.apiKey))
.then(galoyAccount => { .then(galoyAccount => {
@ -215,7 +215,7 @@ function newInvoice (walletId, cryptoAtoms, token) {
} }
function balance (account, cryptoCode, settings, operatorId) { function balance (account, cryptoCode, settings, operatorId) {
const externalCryptoCode = coinUtils.getExternalCryptoCode(cryptoCode) const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => getGaloyAccount(account.apiKey)) .then(() => getGaloyAccount(account.apiKey))
.then(galoyAccount => { .then(galoyAccount => {
@ -232,7 +232,7 @@ function balance (account, cryptoCode, settings, operatorId) {
function newAddress (account, info, tx, settings, operatorId) { function newAddress (account, info, tx, settings, operatorId) {
const { cryptoAtoms, cryptoCode } = tx const { cryptoAtoms, cryptoCode } = tx
const externalCryptoCode = coinUtils.getExternalCryptoCode(cryptoCode) const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => getGaloyAccount(account.apiKey)) .then(() => getGaloyAccount(account.apiKey))
.then(galoyAccount => { .then(galoyAccount => {
@ -260,7 +260,7 @@ function getStatus (account, tx, requested, settings, operatorId) {
if (tx.node.status === TX_SUCCESS) return 'confirmed' if (tx.node.status === TX_SUCCESS) return 'confirmed'
return 'notSeen' return 'notSeen'
} }
const externalCryptoCode = coinUtils.getExternalCryptoCode(cryptoCode) const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
const address = coinUtils.parseUrl(toAddress) const address = coinUtils.parseUrl(toAddress)
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => getGaloyAccount(account.apiKey)) .then(() => getGaloyAccount(account.apiKey))
@ -283,7 +283,7 @@ function getStatus (account, tx, requested, settings, operatorId) {
} }
function newFunding (account, cryptoCode, settings, operatorId) { function newFunding (account, cryptoCode, settings, operatorId) {
const externalCryptoCode = coinUtils.getExternalCryptoCode(cryptoCode) const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
// Regular BTC address // Regular BTC address
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => getGaloyAccount(account.apiKey)) .then(() => getGaloyAccount(account.apiKey))

View file

@ -1,8 +1,8 @@
const { utils: coinUtils } = require('@lamassu/coins') const { utils: coinUtils } = require('@lamassu/coins')
const _ = require('lodash/fp') const _ = require('lodash/fp')
const mem = require('mem') const mem = require('mem')
const configManager = require('./new-config-manager') const configManager = require('./new-config-manager')
const { utils: coinUtils } = require('@lamassu/coins')
const logger = require('./logger') const logger = require('./logger')
const lastRate = {} const lastRate = {}

15485
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -2,14 +2,14 @@
"name": "lamassu-server", "name": "lamassu-server",
"description": "bitcoin atm client server protocol module", "description": "bitcoin atm client server protocol module",
"keywords": [], "keywords": [],
"version": "8.1.5-1", "version": "9.0.0-beta.0",
"license": "Unlicense", "license": "./LICENSE",
"author": "Lamassu (https://lamassu.is)", "author": "Lamassu (https://lamassu.is)",
"dependencies": { "dependencies": {
"@ethereumjs/common": "^2.6.4", "@ethereumjs/common": "^2.6.4",
"@ethereumjs/tx": "^3.5.1", "@ethereumjs/tx": "^3.5.1",
"@graphql-tools/merge": "^6.2.5", "@graphql-tools/merge": "^6.2.5",
"@lamassu/coins": "v1.3.3", "@lamassu/coins": "v1.4.0-beta.1",
"@node-lightning/invoice": "0.28.0", "@node-lightning/invoice": "0.28.0",
"@simplewebauthn/server": "^3.0.0", "@simplewebauthn/server": "^3.0.0",
"@vonage/auth": "^1.5.0", "@vonage/auth": "^1.5.0",
@ -23,9 +23,14 @@
"bchaddrjs": "^0.3.0", "bchaddrjs": "^0.3.0",
"bignumber.js": "9.0.1", "bignumber.js": "9.0.1",
"bip39": "^2.3.1", "bip39": "^2.3.1",
"bitcoind-rpc": "^0.7.0", "@bitgo/sdk-api": "1.21.0",
"bitgo": "11.18.0", "@bitgo/sdk-coin-bch": "1.5.10",
"ccxt": "lamassu/ccxt#1.82.31", "@bitgo/sdk-coin-btc": "1.7.10",
"@bitgo/sdk-coin-dash": "1.5.10",
"@bitgo/sdk-coin-ltc": "2.2.10",
"@bitgo/sdk-coin-zec": "1.5.10",
"@bitgo/utxo-lib": "9.13.0",
"ccxt": "2.9.16",
"compression": "^1.7.4", "compression": "^1.7.4",
"connect-pg-simple": "^6.2.1", "connect-pg-simple": "^6.2.1",
"console-log-level": "^1.4.0", "console-log-level": "^1.4.0",
@ -39,10 +44,7 @@
"ethereumjs-util": "^5.2.0", "ethereumjs-util": "^5.2.0",
"ethereumjs-wallet": "^0.6.3", "ethereumjs-wallet": "^0.6.3",
"express": "4.17.1", "express": "4.17.1",
"express-limiter": "^1.6.0",
"express-rate-limit": "^2.9.0",
"express-session": "^1.17.1", "express-session": "^1.17.1",
"express-ws": "^3.0.0",
"futoin-hkdf": "^1.0.2", "futoin-hkdf": "^1.0.2",
"got": "^7.1.0", "got": "^7.1.0",
"graphql": "^15.5.0", "graphql": "^15.5.0",
@ -65,7 +67,6 @@
"ndjson": "^1.5.0", "ndjson": "^1.5.0",
"nocache": "^2.1.0", "nocache": "^2.1.0",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"numeral": "^2.0.3",
"otplib": "^12.0.1", "otplib": "^12.0.1",
"p-each-series": "^1.0.0", "p-each-series": "^1.0.0",
"p-queue": "^6.6.2", "p-queue": "^6.6.2",
@ -79,8 +80,6 @@
"request-promise": "^4.2.6", "request-promise": "^4.2.6",
"semver": "^7.1.3", "semver": "^7.1.3",
"serve-static": "^1.12.4", "serve-static": "^1.12.4",
"socket.io": "^2.0.3",
"socket.io-client": "^2.0.3",
"talisman": "^0.20.0", "talisman": "^0.20.0",
"telnyx": "^1.25.5", "telnyx": "^1.25.5",
"tronweb": "^5.3.0", "tronweb": "^5.3.0",
@ -89,7 +88,6 @@
"web3": "1.7.1", "web3": "1.7.1",
"winston": "^2.4.2", "winston": "^2.4.2",
"winston-transport": "^4.3.0", "winston-transport": "^4.3.0",
"ws": "^3.1.0",
"xml-stream": "^0.4.5", "xml-stream": "^0.4.5",
"xmlrpc": "^1.3.2", "xmlrpc": "^1.3.2",
"yup": "^0.31.1" "yup": "^0.31.1"