-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Chainalysis sanctioned address check
- Loading branch information
Showing
14 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
UnstoppableWallet/UnstoppableWallet/Core/Address/ChainalysisAddressValidator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Alamofire | ||
import Foundation | ||
import HsToolKit | ||
import ObjectMapper | ||
import RxSwift | ||
|
||
class ChainalysisAddressValidator { | ||
private let baseUrl = "https://public.chainalysis.com/api/v1/address/" | ||
private let networkManager: NetworkManager | ||
private let headers: HTTPHeaders | ||
|
||
init(networkManager: NetworkManager) { | ||
self.networkManager = networkManager | ||
|
||
headers = HTTPHeaders([ | ||
HTTPHeader(name: "X-API-KEY", value: AppConfig.chainalysisApiKey), | ||
HTTPHeader(name: "Accept", value: "application/json"), | ||
]) | ||
} | ||
} | ||
|
||
extension ChainalysisAddressValidator: IAddressSecurityCheckerItem { | ||
func handle(address: Address) -> Single<AddressSecurityCheckerChain.SecurityIssue?> { | ||
let request = networkManager.session.request("\(baseUrl)\(address.raw)", headers: headers) | ||
let response: Single<ChainalysisAddressValidatorResponse> = networkManager.single(request: request) | ||
|
||
return response.map { | ||
if $0.identifications.isEmpty { | ||
return nil | ||
} | ||
|
||
return .sanctioned(description: "Sanctioned address. \($0.identifications.count) identifications found.") | ||
} | ||
} | ||
} | ||
|
||
public struct ChainalysisAddressValidatorResponse: ImmutableMappable { | ||
public let identifications: [Identification] | ||
|
||
public init(map: Map) throws { | ||
identifications = try map.value("identifications") | ||
} | ||
|
||
public struct Identification: ImmutableMappable { | ||
public let category: String | ||
public let name: String? | ||
public let description: String? | ||
public let url: String? | ||
|
||
public init(map: Map) throws { | ||
category = try map.value("category") | ||
name = try map.value("name") | ||
description = try map.value("description") | ||
url = try map.value("url") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters