Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:WalletConnect/WalletConnectSwift…
Browse files Browse the repository at this point in the history
…V2 into #416-e2e-auth-clients-test
  • Loading branch information
llbartekll committed Aug 17, 2022
2 parents bd6424b + 3e83bec commit 0c1adde
Show file tree
Hide file tree
Showing 36 changed files with 409 additions and 480 deletions.
24 changes: 24 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Description

<!--
Please include:
* summary of the changes and the related issue
* relevant motivation and context
-->

Resolves # (issue)

## How Has This Been Tested?

<!--
Please:
* describe the tests that you ran to verify your changes.
* provide instructions so we can reproduce.
-->

<!-- If valid for smoke test on feature add screenshots -->

## Due Dilligence

* [ ] Breaking change
* [ ] Requires a documentation update
3 changes: 2 additions & 1 deletion Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
url: "wallet.connect",
icons: ["https://avatars.githubusercontent.com/u/37784886"])

Sign.configure(metadata: metadata, projectId: "8ba9ee138960775e5231b70cc5ef1c3a", socketFactory: SocketFactory())
Relay.configure(projectId: "8ba9ee138960775e5231b70cc5ef1c3a", socketFactory: SocketFactory())
Sign.configure(metadata: metadata)

if CommandLine.arguments.contains("-cleanInstall") {
try? Sign.instance.cleanup()
Expand Down
10 changes: 5 additions & 5 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
A50C036528AAD32200FE72D3 /* ClientDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50C036428AAD32200FE72D3 /* ClientDelegate.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 */; };
Expand Down Expand Up @@ -128,7 +129,6 @@
A5D85228286333E300DAF5C3 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = A5D85227286333E300DAF5C3 /* Starscream */; };
A5E03DF52864651200888481 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = A5E03DF42864651200888481 /* Starscream */; };
A5E03DFA286465C700888481 /* SignClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E03DF9286465C700888481 /* SignClientTests.swift */; };
A5E03DFB286465C700888481 /* ClientDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E03DF8286465C700888481 /* ClientDelegate.swift */; };
A5E03DFD286465D100888481 /* Stubs.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E03DFC286465D100888481 /* Stubs.swift */; };
A5E03DFF2864662500888481 /* WalletConnect in Frameworks */ = {isa = PBXBuildFile; productRef = A5E03DFE2864662500888481 /* WalletConnect */; };
A5E03E01286466EA00888481 /* WalletConnectChat in Frameworks */ = {isa = PBXBuildFile; productRef = A5E03E00286466EA00888481 /* WalletConnectChat */; };
Expand Down Expand Up @@ -208,6 +208,7 @@
84D2A66528A4F51E0088AE09 /* AuthTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthTests.swift; sourceTree = "<group>"; };
84F568C1279582D200D0A289 /* Signer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signer.swift; sourceTree = "<group>"; };
84F568C32795832A00D0A289 /* EthereumTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumTransaction.swift; sourceTree = "<group>"; };
A50C036428AAD32200FE72D3 /* ClientDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClientDelegate.swift; sourceTree = "<group>"; };
A50F3945288005B200064555 /* Types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
A5629AA82876A23100094373 /* ChatService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatService.swift; sourceTree = "<group>"; };
A5629AB82876CBC000094373 /* ChatListModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListModule.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -285,7 +286,6 @@
A5C2022A287EB89A007E3188 /* WelcomeInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeInteractor.swift; sourceTree = "<group>"; };
A5C2022C287EC3F0007E3188 /* RegisterService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterService.swift; sourceTree = "<group>"; };
A5E03DED286464DB00888481 /* IntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A5E03DF8286465C700888481 /* ClientDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientDelegate.swift; sourceTree = "<group>"; };
A5E03DF9286465C700888481 /* SignClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignClientTests.swift; sourceTree = "<group>"; };
A5E03DFC286465D100888481 /* Stubs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stubs.swift; sourceTree = "<group>"; };
A5E03E02286466F400888481 /* ChatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -445,7 +445,7 @@
767DC83328997F7600080FA9 /* Helpers */ = {
isa = PBXGroup;
children = (
A5E03DF8286465C700888481 /* ClientDelegate.swift */,
A50C036428AAD32200FE72D3 /* ClientDelegate.swift */,
767DC83428997F8E00080FA9 /* EthSendTransaction.swift */,
);
path = Helpers;
Expand Down Expand Up @@ -1274,10 +1274,10 @@
buildActionMask = 2147483647;
files = (
767DC83528997F8E00080FA9 /* EthSendTransaction.swift in Sources */,
A5E03DFB286465C700888481 /* ClientDelegate.swift in Sources */,
A5E03E03286466F400888481 /* ChatTests.swift in Sources */,
84D2A66628A4F51E0088AE09 /* AuthTests.swift in Sources */,
7694A5262874296A0001257E /* RegistryTests.swift in Sources */,
A50C036528AAD32200FE72D3 /* ClientDelegate.swift in Sources */,
A5E03E0D28646AD200888481 /* RelayClientEndToEndTests.swift in Sources */,
A5E03DFA286465C700888481 /* SignClientTests.swift in Sources */,
A5E03E0F28646D8A00888481 /* WebSocketFactory.swift in Sources */,
Expand Down Expand Up @@ -1760,7 +1760,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/flypaper0/Web3.swift";
requirement = {
branch = master;
branch = "feature/eip-155";
kind = branch;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"package": "Web3",
"repositoryURL": "https://github.com/flypaper0/Web3.swift",
"state": {
"branch": "master",
"revision": "23b6940bbda0769d9147bec6696b33a9fee0b120",
"branch": "feature/eip-155",
"revision": "92a43a8c279b9df25fe23dd6f8311e6fb0ea06ed",
"version": null
}
}
Expand Down
3 changes: 2 additions & 1 deletion Example/ExampleApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
url: "example.wallet",
icons: ["https://avatars.githubusercontent.com/u/37784886"])

Sign.configure(metadata: metadata, projectId: "8ba9ee138960775e5231b70cc5ef1c3a", socketFactory: SocketFactory())
Relay.configure(projectId: "8ba9ee138960775e5231b70cc5ef1c3a", socketFactory: SocketFactory())
Sign.configure(metadata: metadata)

if CommandLine.arguments.contains("-cleanInstall") {
try? Sign.instance.cleanup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class SessionDetailViewController: UIHostingController<SessionDetailView>

private let viewModel: SessionDetailViewModel

init(session: Session, client: Sign) {
init(session: Session, client: SignClient) {
self.viewModel = SessionDetailViewModel(session: session, client: client)
super.init(rootView: SessionDetailView(viewModel: viewModel))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import WalletConnectSign
@MainActor
final class SessionDetailViewModel: ObservableObject {
private let session: Session
private let client: Sign
private let client: SignClient

enum Fields {
case accounts
Expand All @@ -18,7 +18,7 @@ final class SessionDetailViewModel: ObservableObject {
@Published var pingSuccess: Bool = false
@Published var pingFailed: Bool = false

init(session: Session, client: Sign) {
init(session: Session, client: SignClient) {
self.session = session
self.client = client
self.namespaces = session.namespaces
Expand Down
10 changes: 6 additions & 4 deletions Example/IntegrationTests/Relay/RelayClientEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ final class RelayClientEndToEndTests: XCTestCase {
expectationA.assertForOverFulfill = false
expectationB.assertForOverFulfill = false

relayA.onMessage = { topic, payload in
relayA.messagePublisher.sink { topic, payload in
(subscriptionATopic, subscriptionAPayload) = (topic, payload)
expectationA.fulfill()
}
relayB.onMessage = { topic, payload in
}.store(in: &publishers)

relayB.messagePublisher.sink { topic, payload in
(subscriptionBTopic, subscriptionBPayload) = (topic, payload)
expectationB.fulfill()
}
}.store(in: &publishers)

relayA.socketConnectionStatusPublisher.sink { _ in
relayA.publish(topic: randomTopic, payload: payloadA, tag: 0, onNetworkAcknowledge: { error in
XCTAssertNil(error)
Expand Down
82 changes: 46 additions & 36 deletions Example/IntegrationTests/Sign/Helpers/ClientDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Foundation
@testable import WalletConnectSign
import Combine

class ClientDelegate: SignClientDelegate {
func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) {
onConnected?()
}
class ClientDelegate {

var client: SignClient
var onSessionSettled: ((Session) -> Void)?
Expand All @@ -15,43 +13,55 @@ class ClientDelegate: SignClientDelegate {
var onSessionRejected: ((Session.Proposal, Reason) -> Void)?
var onSessionDelete: (() -> Void)?
var onSessionUpdateNamespaces: ((String, [String: SessionNamespace]) -> Void)?
var onSessionUpdateEvents: ((String, Set<String>) -> Void)?
var onSessionExtend: ((String, Date) -> Void)?
var onEventReceived: ((Session.Event, String) -> Void)?
var onPairingUpdate: ((Pairing) -> Void)?

internal init(client: SignClient) {
private var publishers = Set<AnyCancellable>()

init(client: SignClient) {
self.client = client
client.delegate = self
setupSubscriptions()
}

func didReject(proposal: Session.Proposal, reason: Reason) {
onSessionRejected?(proposal, reason)
}
func didSettle(session: Session) {
onSessionSettled?(session)
}
func didReceive(sessionProposal: Session.Proposal) {
onSessionProposal?(sessionProposal)
}
func didReceive(sessionRequest: Request) {
onSessionRequest?(sessionRequest)
}
func didDelete(sessionTopic: String, reason: Reason) {
onSessionDelete?()
}
func didUpdate(sessionTopic: String, namespaces: [String: SessionNamespace]) {
onSessionUpdateNamespaces?(sessionTopic, namespaces)
}
func didExtend(sessionTopic: String, to date: Date) {
onSessionExtend?(sessionTopic, date)
}
func didReceive(event: Session.Event, sessionTopic: String, chainId: Blockchain?) {
onEventReceived?(event, sessionTopic)
}
func didReceive(sessionResponse: Response) {
onSessionResponse?(sessionResponse)
}
private func setupSubscriptions() {
client.sessionSettlePublisher.sink { session in
self.onSessionSettled?(session)
}.store(in: &publishers)

client.socketConnectionStatusPublisher.sink { _ in
self.onConnected?()
}.store(in: &publishers)

client.sessionProposalPublisher.sink { proposal in
self.onSessionProposal?(proposal)
}.store(in: &publishers)

client.sessionRequestPublisher.sink { request in
self.onSessionRequest?(request)
}.store(in: &publishers)

client.sessionResponsePublisher.sink { response in
self.onSessionResponse?(response)
}.store(in: &publishers)

func didDisconnect() {}
client.sessionRejectionPublisher.sink { (proposal, reason) in
self.onSessionRejected?(proposal, reason)
}.store(in: &publishers)

client.sessionDeletePublisher.sink { _ in
self.onSessionDelete?()
}.store(in: &publishers)

client.sessionUpdatePublisher.sink { (topic, namespaces) in
self.onSessionUpdateNamespaces?(topic, namespaces)
}.store(in: &publishers)

client.sessionEventPublisher.sink { (event, topic, _) in
self.onEventReceived?(event, topic)
}.store(in: &publishers)

client.sessionExtendPublisher.sink { (topic, date) in
self.onSessionExtend?(topic, date)
}.store(in: &publishers)
}
}
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ let package = Package(
targets: ["Auth"]),
.library(
name: "WalletConnectRouter",
targets: ["WalletConnectRouter"]),
targets: ["WalletConnectRouter"])
],
dependencies: [
.package(url: "https://github.com/flypaper0/Web3.swift", .branch("master"))
.package(url: "https://github.com/flypaper0/Web3.swift", .branch("feature/eip-155"))
],
targets: [
.target(
Expand Down
1 change: 0 additions & 1 deletion Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,3 @@ public class AuthClient {
}
}
}

6 changes: 3 additions & 3 deletions Sources/Auth/AuthClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ 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 messageFormatter = SIWEMessageFormatter()
let appPairService = AppPairService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore)
let appRequestService = AppRequestService(networkingInteractor: networkingInteractor, kms: kms, appMetadata: metadata)
let messageSigner = MessageSigner(signer: Signer())
let appRespondSubscriber = AppRespondSubscriber(networkingInteractor: networkingInteractor, logger: logger, rpcHistory: history, signatureVerifier: messageSigner, messageFormatter: SIWEMessageFormatter)
let appRespondSubscriber = AppRespondSubscriber(networkingInteractor: networkingInteractor, logger: logger, rpcHistory: history, signatureVerifier: messageSigner, messageFormatter: messageFormatter)
let walletPairService = WalletPairService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore)
let walletRequestSubscriber = WalletRequestSubscriber(networkingInteractor: networkingInteractor, logger: logger, messageFormatter: SIWEMessageFormatter, address: account?.address)
let walletRequestSubscriber = WalletRequestSubscriber(networkingInteractor: networkingInteractor, logger: logger, messageFormatter: messageFormatter, address: account?.address)
let walletRespondService = WalletRespondService(networkingInteractor: networkingInteractor, logger: logger, kms: kms, rpcHistory: history)
let pendingRequestsProvider = PendingRequestsProvider(rpcHistory: history)
let cleanupService = CleanupService(pairingStore: pairingStore, kms: kms)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Auth/Services/App/AppRequestService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ actor AppRequestService {
let payload = AuthPayload(requestParams: params, iat: issueAt)
let params = AuthRequestParams(requester: requester, payloadParams: payload)
let request = RPCRequest(method: "wc_authRequest", params: params)
try await networkingInteractor.request(request, topic: topic, tag: AuthRequestParams.tag)
try await networkingInteractor.requestNetworkAck(request, topic: topic, tag: AuthRequestParams.tag)
try await networkingInteractor.subscribe(topic: responseTopic)
}
}
4 changes: 2 additions & 2 deletions Sources/Auth/Services/App/AppRespondSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class AppRespondSubscriber {
private func subscribeForResponse() {
networkingInteractor.responsePublisher.sink { [unowned self] subscriptionPayload in
guard
let requestId = subscriptionPayload.request.id,
let requestId = subscriptionPayload.response.id,
let request = rpcHistory.get(recordId: requestId)?.request,
let requestParams = request.params, request.method == "wc_authRequest"
else { return }

networkingInteractor.unsubscribe(topic: subscriptionPayload.topic)

do {
guard let cacao = try subscriptionPayload.request.result?.get(Cacao.self) else {
guard let cacao = try subscriptionPayload.response.result?.get(Cacao.self) else {
return logger.debug("Malformed auth response params")
}

Expand Down
Loading

0 comments on commit 0c1adde

Please sign in to comment.