feat: add ciphertrace base implementation

This commit is contained in:
Sérgio Salgado 2021-12-16 20:04:43 +00:00
parent 201fec33e4
commit 904c383431
20 changed files with 258 additions and 39 deletions

View file

@ -0,0 +1,52 @@
const axios = require('axios')
const _ = require('lodash/fp')
const { WALLET_SCORE_THRESHOLD } = require('../../../constants')
const NAME = 'CipherTrace'
const SUPPORTED_COINS = ['BTC', 'ETH', 'BCH', 'LTC', 'BNB', 'RSK']
function getClient(account) {
if (_.isNil(account) || !account.enabled) return null
const [ctv1, username, secretKey] = account.authorizationValue.split(':')
if (_.isNil(ctv1) || _.isNil(username) || _.isNil(secretKey)) {
throw new Error('Invalid CipherTrace configuration')
}
const apiVersion = ctv1.slice(-2)
const authHeader = {
"Authorization": account
}
return { apiVersion, authHeader }
}
function rateWallet(account, cryptoCode, address) {
const client = getClient(account)
console.log('client', client)
if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null)
const { apiVersion, authHeader } = client
const score = Math.floor(Math.random() * (10 - 1 + 1)) + 1
const threshold = _.isNil(account.scoreThreshold) ? WALLET_SCORE_THRESHOLD : account.scoreThreshold
return Promise.resolve({ address, score, isValid: score < threshold })
// return axios.get(`https://rest.ciphertrace.com/aml/${apiVersion}/${_.toLower(cryptoCode)}/risk?address=${address}`, {
// headers: authHeader
// })
// .then(res => ({ address, score: res.risk, isValid: res.risk <= SCORE_THRESHOLD }))
}
function isValidWalletScore(account, score) {
const client = getClient(account)
if (_.isNil(client)) return Promise.resolve(true)
const threshold = _.isNil(account) ? WALLET_SCORE_THRESHOLD : account.scoreThreshold
return Promise.resolve(score < threshold)
}
module.exports = {
NAME,
rateWallet,
isValidWalletScore
}

View file

@ -1,15 +1,27 @@
const NAME = 'FakeScoring'
function rateWallet (account, address) {
const { WALLET_SCORE_THRESHOLD } = require('../../../constants')
function rateWallet (account, cryptoCode, address) {
return new Promise((resolve, _) => {
setTimeout(() => {
console.log('[WALLET-SCORING] DEBUG: Mock scoring rating wallet address %s', address)
return resolve({ address, rating: 5 })
return Promise.resolve(7)
.then(score => resolve({ address, score, isValid: score < WALLET_SCORE_THRESHOLD }))
}, 100)
})
}
function isValidWalletScore (account, score) {
return new Promise((resolve, _) => {
setTimeout(() => {
return resolve(score < WALLET_SCORE_THRESHOLD)
}, 100)
})
}
module.exports = {
NAME,
rateWallet
rateWallet,
isValidWalletScore
}