-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from WalletConnect/feature/pairing-services
[Auth] Pairing Services
- Loading branch information
Showing
39 changed files
with
281 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.swiftpm/xcode/xcshareddata/xcschemes/WalletConnectAuth.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1340" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "WalletConnectAuth" | ||
BuildableName = "WalletConnectAuth" | ||
BlueprintName = "WalletConnectAuth" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
</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"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "WalletConnectAuth" | ||
BuildableName = "WalletConnectAuth" | ||
BlueprintName = "WalletConnectAuth" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,31 @@ | ||
import Foundation | ||
|
||
class AuthClient { | ||
enum Errors: Error { | ||
case malformedPairingURI | ||
} | ||
|
||
private let appPairService: AppPairService | ||
private let appRequestService: AuthRequestService | ||
|
||
private let walletPairService: WalletPairService | ||
|
||
init(appPairService: AppPairService, appRequestService: AuthRequestService, walletPairService: WalletPairService) { | ||
self.appPairService = appPairService | ||
self.appRequestService = appRequestService | ||
self.walletPairService = walletPairService | ||
} | ||
|
||
func request(params: RequestParams) async throws -> String { | ||
let uri = try await appPairService.create() | ||
try await appRequestService.request(params: params, topic: uri.topic) | ||
return uri.absoluteString | ||
} | ||
|
||
func pair(uri: String) async throws { | ||
guard let pairingURI = WalletConnectURI(string: uri) else { | ||
throw Errors.malformedPairingURI | ||
} | ||
try await walletPairService.pair(pairingURI) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
import WalletConnectKMS | ||
import WalletConnectPairing | ||
|
||
actor AppPairService { | ||
private let networkingInteractor: NetworkInteracting | ||
private let kms: KeyManagementServiceProtocol | ||
private let pairingStorage: WCPairingStorage | ||
|
||
init(networkingInteractor: NetworkInteracting, kms: KeyManagementServiceProtocol, pairingStorage: WCPairingStorage) { | ||
self.networkingInteractor = networkingInteractor | ||
self.kms = kms | ||
self.pairingStorage = pairingStorage | ||
} | ||
|
||
func create() async throws -> WalletConnectURI { | ||
let topic = String.generateTopic() | ||
try await networkingInteractor.subscribe(topic: topic) | ||
let symKey = try! kms.createSymmetricKey(topic) | ||
let pairing = WCPairing(topic: topic) | ||
let uri = WalletConnectURI(topic: topic, symKey: symKey.hexRepresentation, relay: pairing.relay) | ||
pairingStorage.setPairing(pairing) | ||
return uri | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Foundation | ||
import WalletConnectRelay | ||
|
||
protocol NetworkInteracting { | ||
func subscribe(topic: String) async throws | ||
} | ||
|
||
class NetworkingInteractor: NetworkInteracting { | ||
private let relayClient: RelayClient | ||
|
||
init(relayClient: RelayClient) { | ||
self.relayClient = relayClient | ||
} | ||
|
||
func subscribe(topic: String) async throws { | ||
try await relayClient.subscribe(topic: topic) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
import WalletConnectKMS | ||
import WalletConnectPairing | ||
|
||
actor WalletPairService { | ||
enum Errors: Error { | ||
case pairingAlreadyExist | ||
} | ||
|
||
private let networkingInteractor: NetworkInteracting | ||
private let kms: KeyManagementServiceProtocol | ||
private let pairingStorage: WCPairingStorage | ||
|
||
init(networkingInteractor: NetworkInteracting, | ||
kms: KeyManagementServiceProtocol, | ||
pairingStorage: WCPairingStorage) { | ||
self.networkingInteractor = networkingInteractor | ||
self.kms = kms | ||
self.pairingStorage = pairingStorage | ||
} | ||
|
||
func pair(_ uri: WalletConnectURI) async throws { | ||
guard !hasPairing(for: uri.topic) else { | ||
throw Errors.pairingAlreadyExist | ||
} | ||
var pairing = WCPairing(uri: uri) | ||
try await networkingInteractor.subscribe(topic: pairing.topic) | ||
let symKey = try SymmetricKey(hex: uri.symKey) | ||
try kms.setSymmetricKey(symKey, for: pairing.topic) | ||
pairing.activate() | ||
pairingStorage.setPairing(pairing) | ||
} | ||
|
||
func hasPairing(for topic: String) -> Bool { | ||
return pairingStorage.hasPairing(forTopic: topic) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// | ||
|
||
import Foundation | ||
import WalletConnectUtils | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// | ||
|
||
import Foundation | ||
import WalletConnectUtils | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// | ||
|
||
import Foundation | ||
import CryptoKit | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Foundation | ||
|
||
// Internal namespace for pairing payloads. | ||
public enum PairingType { | ||
|
||
public struct DeleteParams: Codable, Equatable { | ||
let reason: Reason | ||
} | ||
|
||
public struct Reason: Codable, Equatable { | ||
let code: Int | ||
let message: String | ||
} | ||
|
||
public struct PingParams: Codable, Equatable { | ||
public init() { } | ||
} | ||
} |
Oops, something went wrong.