Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chains as an array #1323

Merged
merged 10 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
Web3Modal.configure(
projectId: InputConfig.projectId,
metadata: metadata,
crypto: DefaultCryptoProvider(),
customWallets: [
.init(
id: "swift-sample",
Expand Down
66 changes: 33 additions & 33 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

/* Begin PBXBuildFile section */
767DC83528997F8E00080FA9 /* EthSendTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767DC83428997F8E00080FA9 /* EthSendTransaction.swift */; };
842B1D132B988BC5007F1EF8 /* Web3Modal in Frameworks */ = {isa = PBXBuildFile; productRef = 842B1D122B988BC5007F1EF8 /* Web3Modal */; };
842B1D152B988BC5007F1EF8 /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = 842B1D142B988BC5007F1EF8 /* Web3ModalUI */; };
842B1D172B988BF0007F1EF8 /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = 842B1D162B988BF0007F1EF8 /* Web3ModalUI */; };
84310D05298BC980000C15B6 /* MainInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84310D04298BC980000C15B6 /* MainInteractor.swift */; };
8439CB89293F658E00F2F2E2 /* PushMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8439CB88293F658E00F2F2E2 /* PushMessage.swift */; };
844749F629B9E5B9005F520B /* RelayClientEndToEndTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844749F529B9E5B9005F520B /* RelayClientEndToEndTests.swift */; };
Expand Down Expand Up @@ -58,6 +55,9 @@
84DB38F32983CDAE00BFEE37 /* PushRegisterer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DB38F22983CDAE00BFEE37 /* PushRegisterer.swift */; };
84E6B84A29787A8000428BAF /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E6B84929787A8000428BAF /* NotificationService.swift */; };
84E6B84E29787A8000428BAF /* PNDecryptionService.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 84E6B84729787A8000428BAF /* PNDecryptionService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
84F391FA2BA87CEB00FDC20A /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = 84F391F92BA87CEB00FDC20A /* Web3ModalUI */; };
84F3EFC52BA87C09005FCFAE /* Web3Modal in Frameworks */ = {isa = PBXBuildFile; productRef = 84F3EFC42BA87C09005FCFAE /* Web3Modal */; };
84F3EFC72BA87C09005FCFAE /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = 84F3EFC62BA87C09005FCFAE /* Web3ModalUI */; };
84FE684628ACDB4700C893FF /* RequestParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FE684528ACDB4700C893FF /* RequestParams.swift */; };
A507BE1A29E8032E0038EF70 /* EIP55Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A507BE1929E8032E0038EF70 /* EIP55Tests.swift */; };
A50B6A362B06683800162B01 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = C56EE25D293F56D6004840D1 /* InputConfig.swift */; };
Expand Down Expand Up @@ -692,13 +692,13 @@
buildActionMask = 2147483647;
files = (
8448F1D427E4726F0000B866 /* WalletConnect in Frameworks */,
842B1D132B988BC5007F1EF8 /* Web3Modal in Frameworks */,
84F3EFC52BA87C09005FCFAE /* Web3Modal in Frameworks */,
C5BE01DF2AF692D80064FC88 /* WalletConnectRouter in Frameworks */,
A5B6C0F12A6EAB0800927332 /* WalletConnectNotify in Frameworks */,
A54195A52934E83F0035AD19 /* Web3 in Frameworks */,
8487A9442A836C2A0003D5AF /* Sentry in Frameworks */,
A5D85228286333E300DAF5C3 /* Starscream in Frameworks */,
842B1D152B988BC5007F1EF8 /* Web3ModalUI in Frameworks */,
84F3EFC72BA87C09005FCFAE /* Web3ModalUI in Frameworks */,
8486EDD32B4F2EA6008E53C3 /* SwiftMessages in Frameworks */,
84943C7B2A9BA206007EBAC2 /* Mixpanel in Frameworks */,
A573C53929EC365000E3CBFD /* HDWalletKit in Frameworks */,
Expand Down Expand Up @@ -764,7 +764,7 @@
8487A9462A836C3F0003D5AF /* Sentry in Frameworks */,
C55D349929630D440004314A /* Web3Wallet in Frameworks */,
C56EE255293F569A004840D1 /* Starscream in Frameworks */,
842B1D172B988BF0007F1EF8 /* Web3ModalUI in Frameworks */,
84F391FA2BA87CEB00FDC20A /* Web3ModalUI in Frameworks */,
84AEC2542B4D43CD00E27A5B /* SwiftMessages in Frameworks */,
A5B6C0F52A6EAB2800927332 /* WalletConnectNotify in Frameworks */,
C54C24902AEB1B5600DA4BF6 /* WalletConnectRouter in Frameworks */,
Expand Down Expand Up @@ -1937,8 +1937,8 @@
C5BE01DE2AF692D80064FC88 /* WalletConnectRouter */,
CFDB50712B2869AA00A0CBC2 /* WalletConnectModal */,
8486EDD22B4F2EA6008E53C3 /* SwiftMessages */,
842B1D122B988BC5007F1EF8 /* Web3Modal */,
842B1D142B988BC5007F1EF8 /* Web3ModalUI */,
84F3EFC42BA87C09005FCFAE /* Web3Modal */,
84F3EFC62BA87C09005FCFAE /* Web3ModalUI */,
);
productName = DApp;
productReference = 84CE641C27981DED00142511 /* DApp.app */;
Expand Down Expand Up @@ -2065,7 +2065,7 @@
A59D25ED2AB3672700D7EA3A /* AsyncButton */,
C54C248F2AEB1B5600DA4BF6 /* WalletConnectRouter */,
84AEC2532B4D43CD00E27A5B /* SwiftMessages */,
842B1D162B988BF0007F1EF8 /* Web3ModalUI */,
84F391F92BA87CEB00FDC20A /* Web3ModalUI */,
);
productName = ChatWallet;
productReference = C56EE21B293F55ED004840D1 /* WalletApp.app */;
Expand Down Expand Up @@ -2144,7 +2144,7 @@
8487A9422A836C2A0003D5AF /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
84943C792A9BA206007EBAC2 /* XCRemoteSwiftPackageReference "mixpanel-swift" */,
84AEC2522B4D43CD00E27A5B /* XCRemoteSwiftPackageReference "SwiftMessages" */,
842B1D112B987D40007F1EF8 /* XCRemoteSwiftPackageReference "web3modal-swift" */,
84F3EFC32BA87C09005FCFAE /* XCRemoteSwiftPackageReference "web3modal-swift" */,
);
productRefGroup = 764E1D3D26F8D3FC00A1FB15 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3243,14 +3243,6 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
842B1D112B987D40007F1EF8 /* XCRemoteSwiftPackageReference "web3modal-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/WalletConnect/web3modal-swift";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
8487A9422A836C2A0003D5AF /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/getsentry/sentry-cocoa.git";
Expand All @@ -3275,6 +3267,14 @@
minimumVersion = 9.0.9;
};
};
84F3EFC32BA87C09005FCFAE /* XCRemoteSwiftPackageReference "web3modal-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/WalletConnect/web3modal-swift";
requirement = {
kind = revision;
revision = c73ce390bc249af155b7320346b7045e53b89866;
};
};
A5434021291E6A270068F706 /* XCRemoteSwiftPackageReference "solana-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/flypaper0/solana-swift";
Expand Down Expand Up @@ -3318,21 +3318,6 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
842B1D122B988BC5007F1EF8 /* Web3Modal */ = {
isa = XCSwiftPackageProductDependency;
package = 842B1D112B987D40007F1EF8 /* XCRemoteSwiftPackageReference "web3modal-swift" */;
productName = Web3Modal;
};
842B1D142B988BC5007F1EF8 /* Web3ModalUI */ = {
isa = XCSwiftPackageProductDependency;
package = 842B1D112B987D40007F1EF8 /* XCRemoteSwiftPackageReference "web3modal-swift" */;
productName = Web3ModalUI;
};
842B1D162B988BF0007F1EF8 /* Web3ModalUI */ = {
isa = XCSwiftPackageProductDependency;
package = 842B1D112B987D40007F1EF8 /* XCRemoteSwiftPackageReference "web3modal-swift" */;
productName = Web3ModalUI;
};
844749FC29B9E6B2005F520B /* WalletConnectNetworking */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectNetworking;
Expand Down Expand Up @@ -3380,6 +3365,21 @@
package = 84AEC2522B4D43CD00E27A5B /* XCRemoteSwiftPackageReference "SwiftMessages" */;
productName = SwiftMessages;
};
84F391F92BA87CEB00FDC20A /* Web3ModalUI */ = {
isa = XCSwiftPackageProductDependency;
package = 84F3EFC32BA87C09005FCFAE /* XCRemoteSwiftPackageReference "web3modal-swift" */;
productName = Web3ModalUI;
};
84F3EFC42BA87C09005FCFAE /* Web3Modal */ = {
isa = XCSwiftPackageProductDependency;
package = 84F3EFC32BA87C09005FCFAE /* XCRemoteSwiftPackageReference "web3modal-swift" */;
productName = Web3Modal;
};
84F3EFC62BA87C09005FCFAE /* Web3ModalUI */ = {
isa = XCSwiftPackageProductDependency;
package = 84F3EFC32BA87C09005FCFAE /* XCRemoteSwiftPackageReference "web3modal-swift" */;
productName = Web3ModalUI;
};
A54195A42934E83F0035AD19 /* Web3 */ = {
isa = XCSwiftPackageProductDependency;
package = A5AE354528A1A2AC0059AE8A /* XCRemoteSwiftPackageReference "Web3" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@
"repositoryURL": "https://github.com/WalletConnect/web3modal-swift",
"state": {
"branch": null,
"revision": "4f2f4ca6497b7335a53c7b5c4fb3db554e0351ba",
"version": "1.3.0"
"revision": "c73ce390bc249af155b7320346b7045e53b89866",
"version": null
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Example/IntegrationTests/Stubs/Stubs.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import WalletConnectSign

extension ProposalNamespace {
static func stubRequired(chains: Set<Blockchain> = [Blockchain("eip155:1")!]) -> [String: ProposalNamespace] {
static func stubRequired(chains: [Blockchain] = [Blockchain("eip155:1")!]) -> [String: ProposalNamespace] {
return [
"eip155": ProposalNamespace(
chains: chains,
Expand All @@ -15,7 +15,7 @@ extension SessionNamespace {
static func make(toRespond namespaces: [String: ProposalNamespace]) -> [String: SessionNamespace] {
return namespaces.mapValues { proposalNamespace in
SessionNamespace(
accounts: Set(proposalNamespace.chains!.map { Account(blockchain: $0, address: "0x00")! }),
accounts: proposalNamespace.chains!.map { Account(blockchain: $0, address: "0x00")! },
methods: proposalNamespace.methods,
events: proposalNamespace.events
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ final class SessionProposalInteractor {
let supportedMethods = Set(proposal.requiredNamespaces.flatMap { $0.value.methods } + (proposal.optionalNamespaces?.flatMap { $0.value.methods } ?? []))
let supportedEvents = Set(proposal.requiredNamespaces.flatMap { $0.value.events } + (proposal.optionalNamespaces?.flatMap { $0.value.events } ?? []))

let supportedRequiredChains = proposal.requiredNamespaces["eip155"]?.chains
let supportedRequiredChains = proposal.requiredNamespaces["eip155"]?.chains ?? []
let supportedOptionalChains = proposal.optionalNamespaces?["eip155"]?.chains ?? []
var supportedChains = (supportedRequiredChains ?? []).union(supportedOptionalChains)
var supportedChains = supportedRequiredChains + supportedOptionalChains

let supportedAccounts = Array(supportedChains).map { Account(blockchain: $0, address: account.address)! }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct SessionProposalView: View {
private func sessionProposalView(namespaces: ProposalNamespace) -> some View {
VStack {
VStack(alignment: .leading) {
TagsView(items: Array(namespaces.chains ?? Set())) {
TagsView(items: Array(namespaces.chains ?? [])) {
Text($0.absoluteString.uppercased())
.font(.system(size: 15, weight: .semibold, design: .rounded))
.foregroundColor(.whiteBackground)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AuthClient: AuthClientProtocol {
///
/// Emited result may be an error.
@available(*, deprecated, message: "Use SignClient for dApps and Web3Wallet interface for wallets instead.")
public var authResponsePublisher: AnyPublisher<(id: RPCID, result: Result<Cacao, AuthError>), Never> {
public var authResponsePublisher: AnyPublisher<(id: RPCID, result: Result<Cacao, AuthErrors>), Never> {
authResponsePublisherSubject.eraseToAnyPublisher()
}

Expand All @@ -40,7 +40,7 @@ public class AuthClient: AuthClientProtocol {

private let pairingRegisterer: PairingRegisterer

private var authResponsePublisherSubject = PassthroughSubject<(id: RPCID, result: Result<Cacao, AuthError>), Never>()
private var authResponsePublisherSubject = PassthroughSubject<(id: RPCID, result: Result<Cacao, AuthErrors>), Never>()
private var authRequestPublisherSubject = PassthroughSubject<(request: AuthRequest, context: VerifyContext?), Never>()
private let appRequestService: AppRequestService
private let appRespondSubscriber: AppRespondSubscriber
Expand Down
4 changes: 2 additions & 2 deletions Sources/Auth/Services/App/AppRespondSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AppRespondSubscriber {
private let pairingRegisterer: PairingRegisterer
private var publishers = [AnyCancellable]()

var onResponse: ((_ id: RPCID, _ result: Result<Cacao, AuthError>) -> Void)?
var onResponse: ((_ id: RPCID, _ result: Result<Cacao, AuthErrors>) -> Void)?

init(networkingInteractor: NetworkInteracting,
logger: ConsoleLogging,
Expand All @@ -30,7 +30,7 @@ class AppRespondSubscriber {
private func subscribeForResponse() {
networkingInteractor.responseErrorSubscription(on: AuthRequestProtocolMethod())
.sink { [unowned self] (payload: ResponseSubscriptionErrorPayload<AuthRequestParams>) in
guard let error = AuthError(code: payload.error.code) else { return }
guard let error = AuthErrors(code: payload.error.code) else { return }
onResponse?(payload.id, .failure(error))
}.store(in: &publishers)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Auth/Services/Wallet/WalletErrorResponder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ actor WalletErrorResponder {
self.rpcHistory = rpcHistory
}

func respondError(_ error: AuthError, requestId: RPCID) async throws {
func respondError(_ error: AuthErrors, requestId: RPCID) async throws {
let authRequestParams = try getAuthRequestParams(requestId: requestId)
let (topic, keys) = try generateAgreementKeys(requestParams: authRequestParams)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Auth/Services/Wallet/WalletRespondService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ actor WalletRespondService {
}

func respondError(requestId: RPCID) async throws {
try await walletErrorResponder.respondError(AuthError.userRejeted, requestId: requestId)
try await walletErrorResponder.respondError(AuthErrors.userRejeted, requestId: requestId)
verifyContextStore.delete(forKey: requestId.string)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Auth/Types/Errors/AuthError.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Authentication error
public enum AuthError: Codable, Equatable, Error {
public enum AuthErrors: Codable, Equatable, Error {
case methodUnsupported
case userDisconnected
case userRejeted
Expand All @@ -11,7 +11,7 @@ public enum AuthError: Codable, Equatable, Error {
case signatureVerificationFailed
}

extension AuthError: Reason {
extension AuthErrors: Reason {

init?(code: Int) {
switch code {
Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectModal/WalletConnectModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public struct SessionParams {
public static let `default`: Self = {
let methods: Set<String> = ["eth_sendTransaction", "personal_sign", "eth_signTypedData"]
let events: Set<String> = ["chainChanged", "accountsChanged"]
let blockchains: Set<Blockchain> = [Blockchain("eip155:1")!]
let blockchains = [Blockchain("eip155:1")!]
let namespaces: [String: ProposalNamespace] = [
"eip155": ProposalNamespace(
chains: blockchains,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ProposalNamespaceBuilder {
if methods.isEmpty {
methods = ["personal_sign"]
}
let chains: Set<Blockchain> = Set(params.chains.compactMap { Blockchain($0) })
let chains: [Blockchain] = params.chains.compactMap { Blockchain($0) }
guard chains.allSatisfy({$0.namespace == "eip155"}) else {
throw Errors.unsupportedChain
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SessionNamespaceBuilder {
}

let accounts = cacaos.compactMap { try? DIDPKH(did: $0.p.iss).account }
let accountsSet = Set(accounts)
let accountsSet = accounts
let methods = firstRecapResource.methods
let chains = firstRecapResource.chains
let events: Set<String> = ["chainChanged", "accountsChanged"]
Expand Down
4 changes: 2 additions & 2 deletions Sources/WalletConnectSign/Auth/Services/SignRecap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct SignRecap {
.filter { $0.hasPrefix("request/") }
.map { String($0.dropFirst("request/".count)) })
}
var chains: Set<Blockchain> {
var chains: [Blockchain] {
guard let eip155Actions = recapData.att?["eip155"] else { return [] }

// Attempt to find and decode the first action's chain array from AnyCodable
Expand All @@ -49,7 +49,7 @@ struct SignRecap {
let firstActionValue = firstActionValues.first,
let dict = try? firstActionValue.get([String:[String]].self),
let chainsArray = dict["chains"]{
return Set(chainsArray.compactMap(Blockchain.init))
return chainsArray.compactMap(Blockchain.init)
}

return []
Expand Down
Loading
Loading