From b76d84ff6fe7c4b8b14e109419a24ec43ab771c9 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 20 Sep 2023 16:45:19 +0300 Subject: [PATCH 1/2] add notify host from env var --- Example/IntegrationTests/Push/NotifyTests.swift | 17 +++++++++-------- Example/IntegrationTests/Push/Publisher.swift | 10 +--------- Example/Shared/Tests/InputConfig.swift | 8 ++++---- .../Client/Wallet/NotifyClientFactory.swift | 10 ++++++---- .../NotifyWatchSubscriptionsRequester.swift | 10 ++++++---- Sources/WalletConnectNotify/Notify.swift | 7 ++++--- Sources/WalletConnectNotify/NotifyConfig.swift | 1 + 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Example/IntegrationTests/Push/NotifyTests.swift b/Example/IntegrationTests/Push/NotifyTests.swift index 36c7f82b8..06f5eed3a 100644 --- a/Example/IntegrationTests/Push/NotifyTests.swift +++ b/Example/IntegrationTests/Push/NotifyTests.swift @@ -74,14 +74,15 @@ final class NotifyTests: XCTestCase { environment: .sandbox) let keyserverURL = URL(string: "https://keys.walletconnect.com")! let client = NotifyClientFactory.create(keyserverURL: keyserverURL, - logger: notifyLogger, - keyValueStorage: keyValueStorage, - keychainStorage: keychain, - groupKeychainStorage: KeychainStorageMock(), - networkInteractor: networkingInteractor, - pairingRegisterer: pairingClient, - pushClient: pushClient, - crypto: DefaultCryptoProvider()) + logger: notifyLogger, + keyValueStorage: keyValueStorage, + keychainStorage: keychain, + groupKeychainStorage: KeychainStorageMock(), + networkInteractor: networkingInteractor, + pairingRegisterer: pairingClient, + pushClient: pushClient, + crypto: DefaultCryptoProvider(), + notifyHost: InputConfig.notifyHost) return client } diff --git a/Example/IntegrationTests/Push/Publisher.swift b/Example/IntegrationTests/Push/Publisher.swift index 6908ec50b..4b7165793 100644 --- a/Example/IntegrationTests/Push/Publisher.swift +++ b/Example/IntegrationTests/Push/Publisher.swift @@ -3,15 +3,7 @@ import Foundation class Publisher { func notify(topic: String, account: Account, message: NotifyMessage) async throws { - let url = URL(string: "https://\(InputConfig.castHost)/\(InputConfig.gmDappProjectId)/notify")! - print("________________________________________") - print("________________________________________") - print("________________________________________") - print(InputConfig.gmDappHost) - print("________________________________________") - print("________________________________________") - print("________________________________________") - + let url = URL(string: "https://\(InputConfig.notifyHost)/\(InputConfig.gmDappProjectId)/notify")! var request = URLRequest(url: url) let notifyRequestPayload = NotifyRequest(notification: message, accounts: [account]) let encoder = JSONEncoder() diff --git a/Example/Shared/Tests/InputConfig.swift b/Example/Shared/Tests/InputConfig.swift index 7f3dd03f5..b420b93b8 100644 --- a/Example/Shared/Tests/InputConfig.swift +++ b/Example/Shared/Tests/InputConfig.swift @@ -6,10 +6,6 @@ struct InputConfig { return config(for: "RELAY_HOST")! } - static var castHost: String { - return config(for: "CAST_HOST")! - } - static var gmDappProjectId: String { return config(for: "GM_DAPP_PROJECT_ID")! } @@ -26,6 +22,10 @@ struct InputConfig { return config(for: "JS_CLIENT_API_HOST")! } + static var notifyHost: String { + return config(for: "CAST_HOST")! + } + static var relayUrl: String { return "wss://\(relayHost)" } diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift index c38db543e..500d86291 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift @@ -2,7 +2,7 @@ import Foundation public struct NotifyClientFactory { - public static func create(groupIdentifier: String, networkInteractor: NetworkInteracting, pairingRegisterer: PairingRegisterer, pushClient: PushClient, crypto: CryptoProvider) -> NotifyClient { + public static func create(groupIdentifier: String, networkInteractor: NetworkInteracting, pairingRegisterer: PairingRegisterer, pushClient: PushClient, crypto: CryptoProvider, notifyHost: String) -> NotifyClient { let logger = ConsoleLogger(prefix: "🔔",loggingLevel: .debug) let keyValueStorage = UserDefaults.standard let keyserverURL = URL(string: "https://keys.walletconnect.com")! @@ -18,7 +18,8 @@ public struct NotifyClientFactory { networkInteractor: networkInteractor, pairingRegisterer: pairingRegisterer, pushClient: pushClient, - crypto: crypto + crypto: crypto, + notifyHost: notifyHost ) } @@ -31,7 +32,8 @@ public struct NotifyClientFactory { networkInteractor: NetworkInteracting, pairingRegisterer: PairingRegisterer, pushClient: PushClient, - crypto: CryptoProvider + crypto: CryptoProvider, + notifyHost: String ) -> NotifyClient { let kms = KeyManagementService(keychain: keychainStorage) let subscriptionStore = KeyedDatabase(storage: keyValueStorage, identifier: NotifyStorageIdntifiers.notifySubscription) @@ -56,7 +58,7 @@ public struct NotifyClientFactory { let subscriptionsAutoUpdater = SubscriptionsAutoUpdater(notifyUpdateRequester: notifyUpdateRequester, logger: logger, notifyStorage: notifyStorage) - let notifyWatchSubscriptionsRequester = NotifyWatchSubscriptionsRequester(keyserverURL: keyserverURL, networkingInteractor: networkInteractor, identityClient: identityClient, logger: logger, kms: kms, webDidResolver: webDidResolver) + let notifyWatchSubscriptionsRequester = NotifyWatchSubscriptionsRequester(keyserverURL: keyserverURL, networkingInteractor: networkInteractor, identityClient: identityClient, logger: logger, kms: kms, webDidResolver: webDidResolver, notifyHost: notifyHost) let notifySubscriptionsBuilder = NotifySubscriptionsBuilder(notifyConfigProvider: notifyConfigProvider) let notifyWatchSubscriptionsResponseSubscriber = NotifyWatchSubscriptionsResponseSubscriber(networkingInteractor: networkInteractor, kms: kms, logger: logger, notifyStorage: notifyStorage, groupKeychainStorage: groupKeychainStorage, notifySubscriptionsBuilder: notifySubscriptionsBuilder) let notifySubscriptionsChangedRequestSubscriber = NotifySubscriptionsChangedRequestSubscriber(keyserver: keyserverURL, networkingInteractor: networkInteractor, kms: kms, identityClient: identityClient, logger: logger, groupKeychainStorage: groupKeychainStorage, notifyStorage: notifyStorage, notifySubscriptionsBuilder: notifySubscriptionsBuilder) diff --git a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift index ef37767ac..ab65a9e0c 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift @@ -9,7 +9,7 @@ class NotifyWatchSubscriptionsRequester { private let kms: KeyManagementService private let logger: ConsoleLogging private let webDidResolver: NotifyWebDidResolver - private let notifyServerUrl = "notify.walletconnect.com" + private let notifyHost: String private var account: Account? private var publishers = Set() @@ -18,7 +18,8 @@ class NotifyWatchSubscriptionsRequester { identityClient: IdentityClient, logger: ConsoleLogging, kms: KeyManagementService, - webDidResolver: NotifyWebDidResolver + webDidResolver: NotifyWebDidResolver, + notifyHost: String ) { self.keyserverURL = keyserverURL self.identityClient = identityClient @@ -26,6 +27,7 @@ class NotifyWatchSubscriptionsRequester { self.logger = logger self.kms = kms self.webDidResolver = webDidResolver + self.notifyHost = notifyHost setUpWatchSubscriptionsOnSocketConnection() } @@ -49,8 +51,8 @@ class NotifyWatchSubscriptionsRequester { logger.debug("Watching subscriptions") - let notifyServerPublicKey = try await webDidResolver.resolveAgreementKey(domain: notifyServerUrl) - let notifyServerAuthenticationKey = try await webDidResolver.resolveAuthenticationKey(domain: notifyServerUrl) + let notifyServerPublicKey = try await webDidResolver.resolveAgreementKey(domain: notifyHost) + let notifyServerAuthenticationKey = try await webDidResolver.resolveAuthenticationKey(domain: notifyHost) let notifyServerAuthenticationDidKey = DIDKey(rawData: notifyServerAuthenticationKey) let watchSubscriptionsTopic = notifyServerPublicKey.rawRepresentation.sha256().toHexString() diff --git a/Sources/WalletConnectNotify/Notify.swift b/Sources/WalletConnectNotify/Notify.swift index 9b258d89f..44c178032 100644 --- a/Sources/WalletConnectNotify/Notify.swift +++ b/Sources/WalletConnectNotify/Notify.swift @@ -11,7 +11,8 @@ public class Notify { networkInteractor: Networking.interactor, pairingRegisterer: Pair.registerer, pushClient: Push.instance, - crypto: config.crypto + crypto: config.crypto, + notifyHost: config.notifyHost ) }() @@ -20,8 +21,8 @@ public class Notify { private init() { } /// Wallet's configuration method - static public func configure(pushHost: String = "echo.walletconnect.com", groupIdentifier: String, environment: APNSEnvironment, crypto: CryptoProvider) { - Notify.config = Notify.Config(pushHost: pushHost, groupIdentifier: groupIdentifier, environment: environment, crypto: crypto) + static public func configure(pushHost: String = "echo.walletconnect.com", groupIdentifier: String, environment: APNSEnvironment, crypto: CryptoProvider, notifyHost: String = "notify.walletconnect.com") { + Notify.config = Notify.Config(pushHost: pushHost, groupIdentifier: groupIdentifier, environment: environment, crypto: crypto, notifyHost: notifyHost) } } diff --git a/Sources/WalletConnectNotify/NotifyConfig.swift b/Sources/WalletConnectNotify/NotifyConfig.swift index 977f024f3..c7e699c03 100644 --- a/Sources/WalletConnectNotify/NotifyConfig.swift +++ b/Sources/WalletConnectNotify/NotifyConfig.swift @@ -6,5 +6,6 @@ extension Notify { let groupIdentifier: String let environment: APNSEnvironment let crypto: CryptoProvider + let notifyHost: String } } From d432511896110f7bbf8b3b9c53d2455c2ad1d81f Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 20 Sep 2023 14:05:49 +0000 Subject: [PATCH 2/2] Set User Agent --- Sources/WalletConnectRelay/PackageConfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WalletConnectRelay/PackageConfig.json b/Sources/WalletConnectRelay/PackageConfig.json index d9ac4532e..ad8897ff9 100644 --- a/Sources/WalletConnectRelay/PackageConfig.json +++ b/Sources/WalletConnectRelay/PackageConfig.json @@ -1 +1 @@ -{"version": "1.8.2"} +{"version": "1.8.3"}