chore: use monorepo organization
This commit is contained in:
parent
deaf7d6ecc
commit
a687827f7e
1099 changed files with 8184 additions and 11535 deletions
|
|
@ -0,0 +1,95 @@
|
|||
const { AML } = require('elliptic-sdk')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const NAME = 'Elliptic'
|
||||
|
||||
const HOLLISTIC_COINS = {
|
||||
BTC: 'BTC',
|
||||
ETH: 'ETH',
|
||||
USDT: 'USDT',
|
||||
USDT_TRON: 'USDT',
|
||||
LTC: 'LTC',
|
||||
TRX: 'TRX'
|
||||
}
|
||||
|
||||
const SINGLE_ASSET_COINS = {
|
||||
ZEC: {
|
||||
asset: 'ZEC',
|
||||
blockchain: 'zcash'
|
||||
},
|
||||
BCH: {
|
||||
asset: 'BCH',
|
||||
blockchain: 'bitcoin_cash'
|
||||
}
|
||||
}
|
||||
|
||||
const TYPE = {
|
||||
TRANSACTION: 'transaction',
|
||||
ADDRESS: 'address'
|
||||
}
|
||||
|
||||
const SUPPORTED_COINS = { ...HOLLISTIC_COINS, ...SINGLE_ASSET_COINS }
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
const isHolistic = Object.keys(HOLLISTIC_COINS).includes(cryptoCode)
|
||||
|
||||
const requestBody = {
|
||||
subject: {
|
||||
asset: isHolistic ? 'holistic' : SINGLE_ASSET_COINS[cryptoCode].asset,
|
||||
blockchain: isHolistic ? 'holistic' : SINGLE_ASSET_COINS[cryptoCode].blockchain,
|
||||
type: objectType,
|
||||
hash: objectId
|
||||
},
|
||||
type: objectType === TYPE.ADDRESS ? 'wallet_exposure' : 'source_of_funds'
|
||||
}
|
||||
|
||||
const threshold = account.scoreThreshold
|
||||
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
|
||||
|
||||
// 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) {
|
||||
return rate(account, TYPE.TRANSACTION, cryptoCode, transactionId)
|
||||
}
|
||||
|
||||
function rateAddress (account, cryptoCode, address) {
|
||||
return rate(account, TYPE.ADDRESS, cryptoCode, address)
|
||||
}
|
||||
|
||||
function isWalletScoringEnabled (account, cryptoCode) {
|
||||
const isAccountEnabled = !_.isNil(account) && account.enabled
|
||||
|
||||
if (!isAccountEnabled) return Promise.resolve(false)
|
||||
|
||||
if (!Object.keys(SUPPORTED_COINS).includes(cryptoCode)) {
|
||||
return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
|
||||
}
|
||||
|
||||
return Promise.resolve(true)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
rateAddress,
|
||||
rateTransaction,
|
||||
isWalletScoringEnabled
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
const NAME = 'FakeScoring'
|
||||
|
||||
const { WALLET_SCORE_THRESHOLD } = require('../../../constants')
|
||||
|
||||
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 }))
|
||||
}, 100)
|
||||
})
|
||||
}
|
||||
|
||||
function isWalletScoringEnabled (account, cryptoCode) {
|
||||
return new Promise((resolve, _) => {
|
||||
setTimeout(() => {
|
||||
return resolve(true)
|
||||
}, 100)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
rateAddress,
|
||||
rateTransaction:rateAddress,
|
||||
isWalletScoringEnabled
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
const axios = require('axios')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
|
||||
const NAME = 'Scorechain'
|
||||
const SUPPORTED_COINS = {
|
||||
BTC: 'BITCOIN',
|
||||
ETH: 'ETHEREUM',
|
||||
USDT: 'ETHEREUM',
|
||||
BCH: 'BITCOINCASH',
|
||||
LTC: 'LITECOIN',
|
||||
DASH: 'DASH',
|
||||
TRX: 'TRON',
|
||||
USDT_TRON: 'TRON'
|
||||
}
|
||||
|
||||
const TYPE = {
|
||||
TRANSACTION: 'TRANSACTION',
|
||||
ADDRESS: 'ADDRESS'
|
||||
}
|
||||
|
||||
function rate (account, objectType, cryptoCode, objectId) {
|
||||
return isWalletScoringEnabled(account, cryptoCode).then(isEnabled => {
|
||||
if (!isEnabled) return Promise.resolve(null)
|
||||
|
||||
const threshold = account.scoreThreshold
|
||||
const payload = {
|
||||
analysisType: 'ASSIGNED',
|
||||
objectType,
|
||||
objectId,
|
||||
blockchain: SUPPORTED_COINS[cryptoCode],
|
||||
coin: "ALL"
|
||||
}
|
||||
|
||||
const headers = {
|
||||
'accept': 'application/json',
|
||||
'X-API-KEY': account.apiKey,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
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')
|
||||
|
||||
// normalize score to 0-10 where 0 is the lowest risk
|
||||
return {score: (100 - resScore) / 10, isValid: resScore >= threshold}
|
||||
})
|
||||
.catch(err => {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function rateTransaction (account, cryptoCode, transactionId) {
|
||||
return rate(account, TYPE.TRANSACTION, cryptoCode, transactionId)
|
||||
}
|
||||
|
||||
function rateAddress (account, cryptoCode, address) {
|
||||
return rate(account, TYPE.ADDRESS, cryptoCode, address)
|
||||
}
|
||||
|
||||
function isWalletScoringEnabled (account, cryptoCode) {
|
||||
const isAccountEnabled = !_.isNil(account) && account.enabled
|
||||
|
||||
if (!isAccountEnabled) return Promise.resolve(false)
|
||||
|
||||
if (!Object.keys(SUPPORTED_COINS).includes(cryptoCode)) {
|
||||
return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
|
||||
}
|
||||
|
||||
return Promise.resolve(true)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
rateAddress,
|
||||
rateTransaction,
|
||||
isWalletScoringEnabled
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue