-
Notifications
You must be signed in to change notification settings - Fork 172
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 #206 from WalletConnect/async-pair
Add Concurrency
- Loading branch information
Showing
22 changed files
with
253 additions
and
199 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
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
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
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,33 @@ | ||
|
||
import Foundation | ||
import WalletConnectKMS | ||
|
||
actor PairEngine { | ||
private let networkingInteractor: NetworkInteracting | ||
private let kms: KeyManagementServiceProtocol | ||
private let pairingStore: WCPairingStorage | ||
|
||
init(networkingInteractor: NetworkInteracting, | ||
kms: KeyManagementServiceProtocol, | ||
pairingStore: WCPairingStorage) { | ||
self.networkingInteractor = networkingInteractor | ||
self.kms = kms | ||
self.pairingStore = pairingStore | ||
} | ||
|
||
func pair(_ uri: WalletConnectURI) async throws { | ||
guard !hasPairing(for: uri.topic) else { | ||
throw WalletConnectError.pairingAlreadyExist | ||
} | ||
var pairing = WCPairing(uri: uri) | ||
try await networkingInteractor.subscribe(topic: pairing.topic) | ||
let symKey = try! SymmetricKey(hex: uri.symKey) // FIXME: Malformed QR code from external source can crash the SDK | ||
try! kms.setSymmetricKey(symKey, for: pairing.topic) | ||
pairing.activate() | ||
pairingStore.setPairing(pairing) | ||
} | ||
|
||
func hasPairing(for topic: String) -> Bool { | ||
return pairingStore.hasPairing(forTopic: topic) | ||
} | ||
} |
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
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
Oops, something went wrong.