diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/WalletConnectHistory.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/WalletConnectHistory.xcscheme new file mode 100644 index 000000000..4311c49f7 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/WalletConnectHistory.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Package.swift b/Package.swift index c00641c97..6c0bc8e03 100644 --- a/Package.swift +++ b/Package.swift @@ -43,6 +43,9 @@ let package = Package( .library( name: "WalletConnectVerify", targets: ["WalletConnectVerify"]), + .library( + name: "WalletConnectHistory", + targets: ["WalletConnectHistory"]), .library( name: "Web3Inbox", targets: ["Web3Inbox"]), @@ -91,6 +94,9 @@ let package = Package( .target( name: "WalletConnectPairing", dependencies: ["WalletConnectNetworking"]), + .target( + name: "WalletConnectHistory", + dependencies: ["HTTPClient", "WalletConnectRelay"]), .target( name: "Web3Inbox", dependencies: ["WalletConnectChat", "WalletConnectPush"]), diff --git a/Sources/WalletConnectHistory/HistoryAPI.swift b/Sources/WalletConnectHistory/HistoryAPI.swift new file mode 100644 index 000000000..0bd5e7f61 --- /dev/null +++ b/Sources/WalletConnectHistory/HistoryAPI.swift @@ -0,0 +1,37 @@ +import Foundation + +enum HistoryAPI: HTTPService { + case register(payload: RegisterPayload, jwt: String) + + var path: String { + switch self { + case .register: + return "/register" + } + } + + var method: HTTPMethod { + switch self { + case .register: + return .post + } + } + + var body: Data? { + switch self { + case .register(let payload, _): + return try? JSONEncoder().encode(payload) + } + } + + var additionalHeaderFields: [String : String]? { + switch self { + case .register(_, let jwt): + return ["Authorization": jwt] + } + } + + var queryParameters: [String : String]? { + return nil + } +} diff --git a/Sources/WalletConnectHistory/HistoryClient.swift b/Sources/WalletConnectHistory/HistoryClient.swift new file mode 100644 index 000000000..d465751b7 --- /dev/null +++ b/Sources/WalletConnectHistory/HistoryClient.swift @@ -0,0 +1,9 @@ +import Foundation + +public final class HistoryClient { + + + public func registerTags(payload: RegisterPayload, historyUrl: String) async throws { + + } +} diff --git a/Sources/WalletConnectHistory/HistoryImports.swift b/Sources/WalletConnectHistory/HistoryImports.swift new file mode 100644 index 000000000..e6d4b859c --- /dev/null +++ b/Sources/WalletConnectHistory/HistoryImports.swift @@ -0,0 +1,4 @@ +#if !CocoaPods +@_exported import HTTPClient +@_exported import WalletConnectRelay +#endif diff --git a/Sources/WalletConnectHistory/HistoryNetworkService.swift b/Sources/WalletConnectHistory/HistoryNetworkService.swift new file mode 100644 index 000000000..4af5f29b9 --- /dev/null +++ b/Sources/WalletConnectHistory/HistoryNetworkService.swift @@ -0,0 +1,25 @@ +import Foundation + +final class HistoryNetworkService { + + private let clientIdStorage: ClientIdStorage + + init(clientIdStorage: ClientIdStorage) { + self.clientIdStorage = clientIdStorage + } + + func registerTags(payload: RegisterPayload, historyUrl: String) async throws { + let service = HTTPNetworkClient(host: historyUrl) + let api = HistoryAPI.register(payload: payload, jwt: try await getJwt()) + try await service.request(service: api) + } +} + +private extension HistoryNetworkService { + + func getJwt() async throws -> String { + let keyPair = try clientIdStorage.getOrCreateKeyPair() + let payload = RelayAuthPayload(subject: getSubject(), audience: getAudience()) + return try payload.signAndCreateWrapper(keyPair: keyPair).jwtString + } +} diff --git a/Sources/WalletConnectHistory/Types/RegisterPayload.swift b/Sources/WalletConnectHistory/Types/RegisterPayload.swift new file mode 100644 index 000000000..b759c5ce5 --- /dev/null +++ b/Sources/WalletConnectHistory/Types/RegisterPayload.swift @@ -0,0 +1,11 @@ +import Foundation + +public struct RegisterPayload: Codable { + public let tags: [String] + public let relayUrl: String + + public init(tags: [String], relayUrl: String) { + self.tags = tags + self.relayUrl = relayUrl + } +}