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

Set ----> OrderSet #1057

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,76 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnect_WalletConnectModal"
BuildableName = "WalletConnect_WalletConnectModal"
BlueprintName = "WalletConnect_WalletConnectModal"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectHistory"
BuildableName = "WalletConnectHistory"
BlueprintName = "WalletConnectHistory"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectModal"
BuildableName = "WalletConnectModal"
BlueprintName = "WalletConnectModal"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectSync"
BuildableName = "WalletConnectSync"
BlueprintName = "WalletConnectSync"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "HTTPClient"
BuildableName = "HTTPClient"
BlueprintName = "HTTPClient"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
"version": "14.3.1"
}
},
{
"package": "swift-collections",
"repositoryURL": "https://github.com/apple/swift-collections.git",
"state": {
"branch": null,
"revision": "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version": "1.0.4"
}
},
{
"package": "SwiftDocCPlugin",
"repositoryURL": "https://github.com/apple/swift-docc-plugin",
Expand Down
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
.package(url: "https://github.com/WalletConnect/QRCode", from: "14.3.1")
.package(url: "https://github.com/WalletConnect/QRCode", from: "14.3.1"),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.4")),
],
targets: [
.target(
name: "WalletConnectSign",
dependencies: ["WalletConnectPairing", "WalletConnectVerify"],
dependencies: ["WalletConnectPairing", "WalletConnectVerify", .product(name: "OrderedCollections", package: "swift-collections")],
path: "Sources/WalletConnectSign"),
.target(
name: "WalletConnectChat",
Expand Down
3 changes: 2 additions & 1 deletion Sources/WalletConnectModal/WalletConnectModal.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import OrderedCollections
import SwiftUI

#if canImport(UIKit)
Expand Down Expand Up @@ -146,7 +147,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: OrderedSet<Blockchain> = [Blockchain("eip155:1")!]
let namespaces: [String: ProposalNamespace] = [
"eip155": ProposalNamespace(
chains: blockchains,
Expand Down
30 changes: 16 additions & 14 deletions Sources/WalletConnectSign/Namespace.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import OrderedCollections

public enum AutoNamespacesError: Error {
case requiredChainsNotSatisfied
case requiredAccountsNotSatisfied
Expand All @@ -7,31 +9,31 @@ public enum AutoNamespacesError: Error {

public struct ProposalNamespace: Equatable, Codable {

public let chains: Set<Blockchain>?
public let chains: OrderedSet<Blockchain>?
public let methods: Set<String>
public let events: Set<String>

public init(chains: Set<Blockchain>? = nil, methods: Set<String>, events: Set<String>) {
public init(chains: OrderedSet<Blockchain>? = nil, methods: Set<String>, events: Set<String>) {
self.chains = chains
self.methods = methods
self.events = events
}
}

public struct SessionNamespace: Equatable, Codable {
public var chains: Set<Blockchain>?
public var accounts: Set<Account>
public var chains: OrderedSet<Blockchain>?
public var accounts: OrderedSet<Account>
public var methods: Set<String>
public var events: Set<String>

public init(chains: Set<Blockchain>? = nil, accounts: Set<Account>, methods: Set<String>, events: Set<String>) {
public init(chains: OrderedSet<Blockchain>? = nil, accounts: OrderedSet<Account>, methods: Set<String>, events: Set<String>) {
self.chains = chains
self.accounts = accounts
self.methods = methods
self.events = events
}

static func accountsAreCompliant(_ accounts: Set<Account>, toChains chains: Set<Blockchain>) -> Bool {
static func accountsAreCompliant(_ accounts: OrderedSet<Account>, toChains chains: OrderedSet<Blockchain>) -> Bool {
for chain in chains {
guard accounts.contains(where: { $0.blockchain == chain }) else {
return false
Expand Down Expand Up @@ -186,8 +188,8 @@ public enum AutoNamespaces {
}

let sessionNamespace = SessionNamespace(
chains: sessionChains,
accounts: Set(accounts).filter { sessionChains.contains($0.blockchain) },
chains: OrderedSet(sessionChains),
accounts: OrderedSet(accounts.filter { sessionChains.contains($0.blockchain) }),
methods: sessionMethods,
events: sessionEvents
)
Expand Down Expand Up @@ -229,8 +231,8 @@ public enum AutoNamespaces {
}

let sessionNamespace = SessionNamespace(
chains: Set([Blockchain(namespace: network, reference: chain)!]),
accounts: Set(accounts).filter { $0.blockchain == Blockchain(namespace: network, reference: chain)! },
chains: OrderedSet([Blockchain(namespace: network, reference: chain)!]),
accounts: OrderedSet(accounts.filter { $0.blockchain == Blockchain(namespace: network, reference: chain)! }),
methods: sessionMethods,
events: sessionEvents
)
Expand Down Expand Up @@ -269,8 +271,8 @@ public enum AutoNamespaces {
let sessionEvents = Set(proposalNamespace.events).intersection(Set(events))

let sessionNamespace = SessionNamespace(
chains: sessionChains,
accounts: Set(accounts).filter { sessionChains.contains($0.blockchain) },
chains: OrderedSet(sessionChains),
accounts: OrderedSet(accounts.filter { sessionChains.contains($0.blockchain) }),
methods: sessionMethods,
events: sessionEvents
)
Expand Down Expand Up @@ -304,8 +306,8 @@ public enum AutoNamespaces {
let sessionEvents = Set(proposalNamespace.events).intersection(Set(events))

let sessionNamespace = SessionNamespace(
chains: Set([Blockchain(namespace: network, reference: chain)!]),
accounts: Set(accounts).filter { $0.blockchain == Blockchain(namespace: network, reference: chain)! },
chains: OrderedSet([Blockchain(namespace: network, reference: chain)!]),
accounts: OrderedSet(accounts.filter { $0.blockchain == Blockchain(namespace: network, reference: chain)! }),
methods: sessionMethods,
events: sessionEvents
)
Expand Down
31 changes: 16 additions & 15 deletions Tests/WalletConnectSignTests/AutoNamespacesValidationTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import XCTest
@testable import WalletConnectSign
@testable import OrderedCollections

final class AutoNamespacesValidationTests: XCTestCase {
func testAutoNamespacesSameChainRequiredAndOptional() async {
Expand Down Expand Up @@ -37,7 +38,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -84,7 +85,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -129,7 +130,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -179,7 +180,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!, Blockchain("eip155:3")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -234,7 +235,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!, Blockchain("eip155:3")!, Blockchain("eip155:4")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -287,7 +288,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -341,7 +342,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!, Blockchain("eip155:4")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -390,7 +391,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction", "eth_signTransaction"],
events: ["chainChanged"]
)
Expand Down Expand Up @@ -439,7 +440,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!],
accounts: Set(accounts),
accounts: OrderedSet(accounts),
methods: ["personal_sign", "eth_sendTransaction", "eth_signTransaction"],
events: ["chainChanged", "accountsChanged"]
)
Expand Down Expand Up @@ -544,7 +545,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!, Blockchain("eip155:2")!],
accounts: Set([
accounts: OrderedSet([
Account(blockchain: Blockchain("eip155:1")!, address: "0x57f48fAFeC1d76B27e3f29b8d277b6218CDE6092")!,
Account(blockchain: Blockchain("eip155:2")!, address: "0x57f48fAFeC1d76B27e3f29b8d277b6218CDE6092")!
]),
Expand Down Expand Up @@ -836,7 +837,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!],
accounts: Set([
accounts: OrderedSet([
Account(blockchain: Blockchain("eip155:1")!, address: "0x57f48fAFeC1d76B27e3f29b8d277b6218CDE6092")!
]),
methods: ["eth_signTypedData_v4", "eth_signTransaction", "eth_signTypedData", "eth_sign", "personal_sign", "eth_sendTransaction"],
Expand Down Expand Up @@ -883,7 +884,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!],
accounts: Set([
accounts: OrderedSet([
Account(blockchain: Blockchain("eip155:1")!, address: "0x57f48fAFeC1d76B27e3f29b8d277b6218CDE6092")!
]),
methods: ["eth_signTypedData_v4", "eth_signTransaction", "eth_signTypedData", "eth_sign", "personal_sign", "eth_sendTransaction"],
Expand Down Expand Up @@ -930,7 +931,7 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!],
accounts: Set([
accounts: OrderedSet([
Account(blockchain: Blockchain("eip155:1")!, address: "0x57f48fAFeC1d76B27e3f29b8d277b6218CDE6092")!
]),
methods: ["eth_signTypedData_v4", "eth_signTransaction", "eth_signTypedData", "eth_sign", "personal_sign", "eth_sendTransaction"],
Expand Down Expand Up @@ -982,15 +983,15 @@ final class AutoNamespacesValidationTests: XCTestCase {
let expectedNamespaces: [String: SessionNamespace] = [
"eip155": SessionNamespace(
chains: [Blockchain("eip155:1")!],
accounts: Set([
accounts: OrderedSet([
Account(blockchain: Blockchain("eip155:1")!, address: "0x57f48fAFeC1d76B27e3f29b8d277b6218CDE6092")!
]),
methods: ["eth_signTypedData_v4", "eth_signTransaction", "eth_signTypedData", "eth_sign", "personal_sign", "eth_sendTransaction"],
events: ["chainChanged", "accountsChanged"]
),
"solana": SessionNamespace(
chains: [Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!],
accounts: Set([
accounts: OrderedSet([
Account(blockchain: Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!, address: "4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!,
]),
methods: ["solana_signMessage"],
Expand Down
Loading