-
Notifications
You must be signed in to change notification settings - Fork 183
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 #1251 from WalletConnect/pairing-delete-publish
Pairing delete publisher
- Loading branch information
Showing
10 changed files
with
126 additions
and
76 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
7 changes: 7 additions & 0 deletions
7
Sources/WalletConnectPairing/RPCParams/PairingDeleteParams.swift
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,7 @@ | ||
|
||
import Foundation | ||
|
||
struct PairingDeleteParams: Codable { | ||
let code: Int | ||
let message: String | ||
} |
43 changes: 43 additions & 0 deletions
43
Sources/WalletConnectPairing/Services/Common/Delete/PairingDeleteRequestSubscriber.swift
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,43 @@ | ||
import Combine | ||
|
||
public final class PairingDeleteRequestSubscriber { | ||
private let networkingInteractor: NetworkInteracting | ||
private let logger: ConsoleLogging | ||
private let pairingStorage: WCPairingStorage | ||
private let kms: KeyManagementServiceProtocol | ||
let deletePublisherSubject = PassthroughSubject<(code: Int, message: String), Never>() | ||
|
||
private var publishers = [AnyCancellable]() | ||
|
||
public init( | ||
networkingInteractor: NetworkInteracting, | ||
kms: KeyManagementServiceProtocol, | ||
pairingStorage: WCPairingStorage, | ||
logger: ConsoleLogging | ||
) { | ||
self.networkingInteractor = networkingInteractor | ||
self.kms = kms | ||
self.pairingStorage = pairingStorage | ||
self.logger = logger | ||
subscribeDeleteRequest() | ||
} | ||
|
||
private func subscribeDeleteRequest() { | ||
let method = PairingProtocolMethod.delete | ||
networkingInteractor.requestSubscription(on: method) | ||
.sink { [unowned self] (payload: RequestSubscriptionPayload<PairingDeleteParams>) in | ||
|
||
let topic = payload.topic | ||
logger.debug("Received pairing delete request") | ||
pairingStorage.delete(topic: topic) | ||
kms.deleteSymmetricKey(for: topic) | ||
networkingInteractor.unsubscribe(topic: topic) | ||
|
||
deletePublisherSubject.send((code: payload.request.code, message: payload.request.message)) | ||
Task(priority: .high) { | ||
try? await networkingInteractor.respondSuccess(topic: payload.topic, requestId: payload.id, protocolMethod: method) | ||
} | ||
} | ||
.store(in: &publishers) | ||
} | ||
} |
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