chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -9,34 +9,34 @@ const HOLLISTIC_COINS = {
|
|||
USDT: 'USDT',
|
||||
USDT_TRON: 'USDT',
|
||||
LTC: 'LTC',
|
||||
TRX: 'TRX'
|
||||
TRX: 'TRX',
|
||||
}
|
||||
|
||||
const SINGLE_ASSET_COINS = {
|
||||
ZEC: {
|
||||
asset: 'ZEC',
|
||||
blockchain: 'zcash'
|
||||
blockchain: 'zcash',
|
||||
},
|
||||
BCH: {
|
||||
asset: 'BCH',
|
||||
blockchain: 'bitcoin_cash'
|
||||
}
|
||||
blockchain: 'bitcoin_cash',
|
||||
},
|
||||
}
|
||||
|
||||
const TYPE = {
|
||||
TRANSACTION: 'transaction',
|
||||
ADDRESS: 'address'
|
||||
TRANSACTION: 'transaction',
|
||||
ADDRESS: 'address',
|
||||
}
|
||||
|
||||
const SUPPORTED_COINS = { ...HOLLISTIC_COINS, ...SINGLE_ASSET_COINS }
|
||||
|
||||
function rate (account, objectType, cryptoCode, objectId) {
|
||||
function rate(account, objectType, cryptoCode, objectId) {
|
||||
return isWalletScoringEnabled(account, cryptoCode).then(isEnabled => {
|
||||
if (!isEnabled) return Promise.resolve(null)
|
||||
|
||||
const aml = new AML({
|
||||
key: account.apiKey,
|
||||
secret: account.apiSecret
|
||||
secret: account.apiSecret,
|
||||
})
|
||||
|
||||
const isHolistic = Object.keys(HOLLISTIC_COINS).includes(cryptoCode)
|
||||
|
|
@ -44,38 +44,44 @@ function rate (account, objectType, cryptoCode, objectId) {
|
|||
const requestBody = {
|
||||
subject: {
|
||||
asset: isHolistic ? 'holistic' : SINGLE_ASSET_COINS[cryptoCode].asset,
|
||||
blockchain: isHolistic ? 'holistic' : SINGLE_ASSET_COINS[cryptoCode].blockchain,
|
||||
blockchain: isHolistic
|
||||
? 'holistic'
|
||||
: SINGLE_ASSET_COINS[cryptoCode].blockchain,
|
||||
type: objectType,
|
||||
hash: objectId
|
||||
hash: objectId,
|
||||
},
|
||||
type: objectType === TYPE.ADDRESS ? 'wallet_exposure' : 'source_of_funds'
|
||||
type: objectType === TYPE.ADDRESS ? 'wallet_exposure' : 'source_of_funds',
|
||||
}
|
||||
|
||||
const threshold = account.scoreThreshold
|
||||
const endpoint = objectType === TYPE.ADDRESS ? '/v2/wallet/synchronous' : '/v2/analysis/synchronous'
|
||||
const endpoint =
|
||||
objectType === TYPE.ADDRESS
|
||||
? '/v2/wallet/synchronous'
|
||||
: '/v2/analysis/synchronous'
|
||||
|
||||
return aml.client
|
||||
.post(endpoint, requestBody)
|
||||
.then((res) => {
|
||||
const resScore = res.data?.risk_score
|
||||
return aml.client.post(endpoint, requestBody).then(res => {
|
||||
const resScore = res.data?.risk_score
|
||||
|
||||
// elliptic returns 0-1 score, but we're accepting 0-100 config
|
||||
// normalize score to 0-10 where 0 is the lowest risk
|
||||
// elliptic score can be null and contains decimals
|
||||
return {score: (resScore || 0) * 10, isValid: ((resScore || 0) * 100) < threshold}
|
||||
})
|
||||
// elliptic returns 0-1 score, but we're accepting 0-100 config
|
||||
// normalize score to 0-10 where 0 is the lowest risk
|
||||
// elliptic score can be null and contains decimals
|
||||
return {
|
||||
score: (resScore || 0) * 10,
|
||||
isValid: (resScore || 0) * 100 < threshold,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function rateTransaction (account, cryptoCode, transactionId) {
|
||||
function rateTransaction(account, cryptoCode, transactionId) {
|
||||
return rate(account, TYPE.TRANSACTION, cryptoCode, transactionId)
|
||||
}
|
||||
|
||||
function rateAddress (account, cryptoCode, address) {
|
||||
function rateAddress(account, cryptoCode, address) {
|
||||
return rate(account, TYPE.ADDRESS, cryptoCode, address)
|
||||
}
|
||||
|
||||
function isWalletScoringEnabled (account, cryptoCode) {
|
||||
function isWalletScoringEnabled(account, cryptoCode) {
|
||||
const isAccountEnabled = !_.isNil(account) && account.enabled
|
||||
|
||||
if (!isAccountEnabled) return Promise.resolve(false)
|
||||
|
|
@ -91,5 +97,5 @@ module.exports = {
|
|||
NAME,
|
||||
rateAddress,
|
||||
rateTransaction,
|
||||
isWalletScoringEnabled
|
||||
isWalletScoringEnabled,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,22 @@ const NAME = 'FakeScoring'
|
|||
|
||||
const { WALLET_SCORE_THRESHOLD } = require('../../../constants')
|
||||
|
||||
function rateAddress (account, cryptoCode, address) {
|
||||
return new Promise((resolve, _) => {
|
||||
function rateAddress(account, cryptoCode, address) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
console.log('[WALLET-SCORING] DEBUG: Mock scoring rating wallet address %s', address)
|
||||
return Promise.resolve(2)
|
||||
.then(score => resolve({ address, score, isValid: score < WALLET_SCORE_THRESHOLD }))
|
||||
console.log(
|
||||
'[WALLET-SCORING] DEBUG: Mock scoring rating wallet address %s',
|
||||
address,
|
||||
)
|
||||
return Promise.resolve(2).then(score =>
|
||||
resolve({ address, score, isValid: score < WALLET_SCORE_THRESHOLD }),
|
||||
)
|
||||
}, 100)
|
||||
})
|
||||
}
|
||||
|
||||
function isWalletScoringEnabled (account, cryptoCode) {
|
||||
return new Promise((resolve, _) => {
|
||||
function isWalletScoringEnabled() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
return resolve(true)
|
||||
}, 100)
|
||||
|
|
@ -23,6 +27,6 @@ function isWalletScoringEnabled (account, cryptoCode) {
|
|||
module.exports = {
|
||||
NAME,
|
||||
rateAddress,
|
||||
rateTransaction:rateAddress,
|
||||
isWalletScoringEnabled
|
||||
rateTransaction: rateAddress,
|
||||
isWalletScoringEnabled,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
const axios = require('axios')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
|
||||
const NAME = 'Scorechain'
|
||||
const SUPPORTED_COINS = {
|
||||
BTC: 'BITCOIN',
|
||||
|
|
@ -11,15 +10,15 @@ const SUPPORTED_COINS = {
|
|||
LTC: 'LITECOIN',
|
||||
DASH: 'DASH',
|
||||
TRX: 'TRON',
|
||||
USDT_TRON: 'TRON'
|
||||
USDT_TRON: 'TRON',
|
||||
}
|
||||
|
||||
const TYPE = {
|
||||
TRANSACTION: 'TRANSACTION',
|
||||
ADDRESS: 'ADDRESS'
|
||||
ADDRESS: 'ADDRESS',
|
||||
}
|
||||
|
||||
function rate (account, objectType, cryptoCode, objectId) {
|
||||
function rate(account, objectType, cryptoCode, objectId) {
|
||||
return isWalletScoringEnabled(account, cryptoCode).then(isEnabled => {
|
||||
if (!isEnabled) return Promise.resolve(null)
|
||||
|
||||
|
|
@ -29,21 +28,25 @@ function rate (account, objectType, cryptoCode, objectId) {
|
|||
objectType,
|
||||
objectId,
|
||||
blockchain: SUPPORTED_COINS[cryptoCode],
|
||||
coin: "ALL"
|
||||
coin: 'ALL',
|
||||
}
|
||||
|
||||
const headers = {
|
||||
'accept': 'application/json',
|
||||
accept: 'application/json',
|
||||
'X-API-KEY': account.apiKey,
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
return axios.post(`https://api.scorechain.com/v1/scoringAnalysis`, payload, {headers})
|
||||
return axios
|
||||
.post(`https://api.scorechain.com/v1/scoringAnalysis`, payload, {
|
||||
headers,
|
||||
})
|
||||
.then(res => {
|
||||
const resScore = res.data?.analysis?.assigned?.result?.score
|
||||
if (!resScore) throw new Error('Failed to get score from Scorechain API')
|
||||
if (!resScore)
|
||||
throw new Error('Failed to get score from Scorechain API')
|
||||
|
||||
// normalize score to 0-10 where 0 is the lowest risk
|
||||
return {score: (100 - resScore) / 10, isValid: resScore >= threshold}
|
||||
return { score: (100 - resScore) / 10, isValid: resScore >= threshold }
|
||||
})
|
||||
.catch(err => {
|
||||
throw err
|
||||
|
|
@ -51,15 +54,15 @@ function rate (account, objectType, cryptoCode, objectId) {
|
|||
})
|
||||
}
|
||||
|
||||
function rateTransaction (account, cryptoCode, transactionId) {
|
||||
function rateTransaction(account, cryptoCode, transactionId) {
|
||||
return rate(account, TYPE.TRANSACTION, cryptoCode, transactionId)
|
||||
}
|
||||
|
||||
function rateAddress (account, cryptoCode, address) {
|
||||
function rateAddress(account, cryptoCode, address) {
|
||||
return rate(account, TYPE.ADDRESS, cryptoCode, address)
|
||||
}
|
||||
|
||||
function isWalletScoringEnabled (account, cryptoCode) {
|
||||
function isWalletScoringEnabled(account, cryptoCode) {
|
||||
const isAccountEnabled = !_.isNil(account) && account.enabled
|
||||
|
||||
if (!isAccountEnabled) return Promise.resolve(false)
|
||||
|
|
@ -75,5 +78,5 @@ module.exports = {
|
|||
NAME,
|
||||
rateAddress,
|
||||
rateTransaction,
|
||||
isWalletScoringEnabled
|
||||
isWalletScoringEnabled,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue