From ee76f668a7c2d93da9b99ce77d4591fc487970c8 Mon Sep 17 00:00:00 2001 From: Alexander Lisovik Date: Mon, 30 Oct 2023 12:29:14 +0400 Subject: [PATCH 1/5] Add native redirect --- Example/DApp/Auth/AuthCoordinator.swift | 3 ++- Example/DApp/Info.plist | 19 +++++++++++++------ Example/DApp/SceneDelegate.swift | 3 ++- .../Sign/Connect/ConnectViewController.swift | 2 +- Example/DApp/Sign/SignCoordinator.swift | 4 +++- Example/ExampleApp.xcodeproj/project.pbxproj | 9 ++++++++- .../ConfigurationService.swift | 3 ++- .../AuthRequest/AuthRequestInteractor.swift | 8 ++++++++ .../SessionProposalInteractor.swift | 7 +++++++ .../SessionRequestInteractor.swift | 14 ++++++++++++++ Package.swift | 9 +++++++-- .../Wallet/PendingRequestsProvider.swift | 2 +- .../Wallet/WalletRequestSubscriber.swift | 4 ++-- Sources/Auth/Types/Public/AuthRequest.swift | 1 + .../Modal/Modal+Previews.swift | 3 ++- .../Client/Wallet/NotifyConfig.swift | 6 +++--- .../Types/AppMetadata.swift | 8 ++++---- .../WalletConnectRouter/Router/Router.swift | 9 +++++++++ .../{ => RouterLegacy}/Router.m | 0 .../{ => RouterLegacy}/include/Router.h | 0 .../include/module.modulemap | 0 .../WalletConnectUtils/WalletConnectURI.swift | 9 ++++++--- .../Mocks/AuthClientMock.swift | 3 ++- 23 files changed, 97 insertions(+), 29 deletions(-) create mode 100644 Sources/WalletConnectRouter/Router/Router.swift rename Sources/WalletConnectRouter/{ => RouterLegacy}/Router.m (100%) rename Sources/WalletConnectRouter/{ => RouterLegacy}/include/Router.h (100%) rename Sources/WalletConnectRouter/{ => RouterLegacy}/include/module.modulemap (100%) diff --git a/Example/DApp/Auth/AuthCoordinator.swift b/Example/DApp/Auth/AuthCoordinator.swift index f5594f8ab..0577412f4 100644 --- a/Example/DApp/Auth/AuthCoordinator.swift +++ b/Example/DApp/Auth/AuthCoordinator.swift @@ -29,7 +29,8 @@ final class AuthCoordinator { name: "Swift Dapp", description: "WalletConnect DApp sample", url: "wallet.connect", - icons: ["https://avatars.githubusercontent.com/u/37784886"]) + icons: ["https://avatars.githubusercontent.com/u/37784886"], + redirect: AppMetadata.Redirect(native: "dapp://", universal: nil)) Pair.configure(metadata: metadata) navigationController.viewControllers = [authViewController] diff --git a/Example/DApp/Info.plist b/Example/DApp/Info.plist index 92cddbe74..b991963c0 100644 --- a/Example/DApp/Info.plist +++ b/Example/DApp/Info.plist @@ -2,6 +2,19 @@ + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + dapp + + + + ITSAppUsesNonExemptEncryption + LSApplicationQueriesSchemes metamask @@ -11,12 +24,6 @@ rainbow spot - CFBundleVersion - 7 - CFBundleShortVersionString - $(MARKETING_VERSION) - ITSAppUsesNonExemptEncryption - PROJECT_ID $(PROJECT_ID) UIApplicationSceneManifest diff --git a/Example/DApp/SceneDelegate.swift b/Example/DApp/SceneDelegate.swift index f784fac19..b5a8df419 100644 --- a/Example/DApp/SceneDelegate.swift +++ b/Example/DApp/SceneDelegate.swift @@ -19,7 +19,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { name: "Swift Dapp", description: "WalletConnect DApp sample", url: "wallet.connect", - icons: ["https://avatars.githubusercontent.com/u/37784886"] + icons: ["https://avatars.githubusercontent.com/u/37784886"], + redirect: AppMetadata.Redirect(native: "dapp://", universal: nil) ) WalletConnectModal.configure( diff --git a/Example/DApp/Sign/Connect/ConnectViewController.swift b/Example/DApp/Sign/Connect/ConnectViewController.swift index d69bc4739..59fae59ec 100644 --- a/Example/DApp/Sign/Connect/ConnectViewController.swift +++ b/Example/DApp/Sign/Connect/ConnectViewController.swift @@ -62,7 +62,7 @@ class ConnectViewController: UIViewController, UITableViewDataSource, UITableVie } @objc func connectWithExampleWallet() { - let url = URL(string: "walletapp://wc?uri=\(uri.deeplinkUri)")! + let url = URL(string: "walletapp://wc?uri=\(uri.deeplinkUri.removingPercentEncoding!)")! DispatchQueue.main.async { UIApplication.shared.open(url, options: [:]) { [weak self] _ in self?.dismiss(animated: true, completion: nil) diff --git a/Example/DApp/Sign/SignCoordinator.swift b/Example/DApp/Sign/SignCoordinator.swift index 763cd2463..23e0a1011 100644 --- a/Example/DApp/Sign/SignCoordinator.swift +++ b/Example/DApp/Sign/SignCoordinator.swift @@ -24,7 +24,9 @@ final class SignCoordinator { name: "Swift Dapp", description: "WalletConnect DApp sample", url: "wallet.connect", - icons: ["https://avatars.githubusercontent.com/u/37784886"]) + icons: ["https://avatars.githubusercontent.com/u/37784886"], + redirect: AppMetadata.Redirect(native: "dapp://", universal: nil) + ) Pair.configure(metadata: metadata) #if DEBUG diff --git a/Example/ExampleApp.xcodeproj/project.pbxproj b/Example/ExampleApp.xcodeproj/project.pbxproj index 4cecf980f..5f3a5bfe7 100644 --- a/Example/ExampleApp.xcodeproj/project.pbxproj +++ b/Example/ExampleApp.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -231,6 +231,7 @@ A74D32BA2A1E25AD00CB8536 /* QueryParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74D32B92A1E25AD00CB8536 /* QueryParameters.swift */; }; C5133A78294125CC00A8314C /* Web3 in Frameworks */ = {isa = PBXBuildFile; productRef = C5133A77294125CC00A8314C /* Web3 */; }; C53AA4362941251C008EA57C /* DefaultSignerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59CF4F5292F83D50031A42F /* DefaultSignerFactory.swift */; }; + C54C24902AEB1B5600DA4BF6 /* WalletConnectRouter in Frameworks */ = {isa = PBXBuildFile; productRef = C54C248F2AEB1B5600DA4BF6 /* WalletConnectRouter */; }; C55D347F295DD7140004314A /* AuthRequestModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55D347A295DD7140004314A /* AuthRequestModule.swift */; }; C55D3480295DD7140004314A /* AuthRequestPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55D347B295DD7140004314A /* AuthRequestPresenter.swift */; }; C55D3481295DD7140004314A /* AuthRequestRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55D347C295DD7140004314A /* AuthRequestRouter.swift */; }; @@ -750,6 +751,7 @@ C56EE255293F569A004840D1 /* Starscream in Frameworks */, A5B6C0F52A6EAB2800927332 /* WalletConnectNotify in Frameworks */, C56EE27B293F56F8004840D1 /* WalletConnectAuth in Frameworks */, + C54C24902AEB1B5600DA4BF6 /* WalletConnectRouter in Frameworks */, 84943C7D2A9BA328007EBAC2 /* Mixpanel in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2058,6 +2060,7 @@ 84943C7C2A9BA328007EBAC2 /* Mixpanel */, A59D25ED2AB3672700D7EA3A /* AsyncButton */, A5F1526E2ACDC46B00D745A6 /* Web3ModalUI */, + C54C248F2AEB1B5600DA4BF6 /* WalletConnectRouter */, ); productName = ChatWallet; productReference = C56EE21B293F55ED004840D1 /* WalletApp.app */; @@ -3449,6 +3452,10 @@ package = A5AE354528A1A2AC0059AE8A /* XCRemoteSwiftPackageReference "Web3" */; productName = Web3; }; + C54C248F2AEB1B5600DA4BF6 /* WalletConnectRouter */ = { + isa = XCSwiftPackageProductDependency; + productName = WalletConnectRouter; + }; C55D349829630D440004314A /* Web3Wallet */ = { isa = XCSwiftPackageProductDependency; productName = Web3Wallet; diff --git a/Example/WalletApp/ApplicationLayer/ConfigurationService.swift b/Example/WalletApp/ApplicationLayer/ConfigurationService.swift index a8ca2992a..4e5f57c3e 100644 --- a/Example/WalletApp/ApplicationLayer/ConfigurationService.swift +++ b/Example/WalletApp/ApplicationLayer/ConfigurationService.swift @@ -13,7 +13,8 @@ final class ConfigurationService { name: "Example Wallet", description: "wallet description", url: "example.wallet", - icons: ["https://avatars.githubusercontent.com/u/37784886"] + icons: ["https://avatars.githubusercontent.com/u/37784886"], + redirect: AppMetadata.Redirect(native: "walletapp://", universal: nil) ) Web3Wallet.configure(metadata: metadata, crypto: DefaultCryptoProvider(), environment: BuildConfiguration.shared.apnsEnvironment) diff --git a/Example/WalletApp/PresentationLayer/Wallet/AuthRequest/AuthRequestInteractor.swift b/Example/WalletApp/PresentationLayer/Wallet/AuthRequest/AuthRequestInteractor.swift index 15d6b651c..30edde7f2 100644 --- a/Example/WalletApp/PresentationLayer/Wallet/AuthRequest/AuthRequestInteractor.swift +++ b/Example/WalletApp/PresentationLayer/Wallet/AuthRequest/AuthRequestInteractor.swift @@ -1,5 +1,7 @@ import Foundation + import Web3Wallet +import WalletConnectRouter final class AuthRequestInteractor { @@ -16,10 +18,16 @@ final class AuthRequestInteractor { privateKey: Data(hex: importAccount.privateKey), type: .eip191) try await Web3Wallet.instance.respond(requestId: request.id, signature: signature, from: account) + + /* Redirect */ + WalletConnectRouter.goBack(uri: request.requester.redirect.native) } func reject(request: AuthRequest) async throws { try await Web3Wallet.instance.reject(requestId: request.id) + + /* Redirect */ + WalletConnectRouter.goBack(uri: request.requester.redirect.native) } func formatted(request: AuthRequest, account: Account) -> String { diff --git a/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift b/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift index 0216a3db6..e27b8ee7d 100644 --- a/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift +++ b/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift @@ -1,6 +1,7 @@ import Foundation import Web3Wallet +import WalletConnectRouter final class SessionProposalInteractor { func approve(proposal: Session.Proposal, account: Account) async throws { @@ -28,9 +29,15 @@ final class SessionProposalInteractor { accounts: supportedAccounts ) try await Web3Wallet.instance.approve(proposalId: proposal.id, namespaces: sessionNamespaces, sessionProperties: proposal.sessionProperties) + + /* Redirect */ + WalletConnectRouter.goBack(uri: proposal.proposer.redirect.native) } func reject(proposal: Session.Proposal) async throws { try await Web3Wallet.instance.reject(proposalId: proposal.id, reason: .userRejected) + + /* Redirect */ + WalletConnectRouter.goBack(uri: proposal.proposer.redirect.native) } } diff --git a/Example/WalletApp/PresentationLayer/Wallet/SessionRequest/SessionRequestInteractor.swift b/Example/WalletApp/PresentationLayer/Wallet/SessionRequest/SessionRequestInteractor.swift index 97816ea69..707e1ee57 100644 --- a/Example/WalletApp/PresentationLayer/Wallet/SessionRequest/SessionRequestInteractor.swift +++ b/Example/WalletApp/PresentationLayer/Wallet/SessionRequest/SessionRequestInteractor.swift @@ -1,5 +1,7 @@ import Foundation + import Web3Wallet +import WalletConnectRouter final class SessionRequestInteractor { func approve(sessionRequest: Request, importAccount: ImportAccount) async throws { @@ -10,6 +12,12 @@ final class SessionRequestInteractor { requestId: sessionRequest.id, response: .response(result) ) + + /* Redirect */ + let session = getSession(topic: sessionRequest.topic) + if let uri = session?.peer.redirect.native { + WalletConnectRouter.goBack(uri: uri) + } } catch { throw error } @@ -21,6 +29,12 @@ final class SessionRequestInteractor { requestId: sessionRequest.id, response: .error(.init(code: 0, message: "")) ) + + /* Redirect */ + let session = getSession(topic: sessionRequest.topic) + if let uri = session?.peer.redirect.native { + WalletConnectRouter.goBack(uri: uri) + } } func getSession(topic: String) -> Session? { diff --git a/Package.swift b/Package.swift index edc0d65fe..f10f706a0 100644 --- a/Package.swift +++ b/Package.swift @@ -33,7 +33,7 @@ let package = Package( targets: ["WalletConnectPush"]), .library( name: "WalletConnectRouter", - targets: ["WalletConnectRouter"]), + targets: ["WalletConnectRouter", "WalletConnectRouterLegacy"]), .library( name: "WalletConnectNetworking", targets: ["WalletConnectNetworking"]), @@ -121,7 +121,12 @@ let package = Package( dependencies: ["HTTPClient", "WalletConnectRelay"]), .target( name: "WalletConnectRouter", - dependencies: []), + dependencies: [], + path: "Sources/WalletConnectRouter/Router"), + .target( + name: "WalletConnectRouterLegacy", + dependencies: [], + path: "Sources/WalletConnectRouter/RouterLegacy"), .target( name: "WalletConnectVerify", dependencies: ["WalletConnectUtils", "WalletConnectNetworking"]), diff --git a/Sources/Auth/Services/Wallet/PendingRequestsProvider.swift b/Sources/Auth/Services/Wallet/PendingRequestsProvider.swift index b351be66a..c824760b9 100644 --- a/Sources/Auth/Services/Wallet/PendingRequestsProvider.swift +++ b/Sources/Auth/Services/Wallet/PendingRequestsProvider.swift @@ -17,7 +17,7 @@ class PendingRequestsProvider { .filter {$0.request.method == "wc_authRequest"} .compactMap { guard let params = try? $0.request.params?.get(AuthRequestParams.self) else { return nil } - return AuthRequest(id: $0.request.id!, topic: $0.topic, payload: params.payloadParams) + return AuthRequest(id: $0.request.id!, topic: $0.topic, payload: params.payloadParams, requester: params.requester.metadata) } return pendingRequests.map { ($0, try? verifyContextStore.get(key: $0.id.string)) } diff --git a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift index af26070ab..95d71799e 100644 --- a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift +++ b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift @@ -36,10 +36,10 @@ class WalletRequestSubscriber { pairingRegisterer.register(method: AuthRequestProtocolMethod()) .sink { [unowned self] (payload: RequestSubscriptionPayload) in logger.debug("WalletRequestSubscriber: Received request") - + pairingRegisterer.setReceived(pairingTopic: payload.topic) - let request = AuthRequest(id: payload.id, topic: payload.topic, payload: payload.request.payloadParams) + let request = AuthRequest(id: payload.id, topic: payload.topic, payload: payload.request.payloadParams, requester: payload.request.requester.metadata) Task(priority: .high) { let assertionId = payload.decryptedPayload.sha256().toHexString() diff --git a/Sources/Auth/Types/Public/AuthRequest.swift b/Sources/Auth/Types/Public/AuthRequest.swift index 4cee66bb1..e796d75cf 100644 --- a/Sources/Auth/Types/Public/AuthRequest.swift +++ b/Sources/Auth/Types/Public/AuthRequest.swift @@ -4,4 +4,5 @@ public struct AuthRequest: Equatable, Codable { public let id: RPCID public let topic: String public let payload: AuthPayload + public let requester: AppMetadata } diff --git a/Sources/WalletConnectModal/Modal/Modal+Previews.swift b/Sources/WalletConnectModal/Modal/Modal+Previews.swift index 619db6408..74e370ba5 100644 --- a/Sources/WalletConnectModal/Modal/Modal+Previews.swift +++ b/Sources/WalletConnectModal/Modal/Modal+Previews.swift @@ -38,7 +38,8 @@ struct ModalContainerView_Previews: PreviewProvider { name: "Showcase App", description: "Showcase description", url: "example.wallet", - icons: ["https://avatars.githubusercontent.com/u/37784886"] + icons: ["https://avatars.githubusercontent.com/u/37784886"], + redirect: AppMetadata.Redirect(native: "showcase://", universal: nil) ) Networking.configure(projectId: projectId, socketFactory: WebSocketFactoryMock()) diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift index f9579ba6c..f7b3a1dae 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift @@ -26,10 +26,10 @@ struct NotifyConfig: Codable { var metadata: AppMetadata { return AppMetadata( name: name, - description: - description, + description: description, url: appDomain, - icons: [image_url?.sm, image_url?.md, image_url?.lg].compactMap { $0 } + icons: [image_url?.sm, image_url?.md, image_url?.lg].compactMap { $0 }, + redirect: AppMetadata.Redirect(native: "", universal: nil) ) } } diff --git a/Sources/WalletConnectPairing/Types/AppMetadata.swift b/Sources/WalletConnectPairing/Types/AppMetadata.swift index fc17bfaf6..726f090bc 100644 --- a/Sources/WalletConnectPairing/Types/AppMetadata.swift +++ b/Sources/WalletConnectPairing/Types/AppMetadata.swift @@ -13,7 +13,7 @@ public struct AppMetadata: Codable, Equatable { public struct Redirect: Codable, Equatable { /// Native deeplink URL string. - public let native: String? + public let native: String /// Universal link URL string. public let universal: String? @@ -25,7 +25,7 @@ public struct AppMetadata: Codable, Equatable { - native: Native deeplink URL string. - universal: Universal link URL string. */ - public init(native: String?, universal: String?) { + public init(native: String, universal: String?) { self.native = native self.universal = universal } @@ -44,7 +44,7 @@ public struct AppMetadata: Codable, Equatable { public let icons: [String] /// Redirect links which could be manually used on wallet side. - public let redirect: Redirect? + public let redirect: Redirect /** Creates a new metadata object with the specified information. @@ -61,7 +61,7 @@ public struct AppMetadata: Codable, Equatable { description: String, url: String, icons: [String], - redirect: Redirect? = nil + redirect: Redirect ) { self.name = name self.description = description diff --git a/Sources/WalletConnectRouter/Router/Router.swift b/Sources/WalletConnectRouter/Router/Router.swift new file mode 100644 index 000000000..8f2035dd1 --- /dev/null +++ b/Sources/WalletConnectRouter/Router/Router.swift @@ -0,0 +1,9 @@ +import UIKit + +public struct WalletConnectRouter { + public static func goBack(uri: String) { + DispatchQueue.main.async { + UIApplication.shared.open(URL(string: uri)!) + } + } +} diff --git a/Sources/WalletConnectRouter/Router.m b/Sources/WalletConnectRouter/RouterLegacy/Router.m similarity index 100% rename from Sources/WalletConnectRouter/Router.m rename to Sources/WalletConnectRouter/RouterLegacy/Router.m diff --git a/Sources/WalletConnectRouter/include/Router.h b/Sources/WalletConnectRouter/RouterLegacy/include/Router.h similarity index 100% rename from Sources/WalletConnectRouter/include/Router.h rename to Sources/WalletConnectRouter/RouterLegacy/include/Router.h diff --git a/Sources/WalletConnectRouter/include/module.modulemap b/Sources/WalletConnectRouter/RouterLegacy/include/module.modulemap similarity index 100% rename from Sources/WalletConnectRouter/include/module.modulemap rename to Sources/WalletConnectRouter/RouterLegacy/include/module.modulemap diff --git a/Sources/WalletConnectUtils/WalletConnectURI.swift b/Sources/WalletConnectUtils/WalletConnectURI.swift index 2e16a652d..2f068a67f 100644 --- a/Sources/WalletConnectUtils/WalletConnectURI.swift +++ b/Sources/WalletConnectUtils/WalletConnectURI.swift @@ -47,8 +47,9 @@ public struct WalletConnectURI: Equatable { public init?(deeplinkUri: URL) { if let deeplinkUri = deeplinkUri.query?.replacingOccurrences(of: "uri=", with: "") { self.init(string: deeplinkUri) + } else { + return nil } - return nil } private var relayQuery: String { @@ -76,15 +77,17 @@ extension WalletConnectURI { public init?(connectionOptions: UIScene.ConnectionOptions) { if let uri = connectionOptions.urlContexts.first?.url.query?.replacingOccurrences(of: "uri=", with: "") { self.init(string: uri) + } else { + return nil } - return nil } public init?(urlContext: UIOpenURLContext) { if let uri = urlContext.url.query?.replacingOccurrences(of: "uri=", with: "") { self.init(string: uri) + } else { + return nil } - return nil } } diff --git a/Tests/Web3WalletTests/Mocks/AuthClientMock.swift b/Tests/Web3WalletTests/Mocks/AuthClientMock.swift index a2cde013d..0aebde8d7 100644 --- a/Tests/Web3WalletTests/Mocks/AuthClientMock.swift +++ b/Tests/Web3WalletTests/Mocks/AuthClientMock.swift @@ -23,7 +23,8 @@ final class AuthClientMock: AuthClientProtocol { return AuthRequest( id: .left(""), topic: "", - payload: AuthPayload(requestParams: requestParams, iat: "") + payload: AuthPayload(requestParams: requestParams, iat: ""), + requester: AppMetadata(name: "", description: "", url: "", icons: []) ) } From ce810edf2cf33780db86ac7ddd26030642db3479 Mon Sep 17 00:00:00 2001 From: Alexander Lisovik Date: Mon, 30 Oct 2023 12:30:11 +0400 Subject: [PATCH 2/5] Update tests --- Example/IntegrationTests/Auth/AuthTests.swift | 2 +- .../Pairing/PairingTests.swift | 4 +- .../Sign/SignClientTests.swift | 20 ++--- Example/IntegrationTests/Stubs/Stubs.swift | 3 +- .../Web3Wallet/XPlatformW3WTests.swift | 4 +- Tests/AuthTests/Mocks/AppMetadata.swift | 3 +- .../Stubs/RequestSubscriptionPayload.swift | 2 +- .../TestingUtils/Stubs/AppMetadata+Stub.swift | 3 +- .../AutoNamespacesValidationTests.swift | 84 +++++++++---------- .../Mocks/AuthClientMock.swift | 2 +- .../Mocks/SignClientMock.swift | 6 +- 11 files changed, 68 insertions(+), 65 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 5ab58d0ad..276e14e84 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -55,7 +55,7 @@ final class AuthTests: XCTestCase { networkingClient: networkingClient) let authClient = AuthClientFactory.create( - metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), + metadata: AppMetadata(name: name, description: "", url: "", icons: [""], redirect: AppMetadata.Redirect(native: "", universal: nil)), projectId: InputConfig.projectId, crypto: DefaultCryptoProvider(), logger: logger, diff --git a/Example/IntegrationTests/Pairing/PairingTests.swift b/Example/IntegrationTests/Pairing/PairingTests.swift index f7ade4b87..af668e8c5 100644 --- a/Example/IntegrationTests/Pairing/PairingTests.swift +++ b/Example/IntegrationTests/Pairing/PairingTests.swift @@ -63,7 +63,7 @@ final class PairingTests: XCTestCase { appPairingClient = pairingClient appAuthClient = AuthClientFactory.create( - metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), + metadata: AppMetadata(name: name, description: "", url: "", icons: [""], redirect: AppMetadata.Redirect(native: "dapp://", universal: nil)), projectId: InputConfig.projectId, crypto: DefaultCryptoProvider(), logger: notifyLogger, @@ -88,7 +88,7 @@ final class PairingTests: XCTestCase { logger: notifyLogger ) appAuthClient = AuthClientFactory.create( - metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), + metadata: AppMetadata(name: name, description: "", url: "", icons: [""], redirect: AppMetadata.Redirect(native: "", universal: nil)), projectId: InputConfig.projectId, crypto: DefaultCryptoProvider(), logger: notifyLogger, diff --git a/Example/IntegrationTests/Sign/SignClientTests.swift b/Example/IntegrationTests/Sign/SignClientTests.swift index d28ae7c11..f6e0a9dd8 100644 --- a/Example/IntegrationTests/Sign/SignClientTests.swift +++ b/Example/IntegrationTests/Sign/SignClientTests.swift @@ -37,7 +37,7 @@ final class SignClientTests: XCTestCase { networkingClient: networkingClient ) let client = SignClientFactory.create( - metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), + metadata: AppMetadata(name: name, description: "", url: "", icons: [""], redirect: AppMetadata.Redirect(native: "", universal: nil)), logger: logger, keyValueStorage: keyValueStorage, keychainStorage: keychain, @@ -437,7 +437,7 @@ final class SignClientTests: XCTestCase { requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try AutoNamespaces.build( @@ -505,11 +505,11 @@ final class SignClientTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try AutoNamespaces.build( @@ -563,11 +563,11 @@ final class SignClientTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try AutoNamespaces.build( @@ -629,11 +629,11 @@ final class SignClientTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) do { @@ -692,11 +692,11 @@ final class SignClientTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) do { diff --git a/Example/IntegrationTests/Stubs/Stubs.swift b/Example/IntegrationTests/Stubs/Stubs.swift index 8b815a474..555206db2 100644 --- a/Example/IntegrationTests/Stubs/Stubs.swift +++ b/Example/IntegrationTests/Stubs/Stubs.swift @@ -29,7 +29,8 @@ extension AppMetadata { name: "WalletConnectSwift", description: "WalletConnectSwift", url: "https://walletconnect.com", - icons: [] + icons: [], + redirect: AppMetadata.Redirect(native: "dapp://", universal: nil) ) } } diff --git a/Example/IntegrationTests/XPlatform/Web3Wallet/XPlatformW3WTests.swift b/Example/IntegrationTests/XPlatform/Web3Wallet/XPlatformW3WTests.swift index e08391021..3d794d18a 100644 --- a/Example/IntegrationTests/XPlatform/Web3Wallet/XPlatformW3WTests.swift +++ b/Example/IntegrationTests/XPlatform/Web3Wallet/XPlatformW3WTests.swift @@ -49,7 +49,7 @@ final class XPlatformW3WTests: XCTestCase { networkingClient: networkingClient) let signClient = SignClientFactory.create( - metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), + metadata: AppMetadata(name: name, description: "", url: "", icons: [""], redirect: AppMetadata.Redirect(native: "", universal: nil)), logger: signLogger, keyValueStorage: keyValueStorage, keychainStorage: keychain, @@ -58,7 +58,7 @@ final class XPlatformW3WTests: XCTestCase { ) let authClient = AuthClientFactory.create( - metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), + metadata: AppMetadata(name: name, description: "", url: "", icons: [""], redirect: AppMetadata.Redirect(native: "", universal: nil)), projectId: InputConfig.projectId, crypto: DefaultCryptoProvider(), logger: authLogger, diff --git a/Tests/AuthTests/Mocks/AppMetadata.swift b/Tests/AuthTests/Mocks/AppMetadata.swift index 75d48acb1..ffa368454 100644 --- a/Tests/AuthTests/Mocks/AppMetadata.swift +++ b/Tests/AuthTests/Mocks/AppMetadata.swift @@ -7,7 +7,8 @@ public extension AppMetadata { name: "Wallet Connect", description: "A protocol to connect blockchain wallets to dapps.", url: "https://walletconnect.com/", - icons: [] + icons: [], + redirect: AppMetadata.Redirect(native: "", universal: nil) ) } } diff --git a/Tests/AuthTests/Stubs/RequestSubscriptionPayload.swift b/Tests/AuthTests/Stubs/RequestSubscriptionPayload.swift index baf9546bf..af2d8dd89 100644 --- a/Tests/AuthTests/Stubs/RequestSubscriptionPayload.swift +++ b/Tests/AuthTests/Stubs/RequestSubscriptionPayload.swift @@ -5,7 +5,7 @@ import WalletConnectNetworking extension AuthRequestParams { static func stub(id: RPCID, iat: String) -> AuthRequestParams { - let appMetadata = AppMetadata(name: "", description: "", url: "", icons: []) + let appMetadata = AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)) let requester = AuthRequestParams.Requester(publicKey: "", metadata: appMetadata) let payload = AuthPayload(requestParams: RequestParams.stub(), iat: iat) return AuthRequestParams(requester: requester, payloadParams: payload) diff --git a/Tests/TestingUtils/Stubs/AppMetadata+Stub.swift b/Tests/TestingUtils/Stubs/AppMetadata+Stub.swift index 75d48acb1..ffa368454 100644 --- a/Tests/TestingUtils/Stubs/AppMetadata+Stub.swift +++ b/Tests/TestingUtils/Stubs/AppMetadata+Stub.swift @@ -7,7 +7,8 @@ public extension AppMetadata { name: "Wallet Connect", description: "A protocol to connect blockchain wallets to dapps.", url: "https://walletconnect.com/", - icons: [] + icons: [], + redirect: AppMetadata.Redirect(native: "", universal: nil) ) } } diff --git a/Tests/WalletConnectSignTests/AutoNamespacesValidationTests.swift b/Tests/WalletConnectSignTests/AutoNamespacesValidationTests.swift index 5dd2e2d58..1942c9d75 100644 --- a/Tests/WalletConnectSignTests/AutoNamespacesValidationTests.swift +++ b/Tests/WalletConnectSignTests/AutoNamespacesValidationTests.swift @@ -21,11 +21,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -67,11 +67,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -113,11 +113,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -163,11 +163,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -218,11 +218,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -271,11 +271,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -325,11 +325,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -374,11 +374,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -423,11 +423,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -473,11 +473,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -528,11 +528,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -588,11 +588,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) XCTAssertThrowsError( try AutoNamespaces.build( @@ -631,11 +631,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) XCTAssertThrowsError( try AutoNamespaces.build( @@ -668,11 +668,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) XCTAssertThrowsError( try AutoNamespaces.build( @@ -705,11 +705,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) XCTAssertThrowsError( try AutoNamespaces.build( @@ -742,11 +742,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) XCTAssertThrowsError( try AutoNamespaces.build( @@ -783,11 +783,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) XCTAssertThrowsError( try AutoNamespaces.build( @@ -820,11 +820,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -867,11 +867,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -914,11 +914,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, @@ -966,11 +966,11 @@ final class AutoNamespacesValidationTests: XCTestCase { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) let sessionNamespaces = try! AutoNamespaces.build( sessionProposal: sessionProposal, diff --git a/Tests/Web3WalletTests/Mocks/AuthClientMock.swift b/Tests/Web3WalletTests/Mocks/AuthClientMock.swift index 0aebde8d7..b7956eeda 100644 --- a/Tests/Web3WalletTests/Mocks/AuthClientMock.swift +++ b/Tests/Web3WalletTests/Mocks/AuthClientMock.swift @@ -24,7 +24,7 @@ final class AuthClientMock: AuthClientProtocol { id: .left(""), topic: "", payload: AuthPayload(requestParams: requestParams, iat: ""), - requester: AppMetadata(name: "", description: "", url: "", icons: []) + requester: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)) ) } diff --git a/Tests/Web3WalletTests/Mocks/SignClientMock.swift b/Tests/Web3WalletTests/Mocks/SignClientMock.swift index 62ba27489..e14d222c4 100644 --- a/Tests/Web3WalletTests/Mocks/SignClientMock.swift +++ b/Tests/Web3WalletTests/Mocks/SignClientMock.swift @@ -16,7 +16,7 @@ final class SignClientMock: SignClientProtocol { var connectCalled = false var requestCalled = false - private let metadata = AppMetadata(name: "", description: "", url: "", icons: []) + private let metadata = AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)) private let request = WalletConnectSign.Request(id: .left(""), topic: "", method: "", params: "", chainId: Blockchain("eip155:1")!, expiry: nil) private let response = WalletConnectSign.Response(id: RPCID(1234567890123456789), topic: "", chainId: "", result: .response(AnyCodable(any: ""))) @@ -74,11 +74,11 @@ final class SignClientMock: SignClientProtocol { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: [:], optionalNamespaces: nil, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) return Result.Publisher((sessionProposal, SignReasonCode.userRejectedChains)) From 1401fd2ef2886d450edd4cdaba631d292b228a9f Mon Sep 17 00:00:00 2001 From: Alexander Lisovik Date: Mon, 30 Oct 2023 12:34:17 +0400 Subject: [PATCH 3/5] Update tests --- .../Mocks/ModalSheetInteractorMock.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift b/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift index 37d653d8e..450297eeb 100644 --- a/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift +++ b/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift @@ -30,11 +30,11 @@ final class ModalSheetInteractorMock: ModalSheetInteractor { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: []), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: ni;)), requiredNamespaces: [:], optionalNamespaces: nil, sessionProperties: nil, - proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) + proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil))), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:]) ) return Result.Publisher((sessionProposal, SignReasonCode.userRejectedChains)) From b0affcc894a60298a11dc9bcfefac8f3128b4f81 Mon Sep 17 00:00:00 2001 From: Alexander Lisovik Date: Mon, 30 Oct 2023 12:36:51 +0400 Subject: [PATCH 4/5] Update tests --- .../Mocks/ModalSheetInteractorMock.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift b/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift index 450297eeb..182e50d0f 100644 --- a/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift +++ b/Tests/WalletConnectModalTests/Mocks/ModalSheetInteractorMock.swift @@ -30,7 +30,7 @@ final class ModalSheetInteractorMock: ModalSheetInteractor { let sessionProposal = Session.Proposal( id: "", pairingTopic: "", - proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: ni;)), + proposer: AppMetadata(name: "", description: "", url: "", icons: [], redirect: AppMetadata.Redirect(native: "", universal: nil)), requiredNamespaces: [:], optionalNamespaces: nil, sessionProperties: nil, From 56aa06f2ca305b799da0aaa2ef95ebe9d6e2304f Mon Sep 17 00:00:00 2001 From: Alexander Lisovik Date: Mon, 30 Oct 2023 20:13:44 +0400 Subject: [PATCH 5/5] Update router --- Package.swift | 8 ++++---- Sources/WalletConnectRouter/Router/Router.swift | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index f10f706a0..b4c69b94b 100644 --- a/Package.swift +++ b/Package.swift @@ -119,14 +119,14 @@ let package = Package( .target( name: "WalletConnectNetworking", dependencies: ["HTTPClient", "WalletConnectRelay"]), - .target( - name: "WalletConnectRouter", - dependencies: [], - path: "Sources/WalletConnectRouter/Router"), .target( name: "WalletConnectRouterLegacy", dependencies: [], path: "Sources/WalletConnectRouter/RouterLegacy"), + .target( + name: "WalletConnectRouter", + dependencies: ["WalletConnectRouterLegacy"], + path: "Sources/WalletConnectRouter/Router"), .target( name: "WalletConnectVerify", dependencies: ["WalletConnectUtils", "WalletConnectNetworking"]), diff --git a/Sources/WalletConnectRouter/Router/Router.swift b/Sources/WalletConnectRouter/Router/Router.swift index 8f2035dd1..b97566675 100644 --- a/Sources/WalletConnectRouter/Router/Router.swift +++ b/Sources/WalletConnectRouter/Router/Router.swift @@ -1,9 +1,17 @@ import UIKit +@_exported import WalletConnectRouter + public struct WalletConnectRouter { public static func goBack(uri: String) { - DispatchQueue.main.async { - UIApplication.shared.open(URL(string: uri)!) + if #available(iOS 17, *) { + DispatchQueue.main.async { + if let url = URL(string: uri) { + UIApplication.shared.open(url) + } + } + } else { + Router.goBack() } } }