Skip to content

Commit

Permalink
Add Chainalysis address check
Browse files Browse the repository at this point in the history
  • Loading branch information
omurovch committed Jan 24, 2025
1 parent 5975722 commit 2964656
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ android {
resValue "string", "udnApiKey", "r2phzgatt_zt9-hd_wyvdjrdsrimnxgokm7knyag1malzgcz"
resValue "string", "oneInchApiKey", "3EttyCzgWb2GLFIRoPIUYM0M4uKAVEcq"
resValue "string", "blocksDecodedEthereumRpc", "https://api-dev.blocksdecoded.com/v1/ethereum-rpc/mainnet"
resValue "string", "chainalysisBaseUrl", "https://public.chainalysis.com/api/v1/"
resValue "string", "chainalysisApiKey", "928bb256db73f1cb93e1b3366a145d9fbe06e28581c8b665b82ad70bbfef1db4"
}

appcenterdebug {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/io/horizontalsystems/bankwallet/core/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import com.walletconnect.android.relay.ConnectionType
import com.walletconnect.web3.wallet.client.Wallet
import com.walletconnect.web3.wallet.client.Web3Wallet
import io.horizontalsystems.bankwallet.BuildConfig
import io.horizontalsystems.bankwallet.core.address.AddressSecurityCheckerChain
import io.horizontalsystems.bankwallet.core.factories.AccountFactory
import io.horizontalsystems.bankwallet.core.factories.AdapterFactory
import io.horizontalsystems.bankwallet.core.factories.AddressSecurityCheckerFactory
import io.horizontalsystems.bankwallet.core.factories.EvmAccountManagerFactory
import io.horizontalsystems.bankwallet.core.managers.AccountCleaner
import io.horizontalsystems.bankwallet.core.managers.AccountManager
Expand Down Expand Up @@ -117,6 +119,7 @@ import io.horizontalsystems.core.security.EncryptionManager
import io.horizontalsystems.core.security.KeyStoreManager
import io.horizontalsystems.ethereumkit.core.EthereumKit
import io.horizontalsystems.hdwalletkit.Mnemonic
import io.horizontalsystems.marketkit.models.BlockchainType
import io.horizontalsystems.subscriptions.core.UserSubscriptionManager
import io.reactivex.plugins.RxJavaPlugins
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -201,6 +204,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
lateinit var spamManager: SpamManager
lateinit var statsManager: StatsManager
lateinit var tonConnectManager: TonConnectManager
lateinit var addressSecurityCheckerChain: AddressSecurityCheckerChain
}

private val coroutineScope = CoroutineScope(Dispatchers.Default)
Expand Down Expand Up @@ -300,6 +304,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
tokenAutoEnableManager = TokenAutoEnableManager(appDatabase.tokenAutoEnabledBlockchainDao())

spamManager = SpamManager(localStorage, coinManager, SpamAddressStorage(appDatabase.spamAddressDao()), marketKit, appConfigProvider )
addressSecurityCheckerChain = AddressSecurityCheckerFactory(spamManager, appConfigProvider).securityCheckerChain(BlockchainType.Ethereum)

val evmAccountManagerFactory = EvmAccountManagerFactory(
accountManager,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.horizontalsystems.bankwallet.core.address

import io.horizontalsystems.bankwallet.core.managers.APIClient
import io.horizontalsystems.bankwallet.entities.Address
import retrofit2.http.GET
import retrofit2.http.Path

class ChainalysisAddressValidator(
baseUrl: String,
apiKey: String
) : AddressSecurityCheckerChain.IAddressSecurityCheckerItem {

private val apiService by lazy {
APIClient.build(
baseUrl,
mapOf("Accept" to "application/json", "X-API-KEY" to apiKey)
).create(ChainalysisApi::class.java)
}

override suspend fun handle(address: Address): AddressSecurityCheckerChain.SecurityIssue? {
val response = apiService.address(address.hex)
return if (response.identifications.isNotEmpty())
AddressSecurityCheckerChain.SecurityIssue.Sanctioned("Sanctioned address. ${response.identifications.size} identifications found.")
else
null
}

data class ChainalysisApiResponse(
val identifications: List<Identification>
)

data class Identification(
val category: String,
val name: String?,
val description: String?,
val url: String?
)

private interface ChainalysisApi {
@GET("address/{address}")
suspend fun address(@Path("address") address: String): ChainalysisApiResponse
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package io.horizontalsystems.bankwallet.core.factories

import io.horizontalsystems.bankwallet.core.address.AddressSecurityCheckerChain
import io.horizontalsystems.bankwallet.core.address.AddressSecurityCheckerChain.IAddressSecurityCheckerItem
import io.horizontalsystems.bankwallet.core.address.ChainalysisAddressValidator
import io.horizontalsystems.bankwallet.core.address.SpamAddressDetector
import io.horizontalsystems.bankwallet.core.managers.SpamManager
import io.horizontalsystems.bankwallet.core.providers.AppConfigProvider
import io.horizontalsystems.bankwallet.core.supported
import io.horizontalsystems.marketkit.models.BlockchainType

class AddressSecurityCheckerFactory(
private val spamManager: SpamManager
private val spamManager: SpamManager,
private val appConfigProvider: AppConfigProvider
) {

private fun securityCheckerChainHandlers(blockchainType: BlockchainType): List<IAddressSecurityCheckerItem> =
Expand All @@ -23,10 +26,11 @@ class AddressSecurityCheckerFactory(
BlockchainType.Fantom,
BlockchainType.ArbitrumOne -> {
val evmAddressSecurityCheckerItem = SpamAddressDetector(spamManager)
// val chainalysisAddressValidator = ChainalysisAddressValidator(networkManager: App.shared.networkManager)
val chainalysisAddressValidator =
ChainalysisAddressValidator(appConfigProvider.chainalysisBaseUrl, appConfigProvider.chainalysisApiKey)
val handlers = mutableListOf<IAddressSecurityCheckerItem>()
handlers.add(evmAddressSecurityCheckerItem)
// handlers.add(chainalysisAddressValidator)
handlers.add(chainalysisAddressValidator)
handlers
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ class AppConfigProvider(localStorage: ILocalStorage) {
"stasis-eurs" to 0.01,
)

val chainalysisBaseUrl by lazy {
Translator.getString(R.string.chainalysisBaseUrl)
}

val chainalysisApiKey by lazy {
Translator.getString(R.string.chainalysisApiKey)
}

}

0 comments on commit 2964656

Please sign in to comment.