From 5c8360a184802f5ffa3bcab4ea516c98bd273fe6 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Mon, 24 Oct 2022 22:04:17 +0600 Subject: [PATCH 1/8] Resolve latest packages versions --- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 01652b58f..0fbf7253f 100644 --- a/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/Boilertalk/secp256k1.swift.git", "state": { "branch": null, - "revision": "45e458ec3be46cf0a6eb68bc947f797852dc65d8", - "version": "0.1.6" + "revision": "cd187c632fb812fd93711a9f7e644adb7e5f97f0", + "version": "0.1.7" } }, { From 034266221e9fa7d8aec8ec3e1ff413a485ded984 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Tue, 25 Oct 2022 08:38:13 +0200 Subject: [PATCH 2/8] add derive data path --- .github/actions/ci/action.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/actions/ci/action.yml b/.github/actions/ci/action.yml index 44f9f0988..874175591 100644 --- a/.github/actions/ci/action.yml +++ b/.github/actions/ci/action.yml @@ -24,6 +24,7 @@ runs: -scheme WalletConnect \ -clonedSourcePackagesDirPath SourcePackagesCache \ -destination 'platform=iOS Simulator,name=iPhone 13' \ + -derivedDataPath ~/tmp/ddata \ test" # Integration tests @@ -37,7 +38,8 @@ runs: -project Example/ExampleApp.xcodeproj \ -scheme IntegrationTests \ -clonedSourcePackagesDirPath SourcePackagesCache \ - -destination 'platform=iOS Simulator,name=iPhone 13' \ + -destination 'platform=iOS Simulator,name=iPhone 13' \ + -derivedDataPath ~/tmp/ddata \ RELAY_HOST='$RELAY_ENDPOINT' \ PROJECT_ID='$PROJECT_ID' \ test" @@ -50,6 +52,7 @@ runs: -project Example/ExampleApp.xcodeproj \ -scheme Wallet \ -clonedSourcePackagesDirPath SourcePackagesCache \ + -derivedDataPath ~/tmp/ddata \ -sdk iphonesimulator" # DApp build @@ -60,6 +63,7 @@ runs: -project Example/ExampleApp.xcodeproj \ -scheme DApp \ -clonedSourcePackagesDirPath SourcePackagesCache \ + -derivedDataPath ~/tmp/ddata \ -sdk iphonesimulator" # UI tests @@ -69,6 +73,7 @@ runs: run: "xcodebuild \ -project Example/ExampleApp.xcodeproj \ -scheme UITests \ + -derivedDataPath ~/tmp/ddata \ -clonedSourcePackagesDirPath SourcePackagesCache \ -destination 'platform=iOS Simulator,name=iPhone 13' test" continue-on-error: true From 53f10b5c675a3e8dcc3c1b61d42f3bbf9df40139 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Tue, 25 Oct 2022 12:54:34 +0600 Subject: [PATCH 3/8] Derived data cache --- .github/actions/ci/action.yml | 10 +++++----- .github/workflows/ci.yml | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/actions/ci/action.yml b/.github/actions/ci/action.yml index 874175591..0e21edcae 100644 --- a/.github/actions/ci/action.yml +++ b/.github/actions/ci/action.yml @@ -24,7 +24,7 @@ runs: -scheme WalletConnect \ -clonedSourcePackagesDirPath SourcePackagesCache \ -destination 'platform=iOS Simulator,name=iPhone 13' \ - -derivedDataPath ~/tmp/ddata \ + -derivedDataPath DerivedDataCache \ test" # Integration tests @@ -39,7 +39,7 @@ runs: -scheme IntegrationTests \ -clonedSourcePackagesDirPath SourcePackagesCache \ -destination 'platform=iOS Simulator,name=iPhone 13' \ - -derivedDataPath ~/tmp/ddata \ + -derivedDataPath DerivedDataCache \ RELAY_HOST='$RELAY_ENDPOINT' \ PROJECT_ID='$PROJECT_ID' \ test" @@ -52,7 +52,7 @@ runs: -project Example/ExampleApp.xcodeproj \ -scheme Wallet \ -clonedSourcePackagesDirPath SourcePackagesCache \ - -derivedDataPath ~/tmp/ddata \ + -derivedDataPath DerivedDataCache \ -sdk iphonesimulator" # DApp build @@ -63,7 +63,7 @@ runs: -project Example/ExampleApp.xcodeproj \ -scheme DApp \ -clonedSourcePackagesDirPath SourcePackagesCache \ - -derivedDataPath ~/tmp/ddata \ + -derivedDataPath DerivedDataCache \ -sdk iphonesimulator" # UI tests @@ -73,7 +73,7 @@ runs: run: "xcodebuild \ -project Example/ExampleApp.xcodeproj \ -scheme UITests \ - -derivedDataPath ~/tmp/ddata \ + -derivedDataPath DerivedDataCache \ -clonedSourcePackagesDirPath SourcePackagesCache \ -destination 'platform=iOS Simulator,name=iPhone 13' test" continue-on-error: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b697507a..bf2b26eae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,7 @@ jobs: path: | .build SourcePackagesCache + DerivedDataCache key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} restore-keys: | ${{ runner.os }}-spm- From 23633e2023ae9d67e02f5a6af7a6cc1f0fcb9953 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Tue, 25 Oct 2022 12:06:02 +0200 Subject: [PATCH 4/8] - rename package - add instance wrapper --- Example/ExampleApp.xcodeproj/project.pbxproj | 4 ---- .../ApplicationLayer/Application.swift | 4 ++-- .../DomainLayer/Chat/ChatFactory.swift | 22 ------------------- .../DomainLayer/Chat/ChatService.swift | 10 ++++----- .../Chat/Chat/ChatInteractor.swift | 4 ++-- .../Chat/Chat/ChatModule.swift | 4 ++-- .../Chat/Chat/ChatPresenter.swift | 6 ++--- .../Chat/Chat/Models/MessageViewModel.swift | 6 ++--- .../Chat/ChatList/ChatListInteractor.swift | 6 ++--- .../Chat/ChatList/ChatListRouter.swift | 4 ++-- .../ChatList/Models/ThreadViewModel.swift | 4 ++-- .../InviteList/InviteListInteractor.swift | 2 +- .../Chat/InviteList/InviteListPresenter.swift | 2 +- .../InviteList/Models/InviteViewModel.swift | 2 +- Package.swift | 6 ++--- Sources/Chat/Chat.swift | 12 ++++++++++ Sources/Chat/ChatClientFactory.swift | 13 +++++++++++ 17 files changed, 55 insertions(+), 56 deletions(-) delete mode 100644 Example/Showcase/Classes/DomainLayer/Chat/ChatFactory.swift create mode 100644 Sources/Chat/Chat.swift diff --git a/Example/ExampleApp.xcodeproj/project.pbxproj b/Example/ExampleApp.xcodeproj/project.pbxproj index f0ef7ebf7..ffb400057 100644 --- a/Example/ExampleApp.xcodeproj/project.pbxproj +++ b/Example/ExampleApp.xcodeproj/project.pbxproj @@ -84,7 +84,6 @@ A5629AE42876E6D200094373 /* ThreadViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AE32876E6D200094373 /* ThreadViewModel.swift */; }; A5629AE828772A0100094373 /* InviteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AE728772A0100094373 /* InviteViewModel.swift */; }; A5629AEA2877F2D600094373 /* WalletConnectChat in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AE92877F2D600094373 /* WalletConnectChat */; }; - A5629AED2877F6A600094373 /* ChatFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AEC2877F6A600094373 /* ChatFactory.swift */; }; A5629AF02877F73000094373 /* SocketFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AEF2877F73000094373 /* SocketFactory.swift */; }; A5629AF22877F75100094373 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AF12877F75100094373 /* Starscream */; }; A578FA322873036400AA7720 /* InputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A578FA312873036400AA7720 /* InputView.swift */; }; @@ -277,7 +276,6 @@ A5629ADD2876CC6E00094373 /* InviteListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteListView.swift; sourceTree = ""; }; A5629AE32876E6D200094373 /* ThreadViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadViewModel.swift; sourceTree = ""; }; A5629AE728772A0100094373 /* InviteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteViewModel.swift; sourceTree = ""; }; - A5629AEC2877F6A600094373 /* ChatFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatFactory.swift; sourceTree = ""; }; A5629AEF2877F73000094373 /* SocketFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketFactory.swift; sourceTree = ""; }; A578FA312873036400AA7720 /* InputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputView.swift; sourceTree = ""; }; A578FA34287304A300AA7720 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; @@ -717,7 +715,6 @@ isa = PBXGroup; children = ( A5629AA82876A23100094373 /* ChatService.swift */, - A5629AEC2877F6A600094373 /* ChatFactory.swift */, A5C20225287EB099007E3188 /* AccountNameResolver.swift */, A5C2022C287EC3F0007E3188 /* RegisterService.swift */, ); @@ -1452,7 +1449,6 @@ A59EBEFA28B54A2A003EDAAF /* AuthRequestRouter.swift in Sources */, A5629AF02877F73000094373 /* SocketFactory.swift in Sources */, A55CAAB228B92AFF00844382 /* ScanRouter.swift in Sources */, - A5629AED2877F6A600094373 /* ChatFactory.swift in Sources */, A5C20221287EA5B8007E3188 /* TextFieldView.swift in Sources */, A5C2022B287EB89A007E3188 /* WelcomeInteractor.swift in Sources */, A5C2020C287D9DEE007E3188 /* WelcomePresenter.swift in Sources */, diff --git a/Example/Showcase/Classes/ApplicationLayer/Application.swift b/Example/Showcase/Classes/ApplicationLayer/Application.swift index bd59d3dd3..75d88c640 100644 --- a/Example/Showcase/Classes/ApplicationLayer/Application.swift +++ b/Example/Showcase/Classes/ApplicationLayer/Application.swift @@ -1,10 +1,10 @@ import Foundation -import Chat +import WalletConnectChat final class Application { lazy var chatService: ChatService = { - return ChatService(client: ChatFactory.create()) + return ChatService(client: Chat.instance) }() lazy var accountStorage: AccountStorage = { diff --git a/Example/Showcase/Classes/DomainLayer/Chat/ChatFactory.swift b/Example/Showcase/Classes/DomainLayer/Chat/ChatFactory.swift deleted file mode 100644 index 8b4e0c597..000000000 --- a/Example/Showcase/Classes/DomainLayer/Chat/ChatFactory.swift +++ /dev/null @@ -1,22 +0,0 @@ -import Foundation -import Chat -import WalletConnectNetworking -import WalletConnectRelay -import WalletConnectKMS -import WalletConnectUtils - -class ChatFactory { - - static func create() -> ChatClient { - let keychain = KeychainStorage(serviceIdentifier: "com.walletconnect.showcase") - let client = HTTPNetworkClient(host: "keys.walletconnect.com") - let registry = KeyserverRegistryProvider(client: client) - return ChatClientFactory.create( - registry: registry, - relayClient: Relay.instance, - kms: KeyManagementService(keychain: keychain), - logger: ConsoleLogger(), - keyValueStorage: UserDefaults.standard - ) - } -} diff --git a/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift b/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift index 75d7e59bb..a98e1902e 100644 --- a/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift +++ b/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift @@ -1,6 +1,6 @@ import Foundation import Combine -import Chat +import WalletConnectChat import WalletConnectRelay typealias Stream = AsyncPublisher> @@ -21,7 +21,7 @@ final class ChatService { return client.messagePublisher.values } - var threadPublisher: Stream { + var threadPublisher: Stream { return client.newThreadPublisher.values } @@ -29,15 +29,15 @@ final class ChatService { return client.invitePublisher.values } - func getMessages(thread: Chat.Thread) async -> [Chat.Message] { + func getMessages(thread: WalletConnectChat.Thread) async -> [WalletConnectChat.Message] { await client.getMessages(topic: thread.topic) } - func getThreads() async -> [Chat.Thread] { + func getThreads() async -> [WalletConnectChat.Thread] { await client.getThreads() } - func getInvites(account: Account) async -> [Chat.Invite] { + func getInvites(account: Account) async -> [WalletConnectChat.Invite] { client.getInvites(account: account) } diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatInteractor.swift b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatInteractor.swift index be6326054..466b2d102 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatInteractor.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatInteractor.swift @@ -1,5 +1,5 @@ import Foundation -import Chat +import WalletConnectChat final class ChatInteractor { @@ -9,7 +9,7 @@ final class ChatInteractor { self.chatService = chatService } - func getMessages(thread: Chat.Thread) async -> [Message] { + func getMessages(thread: WalletConnectChat.Thread) async -> [Message] { return await chatService.getMessages(thread: thread) } diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatModule.swift b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatModule.swift index 6cb3d854d..a58326276 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatModule.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatModule.swift @@ -1,10 +1,10 @@ import SwiftUI -import Chat +import WalletConnectChat final class ChatModule { @discardableResult - static func create(thread: Chat.Thread, app: Application) -> UIViewController { + static func create(thread: WalletConnectChat.Thread, app: Application) -> UIViewController { let router = ChatRouter(app: app) let interactor = ChatInteractor(chatService: app.chatService) let presenter = ChatPresenter(thread: thread, interactor: interactor, router: router) diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatPresenter.swift b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatPresenter.swift index 9e8996f45..3012bb953 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatPresenter.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/ChatPresenter.swift @@ -1,10 +1,10 @@ import UIKit import Combine -import Chat +import WalletConnectChat final class ChatPresenter: ObservableObject { - private let thread: Chat.Thread + private let thread: WalletConnectChat.Thread private let interactor: ChatInteractor private let router: ChatRouter private var disposeBag = Set() @@ -12,7 +12,7 @@ final class ChatPresenter: ObservableObject { @Published var messages: [MessageViewModel] = [] @Published var input: String = .empty - init(thread: Chat.Thread, interactor: ChatInteractor, router: ChatRouter) { + init(thread: WalletConnectChat.Thread, interactor: ChatInteractor, router: ChatRouter) { self.thread = thread self.interactor = interactor self.router = router diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/Models/MessageViewModel.swift b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/Models/MessageViewModel.swift index 892674362..538bd1bd7 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/Chat/Models/MessageViewModel.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/Chat/Models/MessageViewModel.swift @@ -1,11 +1,11 @@ import Foundation -import Chat +import WalletConnectChat struct MessageViewModel { private let message: Message - private let thread: Chat.Thread + private let thread: WalletConnectChat.Thread - init(message: Message, thread: Chat.Thread) { + init(message: Message, thread: WalletConnectChat.Thread) { self.message = message self.thread = thread } diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListInteractor.swift b/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListInteractor.swift index 51f8254ca..87e40a7af 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListInteractor.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListInteractor.swift @@ -1,4 +1,4 @@ -import Chat +import WalletConnectChat final class ChatListInteractor { @@ -10,11 +10,11 @@ final class ChatListInteractor { self.accountStorage = accountStorage } - func getThreads() async -> [Chat.Thread] { + func getThreads() async -> [WalletConnectChat.Thread] { return await chatService.getThreads() } - func threadsSubscription() -> Stream { + func threadsSubscription() -> Stream { return chatService.threadPublisher } diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListRouter.swift b/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListRouter.swift index 21f8332aa..eb0564d37 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListRouter.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/ChatListRouter.swift @@ -1,5 +1,5 @@ import UIKit -import Chat +import WalletConnectChat final class ChatListRouter { @@ -21,7 +21,7 @@ final class ChatListRouter { InviteListModule.create(app: app, account: account).push(from: viewController) } - func presentChat(thread: Chat.Thread) { + func presentChat(thread: WalletConnectChat.Thread) { ChatModule.create(thread: thread, app: app).push(from: viewController) } diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/Models/ThreadViewModel.swift b/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/Models/ThreadViewModel.swift index b65f99821..51403f1cb 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/Models/ThreadViewModel.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/ChatList/Models/ThreadViewModel.swift @@ -1,8 +1,8 @@ import Foundation -import Chat +import WalletConnectChat struct ThreadViewModel: Identifiable { - let thread: Chat.Thread + let thread: WalletConnectChat.Thread var topic: String { return thread.topic diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListInteractor.swift b/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListInteractor.swift index 9cd17c6d7..58c404ab9 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListInteractor.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListInteractor.swift @@ -1,4 +1,4 @@ -import Chat +import WalletConnectChat final class InviteListInteractor { private let chatService: ChatService diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListPresenter.swift b/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListPresenter.swift index 6a6f71a90..385a0d37d 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListPresenter.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/InviteListPresenter.swift @@ -1,6 +1,6 @@ import UIKit import Combine -import Chat +import WalletConnectChat final class InviteListPresenter: ObservableObject { diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/Models/InviteViewModel.swift b/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/Models/InviteViewModel.swift index 9ee9c619b..1dcc4a447 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/Models/InviteViewModel.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/InviteList/Models/InviteViewModel.swift @@ -1,5 +1,5 @@ import Foundation -import Chat +import WalletConnectChat struct InviteViewModel { let invite: Invite diff --git a/Package.swift b/Package.swift index bc8515e34..fe87e25ec 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,7 @@ let package = Package( targets: ["WalletConnectSign"]), .library( name: "WalletConnectChat", - targets: ["Chat"]), + targets: ["WalletConnectChat"]), .library( name: "WalletConnectAuth", targets: ["Auth"]), @@ -41,7 +41,7 @@ let package = Package( dependencies: ["WalletConnectNetworking", "WalletConnectPairing"], path: "Sources/WalletConnectSign"), .target( - name: "Chat", + name: "WalletConnectChat", dependencies: ["WalletConnectNetworking"], path: "Sources/Chat"), .target( @@ -86,7 +86,7 @@ let package = Package( dependencies: ["WalletConnectPairing", "TestingUtils"]), .testTarget( name: "ChatTests", - dependencies: ["Chat", "WalletConnectUtils", "TestingUtils"]), + dependencies: ["WalletConnectChat", "WalletConnectUtils", "TestingUtils"]), .testTarget( name: "AuthTests", dependencies: ["Auth", "WalletConnectUtils", "TestingUtils"]), diff --git a/Sources/Chat/Chat.swift b/Sources/Chat/Chat.swift new file mode 100644 index 000000000..9c10e0492 --- /dev/null +++ b/Sources/Chat/Chat.swift @@ -0,0 +1,12 @@ +import Foundation + +/// Chat instatnce wrapper +public class Chat { + + /// Chat client instance + public static var instance: ChatClient = { + return ChatClientFactory.create() + }() + + private init() { } +} diff --git a/Sources/Chat/ChatClientFactory.swift b/Sources/Chat/ChatClientFactory.swift index b5af0d7b2..666558f56 100644 --- a/Sources/Chat/ChatClientFactory.swift +++ b/Sources/Chat/ChatClientFactory.swift @@ -6,6 +6,19 @@ import WalletConnectNetworking public struct ChatClientFactory { + static func create() -> ChatClient { + let keychain = KeychainStorage(serviceIdentifier: "com.walletconnect.showcase") + let client = HTTPNetworkClient(host: "keys.walletconnect.com") + let registry = KeyserverRegistryProvider(client: client) + return ChatClientFactory.create( + registry: registry, + relayClient: Relay.instance, + kms: KeyManagementService(keychain: keychain), + logger: ConsoleLogger(), + keyValueStorage: UserDefaults.standard + ) + } + public static func create( registry: Registry, relayClient: RelayClient, From 0bb476ace5bcaf3dc728221ca8ea5cabd161b4d9 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Tue, 25 Oct 2022 12:08:04 +0200 Subject: [PATCH 5/8] fix tests --- Example/IntegrationTests/Chat/ChatTests.swift | 2 +- Example/IntegrationTests/Chat/RegistryTests.swift | 2 +- Tests/ChatTests/RegistryManagerTests.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Example/IntegrationTests/Chat/ChatTests.swift b/Example/IntegrationTests/Chat/ChatTests.swift index 177bda36f..03d9be7be 100644 --- a/Example/IntegrationTests/Chat/ChatTests.swift +++ b/Example/IntegrationTests/Chat/ChatTests.swift @@ -1,6 +1,6 @@ import Foundation import XCTest -@testable import Chat +@testable import WalletConnectChat import WalletConnectUtils @testable import WalletConnectKMS import WalletConnectRelay diff --git a/Example/IntegrationTests/Chat/RegistryTests.swift b/Example/IntegrationTests/Chat/RegistryTests.swift index eb98d22f2..ab665f828 100644 --- a/Example/IntegrationTests/Chat/RegistryTests.swift +++ b/Example/IntegrationTests/Chat/RegistryTests.swift @@ -2,7 +2,7 @@ import XCTest import WalletConnectNetworking import WalletConnectKMS import WalletConnectUtils -@testable import Chat +@testable import WalletConnectChat final class RegistryTests: XCTestCase { diff --git a/Tests/ChatTests/RegistryManagerTests.swift b/Tests/ChatTests/RegistryManagerTests.swift index c9ff87848..1b87397c6 100644 --- a/Tests/ChatTests/RegistryManagerTests.swift +++ b/Tests/ChatTests/RegistryManagerTests.swift @@ -1,6 +1,6 @@ import Foundation import XCTest -@testable import Chat +@testable import WalletConnectChat import WalletConnectUtils import WalletConnectNetworking import WalletConnectKMS From 9401b0d87e93e94f80a4cd3e0bf6fb85702bd251 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Tue, 25 Oct 2022 13:21:28 +0200 Subject: [PATCH 6/8] increase timeout --- Example/IntegrationTests/Stubs/InputConfig.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/IntegrationTests/Stubs/InputConfig.swift b/Example/IntegrationTests/Stubs/InputConfig.swift index 0e0c2efb7..0a71a0bed 100644 --- a/Example/IntegrationTests/Stubs/InputConfig.swift +++ b/Example/IntegrationTests/Stubs/InputConfig.swift @@ -11,7 +11,7 @@ struct InputConfig { } static var defaultTimeout: TimeInterval { - return 30 + return 45 } private static func config(for key: String) -> String? { From 281c233499e82931d953d2fe74032cf6260e41d2 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Tue, 25 Oct 2022 20:54:55 +0600 Subject: [PATCH 7/8] Filename duplicates removed --- Sources/Chat/ChatClientFactory.swift | 8 ++++---- ...mainIdentifiers.swift => ChatStorageIdentifiers.swift} | 2 +- ...mainIdentifiers.swift => PairStorageIdentifiers.swift} | 2 +- Sources/WalletConnectPairing/PairingClientFactory.swift | 2 +- Sources/WalletConnectSign/Sign/SignClientFactory.swift | 8 ++++---- ...mainIdentifiers.swift => SignStorageIdentifiers.swift} | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) rename Sources/Chat/{StorageDomainIdentifiers.swift => ChatStorageIdentifiers.swift} (89%) rename Sources/WalletConnectPairing/{StorageDomainIdentifiers.swift => PairStorageIdentifiers.swift} (67%) rename Sources/WalletConnectSign/{StorageDomainIdentifiers.swift => SignStorageIdentifiers.swift} (87%) diff --git a/Sources/Chat/ChatClientFactory.swift b/Sources/Chat/ChatClientFactory.swift index 666558f56..7d52dab90 100644 --- a/Sources/Chat/ChatClientFactory.swift +++ b/Sources/Chat/ChatClientFactory.swift @@ -26,18 +26,18 @@ public struct ChatClientFactory { logger: ConsoleLogging, keyValueStorage: KeyValueStorage ) -> ChatClient { - let topicToRegistryRecordStore = CodableStore(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.topicToInvitationPubKey.rawValue) + let topicToRegistryRecordStore = CodableStore(defaults: keyValueStorage, identifier: ChatStorageIdentifiers.topicToInvitationPubKey.rawValue) let serialiser = Serializer(kms: kms) let rpcHistory = RPCHistoryFactory.createForNetwork(keyValueStorage: keyValueStorage) let networkingInteractor = NetworkingInteractor(relayClient: relayClient, serializer: serialiser, logger: logger, rpcHistory: rpcHistory) - let invitePayloadStore = CodableStore>(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.invite.rawValue) + let invitePayloadStore = CodableStore>(defaults: keyValueStorage, identifier: ChatStorageIdentifiers.invite.rawValue) let registryService = RegistryService(registry: registry, networkingInteractor: networkingInteractor, kms: kms, logger: logger, topicToRegistryRecordStore: topicToRegistryRecordStore) - let threadStore = Database(keyValueStorage: keyValueStorage, identifier: StorageDomainIdentifiers.threads.rawValue) + let threadStore = Database(keyValueStorage: keyValueStorage, identifier: ChatStorageIdentifiers.threads.rawValue) let resubscriptionService = ResubscriptionService(networkingInteractor: networkingInteractor, threadStore: threadStore, logger: logger) let invitationHandlingService = InvitationHandlingService(registry: registry, networkingInteractor: networkingInteractor, kms: kms, logger: logger, topicToRegistryRecordStore: topicToRegistryRecordStore, invitePayloadStore: invitePayloadStore, threadsStore: threadStore) let inviteService = InviteService(networkingInteractor: networkingInteractor, kms: kms, threadStore: threadStore, rpcHistory: rpcHistory, logger: logger) let leaveService = LeaveService() - let messagesStore = Database(keyValueStorage: keyValueStorage, identifier: StorageDomainIdentifiers.messages.rawValue) + let messagesStore = Database(keyValueStorage: keyValueStorage, identifier: ChatStorageIdentifiers.messages.rawValue) let messagingService = MessagingService(networkingInteractor: networkingInteractor, messagesStore: messagesStore, threadStore: threadStore, logger: logger) let client = ChatClient( diff --git a/Sources/Chat/StorageDomainIdentifiers.swift b/Sources/Chat/ChatStorageIdentifiers.swift similarity index 89% rename from Sources/Chat/StorageDomainIdentifiers.swift rename to Sources/Chat/ChatStorageIdentifiers.swift index 72795f841..bcf560ed3 100644 --- a/Sources/Chat/StorageDomainIdentifiers.swift +++ b/Sources/Chat/ChatStorageIdentifiers.swift @@ -1,6 +1,6 @@ import Foundation -enum StorageDomainIdentifiers: String { +enum ChatStorageIdentifiers: String { case topicToInvitationPubKey = "com.walletconnect.chat.topicToInvitationPubKey" case invite = "com.walletconnect.chat.invite" case jsonRpcHistory = "com.walletconnect.chat.jsonRpcHistory" diff --git a/Sources/WalletConnectPairing/StorageDomainIdentifiers.swift b/Sources/WalletConnectPairing/PairStorageIdentifiers.swift similarity index 67% rename from Sources/WalletConnectPairing/StorageDomainIdentifiers.swift rename to Sources/WalletConnectPairing/PairStorageIdentifiers.swift index c328999c6..f287e1aad 100644 --- a/Sources/WalletConnectPairing/StorageDomainIdentifiers.swift +++ b/Sources/WalletConnectPairing/PairStorageIdentifiers.swift @@ -1,5 +1,5 @@ import Foundation -enum StorageDomainIdentifiers: String { +enum PairStorageIdentifiers: String { case pairings = "com.walletconnect.sdk.pairingSequences" } diff --git a/Sources/WalletConnectPairing/PairingClientFactory.swift b/Sources/WalletConnectPairing/PairingClientFactory.swift index 9926292e0..83bd66288 100644 --- a/Sources/WalletConnectPairing/PairingClientFactory.swift +++ b/Sources/WalletConnectPairing/PairingClientFactory.swift @@ -14,7 +14,7 @@ public struct PairingClientFactory { } public static func create(logger: ConsoleLogging, keyValueStorage: KeyValueStorage, keychainStorage: KeychainStorageProtocol, networkingClient: NetworkingInteractor) -> PairingClient { - let pairingStore = PairingStorage(storage: SequenceStore(store: .init(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.pairings.rawValue))) + let pairingStore = PairingStorage(storage: SequenceStore(store: .init(defaults: keyValueStorage, identifier: PairStorageIdentifiers.pairings.rawValue))) let kms = KeyManagementService(keychain: keychainStorage) let appPairService = AppPairService(networkingInteractor: networkingClient, kms: kms, pairingStorage: pairingStore) let walletPairService = WalletPairService(networkingInteractor: networkingClient, kms: kms, pairingStorage: pairingStore) diff --git a/Sources/WalletConnectSign/Sign/SignClientFactory.swift b/Sources/WalletConnectSign/Sign/SignClientFactory.swift index a1c086783..ce18e8029 100644 --- a/Sources/WalletConnectSign/Sign/SignClientFactory.swift +++ b/Sources/WalletConnectSign/Sign/SignClientFactory.swift @@ -26,10 +26,10 @@ public struct SignClientFactory { static func create(metadata: AppMetadata, logger: ConsoleLogging, keyValueStorage: KeyValueStorage, keychainStorage: KeychainStorageProtocol, pairingClient: PairingClient, networkingClient: NetworkingInteractor) -> SignClient { let kms = KeyManagementService(keychain: keychainStorage) let rpcHistory = RPCHistoryFactory.createForNetwork(keyValueStorage: keyValueStorage) - let pairingStore = PairingStorage(storage: SequenceStore(store: .init(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.pairings.rawValue))) - let sessionStore = SessionStorage(storage: SequenceStore(store: .init(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.sessions.rawValue))) - let sessionToPairingTopic = CodableStore(defaults: RuntimeKeyValueStorage(), identifier: StorageDomainIdentifiers.sessionToPairingTopic.rawValue) - let proposalPayloadsStore = CodableStore>(defaults: RuntimeKeyValueStorage(), identifier: StorageDomainIdentifiers.proposals.rawValue) + let pairingStore = PairingStorage(storage: SequenceStore(store: .init(defaults: keyValueStorage, identifier: SignStorageIdentifiers.pairings.rawValue))) + let sessionStore = SessionStorage(storage: SequenceStore(store: .init(defaults: keyValueStorage, identifier: SignStorageIdentifiers.sessions.rawValue))) + let sessionToPairingTopic = CodableStore(defaults: RuntimeKeyValueStorage(), identifier: SignStorageIdentifiers.sessionToPairingTopic.rawValue) + let proposalPayloadsStore = CodableStore>(defaults: RuntimeKeyValueStorage(), identifier: SignStorageIdentifiers.proposals.rawValue) let sessionEngine = SessionEngine(networkingInteractor: networkingClient, kms: kms, sessionStore: sessionStore, logger: logger) let nonControllerSessionStateMachine = NonControllerSessionStateMachine(networkingInteractor: networkingClient, kms: kms, sessionStore: sessionStore, logger: logger) let controllerSessionStateMachine = ControllerSessionStateMachine(networkingInteractor: networkingClient, kms: kms, sessionStore: sessionStore, logger: logger) diff --git a/Sources/WalletConnectSign/StorageDomainIdentifiers.swift b/Sources/WalletConnectSign/SignStorageIdentifiers.swift similarity index 87% rename from Sources/WalletConnectSign/StorageDomainIdentifiers.swift rename to Sources/WalletConnectSign/SignStorageIdentifiers.swift index 89a0b52a1..4da79ec0e 100644 --- a/Sources/WalletConnectSign/StorageDomainIdentifiers.swift +++ b/Sources/WalletConnectSign/SignStorageIdentifiers.swift @@ -1,6 +1,6 @@ import Foundation -enum StorageDomainIdentifiers: String { +enum SignStorageIdentifiers: String { case pairings = "com.walletconnect.sdk.pairingSequences" case sessions = "com.walletconnect.sdk.sessionSequences" case proposals = "com.walletconnect.sdk.sessionProposals" From 24ab5de48953d21ce901959c2d4f5ca55e1a1367 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Wed, 26 Oct 2022 18:38:09 +0600 Subject: [PATCH 8/8] PubKey removed from invite --- Example/IntegrationTests/Chat/ChatTests.swift | 13 ++++++------- .../Classes/DomainLayer/Chat/ChatService.swift | 4 ++-- .../Chat/Invite/InviteInteractor.swift | 3 +-- Sources/Chat/ChatClient.swift | 5 +++-- Sources/Chat/ChatClientFactory.swift | 2 +- .../Inviter/InviteService.swift | 18 ++++++++++++------ 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Example/IntegrationTests/Chat/ChatTests.swift b/Example/IntegrationTests/Chat/ChatTests.swift index 03d9be7be..4c305a88f 100644 --- a/Example/IntegrationTests/Chat/ChatTests.swift +++ b/Example/IntegrationTests/Chat/ChatTests.swift @@ -29,8 +29,8 @@ final class ChatTests: XCTestCase { let inviteExpectation = expectation(description: "invitation expectation") let inviteeAccount = Account(chainIdentifier: "eip155:1", address: "0x3627523167367216556273151")! let inviterAccount = Account(chainIdentifier: "eip155:1", address: "0x36275231673672234423f")! - let pubKey = try! await invitee.register(account: inviteeAccount) - try! await inviter.invite(publicKey: pubKey, peerAccount: inviteeAccount, openingMessage: "", account: inviterAccount) + try! await invitee.register(account: inviteeAccount) + try! await inviter.invite(peerAccount: inviteeAccount, openingMessage: "", account: inviterAccount) invitee.invitePublisher.sink { _ in inviteExpectation.fulfill() }.store(in: &publishers) @@ -44,9 +44,8 @@ final class ChatTests: XCTestCase { let inviterAccount = Account(chainIdentifier: "eip155:1", address: "0x36275231673672234423f")! Task(priority: .high) { - let pubKey = try! await invitee.register(account: inviteeAccount) - - try! await inviter.invite(publicKey: pubKey, peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount) + try! await invitee.register(account: inviteeAccount) + try! await inviter.invite(peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount) } invitee.invitePublisher.sink { [unowned self] invite in @@ -72,8 +71,8 @@ final class ChatTests: XCTestCase { let inviterAccount = Account(chainIdentifier: "eip155:1", address: "0x36275231673672234423f")! Task(priority: .high) { - let pubKey = try! await invitee.register(account: inviteeAccount) - try! await inviter.invite(publicKey: pubKey, peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount) + try! await invitee.register(account: inviteeAccount) + try! await inviter.invite(peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount) } invitee.invitePublisher.sink { [unowned self] invite in diff --git a/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift b/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift index a98e1902e..991c06c66 100644 --- a/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift +++ b/Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift @@ -53,8 +53,8 @@ final class ChatService { try await client.reject(inviteId: invite.id) } - func invite(peerPubkey publicKey: String, peerAccount: Account, message: String, selfAccount: Account) async throws { - try await client.invite(publicKey: publicKey, peerAccount: peerAccount, openingMessage: message, account: selfAccount) + func invite(peerAccount: Account, message: String, selfAccount: Account) async throws { + try await client.invite(peerAccount: peerAccount, openingMessage: message, account: selfAccount) } func register(account: Account) async throws { diff --git a/Example/Showcase/Classes/PresentationLayer/Chat/Invite/InviteInteractor.swift b/Example/Showcase/Classes/PresentationLayer/Chat/Invite/InviteInteractor.swift index e51575584..26af501c6 100644 --- a/Example/Showcase/Classes/PresentationLayer/Chat/Invite/InviteInteractor.swift +++ b/Example/Showcase/Classes/PresentationLayer/Chat/Invite/InviteInteractor.swift @@ -6,7 +6,6 @@ final class InviteInteractor { } func invite(peerAccount: Account, message: String, selfAccount: Account) async { - let publicKey = try! await chatService.resolve(account: peerAccount) - try! await chatService.invite(peerPubkey: publicKey, peerAccount: peerAccount, message: message, selfAccount: selfAccount) + try! await chatService.invite(peerAccount: peerAccount, message: message, selfAccount: selfAccount) } } diff --git a/Sources/Chat/ChatClient.swift b/Sources/Chat/ChatClient.swift index 19b3fc550..fdae06f01 100644 --- a/Sources/Chat/ChatClient.swift +++ b/Sources/Chat/ChatClient.swift @@ -73,6 +73,7 @@ public class ChatClient { /// record is a blockchain account with a client generated public key /// - Parameter account: CAIP10 blockchain account /// - Returns: public key + @discardableResult public func register(account: Account) async throws -> String { try await registryService.register(account: account) } @@ -89,8 +90,8 @@ public class ChatClient { /// - publicKey: publicKey associated with a peer /// - openingMessage: oppening message for a chat invite /// TODO - peerAccount should be derived - public func invite(publicKey: String, peerAccount: Account, openingMessage: String, account: Account) async throws { - try await inviteService.invite(peerPubKey: publicKey, peerAccount: peerAccount, openingMessage: openingMessage, account: account) + public func invite(peerAccount: Account, openingMessage: String, account: Account) async throws { + try await inviteService.invite(peerAccount: peerAccount, openingMessage: openingMessage, account: account) } public func accept(inviteId: String) async throws { diff --git a/Sources/Chat/ChatClientFactory.swift b/Sources/Chat/ChatClientFactory.swift index 7d52dab90..538040bbd 100644 --- a/Sources/Chat/ChatClientFactory.swift +++ b/Sources/Chat/ChatClientFactory.swift @@ -35,7 +35,7 @@ public struct ChatClientFactory { let threadStore = Database(keyValueStorage: keyValueStorage, identifier: ChatStorageIdentifiers.threads.rawValue) let resubscriptionService = ResubscriptionService(networkingInteractor: networkingInteractor, threadStore: threadStore, logger: logger) let invitationHandlingService = InvitationHandlingService(registry: registry, networkingInteractor: networkingInteractor, kms: kms, logger: logger, topicToRegistryRecordStore: topicToRegistryRecordStore, invitePayloadStore: invitePayloadStore, threadsStore: threadStore) - let inviteService = InviteService(networkingInteractor: networkingInteractor, kms: kms, threadStore: threadStore, rpcHistory: rpcHistory, logger: logger) + let inviteService = InviteService(networkingInteractor: networkingInteractor, kms: kms, threadStore: threadStore, rpcHistory: rpcHistory, logger: logger, registry: registry) let leaveService = LeaveService() let messagesStore = Database(keyValueStorage: keyValueStorage, identifier: ChatStorageIdentifiers.messages.rawValue) let messagingService = MessagingService(networkingInteractor: networkingInteractor, messagesStore: messagesStore, threadStore: threadStore, logger: logger) diff --git a/Sources/Chat/ProtocolServices/Inviter/InviteService.swift b/Sources/Chat/ProtocolServices/Inviter/InviteService.swift index 9568bfac4..9e88cc815 100644 --- a/Sources/Chat/ProtocolServices/Inviter/InviteService.swift +++ b/Sources/Chat/ProtocolServices/Inviter/InviteService.swift @@ -12,31 +12,37 @@ class InviteService { private let kms: KeyManagementService private let threadStore: Database private let rpcHistory: RPCHistory + private let registry: Registry var onNewThread: ((Thread) -> Void)? var onInvite: ((Invite) -> Void)? - init(networkingInteractor: NetworkInteracting, - kms: KeyManagementService, - threadStore: Database, - rpcHistory: RPCHistory, - logger: ConsoleLogging) { + init( + networkingInteractor: NetworkInteracting, + kms: KeyManagementService, + threadStore: Database, + rpcHistory: RPCHistory, + logger: ConsoleLogging, + registry: Registry + ) { self.kms = kms self.networkingInteractor = networkingInteractor self.logger = logger self.threadStore = threadStore self.rpcHistory = rpcHistory + self.registry = registry setUpResponseHandling() } var peerAccount: Account! - func invite(peerPubKey: String, peerAccount: Account, openingMessage: String, account: Account) async throws { + func invite(peerAccount: Account, openingMessage: String, account: Account) async throws { // TODO ad storage let protocolMethod = ChatInviteProtocolMethod() self.peerAccount = peerAccount let selfPubKeyY = try kms.createX25519KeyPair() let invite = Invite(message: openingMessage, account: account, publicKey: selfPubKeyY.hexRepresentation) + let peerPubKey = try await registry.resolve(account: peerAccount) let symKeyI = try kms.performKeyAgreement(selfPublicKey: selfPubKeyY, peerPublicKey: peerPubKey) let inviteTopic = try AgreementPublicKey(hex: peerPubKey).rawRepresentation.sha256().toHexString()