diff --git a/Sources/Auth/AuthClient.swift b/Sources/Auth/AuthClient.swift index 5e7e6ad08..c75a2895e 100644 --- a/Sources/Auth/AuthClient.swift +++ b/Sources/Auth/AuthClient.swift @@ -60,6 +60,7 @@ public class AuthClient { private let pairingStorage: WCPairingStorage private let pendingRequestsProvider: PendingRequestsProvider private let pingService: PairingPingService + private let pairingsProvider: PairingsProvider private var account: Account? init(appPairService: AppPairService, @@ -75,7 +76,8 @@ public class AuthClient { logger: ConsoleLogging, pairingStorage: WCPairingStorage, socketConnectionStatusPublisher: AnyPublisher, - pingService: PairingPingService + pingService: PairingPingService, + pairingsProvider: PairingsProvider ) { self.appPairService = appPairService self.appRequestService = appRequestService @@ -91,6 +93,7 @@ public class AuthClient { self.socketConnectionStatusPublisher = socketConnectionStatusPublisher self.deletePairingService = deletePairingService self.pingService = pingService + self.pairingsProvider = pairingsProvider setUpPublishers() } @@ -153,6 +156,10 @@ public class AuthClient { try await pingService.ping(topic: topic) } + public func getPairings() -> [Pairing] { + pairingsProvider.getPairings() + } + /// Query pending authentication requests /// - Returns: Pending authentication requests public func getPendingRequests() throws -> [AuthRequest] { diff --git a/Sources/Auth/AuthClientFactory.swift b/Sources/Auth/AuthClientFactory.swift index ba307a926..e0fe3f586 100644 --- a/Sources/Auth/AuthClientFactory.swift +++ b/Sources/Auth/AuthClientFactory.swift @@ -34,6 +34,7 @@ public struct AuthClientFactory { let cleanupService = CleanupService(pairingStore: pairingStore, kms: kms) let deletePairingService = DeletePairingService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore, logger: logger) let pingService = PairingPingService(pairingStorage: pairingStore, networkingInteractor: networkingInteractor, logger: logger) + let pairingsProvider = PairingsProvider(pairingStorage: pairingStore) return AuthClient(appPairService: appPairService, appRequestService: appRequestService, @@ -47,6 +48,7 @@ public struct AuthClientFactory { logger: logger, pairingStorage: pairingStore, socketConnectionStatusPublisher: relayClient.socketConnectionStatusPublisher, - pingService: pingService) + pingService: pingService, + pairingsProvider: pairingsProvider) } } diff --git a/Sources/Auth/Services/Common/PairingsProvider.swift b/Sources/Auth/Services/Common/PairingsProvider.swift new file mode 100644 index 000000000..081f3fa6d --- /dev/null +++ b/Sources/Auth/Services/Common/PairingsProvider.swift @@ -0,0 +1,15 @@ +import Foundation +import WalletConnectPairing + +public class PairingsProvider { + private let pairingStorage: WCPairingStorage + + public init(pairingStorage: WCPairingStorage) { + self.pairingStorage = pairingStorage + } + + func getPairings() -> [Pairing] { + pairingStorage.getAll() + .map {Pairing(topic: $0.topic, peer: $0.peerMetadata, expiryDate: $0.expiryDate)} + } +} diff --git a/Sources/Auth/Types/Aliases/Pairing.swift b/Sources/Auth/Types/Aliases/Pairing.swift new file mode 100644 index 000000000..7a09951e2 --- /dev/null +++ b/Sources/Auth/Types/Aliases/Pairing.swift @@ -0,0 +1,4 @@ +import Foundation +import WalletConnectPairing + +public typealias Pairing = WalletConnectPairing.Pairing diff --git a/Sources/WalletConnectSign/Pairing.swift b/Sources/WalletConnectPairing/Types/Pairing.swift similarity index 54% rename from Sources/WalletConnectSign/Pairing.swift rename to Sources/WalletConnectPairing/Types/Pairing.swift index 4b459ebbe..f9886d6a2 100644 --- a/Sources/WalletConnectSign/Pairing.swift +++ b/Sources/WalletConnectPairing/Types/Pairing.swift @@ -6,4 +6,10 @@ public struct Pairing { public let topic: String public let peer: AppMetadata? public let expiryDate: Date + + public init(topic: String, peer: AppMetadata?, expiryDate: Date) { + self.topic = topic + self.peer = peer + self.expiryDate = expiryDate + } } diff --git a/Sources/WalletConnectSign/Types/Aliases/Pairing.swift b/Sources/WalletConnectSign/Types/Aliases/Pairing.swift new file mode 100644 index 000000000..7a09951e2 --- /dev/null +++ b/Sources/WalletConnectSign/Types/Aliases/Pairing.swift @@ -0,0 +1,4 @@ +import Foundation +import WalletConnectPairing + +public typealias Pairing = WalletConnectPairing.Pairing