-
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.
- Loading branch information
Showing
28 changed files
with
615 additions
and
103 deletions.
There are no files selected for viewing
44 changes: 43 additions & 1 deletion
44
UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
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
48 changes: 48 additions & 0 deletions
48
UnstoppableWallet/UnstoppableWallet/Core/Address/AddressSecurityCheckerChain.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,48 @@ | ||
import Foundation | ||
import MarketKit | ||
import RxCocoa | ||
import RxRelay | ||
import RxSwift | ||
|
||
protocol IAddressSecurityCheckerItem: AnyObject { | ||
func handle(address: Address) -> Single<AddressSecurityCheckerChain.SecurityCheckResult> | ||
} | ||
|
||
class AddressSecurityCheckerChain { | ||
private let disposeBag = DisposeBag() | ||
private var handlers = [IAddressSecurityCheckerItem]() | ||
} | ||
|
||
extension AddressSecurityCheckerChain { | ||
@discardableResult func append(handlers: [IAddressSecurityCheckerItem]) -> Self { | ||
self.handlers.append(contentsOf: handlers) | ||
return self | ||
} | ||
|
||
@discardableResult func append(handler: IAddressSecurityCheckerItem) -> Self { | ||
handlers.append(handler) | ||
return self | ||
} | ||
|
||
func handle(address: Address) -> Single<[SecurityCheckResult]> { | ||
Single.zip(handlers.map { handler -> Single<SecurityCheckResult> in | ||
handler.handle(address: address) | ||
}) | ||
} | ||
} | ||
|
||
extension AddressSecurityCheckerChain { | ||
public enum SecurityCheckResult { | ||
case valid | ||
case spam(transactionHash: String) | ||
case sanctioned(description: String) | ||
|
||
public var description: String? { | ||
switch self { | ||
case .valid: return nil | ||
case let .spam(transactionHash): return "Possibly phishing address. Transaction hash: \(transactionHash)" | ||
case let .sanctioned(description): return description | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
UnstoppableWallet/UnstoppableWallet/Core/Address/SpamAddressDetector.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,24 @@ | ||
import RxSwift | ||
|
||
class SpamAddressDetector { | ||
private let spamAddressManager: SpamAddressManager | ||
|
||
init() { | ||
spamAddressManager = App.shared.spamAddressManager | ||
} | ||
} | ||
|
||
extension SpamAddressDetector: IAddressSecurityCheckerItem { | ||
func handle(address: Address) -> Single<AddressSecurityCheckerChain.SecurityCheckResult> { | ||
let result: AddressSecurityCheckerChain.SecurityCheckResult | ||
|
||
let spamAddress = spamAddressManager.find(address: address.raw.uppercased()) | ||
if let spamAddress { | ||
result = .spam(transactionHash: spamAddress.transactionHash.hs.hexString) | ||
} else { | ||
result = .valid | ||
} | ||
|
||
return Single.just(result) | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
UnstoppableWallet/UnstoppableWallet/Core/Factories/AddressSecurityCheckerFactory.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,30 @@ | ||
import MarketKit | ||
|
||
enum AddressSecurityCheckerFactory { | ||
static func securityCheckerChainHandlers(blockchainType: BlockchainType) -> [IAddressSecurityCheckerItem] { | ||
switch blockchainType { | ||
case .ethereum, .gnosis, .fantom, .polygon, .arbitrumOne, .avalanche, .optimism, .binanceSmartChain, .base: | ||
let evmAddressSecurityCheckerItem = SpamAddressDetector() | ||
|
||
var handlers = [IAddressSecurityCheckerItem]() | ||
handlers.append(evmAddressSecurityCheckerItem) | ||
|
||
return handlers | ||
default: | ||
return [] | ||
} | ||
} | ||
|
||
static func securityCheckerChain(blockchainType: BlockchainType?) -> AddressSecurityCheckerChain { | ||
if let blockchainType { | ||
return AddressSecurityCheckerChain().append(handlers: securityCheckerChainHandlers(blockchainType: blockchainType)) | ||
} | ||
|
||
var handlers = [IAddressSecurityCheckerItem]() | ||
for blockchainType in BlockchainType.supported { | ||
handlers.append(contentsOf: securityCheckerChainHandlers(blockchainType: blockchainType)) | ||
} | ||
|
||
return AddressSecurityCheckerChain().append(handlers: handlers) | ||
} | ||
} |
Oops, something went wrong.