diff --git a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnectVerify.xcscheme b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnectVerify.xcscheme
index 5b4aa4030..0f35eb712 100644
--- a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnectVerify.xcscheme
+++ b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnectVerify.xcscheme
@@ -28,6 +28,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
+
+
+
+
VerifyContext {
- guard isScam != true else {
- return VerifyContext(
- origin: origin,
- 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
- )
- } else {
- return VerifyContext(
- origin: origin,
- validation: .unknown
- )
- }
+ verifyContextFactory.createVerifyContext(origin: origin, domain: domain, isScam: isScam)
}
public func registerAssertion() async throws {
diff --git a/Sources/WalletConnectVerify/VerifyContextFactory.swift b/Sources/WalletConnectVerify/VerifyContextFactory.swift
new file mode 100644
index 000000000..b687932e4
--- /dev/null
+++ b/Sources/WalletConnectVerify/VerifyContextFactory.swift
@@ -0,0 +1,24 @@
+
+import Foundation
+
+class VerifyContextFactory {
+ public func createVerifyContext(origin: String?, domain: String, isScam: Bool?) -> VerifyContext {
+ guard isScam != true else {
+ return VerifyContext(
+ origin: origin,
+ 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
+ )
+ } else {
+ return VerifyContext(
+ origin: origin,
+ validation: .unknown
+ )
+ }
+ }
+}
diff --git a/Tests/VerifyTests/VerifyContextFactoryTests.swift b/Tests/VerifyTests/VerifyContextFactoryTests.swift
new file mode 100644
index 000000000..ac540cc0e
--- /dev/null
+++ b/Tests/VerifyTests/VerifyContextFactoryTests.swift
@@ -0,0 +1,38 @@
+import Foundation
+import XCTest
+@testable import WalletConnectVerify
+
+
+class VerifyContextFactoryTests: XCTestCase {
+ var factory: VerifyContextFactory!
+
+ override func setUp() {
+ super.setUp()
+ factory = VerifyContextFactory()
+ }
+
+ override func tearDown() {
+ factory = nil
+ super.tearDown()
+ }
+
+ func testScamValidation() {
+ let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://example.com", isScam: true)
+ XCTAssertEqual(context.validation, .scam)
+ }
+
+ func testValidOriginAndDomain() {
+ let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://example.com", isScam: false)
+ XCTAssertEqual(context.validation, .valid)
+ }
+
+ func testInvalidOriginAndDomain() {
+ let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://different.com", isScam: false)
+ XCTAssertEqual(context.validation, .invalid)
+ }
+
+ func testUnknownValidation() {
+ let context = factory.createVerifyContext(origin: nil, domain: "http://example.com", isScam: false)
+ XCTAssertEqual(context.validation, .unknown)
+ }
+ }