From 895da5c79da3f79322d2fe0744c39319d78f2a13 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 10:17:32 +0200 Subject: [PATCH 01/17] create request test --- Example/ExampleApp.xcodeproj/project.pbxproj | 4 +++ Example/IntegrationTests/Auth/AuthTests.swift | 9 ++++++- .../Stubs/RequestParams.swift | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Example/IntegrationTests/Stubs/RequestParams.swift diff --git a/Example/ExampleApp.xcodeproj/project.pbxproj b/Example/ExampleApp.xcodeproj/project.pbxproj index 1b2c1316e..cd4858011 100644 --- a/Example/ExampleApp.xcodeproj/project.pbxproj +++ b/Example/ExampleApp.xcodeproj/project.pbxproj @@ -47,6 +47,7 @@ 84DDB4ED28ABB663003D66ED /* WalletConnectAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 84DDB4EC28ABB663003D66ED /* WalletConnectAuth */; }; 84F568C2279582D200D0A289 /* Signer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F568C1279582D200D0A289 /* Signer.swift */; }; 84F568C42795832A00D0A289 /* EthereumTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F568C32795832A00D0A289 /* EthereumTransaction.swift */; }; + 84FE684628ACDB4700C893FF /* RequestParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FE684528ACDB4700C893FF /* RequestParams.swift */; }; A50F3946288005B200064555 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50F3945288005B200064555 /* Types.swift */; }; A5629AA92876A23100094373 /* ChatService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AA82876A23100094373 /* ChatService.swift */; }; A5629ABD2876CBC000094373 /* ChatListModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AB82876CBC000094373 /* ChatListModule.swift */; }; @@ -208,6 +209,7 @@ 84D2A66528A4F51E0088AE09 /* AuthTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthTests.swift; sourceTree = ""; }; 84F568C1279582D200D0A289 /* Signer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signer.swift; sourceTree = ""; }; 84F568C32795832A00D0A289 /* EthereumTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumTransaction.swift; sourceTree = ""; }; + 84FE684528ACDB4700C893FF /* RequestParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestParams.swift; sourceTree = ""; }; A50F3945288005B200064555 /* Types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = ""; }; A5629AA82876A23100094373 /* ChatService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatService.swift; sourceTree = ""; }; A5629AB82876CBC000094373 /* ChatListModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListModule.swift; sourceTree = ""; }; @@ -898,6 +900,7 @@ A5E03E1028646F8000888481 /* KeychainStorageMock.swift */, A5E03E0E28646D8A00888481 /* WebSocketFactory.swift */, A5E03DFC286465D100888481 /* Stubs.swift */, + 84FE684528ACDB4700C893FF /* RequestParams.swift */, ); path = Stubs; sourceTree = ""; @@ -1277,6 +1280,7 @@ A5E03DFB286465C700888481 /* ClientDelegate.swift in Sources */, A5E03E03286466F400888481 /* ChatTests.swift in Sources */, 84D2A66628A4F51E0088AE09 /* AuthTests.swift in Sources */, + 84FE684628ACDB4700C893FF /* RequestParams.swift in Sources */, 7694A5262874296A0001257E /* RegistryTests.swift in Sources */, A5E03E0D28646AD200888481 /* RelayClientEndToEndTests.swift in Sources */, A5E03DFA286465C700888481 /* SignClientTests.swift in Sources */, diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 99dce1da0..5191ca412 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -50,6 +50,13 @@ final class AuthTests: XCTestCase { } func testRequest() async { - + let requestExpectation = expectation(description: "request") + Task(priority: .high) { + try await app.request(RequestParams.stub()) + } + wallet.authRequestPublisher.sink { _ in + requestExpectation.fulfill() + }.store(in: &publishers) + wait(for: [requestExpectation], timeout: 2) } } diff --git a/Example/IntegrationTests/Stubs/RequestParams.swift b/Example/IntegrationTests/Stubs/RequestParams.swift new file mode 100644 index 000000000..89cb11ae9 --- /dev/null +++ b/Example/IntegrationTests/Stubs/RequestParams.swift @@ -0,0 +1,25 @@ + +import Foundation +@testable import Auth + +extension RequestParams { + static func stub(domain: String = "service.invalid", + chainId: String = "1", + nonce: String = "32891756", + aud: String = "https://service.invalid/login", + nbf: String? = nil, + exp: String? = nil, + statement: String? = "I accept the ServiceOrg Terms of Service: https://service.invalid/tos", + requestId: String? = nil, + resources: [String]? = ["ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/", "https://example.com/my-web2-claim.json"]) -> RequestParams { + return RequestParams(domain: domain, + chainId: chainId, + nonce: nonce, + aud: aud, + nbf: nbf, + exp: exp, + statement: statement, + requestId: requestId, + resources: resources) + } +} From 81152cce84a3691aa2218770b472b27a9cae8122 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 10:22:57 +0200 Subject: [PATCH 02/17] fix subscription bug --- .../Auth/Services/Wallet/WalletRequestSubscriber.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift index 2dfad7f3a..7f8cd0516 100644 --- a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift +++ b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift @@ -19,14 +19,12 @@ class WalletRequestSubscriber { self.logger = logger self.address = address self.messageFormatter = messageFormatter - subscribeForRequest() + if let address = address { + subscribeForRequest() + } } private func subscribeForRequest() { - guard let address = address else { - logger.warn("unexpected request") - return - } networkingInteractor.requestPublisher.sink { [unowned self] subscriptionPayload in guard let requestId = subscriptionPayload.request.id, From a29ad06e585e2ece1cdf83b1013158ddfd800cf9 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 10:24:11 +0200 Subject: [PATCH 03/17] fix buiild --- Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift index 7f8cd0516..77c4c2847 100644 --- a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift +++ b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift @@ -19,7 +19,7 @@ class WalletRequestSubscriber { self.logger = logger self.address = address self.messageFormatter = messageFormatter - if let address = address { + if address != nil { subscribeForRequest() } } @@ -36,7 +36,7 @@ class WalletRequestSubscriber { let message = messageFormatter.formatMessage( from: authRequestParams.payloadParams, - address: address + address: address! ) onRequest?(requestId, message) From 824a0eeb23f73617f92d8077c0a3932b485621a4 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 10:35:25 +0200 Subject: [PATCH 04/17] refactor Auth client factory --- Example/IntegrationTests/Auth/AuthTests.swift | 6 ++++-- Sources/Auth/AuthClientFactory.swift | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 5191ca412..842953fa4 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -45,8 +45,10 @@ final class AuthTests: XCTestCase { return AuthClientFactory.create( metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), account: account, - relayClient: relayClient, - logger: logger) + logger: logger, + keyValueStorage: RuntimeKeyValueStorage(), + keychainStorage: keychain, + relayClient: relayClient) } func testRequest() async { diff --git a/Sources/Auth/AuthClientFactory.swift b/Sources/Auth/AuthClientFactory.swift index c3b128e0f..9948bb638 100644 --- a/Sources/Auth/AuthClientFactory.swift +++ b/Sources/Auth/AuthClientFactory.swift @@ -6,10 +6,15 @@ import WalletConnectPairing public struct AuthClientFactory { - public static func create(metadata: AppMetadata, account: Account?, relayClient: RelayClient, logger: ConsoleLogging) -> AuthClient { + public static func create(metadata: AppMetadata, account: Account?, relayClient: RelayClient) -> AuthClient { + let logger = ConsoleLogger(loggingLevel: .off) let keyValueStorage = UserDefaults.standard - let historyStorage = CodableStore(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.jsonRpcHistory.rawValue) let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") + return AuthClientFactory.create(metadata: metadata, account: account, logger: logger, keyValueStorage: keyValueStorage, keychainStorage: keychainStorage, relayClient: relayClient) + } + + static func create(metadata: AppMetadata, account: Account?, logger: ConsoleLogging, keyValueStorage: KeyValueStorage, keychainStorage: KeychainStorageProtocol, relayClient: RelayClient) -> AuthClient { + let historyStorage = CodableStore(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.jsonRpcHistory.rawValue) let pairingStore = PairingStorage(storage: SequenceStore(store: .init(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.pairings.rawValue))) let kms = KeyManagementService(keychain: keychainStorage) let serializer = Serializer(kms: kms) From a4cb644e8267f980d56fcdd95ebe8b4f7de4ca68 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 10:41:31 +0200 Subject: [PATCH 05/17] update auth test --- Example/IntegrationTests/Auth/AuthTests.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 842953fa4..6a3151e7b 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -54,7 +54,8 @@ final class AuthTests: XCTestCase { func testRequest() async { let requestExpectation = expectation(description: "request") Task(priority: .high) { - try await app.request(RequestParams.stub()) + let uri = try await app.request(RequestParams.stub()) + try await wallet.pair(uri: uri) } wallet.authRequestPublisher.sink { _ in requestExpectation.fulfill() From 57b5400b411e71922167fa6b9c7a1e4f0eb82bfc Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 11:10:07 +0200 Subject: [PATCH 06/17] fix build --- Sources/Auth/AuthClientFactory.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Auth/AuthClientFactory.swift b/Sources/Auth/AuthClientFactory.swift index 9948bb638..38630ab24 100644 --- a/Sources/Auth/AuthClientFactory.swift +++ b/Sources/Auth/AuthClientFactory.swift @@ -19,7 +19,7 @@ public struct AuthClientFactory { let kms = KeyManagementService(keychain: keychainStorage) let serializer = Serializer(kms: kms) let history = RPCHistory(keyValueStore: historyStorage) - let networkingInteractor = NetworkingInteractor(relayClient: relayClient, serializer: serializer, rpcHistory: history) + let networkingInteractor = NetworkingInteractor(relayClient: relayClient, serializer: serializer, logger: logger, rpcHistory: history) let SIWEMessageFormatter = SIWEMessageFormatter() let appPairService = AppPairService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore) let appRequestService = AppRequestService(networkingInteractor: networkingInteractor, kms: kms, appMetadata: metadata) From b289accd9671c2cc24df67a3fb396d746fa30825 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 11:14:34 +0200 Subject: [PATCH 07/17] pass test request --- Example/IntegrationTests/Auth/AuthTests.swift | 2 +- Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 6a3151e7b..1f5bd6d78 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -52,7 +52,7 @@ final class AuthTests: XCTestCase { } func testRequest() async { - let requestExpectation = expectation(description: "request") + let requestExpectation = expectation(description: "request delivered to wallet") Task(priority: .high) { let uri = try await app.request(RequestParams.stub()) try await wallet.pair(uri: uri) diff --git a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift index 77c4c2847..30abea341 100644 --- a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift +++ b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift @@ -25,6 +25,7 @@ class WalletRequestSubscriber { } private func subscribeForRequest() { + print("adasdadsadsadsadsadsdscaadsdasdasdsdsds") networkingInteractor.requestPublisher.sink { [unowned self] subscriptionPayload in guard let requestId = subscriptionPayload.request.id, From 3497e47d97676e869fb7f540e0f0afe70573a2d8 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 17 Aug 2022 13:24:33 +0200 Subject: [PATCH 08/17] savepoint respond test --- Example/IntegrationTests/Auth/AuthTests.swift | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 1f5bd6d78..8e59d6395 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -53,13 +53,27 @@ final class AuthTests: XCTestCase { func testRequest() async { let requestExpectation = expectation(description: "request delivered to wallet") - Task(priority: .high) { - let uri = try await app.request(RequestParams.stub()) - try await wallet.pair(uri: uri) - } + let uri = try! await app.request(RequestParams.stub()) + try! await wallet.pair(uri: uri) wallet.authRequestPublisher.sink { _ in requestExpectation.fulfill() }.store(in: &publishers) wait(for: [requestExpectation], timeout: 2) } + + func testRespondSuccess() async { + let uri = try! await app.request(RequestParams.stub()) + try! await wallet.pair(uri: uri) + wallet.authRequestPublisher.sink { _ in + Task(priority: .high) { + await wallet.respond(.success(<#T##RespondParams#>)) + } + }.store(in: &publishers) + } +} + +extension RespondParams { + static func stub() -> RespondParams { + + } } From c4f0ffe153f63f51feb903816a3d0b6d9a574f65 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 08:51:55 +0200 Subject: [PATCH 09/17] comment out code --- Example/IntegrationTests/Auth/AuthTests.swift | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 8e59d6395..20ccc0a00 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -61,19 +61,19 @@ final class AuthTests: XCTestCase { wait(for: [requestExpectation], timeout: 2) } - func testRespondSuccess() async { - let uri = try! await app.request(RequestParams.stub()) - try! await wallet.pair(uri: uri) - wallet.authRequestPublisher.sink { _ in - Task(priority: .high) { - await wallet.respond(.success(<#T##RespondParams#>)) - } - }.store(in: &publishers) - } +// func testRespondSuccess() async { +// let uri = try! await app.request(RequestParams.stub()) +// try! await wallet.pair(uri: uri) +// wallet.authRequestPublisher.sink { _ in +// Task(priority: .high) { +// await wallet.respond(.success(<#T##RespondParams#>)) +// } +// }.store(in: &publishers) +// } } -extension RespondParams { - static func stub() -> RespondParams { - - } -} +//extension RespondParams { +// static func stub() -> RespondParams { +// +// } +//} From 35601828e284f241ba91c552208f355370b4d4cc Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 09:27:00 +0200 Subject: [PATCH 10/17] savepoint --- Example/IntegrationTests/Auth/AuthTests.swift | 45 ++++++++++++------- .../Wallet/WalletRespondService.swift | 2 +- Sources/Auth/Types/RespondParams.swift | 1 - 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index 20ccc0a00..bd130920e 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -13,7 +13,7 @@ final class AuthTests: XCTestCase { override func setUp() { app = makeClient(prefix: "👻 App") - let walletAccount = Account(chainIdentifier: "eip155:1", address: "0x3627523167367216556273151")! + let walletAccount = Account(chainIdentifier: "eip155:1", address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")! wallet = makeClient(prefix: "🤑 Wallet", account: walletAccount) let expectation = expectation(description: "Wait Clients Connected") @@ -61,19 +61,34 @@ final class AuthTests: XCTestCase { wait(for: [requestExpectation], timeout: 2) } -// func testRespondSuccess() async { -// let uri = try! await app.request(RequestParams.stub()) -// try! await wallet.pair(uri: uri) -// wallet.authRequestPublisher.sink { _ in -// Task(priority: .high) { -// await wallet.respond(.success(<#T##RespondParams#>)) -// } -// }.store(in: &publishers) -// } + func testRespondSuccess() async { + let responseExpectation = expectation(description: "successful response delivered") + let uri = try! await app.request(RequestParams.stub()) + try! await wallet.pair(uri: uri) + wallet.authRequestPublisher.sink { [unowned self] (id, message) in + Task(priority: .high) { + try! await wallet.respond(.success(RespondParams.stub(id: id))) + } + } + .store(in: &publishers) + app.authResponsePublisher.sink { (id, result) in + guard case .success = result else { XCTFail(); return } + responseExpectation.fulfill() + } + .store(in: &publishers) + } } -//extension RespondParams { -// static func stub() -> RespondParams { -// -// } -//} +extension RespondParams { + static func stub(id: Int64) -> RespondParams { + RespondParams( + id: id, + signature: CacaoSignature.stub()) + } +} + +extension CacaoSignature { + static func stub() -> CacaoSignature { + return CacaoSignature( + } +} diff --git a/Sources/Auth/Services/Wallet/WalletRespondService.swift b/Sources/Auth/Services/Wallet/WalletRespondService.swift index db2a598bc..a40bc384c 100644 --- a/Sources/Auth/Services/Wallet/WalletRespondService.swift +++ b/Sources/Auth/Services/Wallet/WalletRespondService.swift @@ -45,6 +45,6 @@ actor WalletRespondService { let cacao = CacaoFormatter().format(authRequestParams, respondParams.signature, account) let response = RPCResponse(id: request.id!, result: cacao) - try await networkingInteractor.respond(topic: respondParams.topic, response: response, tag: AuthResponseParams.tag, envelopeType: .type1(pubKey: selfPubKey.rawRepresentation)) + try await networkingInteractor.respond(topic: responseTopic, response: response, tag: AuthResponseParams.tag, envelopeType: .type1(pubKey: selfPubKey.rawRepresentation)) } } diff --git a/Sources/Auth/Types/RespondParams.swift b/Sources/Auth/Types/RespondParams.swift index b3757a64a..63f0e7d29 100644 --- a/Sources/Auth/Types/RespondParams.swift +++ b/Sources/Auth/Types/RespondParams.swift @@ -2,6 +2,5 @@ import Foundation public struct RespondParams { let id: Int64 - let topic: String let signature: CacaoSignature } From 51b5e54d9576b953c62a0545c58ad7d2fa3e3bd6 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 09:52:40 +0200 Subject: [PATCH 11/17] #400 cacao object formatter --- .../Auth/Services/Common/CacaoFormatter.swift | 8 ++++--- .../Wallet/WalletRespondService.swift | 3 ++- Sources/Auth/Types/Cacao/CacaoPayload.swift | 24 +++++++++++++++---- .../ProtocolRPCParams/AuthRequestParams.swift | 1 + .../AuthResponseParams.swift | 1 + 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Sources/Auth/Services/Common/CacaoFormatter.swift b/Sources/Auth/Services/Common/CacaoFormatter.swift index c35286b87..fef3b8a3d 100644 --- a/Sources/Auth/Services/Common/CacaoFormatter.swift +++ b/Sources/Auth/Services/Common/CacaoFormatter.swift @@ -2,11 +2,13 @@ import Foundation import WalletConnectUtils protocol CacaoFormatting { - func format(_ request: AuthRequestParams, _ signature: CacaoSignature, _ account: Account) -> Cacao + func format(_ request: AuthRequestParams, _ signature: CacaoSignature, _ didpkh: DIDPKH) -> Cacao } class CacaoFormatter: CacaoFormatting { - func format(_ request: AuthRequestParams, _ signature: CacaoSignature, _ account: Account) -> Cacao { - fatalError("not implemented") + func format(_ request: AuthRequestParams, _ signature: CacaoSignature, _ didpkh: DIDPKH) -> Cacao { + let header = CacaoHeader(t: "eip191") + let payload = CacaoPayload(params: request.payloadParams, didpkh: didpkh) + return Cacao(header: header, payload: payload, signature: signature) } } diff --git a/Sources/Auth/Services/Wallet/WalletRespondService.swift b/Sources/Auth/Services/Wallet/WalletRespondService.swift index a40bc384c..9effae7fe 100644 --- a/Sources/Auth/Services/Wallet/WalletRespondService.swift +++ b/Sources/Auth/Services/Wallet/WalletRespondService.swift @@ -42,7 +42,8 @@ actor WalletRespondService { let agreementKeys = try kms.performKeyAgreement(selfPublicKey: selfPubKey, peerPublicKey: peerPubKey) try kms.setAgreementSecret(agreementKeys, topic: responseTopic) - let cacao = CacaoFormatter().format(authRequestParams, respondParams.signature, account) + let didpkh = DIDPKH(account: account) + let cacao = CacaoFormatter().format(authRequestParams, respondParams.signature, didpkh) let response = RPCResponse(id: request.id!, result: cacao) try await networkingInteractor.respond(topic: responseTopic, response: response, tag: AuthResponseParams.tag, envelopeType: .type1(pubKey: selfPubKey.rawRepresentation)) diff --git a/Sources/Auth/Types/Cacao/CacaoPayload.swift b/Sources/Auth/Types/Cacao/CacaoPayload.swift index b38a3206c..1a71050c7 100644 --- a/Sources/Auth/Types/Cacao/CacaoPayload.swift +++ b/Sources/Auth/Types/Cacao/CacaoPayload.swift @@ -7,9 +7,23 @@ struct CacaoPayload: Codable, Equatable { let version: Int let nonce: String let iat: String - let nbf: String - let exp: String - let statement: String - let requestId: String - let resources: [String] + let nbf: String? + let exp: String? + let statement: String? + let requestId: String? + let resources: [String]? + + init(params: AuthPayload, didpkh: DIDPKH) { + self.iss = didpkh.iss + self.domain = params.domain + self.aud = params.aud + self.version = 1 + self.nonce = params.nonce + self.iat = params.iat + self.nbf = params.nbf + self.exp = params.exp + self.statement = params.statement + self.requestId = params.requestId + self.resources = params.resources + } } diff --git a/Sources/Auth/Types/ProtocolRPCParams/AuthRequestParams.swift b/Sources/Auth/Types/ProtocolRPCParams/AuthRequestParams.swift index c39ba3489..46feee75f 100644 --- a/Sources/Auth/Types/ProtocolRPCParams/AuthRequestParams.swift +++ b/Sources/Auth/Types/ProtocolRPCParams/AuthRequestParams.swift @@ -1,6 +1,7 @@ import Foundation import WalletConnectUtils +/// wc_authRequest RPC method request param struct AuthRequestParams: Codable, Equatable { let requester: Requester let payloadParams: AuthPayload diff --git a/Sources/Auth/Types/ProtocolRPCParams/AuthResponseParams.swift b/Sources/Auth/Types/ProtocolRPCParams/AuthResponseParams.swift index a0d64b152..2dab1477b 100644 --- a/Sources/Auth/Types/ProtocolRPCParams/AuthResponseParams.swift +++ b/Sources/Auth/Types/ProtocolRPCParams/AuthResponseParams.swift @@ -1,6 +1,7 @@ import Foundation import WalletConnectUtils +/// wc_authRequest RPC method respond param struct AuthResponseParams: Codable, Equatable { let header: CacaoHeader let payload: CacaoPayload From 6d463dff743ee890c2950ca2c5decf7bf5bb80af Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 12:54:58 +0200 Subject: [PATCH 12/17] savepoint --- Example/IntegrationTests/Auth/AuthTests.swift | 7 +++++-- Sources/Auth/Services/Common/CacaoFormatter.swift | 2 +- Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift | 5 +++-- Sources/Auth/Services/Wallet/WalletRespondService.swift | 2 +- Sources/Auth/Types/Cacao/CacaoSignature.swift | 2 +- Sources/Auth/Types/RespondParams.swift | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index bd130920e..a89765966 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -67,6 +67,7 @@ final class AuthTests: XCTestCase { try! await wallet.pair(uri: uri) wallet.authRequestPublisher.sink { [unowned self] (id, message) in Task(priority: .high) { + print("responding") try! await wallet.respond(.success(RespondParams.stub(id: id))) } } @@ -76,11 +77,13 @@ final class AuthTests: XCTestCase { responseExpectation.fulfill() } .store(in: &publishers) + wait(for: [responseExpectation], timeout: 2) + } } extension RespondParams { - static func stub(id: Int64) -> RespondParams { + static func stub(id: RPCID) -> RespondParams { RespondParams( id: id, signature: CacaoSignature.stub()) @@ -89,6 +92,6 @@ extension RespondParams { extension CacaoSignature { static func stub() -> CacaoSignature { - return CacaoSignature( + return CacaoSignature(t: "eip191", s: "438effc459956b57fcd9f3dac6c675f9cee88abf21acab7305e8e32aa0303a883b06dcbd956279a7a2ca21ffa882ff55cc22e8ab8ec0f3fe90ab45f306938cfa1b") } } diff --git a/Sources/Auth/Services/Common/CacaoFormatter.swift b/Sources/Auth/Services/Common/CacaoFormatter.swift index fef3b8a3d..b8331b577 100644 --- a/Sources/Auth/Services/Common/CacaoFormatter.swift +++ b/Sources/Auth/Services/Common/CacaoFormatter.swift @@ -7,7 +7,7 @@ protocol CacaoFormatting { class CacaoFormatter: CacaoFormatting { func format(_ request: AuthRequestParams, _ signature: CacaoSignature, _ didpkh: DIDPKH) -> Cacao { - let header = CacaoHeader(t: "eip191") + let header = CacaoHeader(t: "eip4361") let payload = CacaoPayload(params: request.payloadParams, didpkh: didpkh) return Cacao(header: header, payload: payload, signature: signature) } diff --git a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift index e678d8f5e..633f2c76d 100644 --- a/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift +++ b/Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift @@ -25,8 +25,9 @@ class WalletRequestSubscriber { } private func subscribeForRequest() { - print("adasdadsadsadsadsadsdscaadsdasdasdsdsds") + guard let address = address else {return} networkingInteractor.requestPublisher.sink { [unowned self] subscriptionPayload in + logger.debug("WalletRequestSubscriber: Received request") guard let requestId = subscriptionPayload.request.id, subscriptionPayload.request.method == "wc_authRequest" else { return } @@ -37,7 +38,7 @@ class WalletRequestSubscriber { let message = messageFormatter.formatMessage( from: authRequestParams.payloadParams, - address: address! + address: address ) onRequest?(requestId, message) diff --git a/Sources/Auth/Services/Wallet/WalletRespondService.swift b/Sources/Auth/Services/Wallet/WalletRespondService.swift index 9effae7fe..ab38a20a4 100644 --- a/Sources/Auth/Services/Wallet/WalletRespondService.swift +++ b/Sources/Auth/Services/Wallet/WalletRespondService.swift @@ -33,7 +33,7 @@ actor WalletRespondService { } private func respond(respondParams: RespondParams, account: Account) async throws { - guard let request = rpcHistory.get(recordId: RPCID(respondParams.id))?.request else { throw Errors.recordForIdNotFound } + guard let request = rpcHistory.get(recordId: respondParams.id)?.request else { throw Errors.recordForIdNotFound } guard let authRequestParams = try? request.params?.get(AuthRequestParams.self) else { throw Errors.malformedAuthRequestParams } let peerPubKey = authRequestParams.requester.publicKey diff --git a/Sources/Auth/Types/Cacao/CacaoSignature.swift b/Sources/Auth/Types/Cacao/CacaoSignature.swift index 97c04c142..2c6c4c49e 100644 --- a/Sources/Auth/Types/Cacao/CacaoSignature.swift +++ b/Sources/Auth/Types/Cacao/CacaoSignature.swift @@ -3,5 +3,5 @@ import Foundation struct CacaoSignature: Codable, Equatable { let t: String let s: String - let m: String + let m: String? = nil } diff --git a/Sources/Auth/Types/RespondParams.swift b/Sources/Auth/Types/RespondParams.swift index 63f0e7d29..79926445e 100644 --- a/Sources/Auth/Types/RespondParams.swift +++ b/Sources/Auth/Types/RespondParams.swift @@ -1,6 +1,6 @@ import Foundation public struct RespondParams { - let id: Int64 + let id: RPCID let signature: CacaoSignature } From 55864ebb40286b30a08e62104e26747eb0397678 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 13:48:03 +0200 Subject: [PATCH 13/17] Update tests fix key exchange bug --- Example/IntegrationTests/Auth/AuthTests.swift | 1 - Sources/Auth/AuthClientFactory.swift | 2 +- Sources/Auth/Services/App/AppRequestService.swift | 8 ++++++-- Sources/Auth/Services/Wallet/WalletRespondService.swift | 1 - 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index a89765966..ed7796ee6 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -78,7 +78,6 @@ final class AuthTests: XCTestCase { } .store(in: &publishers) wait(for: [responseExpectation], timeout: 2) - } } diff --git a/Sources/Auth/AuthClientFactory.swift b/Sources/Auth/AuthClientFactory.swift index 6d48fa179..cf75c3ce1 100644 --- a/Sources/Auth/AuthClientFactory.swift +++ b/Sources/Auth/AuthClientFactory.swift @@ -22,7 +22,7 @@ public struct AuthClientFactory { let networkingInteractor = NetworkingInteractor(relayClient: relayClient, serializer: serializer, logger: logger, rpcHistory: history) let messageFormatter = SIWEMessageFormatter() let appPairService = AppPairService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore) - let appRequestService = AppRequestService(networkingInteractor: networkingInteractor, kms: kms, appMetadata: metadata) + let appRequestService = AppRequestService(networkingInteractor: networkingInteractor, kms: kms, appMetadata: metadata, logger: logger) let messageSigner = MessageSigner(signer: Signer()) let appRespondSubscriber = AppRespondSubscriber(networkingInteractor: networkingInteractor, logger: logger, rpcHistory: history, signatureVerifier: messageSigner, messageFormatter: messageFormatter) let walletPairService = WalletPairService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore) diff --git a/Sources/Auth/Services/App/AppRequestService.swift b/Sources/Auth/Services/App/AppRequestService.swift index 216038deb..3d2c43443 100644 --- a/Sources/Auth/Services/App/AppRequestService.swift +++ b/Sources/Auth/Services/App/AppRequestService.swift @@ -7,23 +7,27 @@ actor AppRequestService { private let networkingInteractor: NetworkInteracting private let appMetadata: AppMetadata private let kms: KeyManagementService + private let logger: ConsoleLogging init(networkingInteractor: NetworkInteracting, kms: KeyManagementService, - appMetadata: AppMetadata) { + appMetadata: AppMetadata, + logger: ConsoleLogging) { self.networkingInteractor = networkingInteractor self.kms = kms self.appMetadata = appMetadata + self.logger = logger } func request(params: RequestParams, topic: String) async throws { let pubKey = try kms.createX25519KeyPair() - let responseTopic = pubKey.rawRepresentation.sha256().toHexString() + let responseTopic = pubKey.hexRepresentation let requester = AuthRequestParams.Requester(publicKey: pubKey.hexRepresentation, metadata: appMetadata) let issueAt = ISO8601DateFormatter().string(from: Date()) let payload = AuthPayload(requestParams: params, iat: issueAt) let params = AuthRequestParams(requester: requester, payloadParams: payload) let request = RPCRequest(method: "wc_authRequest", params: params) + logger.debug("Subscribibg for response topic: \(responseTopic)") try await networkingInteractor.requestNetworkAck(request, topic: topic, tag: AuthRequestParams.tag) try await networkingInteractor.subscribe(topic: responseTopic) } diff --git a/Sources/Auth/Services/Wallet/WalletRespondService.swift b/Sources/Auth/Services/Wallet/WalletRespondService.swift index ab38a20a4..6fac162ae 100644 --- a/Sources/Auth/Services/Wallet/WalletRespondService.swift +++ b/Sources/Auth/Services/Wallet/WalletRespondService.swift @@ -41,7 +41,6 @@ actor WalletRespondService { let selfPubKey = try kms.createX25519KeyPair() let agreementKeys = try kms.performKeyAgreement(selfPublicKey: selfPubKey, peerPublicKey: peerPubKey) try kms.setAgreementSecret(agreementKeys, topic: responseTopic) - let didpkh = DIDPKH(account: account) let cacao = CacaoFormatter().format(authRequestParams, respondParams.signature, didpkh) let response = RPCResponse(id: request.id!, result: cacao) From a2dc2027c878ad216e593af076fcd57057724171 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 13:57:31 +0200 Subject: [PATCH 14/17] fix protocol issue --- Sources/Auth/Services/App/AppRequestService.swift | 2 +- Sources/Auth/Services/Wallet/WalletRespondService.swift | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/Auth/Services/App/AppRequestService.swift b/Sources/Auth/Services/App/AppRequestService.swift index 3d2c43443..22a79b87c 100644 --- a/Sources/Auth/Services/App/AppRequestService.swift +++ b/Sources/Auth/Services/App/AppRequestService.swift @@ -21,7 +21,7 @@ actor AppRequestService { func request(params: RequestParams, topic: String) async throws { let pubKey = try kms.createX25519KeyPair() - let responseTopic = pubKey.hexRepresentation + let responseTopic = pubKey.rawRepresentation.sha256().toHexString() let requester = AuthRequestParams.Requester(publicKey: pubKey.hexRepresentation, metadata: appMetadata) let issueAt = ISO8601DateFormatter().string(from: Date()) let payload = AuthPayload(requestParams: params, iat: issueAt) diff --git a/Sources/Auth/Services/Wallet/WalletRespondService.swift b/Sources/Auth/Services/Wallet/WalletRespondService.swift index 6fac162ae..6b5030df9 100644 --- a/Sources/Auth/Services/Wallet/WalletRespondService.swift +++ b/Sources/Auth/Services/Wallet/WalletRespondService.swift @@ -36,11 +36,12 @@ actor WalletRespondService { guard let request = rpcHistory.get(recordId: respondParams.id)?.request else { throw Errors.recordForIdNotFound } guard let authRequestParams = try? request.params?.get(AuthRequestParams.self) else { throw Errors.malformedAuthRequestParams } - let peerPubKey = authRequestParams.requester.publicKey + let peerPubKey = try AgreementPublicKey(hex: authRequestParams.requester.publicKey) let responseTopic = peerPubKey.rawRepresentation.sha256().toHexString() let selfPubKey = try kms.createX25519KeyPair() - let agreementKeys = try kms.performKeyAgreement(selfPublicKey: selfPubKey, peerPublicKey: peerPubKey) + let agreementKeys = try kms.performKeyAgreement(selfPublicKey: selfPubKey, peerPublicKey: peerPubKey.hexRepresentation) try kms.setAgreementSecret(agreementKeys, topic: responseTopic) + let didpkh = DIDPKH(account: account) let cacao = CacaoFormatter().format(authRequestParams, respondParams.signature, didpkh) let response = RPCResponse(id: request.id!, result: cacao) From 6d3f46c662269bb162334127bba2e0b34e96894f Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 14:43:04 +0200 Subject: [PATCH 15/17] fix protocol issue - store pub key for response topic --- Sources/Auth/Services/App/AppRequestService.swift | 3 ++- Sources/Auth/Services/Common/NetworkingInteractor.swift | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/Auth/Services/App/AppRequestService.swift b/Sources/Auth/Services/App/AppRequestService.swift index 22a79b87c..7dff38849 100644 --- a/Sources/Auth/Services/App/AppRequestService.swift +++ b/Sources/Auth/Services/App/AppRequestService.swift @@ -21,12 +21,13 @@ actor AppRequestService { func request(params: RequestParams, topic: String) async throws { let pubKey = try kms.createX25519KeyPair() - let responseTopic = pubKey.rawRepresentation.sha256().toHexString() + let responseTopic = pubKey.rawRepresentation.sha256().toHexString() let requester = AuthRequestParams.Requester(publicKey: pubKey.hexRepresentation, metadata: appMetadata) let issueAt = ISO8601DateFormatter().string(from: Date()) let payload = AuthPayload(requestParams: params, iat: issueAt) let params = AuthRequestParams(requester: requester, payloadParams: payload) let request = RPCRequest(method: "wc_authRequest", params: params) + try kms.setPublicKey(publicKey: pubKey, for: responseTopic) logger.debug("Subscribibg for response topic: \(responseTopic)") try await networkingInteractor.requestNetworkAck(request, topic: topic, tag: AuthRequestParams.tag) try await networkingInteractor.subscribe(topic: responseTopic) diff --git a/Sources/Auth/Services/Common/NetworkingInteractor.swift b/Sources/Auth/Services/Common/NetworkingInteractor.swift index d3bc9a3bb..fba8bf01d 100644 --- a/Sources/Auth/Services/Common/NetworkingInteractor.swift +++ b/Sources/Auth/Services/Common/NetworkingInteractor.swift @@ -57,7 +57,7 @@ class NetworkingInteractor: NetworkInteracting { } func unsubscribe(topic: String) { - fatalError("not implemented") +// fatalError("not implemented") } func request(_ request: RPCRequest, topic: String, tag: Int, envelopeType: Envelope.EnvelopeType) async throws { From a3239f871419b2e3d43075d8025a28089f502826 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 18 Aug 2022 15:06:27 +0200 Subject: [PATCH 16/17] update auth e2e test: received successful response --- Example/IntegrationTests/Auth/AuthTests.swift | 7 +++++-- Sources/Auth/Services/App/AppRespondSubscriber.swift | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index ed7796ee6..c5d7046c4 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -13,7 +13,7 @@ final class AuthTests: XCTestCase { override func setUp() { app = makeClient(prefix: "👻 App") - let walletAccount = Account(chainIdentifier: "eip155:1", address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")! + let walletAccount = Account(chainIdentifier: "eip155:1", address: "0x724d0D2DaD3fbB0C168f947B87Fa5DBe36F1A8bf")! wallet = makeClient(prefix: "🤑 Wallet", account: walletAccount) let expectation = expectation(description: "Wait Clients Connected") @@ -68,7 +68,10 @@ final class AuthTests: XCTestCase { wallet.authRequestPublisher.sink { [unowned self] (id, message) in Task(priority: .high) { print("responding") - try! await wallet.respond(.success(RespondParams.stub(id: id))) + let prvKey = Data(hex: "462c1dad6832d7d96ccf87bd6a686a4110e114aaaebd5512e552c0e3a87b480f") + let sig = try! MessageSigner(signer: Signer()).sign(message: message, privateKey: prvKey) + let cacaoSig = CacaoSignature(t: "eip191", s: sig) + try! await wallet.respond(.success(RespondParams(id: id, signature: cacaoSig))) } } .store(in: &publishers) diff --git a/Sources/Auth/Services/App/AppRespondSubscriber.swift b/Sources/Auth/Services/App/AppRespondSubscriber.swift index f9005587b..cba492bf3 100644 --- a/Sources/Auth/Services/App/AppRespondSubscriber.swift +++ b/Sources/Auth/Services/App/AppRespondSubscriber.swift @@ -55,6 +55,7 @@ class AppRespondSubscriber { message: message, address: address ) + logger.debug("Received response with valid signature") onResponse?(requestId, .success(cacao)) } catch { logger.debug("Received response with invalid signature") From 70d85d4fbbf45ab6e8802cd4e6614f3bc60db230 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 19 Aug 2022 10:45:10 +0200 Subject: [PATCH 17/17] update style, logs add unsubscribe to networking interactor --- Example/IntegrationTests/Auth/AuthTests.swift | 23 ++++--------------- .../Auth/Services/App/AppRequestService.swift | 2 +- .../Common/NetworkingInteractor.swift | 8 ++++++- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index c5d7046c4..05cb74088 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -9,6 +9,7 @@ import Combine final class AuthTests: XCTestCase { var app: AuthClient! var wallet: AuthClient! + let prvKey = Data(hex: "462c1dad6832d7d96ccf87bd6a686a4110e114aaaebd5512e552c0e3a87b480f") private var publishers = [AnyCancellable]() override func setUp() { @@ -67,11 +68,9 @@ final class AuthTests: XCTestCase { try! await wallet.pair(uri: uri) wallet.authRequestPublisher.sink { [unowned self] (id, message) in Task(priority: .high) { - print("responding") - let prvKey = Data(hex: "462c1dad6832d7d96ccf87bd6a686a4110e114aaaebd5512e552c0e3a87b480f") - let sig = try! MessageSigner(signer: Signer()).sign(message: message, privateKey: prvKey) - let cacaoSig = CacaoSignature(t: "eip191", s: sig) - try! await wallet.respond(.success(RespondParams(id: id, signature: cacaoSig))) + let signature = try! MessageSigner(signer: Signer()).sign(message: message, privateKey: prvKey) + let cacaoSignature = CacaoSignature(t: "eip191", s: signature) + try! await wallet.respond(.success(RespondParams(id: id, signature: cacaoSignature))) } } .store(in: &publishers) @@ -83,17 +82,3 @@ final class AuthTests: XCTestCase { wait(for: [responseExpectation], timeout: 2) } } - -extension RespondParams { - static func stub(id: RPCID) -> RespondParams { - RespondParams( - id: id, - signature: CacaoSignature.stub()) - } -} - -extension CacaoSignature { - static func stub() -> CacaoSignature { - return CacaoSignature(t: "eip191", s: "438effc459956b57fcd9f3dac6c675f9cee88abf21acab7305e8e32aa0303a883b06dcbd956279a7a2ca21ffa882ff55cc22e8ab8ec0f3fe90ab45f306938cfa1b") - } -} diff --git a/Sources/Auth/Services/App/AppRequestService.swift b/Sources/Auth/Services/App/AppRequestService.swift index 7dff38849..b3186e77d 100644 --- a/Sources/Auth/Services/App/AppRequestService.swift +++ b/Sources/Auth/Services/App/AppRequestService.swift @@ -28,7 +28,7 @@ actor AppRequestService { let params = AuthRequestParams(requester: requester, payloadParams: payload) let request = RPCRequest(method: "wc_authRequest", params: params) try kms.setPublicKey(publicKey: pubKey, for: responseTopic) - logger.debug("Subscribibg for response topic: \(responseTopic)") + logger.debug("AppRequestService: Subscribibg for response topic: \(responseTopic)") try await networkingInteractor.requestNetworkAck(request, topic: topic, tag: AuthRequestParams.tag) try await networkingInteractor.subscribe(topic: responseTopic) } diff --git a/Sources/Auth/Services/Common/NetworkingInteractor.swift b/Sources/Auth/Services/Common/NetworkingInteractor.swift index fba8bf01d..62d152ccb 100644 --- a/Sources/Auth/Services/Common/NetworkingInteractor.swift +++ b/Sources/Auth/Services/Common/NetworkingInteractor.swift @@ -57,7 +57,13 @@ class NetworkingInteractor: NetworkInteracting { } func unsubscribe(topic: String) { -// fatalError("not implemented") + relayClient.unsubscribe(topic: topic) { [unowned self] error in + if let error = error { + logger.error(error) + } else { + rpcHistory.deleteAll(forTopic: topic) + } + } } func request(_ request: RPCRequest, topic: String, tag: Int, envelopeType: Envelope.EnvelopeType) async throws {