diff --git a/Example/DApp/Sign/SelectChain/SelectChainViewController.swift b/Example/DApp/Sign/SelectChain/SelectChainViewController.swift index bd577d639..4e7aa7804 100644 --- a/Example/DApp/Sign/SelectChain/SelectChainViewController.swift +++ b/Example/DApp/Sign/SelectChain/SelectChainViewController.swift @@ -38,32 +38,13 @@ class SelectChainViewController: UIViewController, UITableViewDataSource { let namespaces: [String: ProposalNamespace] = [ "eip155": ProposalNamespace( chains: [ - Blockchain("eip155:137")! + Blockchain("eip155:1")! ], methods: [ "eth_sendTransaction", "personal_sign", "eth_signTypedData" ], events: [] - ), - "eip155:1": ProposalNamespace( - methods: [ - "eth_sendTransaction", - "personal_sign", - "eth_signTypedData" - ], - events: [] - ) - ] - let optionalNamespaces: [String: ProposalNamespace] = [ - "solana": ProposalNamespace( - chains: [ - Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")! - ], - methods: [ - "solana_signMessage", - "solana_signTransaction" - ], events: [] ) ] let sessionProperties: [String: String] = [ @@ -73,7 +54,7 @@ class SelectChainViewController: UIViewController, UITableViewDataSource { Task { WalletConnectModal.set(sessionParams: .init( requiredNamespaces: namespaces, - optionalNamespaces: optionalNamespaces, + optionalNamespaces: [:], sessionProperties: sessionProperties )) } diff --git a/Sources/Auth/Services/App/AppRequestService.swift b/Sources/Auth/Services/App/AppRequestService.swift index afc45eac9..ede0b8a31 100644 --- a/Sources/Auth/Services/App/AppRequestService.swift +++ b/Sources/Auth/Services/App/AppRequestService.swift @@ -25,7 +25,7 @@ actor AppRequestService { let requester = AuthRequestParams.Requester(publicKey: pubKey.hexRepresentation, metadata: appMetadata) let payload = AuthPayload(requestParams: params, iat: iatProvader.iat) let params = AuthRequestParams(requester: requester, payloadParams: payload) - let request = RPCRequest(method: "wc_authRequest", params: params) + let request = RPCRequest(method: "wc_authRequest", params: params, topic: topic) try kms.setPublicKey(publicKey: pubKey, for: responseTopic) logger.debug("AppRequestService: Subscribibg for response topic: \(responseTopic)") try await networkingInteractor.request(request, topic: topic, protocolMethod: AuthRequestProtocolMethod()) diff --git a/Sources/Chat/ChatClient.swift b/Sources/Chat/ChatClient.swift index 445c96ab8..009160eee 100644 --- a/Sources/Chat/ChatClient.swift +++ b/Sources/Chat/ChatClient.swift @@ -182,6 +182,7 @@ public class ChatClient { /// Ping its peer to evaluate if it's currently online /// - Parameter topic: chat thread topic public func ping(topic: String) { + // Pass 'topic' value to the RPCRequest when implemented fatalError("not implemented") } diff --git a/Sources/Chat/ProtocolServices/Common/LeaveService.swift b/Sources/Chat/ProtocolServices/Common/LeaveService.swift index 54e724b96..0b46ea9d4 100644 --- a/Sources/Chat/ProtocolServices/Common/LeaveService.swift +++ b/Sources/Chat/ProtocolServices/Common/LeaveService.swift @@ -2,6 +2,7 @@ import Foundation class LeaveService { func leave(topic: String) async throws { + // Pass 'topic' value to the RPCRequest when implemented fatalError("not implemented") } } diff --git a/Sources/Chat/ProtocolServices/Common/MessagingService.swift b/Sources/Chat/ProtocolServices/Common/MessagingService.swift index f032b3b97..6c0b8c223 100644 --- a/Sources/Chat/ProtocolServices/Common/MessagingService.swift +++ b/Sources/Chat/ProtocolServices/Common/MessagingService.swift @@ -38,7 +38,7 @@ class MessagingService { ) let protocolMethod = ChatMessageProtocolMethod() - let request = RPCRequest(method: protocolMethod.method, params: wrapper) + let request = RPCRequest(method: protocolMethod.method, params: wrapper, topic: topic) try await networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) logger.debug("Message sent on topic: \(topic)") diff --git a/Sources/Chat/ProtocolServices/Inviter/InviteService.swift b/Sources/Chat/ProtocolServices/Inviter/InviteService.swift index f1f09d31f..9523a42db 100644 --- a/Sources/Chat/ProtocolServices/Inviter/InviteService.swift +++ b/Sources/Chat/ProtocolServices/Inviter/InviteService.swift @@ -60,7 +60,7 @@ class InviteService { ) let inviteId = RPCID() - let request = RPCRequest(method: protocolMethod.method, params: wrapper, rpcid: inviteId) + let request = RPCRequest(method: protocolMethod.method, params: wrapper, rpcid: inviteId, topic: inviteTopic) try await networkingInteractor.subscribe(topic: responseTopic) try await networkingInteractor.request(request, topic: inviteTopic, protocolMethod: protocolMethod, envelopeType: .type1(pubKey: selfPubKeyY.rawRepresentation)) diff --git a/Sources/JSONRPC/RPCRequest.swift b/Sources/JSONRPC/RPCRequest.swift index f11581320..f98ff6d44 100644 --- a/Sources/JSONRPC/RPCRequest.swift +++ b/Sources/JSONRPC/RPCRequest.swift @@ -16,59 +16,62 @@ public struct RPCRequest: Equatable { public let params: AnyCodable? public let id: RPCID? + + public let topic: String? - internal init(method: String, params: AnyCodable?, id: RPCID?) { + internal init(method: String, params: AnyCodable?, id: RPCID?, topic: String? = nil) { self.jsonrpc = "2.0" self.method = method self.params = params self.id = id + self.topic = topic } - internal init(method: String, checkedParams params: C, id: RPCID) throws where C: Codable { + internal init(method: String, checkedParams params: C, id: RPCID, topic: String?) throws where C: Codable { if params is Int || params is Double || params is String || params is Bool { throw Error.invalidPrimitiveParameter } - self.init(method: method, params: AnyCodable(params), id: id) + self.init(method: method, params: AnyCodable(params), id: id, topic: topic) } - public init(method: String, checkedParams params: C, idGenerator: IdentifierGenerator = defaultIdentifierGenerator) throws where C: Codable { - try self.init(method: method, checkedParams: params, id: idGenerator.next()) + public init(method: String, checkedParams params: C, idGenerator: IdentifierGenerator = defaultIdentifierGenerator, topic: String?) throws where C: Codable { + try self.init(method: method, checkedParams: params, id: idGenerator.next(), topic: topic) } - public init(method: String, checkedParams params: C, id: Int64) throws where C: Codable { - try self.init(method: method, checkedParams: params, id: .right(id)) + public init(method: String, checkedParams params: C, id: Int64, topic: String?) throws where C: Codable { + try self.init(method: method, checkedParams: params, id: .right(id), topic: topic) } - public init(method: String, checkedParams params: C, id: String) throws where C: Codable { - try self.init(method: method, checkedParams: params, id: .left(id)) + public init(method: String, checkedParams params: C, id: String, topic: String?) throws where C: Codable { + try self.init(method: method, checkedParams: params, id: .left(id), topic: topic) } - public init(method: String, params: C, idGenerator: IdentifierGenerator = defaultIdentifierGenerator) where C: Codable { - self.init(method: method, params: AnyCodable(params), id: idGenerator.next()) + public init(method: String, params: C, idGenerator: IdentifierGenerator = defaultIdentifierGenerator, topic: String?) where C: Codable { + self.init(method: method, params: AnyCodable(params), id: idGenerator.next(), topic: topic) } - public init(method: String, params: C, id: Int64) where C: Codable { - self.init(method: method, params: AnyCodable(params), id: .right(id)) + public init(method: String, params: C, id: Int64, topic: String?) where C: Codable { + self.init(method: method, params: AnyCodable(params), id: .right(id), topic: topic) } - public init(method: String, params: C, rpcid: RPCID) where C: Codable { - self.init(method: method, params: AnyCodable(params), id: rpcid) + public init(method: String, params: C, rpcid: RPCID, topic: String?) where C: Codable { + self.init(method: method, params: AnyCodable(params), id: rpcid, topic: topic) } - public init(method: String, params: C, id: String) where C: Codable { - self.init(method: method, params: AnyCodable(params), id: .left(id)) + public init(method: String, params: C, id: String, topic: String?) where C: Codable { + self.init(method: method, params: AnyCodable(params), id: .left(id), topic: topic) } - public init(method: String, idGenerator: IdentifierGenerator = defaultIdentifierGenerator) { - self.init(method: method, params: nil, id: idGenerator.next()) + public init(method: String, idGenerator: IdentifierGenerator = defaultIdentifierGenerator, topic: String?) { + self.init(method: method, params: nil, id: idGenerator.next(), topic: topic) } - public init(method: String, id: Int64) { - self.init(method: method, params: nil, id: .right(id)) + public init(method: String, id: Int64, topic: String?) { + self.init(method: method, params: nil, id: .right(id), topic: topic) } - public init(method: String, id: String) { - self.init(method: method, params: nil, id: .left(id)) + public init(method: String, id: String, topic: String?) { + self.init(method: method, params: nil, id: .left(id), topic: topic) } } @@ -101,6 +104,7 @@ extension RPCRequest: Codable { id = try container.decodeIfPresent(RPCID.self, forKey: .id) method = try container.decode(String.self, forKey: .method) params = try container.decodeIfPresent(AnyCodable.self, forKey: .params) + topic = try container.decodeIfPresent(String.self, forKey: .topic) if let decodedParams = params { if decodedParams.value is Int || decodedParams.value is Double || decodedParams.value is String || decodedParams.value is Bool { throw DecodingError.dataCorruptedError( diff --git a/Sources/WalletConnectNetworking/NetworkingInteractor.swift b/Sources/WalletConnectNetworking/NetworkingInteractor.swift index f311cdc5b..5b5441d51 100644 --- a/Sources/WalletConnectNetworking/NetworkingInteractor.swift +++ b/Sources/WalletConnectNetworking/NetworkingInteractor.swift @@ -193,7 +193,15 @@ public class NetworkingInteractor: NetworkInteracting { private func manageSubscription(_ topic: String, _ encodedEnvelope: String, _ publishedAt: Date) { if let (deserializedJsonRpcRequest, derivedTopic, decryptedPayload): (RPCRequest, String?, Data) = serializer.tryDeserialize(topic: topic, encodedEnvelope: encodedEnvelope) { - handleRequest(topic: topic, request: deserializedJsonRpcRequest, decryptedPayload: decryptedPayload, publishedAt: publishedAt, derivedTopic: derivedTopic) + if let rpcRequestTopic = deserializedJsonRpcRequest.topic { + if rpcRequestTopic == topic { + handleRequest(topic: topic, request: deserializedJsonRpcRequest, decryptedPayload: decryptedPayload, publishedAt: publishedAt, derivedTopic: derivedTopic) + } else { + logger.debug("Networking Interactor - Mismatched topic decoded from message") + } + } else { + handleRequest(topic: topic, request: deserializedJsonRpcRequest, decryptedPayload: decryptedPayload, publishedAt: publishedAt, derivedTopic: derivedTopic) + } } else if let (response, derivedTopic, _): (RPCResponse, String?, Data) = serializer.tryDeserialize(topic: topic, encodedEnvelope: encodedEnvelope) { handleResponse(topic: topic, response: response, publishedAt: publishedAt, derivedTopic: derivedTopic) } else { diff --git a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyDelete/DeleteNotifySubscriptionRequester.swift b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyDelete/DeleteNotifySubscriptionRequester.swift index ea3281849..afcbf662e 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyDelete/DeleteNotifySubscriptionRequester.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyDelete/DeleteNotifySubscriptionRequester.swift @@ -46,7 +46,7 @@ class DeleteNotifySubscriptionRequester { account: subscription.account ) - let request = RPCRequest(method: protocolMethod.method, params: wrapper) + let request = RPCRequest(method: protocolMethod.method, params: wrapper, topic: topic) try await networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) try notifyStorage.deleteSubscription(topic: topic) diff --git a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyUpdate/NotifyUpdateRequester.swift b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyUpdate/NotifyUpdateRequester.swift index 7ddb67379..d54e84953 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyUpdate/NotifyUpdateRequester.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyUpdate/NotifyUpdateRequester.swift @@ -45,7 +45,8 @@ class NotifyUpdateRequester: NotifyUpdateRequesting { let request = try createJWTRequest( dappPubKey: DIDKey(rawData: dappAuthenticationKey), subscriptionAccount: subscription.account, - appDomain: subscription.metadata.url, scope: scope + appDomain: subscription.metadata.url, scope: scope, + topic: topic ) let protocolMethod = NotifyUpdateProtocolMethod() @@ -53,7 +54,7 @@ class NotifyUpdateRequester: NotifyUpdateRequesting { try await networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) } - private func createJWTRequest(dappPubKey: DIDKey, subscriptionAccount: Account, appDomain: String, scope: Set) throws -> RPCRequest { + private func createJWTRequest(dappPubKey: DIDKey, subscriptionAccount: Account, appDomain: String, scope: Set, topic: String) throws -> RPCRequest { let protocolMethod = NotifyUpdateProtocolMethod().method let scopeClaim = scope.joined(separator: " ") let app = DIDWeb(host: appDomain) @@ -62,6 +63,6 @@ class NotifyUpdateRequester: NotifyUpdateRequesting { payload: jwtPayload, account: subscriptionAccount ) - return RPCRequest(method: protocolMethod, params: wrapper) + return RPCRequest(method: protocolMethod, params: wrapper, topic: topic) } } diff --git a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift index ab65a9e0c..538d83a66 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyWatchSubscriptions/NotifyWatchSubscriptionsRequester.swift @@ -70,7 +70,7 @@ class NotifyWatchSubscriptionsRequester { subscriptionAccount: account) - let request = RPCRequest(method: protocolMethod.method, params: watchSubscriptionsAuthWrapper) + let request = RPCRequest(method: protocolMethod.method, params: watchSubscriptionsAuthWrapper, topic: responseTopic) logger.debug("Subscribing to response topic: \(responseTopic)") diff --git a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_pushSubscribe/NotifySubscribeRequester.swift b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_pushSubscribe/NotifySubscribeRequester.swift index 6601d77b7..70afbe98a 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_pushSubscribe/NotifySubscribeRequester.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_pushSubscribe/NotifySubscribeRequester.swift @@ -62,7 +62,7 @@ class NotifySubscribeRequester { subscriptionAccount: account, appDomain: appDomain ) - let request = RPCRequest(method: protocolMethod.method, params: subscriptionAuthWrapper) + let request = RPCRequest(method: protocolMethod.method, params: subscriptionAuthWrapper, topic: responseTopic) logger.debug("Subscribing to response topic: \(responseTopic)") diff --git a/Sources/WalletConnectPairing/Services/Common/DeletePairingService.swift b/Sources/WalletConnectPairing/Services/Common/DeletePairingService.swift index afa43e517..eb7f99ebc 100644 --- a/Sources/WalletConnectPairing/Services/Common/DeletePairingService.swift +++ b/Sources/WalletConnectPairing/Services/Common/DeletePairingService.swift @@ -20,7 +20,7 @@ class DeletePairingService { let reason = PairingReasonCode.userDisconnected let protocolMethod = PairingProtocolMethod.delete logger.debug("Will delete pairing for reason: message: \(reason.message) code: \(reason.code)") - let request = RPCRequest(method: protocolMethod.method, params: reason) + let request = RPCRequest(method: protocolMethod.method, params: reason, topic: topic) try await networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) pairingStorage.delete(topic: topic) kms.deleteSymmetricKey(for: topic) diff --git a/Sources/WalletConnectPairing/Services/Common/Ping/PingRequester.swift b/Sources/WalletConnectPairing/Services/Common/Ping/PingRequester.swift index fbe37bee6..6a7f59b7f 100644 --- a/Sources/WalletConnectPairing/Services/Common/Ping/PingRequester.swift +++ b/Sources/WalletConnectPairing/Services/Common/Ping/PingRequester.swift @@ -10,7 +10,7 @@ public class PingRequester { } public func ping(topic: String) async throws { - let request = RPCRequest(method: method.method, params: PairingPingParams()) + let request = RPCRequest(method: method.method, params: PairingPingParams(), topic: topic) try await networkingInteractor.request(request, topic: topic, protocolMethod: method) } } diff --git a/Sources/WalletConnectRelay/RPC/RelayRPC.swift b/Sources/WalletConnectRelay/RPC/RelayRPC.swift index 95362a7ba..90042550d 100644 --- a/Sources/WalletConnectRelay/RPC/RelayRPC.swift +++ b/Sources/WalletConnectRelay/RPC/RelayRPC.swift @@ -7,7 +7,7 @@ extension RelayRPC where Parameters: Codable { } func asRPCRequest() -> RPCRequest { - RPCRequest(method: self.method, params: self.params, idGenerator: self.idGenerator) + RPCRequest(method: self.method, params: self.params, idGenerator: self.idGenerator, topic: nil) } } diff --git a/Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift b/Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift index 7e26a2725..c4a868540 100644 --- a/Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift +++ b/Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift @@ -169,7 +169,7 @@ final class ApproveEngine { sessionStore.setSession(session) let protocolMethod = SessionSettleProtocolMethod() - let request = RPCRequest(method: protocolMethod.method, params: settleParams) + let request = RPCRequest(method: protocolMethod.method, params: settleParams, topic: topic) async let subscription: () = networkingInteractor.subscribe(topic: topic) async let settleRequest: () = networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) diff --git a/Sources/WalletConnectSign/Engine/Common/DeleteSessionService.swift b/Sources/WalletConnectSign/Engine/Common/DeleteSessionService.swift index a1c617e49..3c8314883 100644 --- a/Sources/WalletConnectSign/Engine/Common/DeleteSessionService.swift +++ b/Sources/WalletConnectSign/Engine/Common/DeleteSessionService.swift @@ -21,7 +21,7 @@ class DeleteSessionService { let protocolMethod = SessionDeleteProtocolMethod() let reason = SessionType.Reason(code: reasonCode.code, message: reasonCode.message) logger.debug("Will delete session for reason: message: \(reason.message) code: \(reason.code)") - let request = RPCRequest(method: protocolMethod.method, params: reason) + let request = RPCRequest(method: protocolMethod.method, params: reason, topic: topic) try await networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) sessionStore.delete(topic: topic) logger.debug("Session disconnected") diff --git a/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift b/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift index 3e6cec6bf..bb75f153c 100644 --- a/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift +++ b/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift @@ -67,7 +67,7 @@ final class SessionEngine { let chainRequest = SessionType.RequestParams.Request(method: request.method, params: request.params, expiry: request.expiry) let sessionRequestParams = SessionType.RequestParams(request: chainRequest, chainId: request.chainId) let protocolMethod = SessionRequestProtocolMethod(ttl: request.calculateTtl()) - let rpcRequest = RPCRequest(method: protocolMethod.method, params: sessionRequestParams, rpcid: request.id) + let rpcRequest = RPCRequest(method: protocolMethod.method, params: sessionRequestParams, rpcid: request.id, topic: request.topic) try await networkingInteractor.request(rpcRequest, topic: request.topic, protocolMethod: SessionRequestProtocolMethod()) } @@ -106,7 +106,7 @@ final class SessionEngine { guard session.hasPermission(forEvent: event.name, onChain: chainId) else { throw WalletConnectError.invalidEvent } - let rpcRequest = RPCRequest(method: protocolMethod.method, params: SessionType.EventParams(event: event, chainId: chainId)) + let rpcRequest = RPCRequest(method: protocolMethod.method, params: SessionType.EventParams(event: event, chainId: chainId), topic: topic) try await networkingInteractor.request(rpcRequest, topic: topic, protocolMethod: protocolMethod) } } diff --git a/Sources/WalletConnectSign/Engine/Controller/ControllerSessionStateMachine.swift b/Sources/WalletConnectSign/Engine/Controller/ControllerSessionStateMachine.swift index eb6becf93..3b6eb9959 100644 --- a/Sources/WalletConnectSign/Engine/Controller/ControllerSessionStateMachine.swift +++ b/Sources/WalletConnectSign/Engine/Controller/ControllerSessionStateMachine.swift @@ -31,7 +31,7 @@ final class ControllerSessionStateMachine { try Namespace.validate(namespaces) logger.debug("Controller will update methods") sessionStore.setSession(session) - let request = RPCRequest(method: protocolMethod.method, params: SessionType.UpdateParams(namespaces: namespaces)) + let request = RPCRequest(method: protocolMethod.method, params: SessionType.UpdateParams(namespaces: namespaces), topic: topic) try await networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) } @@ -42,7 +42,7 @@ final class ControllerSessionStateMachine { try session.updateExpiry(by: ttl) let newExpiry = Int64(session.expiryDate.timeIntervalSince1970 ) sessionStore.setSession(session) - let request = RPCRequest(method: protocolMethod.method, params: SessionType.UpdateExpiryParams(expiry: newExpiry)) + let request = RPCRequest(method: protocolMethod.method, params: SessionType.UpdateExpiryParams(expiry: newExpiry), topic: topic) try await networkingInteractor.request(request, topic: topic, protocolMethod: protocolMethod) } diff --git a/Sources/WalletConnectSign/Services/App/AppProposeService.swift b/Sources/WalletConnectSign/Services/App/AppProposeService.swift index 541999a1a..47b44914a 100644 --- a/Sources/WalletConnectSign/Services/App/AppProposeService.swift +++ b/Sources/WalletConnectSign/Services/App/AppProposeService.swift @@ -47,7 +47,7 @@ final class AppProposeService { sessionProperties: sessionProperties ) - let request = RPCRequest(method: protocolMethod.method, params: proposal) + let request = RPCRequest(method: protocolMethod.method, params: proposal, topic: pairingTopic) try await networkingInteractor.request(request, topic: pairingTopic, protocolMethod: protocolMethod) } } diff --git a/Sources/WalletConnectSigner/Ethereum/EIP1271/EIP1271Verifier.swift b/Sources/WalletConnectSigner/Ethereum/EIP1271/EIP1271Verifier.swift index bd3c318da..ad9f943ba 100644 --- a/Sources/WalletConnectSigner/Ethereum/EIP1271/EIP1271Verifier.swift +++ b/Sources/WalletConnectSigner/Ethereum/EIP1271/EIP1271Verifier.swift @@ -16,7 +16,7 @@ actor EIP1271Verifier { let encoder = ValidSignatureMethod(signature: signature, messageHash: messageHash) let call = EthCall(to: address, data: encoder.encode()) let params = AnyCodable([AnyCodable(call), AnyCodable("latest")]) - let request = RPCRequest(method: "eth_call", params: params) + let request = RPCRequest(method: "eth_call", params: params, topic: nil) let data = try JSONEncoder().encode(request) let httpService = RPCService(data: data, projectId: projectId, chainId: chainId) let response = try await httpClient.request(RPCResponse.self, at: httpService) diff --git a/Sources/WalletConnectSigner/Ethereum/ENS/ENSRegistryContract.swift b/Sources/WalletConnectSigner/Ethereum/ENS/ENSRegistryContract.swift index 1e6ba1855..fda24d16e 100644 --- a/Sources/WalletConnectSigner/Ethereum/ENS/ENSRegistryContract.swift +++ b/Sources/WalletConnectSigner/Ethereum/ENS/ENSRegistryContract.swift @@ -16,7 +16,7 @@ actor ENSRegistryContract { let encoder = ENSResolverMethod(namehash: namehash) let call = EthCall(to: address, data: encoder.encode()) let params = AnyCodable([AnyCodable(call), AnyCodable("latest")]) - let request = RPCRequest(method: "eth_call", params: params) + let request = RPCRequest(method: "eth_call", params: params, topic: nil) let data = try JSONEncoder().encode(request) let httpService = RPCService(data: data, projectId: projectId, chainId: chainId) let response = try await httpClient.request(RPCResponse.self, at: httpService) diff --git a/Sources/WalletConnectSigner/Ethereum/ENS/ENSResolverContract.swift b/Sources/WalletConnectSigner/Ethereum/ENS/ENSResolverContract.swift index e91f17972..5860d9f94 100644 --- a/Sources/WalletConnectSigner/Ethereum/ENS/ENSResolverContract.swift +++ b/Sources/WalletConnectSigner/Ethereum/ENS/ENSResolverContract.swift @@ -37,7 +37,7 @@ private extension ENSResolverContract { func ethCall(with data: String) async throws -> RPCResponse { let call = EthCall(to: address, data: data) let params = AnyCodable([AnyCodable(call), AnyCodable("latest")]) - let request = RPCRequest(method: "eth_call", params: params) + let request = RPCRequest(method: "eth_call", params: params, topic: nil) let data = try JSONEncoder().encode(request) let httpService = RPCService(data: data, projectId: projectId, chainId: chainId) return try await httpClient.request(RPCResponse.self, at: httpService) diff --git a/Sources/WalletConnectSync/Services/SyncService.swift b/Sources/WalletConnectSync/Services/SyncService.swift index 9902578de..79b7c499d 100644 --- a/Sources/WalletConnectSync/Services/SyncService.swift +++ b/Sources/WalletConnectSync/Services/SyncService.swift @@ -51,7 +51,7 @@ final class SyncService { let protocolMethod = SyncSetMethod() let params = StoreSet(key: object.databaseId, value: try object.json()) let rpcid = RPCID() - let request = RPCRequest(method: protocolMethod.method, params: params, rpcid: rpcid) + let request = RPCRequest(method: protocolMethod.method, params: params, rpcid: rpcid, topic: nil) let record = try indexStore.getRecord(account: account, name: store) try await networkInteractor.request(request, topic: record.topic, protocolMethod: protocolMethod) @@ -64,7 +64,7 @@ final class SyncService { func delete(account: Account, store: String, key: String) async throws { let protocolMethod = SyncDeleteMethod() let rpcid = RPCID() - let request = RPCRequest(method: protocolMethod.method, params: ["key": key], rpcid: rpcid) + let request = RPCRequest(method: protocolMethod.method, params: ["key": key], rpcid: rpcid, topic: nil) let record = try indexStore.getRecord(account: account, name: store) try await networkInteractor.request(request, topic: record.topic, protocolMethod: protocolMethod) diff --git a/Tests/AuthTests/AppRespondSubscriberTests.swift b/Tests/AuthTests/AppRespondSubscriberTests.swift index 4383374d7..4dcdff38d 100644 --- a/Tests/AuthTests/AppRespondSubscriberTests.swift +++ b/Tests/AuthTests/AppRespondSubscriberTests.swift @@ -46,7 +46,7 @@ class AppRespondSubscriberTests: XCTestCase { XCTAssertNotEqual(params.payloadParams, compromissedParams.payloadParams) - let request = RPCRequest(method: "wc_authRequest", params: AuthRequestParams.stub(), id: requestId.right!) + let request = RPCRequest(method: "wc_authRequest", params: AuthRequestParams.stub(), id: requestId.right!, topic: topic) try! rpcHistory.set(request, forTopic: topic, emmitedBy: .local) var messageId: RPCID! diff --git a/Tests/JSONRPCTests/RPCRequestTests.swift b/Tests/JSONRPCTests/RPCRequestTests.swift index f34d365ba..938279744 100644 --- a/Tests/JSONRPCTests/RPCRequestTests.swift +++ b/Tests/JSONRPCTests/RPCRequestTests.swift @@ -5,14 +5,14 @@ import TestingUtils private func makeRequests() -> [RPCRequest] { return [ - RPCRequest(method: String.random(), id: Int64.random()), - RPCRequest(method: String.random(), id: String.random()), - RPCRequest(method: String.random(), params: EmptyCodable(), id: Int64.random()), - RPCRequest(method: String.random(), params: EmptyCodable(), id: String.random()), - RPCRequest(method: String.random(), params: [0, 1, 2], id: Int64.random()), - RPCRequest(method: String.random(), params: ["0", "1", "2"], id: String.random()), - RPCRequest(method: String.random(), params: [AnyCodable(0), AnyCodable("0")], id: Int64.random()), - RPCRequest(method: String.random(), params: [AnyCodable(0), AnyCodable("0")], id: String.random()) + RPCRequest(method: String.random(), id: Int64.random(), topic: "topic"), + RPCRequest(method: String.random(), id: String.random(), topic: "topic"), + RPCRequest(method: String.random(), params: EmptyCodable(), id: Int64.random(), topic: "topic"), + RPCRequest(method: String.random(), params: EmptyCodable(), id: String.random(), topic: "topic"), + RPCRequest(method: String.random(), params: [0, 1, 2], id: Int64.random(), topic: "topic"), + RPCRequest(method: String.random(), params: ["0", "1", "2"], id: String.random(), topic: "topic"), + RPCRequest(method: String.random(), params: [AnyCodable(0), AnyCodable("0")], id: Int64.random(), topic: "topic"), + RPCRequest(method: String.random(), params: [AnyCodable(0), AnyCodable("0")], id: String.random(), topic: "topic") ] } @@ -29,31 +29,31 @@ final class RPCRequestTests: XCTestCase { let idGenerator = TestIdentifierGenerator() let cachedGenerator = RPCRequest.defaultIdentifierGenerator RPCRequest.defaultIdentifierGenerator = idGenerator - let requestA = RPCRequest(method: String.random(), params: EmptyCodable()) - let requestB = RPCRequest(method: String.random()) + let requestA = RPCRequest(method: String.random(), params: EmptyCodable(), topic: "topic") + let requestB = RPCRequest(method: String.random(), topic: "topic") XCTAssertEqual(requestA.id, idGenerator.id) XCTAssertEqual(requestB.id, idGenerator.id) RPCRequest.defaultIdentifierGenerator = cachedGenerator } func testCheckedParamsInit() { - XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0])) - XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], id: Int64.random())) - XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], id: String.random())) - XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable())) - XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), id: Int64.random())) - XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), id: String.random())) + XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], topic: "topic")) + XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], id: Int64.random(), topic: "topic")) + XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], id: String.random(), topic: "topic")) + XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), topic: "topic")) + XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), id: Int64.random(), topic: "topic")) + XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), id: String.random(), topic: "topic")) } func testCheckedParamsInitFailsWithPrimitives() { - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: 0, id: Int64.random())) - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: 0, id: String.random())) - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: "string", id: Int64.random())) - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: "string", id: String.random())) - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: Double.pi, id: Int64.random())) - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: Double.pi, id: String.random())) - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: true, id: Int64.random())) - XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: true, id: String.random())) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: 0, id: Int64.random(), topic: "topic")) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: 0, id: String.random(), topic: "topic")) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: "string", id: Int64.random(), topic: "topic")) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: "string", id: String.random(), topic: "topic")) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: Double.pi, id: Int64.random(), topic: "topic")) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: Double.pi, id: String.random(), topic: "topic")) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: true, id: Int64.random(), topic: "topic")) + XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: true, id: String.random(), topic: "topic")) } func testRoundTripCoding() throws { diff --git a/Tests/TestingUtils/Mocks/RPC.swift b/Tests/TestingUtils/Mocks/RPC.swift index a8255b7a0..babd179ab 100644 --- a/Tests/TestingUtils/Mocks/RPC.swift +++ b/Tests/TestingUtils/Mocks/RPC.swift @@ -3,10 +3,10 @@ import JSONRPC public extension RPCRequest { static func stub() -> RPCRequest { - RPCRequest(method: "method", params: EmptyCodable()) + RPCRequest(method: "method", params: EmptyCodable(), topic: "topic") } static func stub(method: String, id: Int64) -> RPCRequest { - RPCRequest(method: method, params: EmptyCodable(), id: id) + RPCRequest(method: method, params: EmptyCodable(), id: id, topic: "topic") } } diff --git a/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift b/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift index 4f88e9c94..72a710ffa 100644 --- a/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift +++ b/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift @@ -28,9 +28,9 @@ final class WalletPairServiceTestsTests: XCTestCase { } func testPairOnSameUriPresentsRequest() async { - let rpcRequest = RPCRequest(method: "session_propose", id: 1234) - let uri = WalletConnectURI.stub() + let rpcRequest = RPCRequest(method: "session_propose", id: 1234, topic: uri.topic) + try! await service.pair(uri) var pairing = storageMock.getPairing(forTopic: uri.topic) pairing?.receivedRequest() diff --git a/Tests/WalletConnectSignTests/ApproveEngineTests.swift b/Tests/WalletConnectSignTests/ApproveEngineTests.swift index de84c86d2..9054977bb 100644 --- a/Tests/WalletConnectSignTests/ApproveEngineTests.swift +++ b/Tests/WalletConnectSignTests/ApproveEngineTests.swift @@ -125,7 +125,7 @@ final class ApproveEngineTests: XCTestCase { let session = WCSession.stub(isSelfController: true, acknowledged: false) sessionStorageMock.setSession(session) - let request = RPCRequest(method: SessionSettleProtocolMethod().method, params: SessionType.SettleParams.stub()) + let request = RPCRequest(method: SessionSettleProtocolMethod().method, params: SessionType.SettleParams.stub(), topic: session.topic) let response = RPCResponse(matchingRequest: request, result: RPCResult.response(AnyCodable(true))) networkingInteractor.responsePublisherSubject.send((session.topic, request, response, Date(), nil)) @@ -140,7 +140,7 @@ final class ApproveEngineTests: XCTestCase { cryptoMock.setAgreementSecret(AgreementKeys.stub(), topic: session.topic) try! cryptoMock.setPrivateKey(privateKey) - let request = RPCRequest(method: SessionSettleProtocolMethod().method, params: SessionType.SettleParams.stub()) + let request = RPCRequest(method: SessionSettleProtocolMethod().method, params: SessionType.SettleParams.stub(), topic: session.topic) let response = RPCResponse.stubError(forRequest: request) networkingInteractor.responsePublisherSubject.send((session.topic, request, response, Date(), nil)) diff --git a/Tests/WalletConnectSignTests/Stub/Stubs.swift b/Tests/WalletConnectSignTests/Stub/Stubs.swift index 2f7961e22..e4f8d1d0c 100644 --- a/Tests/WalletConnectSignTests/Stub/Stubs.swift +++ b/Tests/WalletConnectSignTests/Stub/Stubs.swift @@ -55,22 +55,22 @@ extension AgreementPeer { extension RPCRequest { static func stubUpdateNamespaces(namespaces: [String: SessionNamespace] = SessionNamespace.stubDictionary()) -> RPCRequest { - return RPCRequest(method: SessionUpdateProtocolMethod().method, params: SessionType.UpdateParams(namespaces: namespaces)) + return RPCRequest(method: SessionUpdateProtocolMethod().method, params: SessionType.UpdateParams(namespaces: namespaces), topic: "topic") } static func stubUpdateExpiry(expiry: Int64) -> RPCRequest { - return RPCRequest(method: SessionExtendProtocolMethod().method, params: SessionType.UpdateExpiryParams(expiry: expiry)) + return RPCRequest(method: SessionExtendProtocolMethod().method, params: SessionType.UpdateExpiryParams(expiry: expiry), topic: "topic") } static func stubSettle() -> RPCRequest { - return RPCRequest(method: SessionSettleProtocolMethod().method, params: SessionType.SettleParams.stub()) + return RPCRequest(method: SessionSettleProtocolMethod().method, params: SessionType.SettleParams.stub(), topic: "topic") } static func stubRequest(method: String, chainId: Blockchain, expiry: UInt64? = nil) -> RPCRequest { let params = SessionType.RequestParams( request: SessionType.RequestParams.Request(method: method, params: AnyCodable(EmptyCodable()), expiry: expiry), chainId: chainId) - return RPCRequest(method: SessionRequestProtocolMethod().method, params: params) + return RPCRequest(method: SessionRequestProtocolMethod().method, params: params, topic: "topic") } } diff --git a/Tests/WalletConnectSignTests/WCResponseTests.swift b/Tests/WalletConnectSignTests/WCResponseTests.swift index fc3be3ae9..ee9a1b3ec 100644 --- a/Tests/WalletConnectSignTests/WCResponseTests.swift +++ b/Tests/WalletConnectSignTests/WCResponseTests.swift @@ -5,7 +5,7 @@ import JSONRPC final class RPCIDTests: XCTestCase { func testTimestamp() { - let request = RPCRequest(method: "method") + let request = RPCRequest(method: "method", topic: nil) let response = RPCResponse(matchingRequest: request, error: JSONRPCError(code: 0, message: "message")) let timestamp = Date(timeIntervalSince1970: TimeInterval(request.id!.right! / 1000 / 1000))