diff --git a/Sources/CommonSources/Models/AllNodeDetailsModel.swift b/Sources/CommonSources/Models/AllNodeDetailsModel.swift index cbcbd49..272b7bf 100644 --- a/Sources/CommonSources/Models/AllNodeDetailsModel.swift +++ b/Sources/CommonSources/Models/AllNodeDetailsModel.swift @@ -6,14 +6,14 @@ public struct AllNodeDetailsModel:Equatable, Decodable { return lhs.currentEpoch == rhs.currentEpoch && lhs.torusNodeEndpoints == rhs.torusNodeEndpoints && lhs.torusNodePub == rhs.torusNodePub && lhs.currentEpoch == rhs.currentEpoch && lhs.torusIndexes == rhs.torusIndexes && lhs.updated == rhs.updated } - public var currentEpoch : String - public var torusNodeEndpoints : Array - public var torusNodeSSSEndpoints : Array - public var torusNodeRSSEndpoints : Array - public var torusNodeTSSEndpoints : Array - public var torusIndexes : Array - public var torusNodePub : Array - public var updated = false + private var currentEpoch : String + private var torusNodeEndpoints : Array + private var torusNodeSSSEndpoints : Array + private var torusNodeRSSEndpoints : Array + private var torusNodeTSSEndpoints : Array + private var torusIndexes : Array + private var torusNodePub : Array + private var updated = false public enum CodingKeys: String, CodingKey { case currentEpoch = "currentEpoch" diff --git a/Sources/CommonSources/TorusNetwork.swift b/Sources/CommonSources/TorusNetwork.swift index af55642..5b26f8c 100644 --- a/Sources/CommonSources/TorusNetwork.swift +++ b/Sources/CommonSources/TorusNetwork.swift @@ -1,6 +1,6 @@ import Foundation -public enum TorusNetwork : Equatable, Hashable { +internal enum TorusNetwork : Equatable, Hashable { case legacy(LegacyNetwork) case sapphire(SapphireNetwork) @@ -68,7 +68,6 @@ public enum LegacyNetwork: Equatable, Hashable { case CYAN case AQUA case CELESTE - case CUSTOM(path: String) public var path: String { switch self { @@ -78,8 +77,6 @@ public enum LegacyNetwork: Equatable, Hashable { return "goerli" case .CYAN, .AQUA, .CELESTE: return "polygon-mainnet" - case let .CUSTOM(path): - return path } } @@ -95,8 +92,6 @@ public enum LegacyNetwork: Equatable, Hashable { return "aqua" case .CELESTE: return "celeste" - case .CUSTOM(_): - return "custom" } } @@ -112,8 +107,6 @@ public enum LegacyNetwork: Equatable, Hashable { return LegacyNetworkMigrationInfo(migrationCompleted: true, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET) case .CELESTE: return LegacyNetworkMigrationInfo(migrationCompleted: true, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET) - case .CUSTOM(_): - return LegacyNetworkMigrationInfo(migrationCompleted: false, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET) } } @@ -124,7 +117,6 @@ public enum LegacyNetwork: Equatable, Hashable { case .CYAN: return "polygon-mainnet" case .AQUA: return "polygon-mainnet" case .CELESTE: return "polygon-mainnet" - case .CUSTOM(let path) : return path } } @@ -135,7 +127,6 @@ public enum LegacyNetwork: Equatable, Hashable { case .CYAN: return "https://signer-polygon.web3auth.io" case .AQUA: return "https://signer-polygon.web3auth.io" case .CELESTE: return "https://signer-polygon.web3auth.io" - case .CUSTOM(let path) : return path } } @@ -146,7 +137,6 @@ public enum LegacyNetwork: Equatable, Hashable { case .CYAN: return "https://metadata.web3auth.io" case .AQUA: return "https://metadata.web3auth.io" case .CELESTE: return "https://metadata.web3auth.io" - case .CUSTOM(let path): return path } } } diff --git a/Sources/CommonSources/Web3AuthNetwork.swift b/Sources/CommonSources/Web3AuthNetwork.swift new file mode 100644 index 0000000..86b2c6e --- /dev/null +++ b/Sources/CommonSources/Web3AuthNetwork.swift @@ -0,0 +1,73 @@ +public enum Web3AuthNetwork : Equatable, Hashable { + case SAPPHIRE_DEVNET + case SAPPHIRE_MAINNET + case MAINNET + case TESTNET + case CYAN + case AQUA + case CELESTE + + public var path: String { + return self.torusNetwork.path + } + + public var name: String { + return self.torusNetwork.name + } + + public var signerMap: String { + return self.torusNetwork.signerMap + } + + public var isLegacy: Bool { + if case .legacy(_) = torusNetwork { + return true + } + return false + } + + public var isSapphire: Bool { + if case .sapphire(_) = torusNetwork { + return true + } + return false + } + + public var metadataMap: String { + get throws { + if case .legacy(let legacyNetwork) = torusNetwork { + return legacyNetwork.metadataMap + } + + if case .sapphire(let sapphireNetwork) = torusNetwork { + if sapphireNetwork == .SAPPHIRE_MAINNET { + return "https://node-1.node.web3auth.io/metadata" + } else { + return "https://node-1.dev-node.web3auth.io/metadata" + } + } + + throw FetchNodeError.InvalidNetwork(self.name) + } + } + + + internal var torusNetwork: TorusNetwork { + switch self { + case .SAPPHIRE_DEVNET: + return .sapphire(.SAPPHIRE_DEVNET) + case .SAPPHIRE_MAINNET: + return .sapphire(.SAPPHIRE_MAINNET) + case .MAINNET: + return .legacy(.MAINNET) + case .TESTNET: + return .legacy(.TESTNET) + case .CYAN: + return .legacy(.CYAN) + case .AQUA: + return .legacy(.AQUA) + case .CELESTE: + return .legacy(.CELESTE) + } + } +} diff --git a/Sources/FetchNodeDetails/Extensions/String.swift b/Sources/FetchNodeDetails/Extensions/String.swift deleted file mode 100644 index c5f6c9c..0000000 --- a/Sources/FetchNodeDetails/Extensions/String.swift +++ /dev/null @@ -1,6 +0,0 @@ -import Foundation - -// Used in error thrown from guard let -extension String: LocalizedError { - public var errorDescription: String? { return self } -} diff --git a/Sources/FetchNodeDetails/NodeDetailManager.swift b/Sources/FetchNodeDetails/NodeDetailManager.swift index 29d90d9..419ceaf 100644 --- a/Sources/FetchNodeDetails/NodeDetailManager.swift +++ b/Sources/FetchNodeDetails/NodeDetailManager.swift @@ -15,7 +15,7 @@ open class NodeDetailManager { private var torusNodeRSSEndpoints: [String] = [] private var torusNodeTSSEndpoints: [String] = [] - private var network: TorusNetwork = .sapphire( SapphireNetwork.SAPPHIRE_MAINNET ) + private var network: Web3AuthNetwork = .SAPPHIRE_MAINNET private var urlSession: URLSession private var updated = false @@ -24,7 +24,7 @@ open class NodeDetailManager { } - public init(network: TorusNetwork, fndEndpoint: String? = nil, logLevel: OSLogType = .default, urlSession: URLSession = URLSession.shared) { + public init(network: Web3AuthNetwork, fndEndpoint: String? = nil, logLevel: OSLogType = .default, urlSession: URLSession = URLSession.shared) { fndLogType = logLevel // to be used across application self.network = network self.urlSession = urlSession @@ -34,8 +34,7 @@ open class NodeDetailManager { } public func getNodeDetails(verifier: String, verifierID: String) async throws -> AllNodeDetailsModel { - - switch network { + switch network.torusNetwork { case .legacy(let legacyNetwork): if updated && !MULTI_CLUSTER_NETWORKS.contains(legacyNetwork) { return nodeDetails @@ -74,11 +73,11 @@ open class NodeDetailManager { } public func getMetadataUrl() async throws -> String { - switch network { + switch network.torusNetwork { case .legacy(let legacyNetwork): return legacyNetwork.metadataMap case .sapphire(_): - return try await self.getNodeDetails(verifier: "test-verifier", verifierID: "test-verifier-id").torusNodeEndpoints[0].replacingOccurrences(of: "/sss/jrpc", with: "/metadata") + return try await self.getNodeDetails(verifier: "test-verifier", verifierID: "test-verifier-id").getTorusNodeEndpoints()[0].replacingOccurrences(of: "/sss/jrpc", with: "/metadata") } } diff --git a/Sources/FndBase/Utils/Utils.swift b/Sources/FndBase/Utils/Utils.swift index ef7b4ee..22acfde 100644 --- a/Sources/FndBase/Utils/Utils.swift +++ b/Sources/FndBase/Utils/Utils.swift @@ -1,6 +1,6 @@ -public func fetchLocalConfig(network: TorusNetwork) throws -> AllNodeDetailsModel { +public func fetchLocalConfig(network: Web3AuthNetwork) throws -> AllNodeDetailsModel { - switch network { + switch network.torusNetwork { case .legacy(let network ) : if (network.migration_map.migrationCompleted) { return try SapphireConfig(network: network.migration_map.networkMigratedTo ) diff --git a/Tests/FetchNodeDetailsTests/fetchNodeDetailsTests.swift b/Tests/FetchNodeDetailsTests/fetchNodeDetailsTests.swift index 525b83a..19b9363 100644 --- a/Tests/FetchNodeDetailsTests/fetchNodeDetailsTests.swift +++ b/Tests/FetchNodeDetailsTests/fetchNodeDetailsTests.swift @@ -6,7 +6,7 @@ class fetchNodeDetailsTests: XCTestCase { var timeout: TimeInterval = 10 var verifierId = "hello@tor.us" func test_getNode_Mainnet() async throws { - let fnd = NodeDetailManager(network: .legacy(.MAINNET)) + let fnd = NodeDetailManager(network: .MAINNET) let result = try await fnd.getNodeDetails(verifier: "google", verifierID: verifierId) XCTAssertEqual(result, SampleOutputMainnet().val) } @@ -23,56 +23,56 @@ class fetchNodeDetailsTests: XCTestCase { // } func test_getNode_Testnet() async throws { - let fnd = NodeDetailManager(network: .legacy(.TESTNET)) + let fnd = NodeDetailManager(network: .TESTNET) let result = try await fnd.getNodeDetails(verifier: "google", verifierID: verifierId) XCTAssertEqual(result, SampleOutputTestnet().val) } func test_getNode_SapphireDevnet() async throws { - let fnd = NodeDetailManager(network: .sapphire(.SAPPHIRE_DEVNET)) + let fnd = NodeDetailManager(network: .SAPPHIRE_DEVNET) let result = try await fnd.getNodeDetails(verifier: "google", verifierID: verifierId) var config = try! SapphireConfig(network: .SAPPHIRE_DEVNET) - config.updated = true + config.setUpdated(updated: true) XCTAssertEqual(result, config) XCTAssertEqual(result, SampleOutputSAPPHIREDEVNET().val) } func test_getNode_SapphireMainnet() async throws { - let fnd = NodeDetailManager(network: .sapphire(.SAPPHIRE_MAINNET)) + let fnd = NodeDetailManager(network: .SAPPHIRE_MAINNET) let result = try await fnd.getNodeDetails(verifier: "google", verifierID: verifierId) var config = try! SapphireConfig(network: .SAPPHIRE_MAINNET) - config.updated = true + config.setUpdated(updated: true) XCTAssertEqual(result, config) XCTAssertEqual(result, SampleOutputSAPPHIREMAINNET().val) } func test_getNode_Cyan() async throws { - let fnd = NodeDetailManager(network: .legacy(.CYAN)) + let fnd = NodeDetailManager(network: .CYAN) let result = try await fnd.getNodeDetails(verifier: "google", verifierID: verifierId) XCTAssertEqual(result, SampleOutputCyan().val) } func test_getNode_Aqua() async throws { - let fnd = NodeDetailManager(network: .legacy(.AQUA)) + let fnd = NodeDetailManager(network: .AQUA) let result = try await fnd.getNodeDetails(verifier: "google", verifierID: verifierId) XCTAssertEqual(result, SampleOutputAqua().val) } func test_getNode_Celeste() async throws { - let fnd = NodeDetailManager(network: .legacy(.CELESTE)) + let fnd = NodeDetailManager(network: .CELESTE) let result = try await fnd.getNodeDetails(verifier: "google", verifierID: "hello@tor.us") XCTAssertEqual(result, SampleOutputCeleste().val) } func test_getMetadata_Mainnet() async throws { - let fnd = NodeDetailManager(network: .legacy(.MAINNET)) + let fnd = NodeDetailManager(network: .MAINNET) let result = try await fnd.getMetadataUrl() XCTAssertEqual(result, "https://metadata.web3auth.io") } func test_getMetadata_SapphireMainnet() async throws { - let fnd = NodeDetailManager(network: .sapphire(.SAPPHIRE_MAINNET)) + let fnd = NodeDetailManager(network: .SAPPHIRE_MAINNET) let result = try await fnd.getMetadataUrl() - XCTAssertEqual(result, SampleOutputSAPPHIREMAINNET().val.torusNodeEndpoints[0].replacingOccurrences(of: "/sss/jrpc", with: "/metadata")) + XCTAssertEqual(result, SampleOutputSAPPHIREMAINNET().val.getTorusNodeEndpoints()[0].replacingOccurrences(of: "/sss/jrpc", with: "/metadata")) } } diff --git a/Torus-fetchNodeDetails.podspec b/Torus-fetchNodeDetails.podspec index 19df619..3554070 100644 --- a/Torus-fetchNodeDetails.podspec +++ b/Torus-fetchNodeDetails.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "Torus-fetchNodeDetails" - spec.version = "6.0.3" + spec.version = "7.0.0" spec.ios.deployment_target = '13.0' spec.summary = "Fetches the node details from torus nodelist smart contract" spec.homepage = "https://github.com/torusresearch/fetch-node-details-swift" diff --git a/cocoapods/.DS_Store b/cocoapods/.DS_Store deleted file mode 100644 index 5a4f277..0000000 Binary files a/cocoapods/.DS_Store and /dev/null differ diff --git a/cocoapods/Podfile.lock b/cocoapods/Podfile.lock index e23f6a0..917ced7 100644 --- a/cocoapods/Podfile.lock +++ b/cocoapods/Podfile.lock @@ -1,13 +1,7 @@ PODS: - - BigInt (5.0.0) - - GenericJSON (2.0.2) - - secp256k1.swift (0.1.4) - - Torus-fetchNodeDetails (4.0.1): - - web3.swift (~> 0.9.3) - - web3.swift (0.9.3): - - BigInt (~> 5.0.0) - - GenericJSON (~> 2.0) - - secp256k1.swift (~> 0.1) + - BigInt (5.2.0) + - Torus-fetchNodeDetails (7.0.0): + - BigInt (~> 5.2.0) DEPENDENCIES: - Torus-fetchNodeDetails (from `../`) @@ -15,21 +9,15 @@ DEPENDENCIES: SPEC REPOS: trunk: - BigInt - - GenericJSON - - secp256k1.swift - - web3.swift EXTERNAL SOURCES: Torus-fetchNodeDetails: :path: "../" SPEC CHECKSUMS: - BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 - GenericJSON: 79a840eeb77030962e8cf02a62d36bd413b67626 - secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 - Torus-fetchNodeDetails: a92d02f1bfe91bd61c90f92d64df023babaa5bfa - web3.swift: c6c3bf1f853743f8a7a58d263e5f7e46545e22c7 + BigInt: f668a80089607f521586bbe29513d708491ef2f7 + Torus-fetchNodeDetails: d12f3511de52bdca33ccabf35f618c296edf94c5 PODFILE CHECKSUM: 33add72342a492adb43676625c404c97ced731da -COCOAPODS: 1.11.3 +COCOAPODS: 1.15.2 diff --git a/cocoapods/cptest/ContentView.swift b/cocoapods/cptest/ContentView.swift index 1ae00db..46c523a 100644 --- a/cocoapods/cptest/ContentView.swift +++ b/cocoapods/cptest/ContentView.swift @@ -35,12 +35,12 @@ struct ContentView: View { func execute() { Task { - let fnd = FetchNodeDetails() + let fnd = NodeDetailManager(network: .SAPPHIRE_MAINNET) do { let val = try await fnd.getNodeDetails(verifier: "google", verifierID: "hello@tor.us") print(val) success = true - message = val.getNodeListAddress() + message = val.getTorusNodeEndpoints().joined(separator: "; ") showAlert = true } catch let err { success = false