Skip to content

Commit

Permalink
HistoryNetworkService
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Jun 13, 2023
1 parent 4c86fd6 commit 676725a
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectHistory"
BuildableName = "WalletConnectHistory"
BlueprintName = "WalletConnectHistory"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectHistory"
BuildableName = "WalletConnectHistory"
BlueprintName = "WalletConnectHistory"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
6 changes: 6 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ let package = Package(
.library(
name: "WalletConnectVerify",
targets: ["WalletConnectVerify"]),
.library(
name: "WalletConnectHistory",
targets: ["WalletConnectHistory"]),
.library(
name: "Web3Inbox",
targets: ["Web3Inbox"]),
Expand Down Expand Up @@ -91,6 +94,9 @@ let package = Package(
.target(
name: "WalletConnectPairing",
dependencies: ["WalletConnectNetworking"]),
.target(
name: "WalletConnectHistory",
dependencies: ["HTTPClient", "WalletConnectRelay"]),
.target(
name: "Web3Inbox",
dependencies: ["WalletConnectChat", "WalletConnectPush"]),
Expand Down
37 changes: 37 additions & 0 deletions Sources/WalletConnectHistory/HistoryAPI.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 9 additions & 0 deletions Sources/WalletConnectHistory/HistoryClient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

public final class HistoryClient {


public func registerTags(payload: RegisterPayload, historyUrl: String) async throws {

}
}
4 changes: 4 additions & 0 deletions Sources/WalletConnectHistory/HistoryImports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if !CocoaPods
@_exported import HTTPClient
@_exported import WalletConnectRelay
#endif
25 changes: 25 additions & 0 deletions Sources/WalletConnectHistory/HistoryNetworkService.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions Sources/WalletConnectHistory/Types/RegisterPayload.swift
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 676725a

Please sign in to comment.