Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove verify host #1170

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Sources/WalletConnectVerify/OriginVerifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ public final class OriginVerifier {
case registrationFailed
}

private var verifyHost: String
private var verifyHost = "verify.walletconnect.com"
/// The property is used to determine whether verify.walletconnect.org will be used
/// in case verify.walletconnect.com doesn't respond for some reason (most likely due to being blocked in the user's location).
private var fallback = false

init(verifyHost: String) {
self.verifyHost = verifyHost
}


func verifyOrigin(assertionId: String) async throws -> VerifyResponse {
let sessionConfiguration = URLSessionConfiguration.default
sessionConfiguration.timeoutIntervalForRequest = 5.0
Expand All @@ -27,7 +23,7 @@ public final class OriginVerifier {
VerifyResponse.self,
at: VerifyAPI.resolve(assertionId: assertionId)
)
guard let origin = response.origin else {
guard let _ = response.origin else {
throw Errors.registrationFailed
}
return response
Expand Down
15 changes: 4 additions & 11 deletions Sources/WalletConnectVerify/VerifyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ public actor VerifyClient: VerifyClientProtocol {
let originVerifier: OriginVerifier
let assertionRegistrer: AssertionRegistrer
let appAttestationRegistrer: AppAttestationRegistrer

private let verifyHost: String

init(
verifyHost: String,
originVerifier: OriginVerifier,
assertionRegistrer: AssertionRegistrer,
appAttestationRegistrer: AppAttestationRegistrer
) {
self.verifyHost = verifyHost
self.originVerifier = originVerifier
self.assertionRegistrer = assertionRegistrer
self.appAttestationRegistrer = appAttestationRegistrer
Expand All @@ -41,21 +37,18 @@ public actor VerifyClient: VerifyClientProtocol {
guard isScam == nil else {
return VerifyContext(
origin: origin,
validation: .scam,
verifyUrl: verifyHost
validation: .scam
)
}
if let origin, let originUrl = URL(string: origin), let domainUrl = URL(string: domain) {
return VerifyContext(
origin: origin,
validation: (originUrl.host == domainUrl.host) ? .valid : .invalid,
verifyUrl: verifyHost
validation: (originUrl.host == domainUrl.host) ? .valid : .invalid
)
} else {
return VerifyContext(
origin: origin,
validation: .unknown,
verifyUrl: verifyHost
validation: .unknown
)
}
}
Expand All @@ -75,7 +68,7 @@ public struct VerifyClientMock: VerifyClientProtocol {
}

public func createVerifyContext(origin: String?, domain: String, isScam: Bool?) -> VerifyContext {
return VerifyContext(origin: "domain.com", validation: .valid, verifyUrl: "verify.walletconnect.com")
return VerifyContext(origin: "domain.com", validation: .valid)
}
}

Expand Down
5 changes: 2 additions & 3 deletions Sources/WalletConnectVerify/VerifyClientFactory.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation

public class VerifyClientFactory {
public static func create(verifyHost: String = "verify.walletconnect.com") -> VerifyClient {
let originVerifier = OriginVerifier(verifyHost: verifyHost)
public static func create() -> VerifyClient {
let originVerifier = OriginVerifier()
let assertionRegistrer = AssertionRegistrer()
let logger = ConsoleLogger(loggingLevel: .off)
let keyValueStorage = UserDefaults.standard
Expand All @@ -18,7 +18,6 @@ public class VerifyClientFactory {
keyAttestationService: keyAttestationService
)
return VerifyClient(
verifyHost: verifyHost,
originVerifier: originVerifier,
assertionRegistrer: assertionRegistrer,
appAttestationRegistrer: appAttestationRegistrer
Expand Down
4 changes: 1 addition & 3 deletions Sources/WalletConnectVerify/VerifyContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ public struct VerifyContext: Equatable, Hashable, Codable {

public let origin: String?
public let validation: ValidationStatus
public let verifyUrl: String

public init(origin: String?, validation: ValidationStatus, verifyUrl: String) {
public init(origin: String?, validation: ValidationStatus) {
self.origin = origin
self.validation = validation
self.verifyUrl = verifyUrl
}
}