diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/AuthTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/AuthTests.xcscheme new file mode 100644 index 000000000..b6a508a85 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/AuthTests.xcscheme @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Package.swift b/Package.swift index 537aeed2a..d39b1d0ce 100644 --- a/Package.swift +++ b/Package.swift @@ -27,6 +27,10 @@ let package = Package( name: "Chat", dependencies: ["WalletConnectRelay", "WalletConnectUtils", "WalletConnectKMS"], path: "Sources/Chat"), + .target( + name: "Auth", + dependencies: ["WalletConnectRelay", "WalletConnectUtils", "WalletConnectKMS"], + path: "Sources/Auth"), .target( name: "WalletConnectRelay", dependencies: ["WalletConnectUtils", "WalletConnectKMS"], @@ -50,6 +54,9 @@ let package = Package( .testTarget( name: "ChatTests", dependencies: ["Chat", "WalletConnectUtils", "TestingUtils"]), + .testTarget( + name: "AuthTests", + dependencies: ["Auth", "WalletConnectUtils", "TestingUtils"]), .testTarget( name: "RelayerTests", dependencies: ["WalletConnectRelay", "WalletConnectUtils", "TestingUtils"]), diff --git a/Sources/Auth/AuthClient.swift b/Sources/Auth/AuthClient.swift new file mode 100644 index 000000000..10888619f --- /dev/null +++ b/Sources/Auth/AuthClient.swift @@ -0,0 +1,5 @@ +import Foundation + +class AuthClient { + +} diff --git a/Sources/Auth/Services/App/AuthRequestService.swift b/Sources/Auth/Services/App/AuthRequestService.swift new file mode 100644 index 000000000..af1240aa1 --- /dev/null +++ b/Sources/Auth/Services/App/AuthRequestService.swift @@ -0,0 +1,7 @@ +import Foundation + +actor AuthRequestService { + + func request(params: RequestParams, topic: String) async throws { + } +} diff --git a/Sources/Auth/Services/App/CreatePairingService.swift b/Sources/Auth/Services/App/CreatePairingService.swift new file mode 100644 index 000000000..2b3f3aaeb --- /dev/null +++ b/Sources/Auth/Services/App/CreatePairingService.swift @@ -0,0 +1,8 @@ +import Foundation + +actor CreatePairingService { + + func create() async throws -> WalletConnectURI { + fatalError("not implemented") + } +} diff --git a/Sources/Auth/Services/Wallet/AuthService.swift b/Sources/Auth/Services/Wallet/AuthService.swift new file mode 100644 index 000000000..4e73117f0 --- /dev/null +++ b/Sources/Auth/Services/Wallet/AuthService.swift @@ -0,0 +1,8 @@ +import Foundation + +actor AuthService { + + func respond(respondParams: RespondParams) async throws { + + } +} diff --git a/Sources/Auth/Services/Wallet/PairService.swift b/Sources/Auth/Services/Wallet/PairService.swift new file mode 100644 index 000000000..7aa241a02 --- /dev/null +++ b/Sources/Auth/Services/Wallet/PairService.swift @@ -0,0 +1,8 @@ +import Foundation + +actor PairService { + + func pair(_ uri: WalletConnectURI) async throws { + fatalError("not implemented") + } +} diff --git a/Sources/Auth/Types/RelayProtocolOptions.swift b/Sources/Auth/Types/RelayProtocolOptions.swift new file mode 100644 index 000000000..087d73ce7 --- /dev/null +++ b/Sources/Auth/Types/RelayProtocolOptions.swift @@ -0,0 +1,6 @@ +// + +import Foundation +import WalletConnectUtils + +typealias RelayProtocolOptions = WalletConnectUtils.RelayProtocolOptions diff --git a/Sources/Auth/Types/RequestParams.swift b/Sources/Auth/Types/RequestParams.swift new file mode 100644 index 000000000..3489b2f83 --- /dev/null +++ b/Sources/Auth/Types/RequestParams.swift @@ -0,0 +1,7 @@ +// + +import Foundation + +struct RequestParams { + +} diff --git a/Sources/Auth/Types/RespondParams.swift b/Sources/Auth/Types/RespondParams.swift new file mode 100644 index 000000000..6ff4318ad --- /dev/null +++ b/Sources/Auth/Types/RespondParams.swift @@ -0,0 +1,7 @@ +// + +import Foundation + +struct RespondParams { + +} diff --git a/Sources/Auth/Types/WalletConnectURI.swift b/Sources/Auth/Types/WalletConnectURI.swift new file mode 100644 index 000000000..d5cdf5f31 --- /dev/null +++ b/Sources/Auth/Types/WalletConnectURI.swift @@ -0,0 +1,6 @@ +// + +import Foundation +import WalletConnectUtils + +typealias WalletConnectURI = WalletConnectUtils.WalletConnectURI diff --git a/Sources/WalletConnectSign/Types/Common/RelayProtocolOptions.swift b/Sources/WalletConnectSign/Types/Common/RelayProtocolOptions.swift deleted file mode 100644 index 2d0009aa9..000000000 --- a/Sources/WalletConnectSign/Types/Common/RelayProtocolOptions.swift +++ /dev/null @@ -1,6 +0,0 @@ -import Foundation - -struct RelayProtocolOptions: Codable, Equatable { - let `protocol`: String - let data: String? -} diff --git a/Sources/WalletConnectSign/Types/RelayProtocolOptions.swift b/Sources/WalletConnectSign/Types/RelayProtocolOptions.swift new file mode 100644 index 000000000..24094e9c2 --- /dev/null +++ b/Sources/WalletConnectSign/Types/RelayProtocolOptions.swift @@ -0,0 +1,6 @@ +// + +import Foundation +import WalletConnectUtils + +typealias RelayProtocolOptions = WalletConnectUtils.RelayProtocolOptions diff --git a/Sources/WalletConnectSign/Types/WalletConnectURI.swift b/Sources/WalletConnectSign/Types/WalletConnectURI.swift index 0d43287a6..a2cfe2de9 100644 --- a/Sources/WalletConnectSign/Types/WalletConnectURI.swift +++ b/Sources/WalletConnectSign/Types/WalletConnectURI.swift @@ -1,50 +1,4 @@ import Foundation +import WalletConnectUtils -public struct WalletConnectURI: Equatable { - - let topic: String - let version: String - let symKey: String - let relay: RelayProtocolOptions - - init(topic: String, symKey: String, relay: RelayProtocolOptions) { - self.version = "2" - self.topic = topic - self.symKey = symKey - self.relay = relay - } - - public init?(string: String) { - guard string.hasPrefix("wc:") else { - return nil - } - let urlString = !string.hasPrefix("wc://") ? string.replacingOccurrences(of: "wc:", with: "wc://") : string - guard let components = URLComponents(string: urlString) else { - return nil - } - let query: [String: String]? = components.queryItems?.reduce(into: [:]) { $0[$1.name] = $1.value } - - guard let topic = components.user, - let version = components.host, - let symKey = query?["symKey"], - let relayProtocol = query?["relay-protocol"] - else { return nil } - let relayData = query?["relay-data"] - self.version = version - self.topic = topic - self.symKey = symKey - self.relay = RelayProtocolOptions(protocol: relayProtocol, data: relayData) - } - - public var absoluteString: String { - return "wc:\(topic)@\(version)?symKey=\(symKey)&\(relayQuery)" - } - - private var relayQuery: String { - var query = "relay-protocol=\(relay.protocol)" - if let relayData = relay.data { - query = "\(query)&relay-data=\(relayData)" - } - return query - } -} +typealias WalletConnectURI = WalletConnectUtils.WalletConnectURI diff --git a/Sources/WalletConnectUtils/RelayProtocolOptions.swift b/Sources/WalletConnectUtils/RelayProtocolOptions.swift new file mode 100644 index 000000000..e437e9342 --- /dev/null +++ b/Sources/WalletConnectUtils/RelayProtocolOptions.swift @@ -0,0 +1,11 @@ +import Foundation + +public struct RelayProtocolOptions: Codable, Equatable { + public let `protocol`: String + public let data: String? + + public init(protocol: String, data: String?) { + self.protocol = `protocol` + self.data = data + } +} diff --git a/Sources/WalletConnectUtils/WalletConnectURI.swift b/Sources/WalletConnectUtils/WalletConnectURI.swift new file mode 100644 index 000000000..d149f7f70 --- /dev/null +++ b/Sources/WalletConnectUtils/WalletConnectURI.swift @@ -0,0 +1,50 @@ +import Foundation + +public struct WalletConnectURI: Equatable { + + public let topic: String + public let version: String + public let symKey: String + public let relay: RelayProtocolOptions + + public init(topic: String, symKey: String, relay: RelayProtocolOptions) { + self.version = "2" + self.topic = topic + self.symKey = symKey + self.relay = relay + } + + public init?(string: String) { + guard string.hasPrefix("wc:") else { + return nil + } + let urlString = !string.hasPrefix("wc://") ? string.replacingOccurrences(of: "wc:", with: "wc://") : string + guard let components = URLComponents(string: urlString) else { + return nil + } + let query: [String: String]? = components.queryItems?.reduce(into: [:]) { $0[$1.name] = $1.value } + + guard let topic = components.user, + let version = components.host, + let symKey = query?["symKey"], + let relayProtocol = query?["relay-protocol"] + else { return nil } + let relayData = query?["relay-data"] + self.version = version + self.topic = topic + self.symKey = symKey + self.relay = RelayProtocolOptions(protocol: relayProtocol, data: relayData) + } + + public var absoluteString: String { + return "wc:\(topic)@\(version)?symKey=\(symKey)&\(relayQuery)" + } + + private var relayQuery: String { + var query = "relay-protocol=\(relay.protocol)" + if let relayData = relay.data { + query = "\(query)&relay-data=\(relayData)" + } + return query + } +} diff --git a/Tests/AuthTests/AuthClientTest.swift b/Tests/AuthTests/AuthClientTest.swift new file mode 100644 index 000000000..69cfe3f72 --- /dev/null +++ b/Tests/AuthTests/AuthClientTest.swift @@ -0,0 +1,6 @@ +import Foundation +import XCTest + +class AuthClientTest: XCTestCase { + +}