Skip to content

Commit

Permalink
Merge pull request #371 from WalletConnect/#367-auth-target
Browse files Browse the repository at this point in the history
[Auth] #367 auth target
  • Loading branch information
llbartekll authored Jul 28, 2022
2 parents 18a07a0 + 8b650e8 commit 0614b88
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 54 deletions.
52 changes: 52 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/AuthTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AuthTests"
BuildableName = "AuthTests"
BlueprintName = "AuthTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</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">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
7 changes: 7 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"]),
Expand Down
5 changes: 5 additions & 0 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

class AuthClient {

}
7 changes: 7 additions & 0 deletions Sources/Auth/Services/App/AuthRequestService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

actor AuthRequestService {

func request(params: RequestParams, topic: String) async throws {
}
}
8 changes: 8 additions & 0 deletions Sources/Auth/Services/App/CreatePairingService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

actor CreatePairingService {

func create() async throws -> WalletConnectURI {
fatalError("not implemented")
}
}
8 changes: 8 additions & 0 deletions Sources/Auth/Services/Wallet/AuthService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

actor AuthService {

func respond(respondParams: RespondParams) async throws {

}
}
8 changes: 8 additions & 0 deletions Sources/Auth/Services/Wallet/PairService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

actor PairService {

func pair(_ uri: WalletConnectURI) async throws {
fatalError("not implemented")
}
}
6 changes: 6 additions & 0 deletions Sources/Auth/Types/RelayProtocolOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//

import Foundation
import WalletConnectUtils

typealias RelayProtocolOptions = WalletConnectUtils.RelayProtocolOptions
7 changes: 7 additions & 0 deletions Sources/Auth/Types/RequestParams.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//

import Foundation

struct RequestParams {

}
7 changes: 7 additions & 0 deletions Sources/Auth/Types/RespondParams.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//

import Foundation

struct RespondParams {

}
6 changes: 6 additions & 0 deletions Sources/Auth/Types/WalletConnectURI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//

import Foundation
import WalletConnectUtils

typealias WalletConnectURI = WalletConnectUtils.WalletConnectURI

This file was deleted.

6 changes: 6 additions & 0 deletions Sources/WalletConnectSign/Types/RelayProtocolOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//

import Foundation
import WalletConnectUtils

typealias RelayProtocolOptions = WalletConnectUtils.RelayProtocolOptions
50 changes: 2 additions & 48 deletions Sources/WalletConnectSign/Types/WalletConnectURI.swift
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions Sources/WalletConnectUtils/RelayProtocolOptions.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
50 changes: 50 additions & 0 deletions Sources/WalletConnectUtils/WalletConnectURI.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions Tests/AuthTests/AuthClientTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation
import XCTest

class AuthClientTest: XCTestCase {

}

0 comments on commit 0614b88

Please sign in to comment.