From 2b3277904d40649984eb26a442ca346d733d1c52 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Thu, 4 Apr 2024 11:03:10 +0530 Subject: [PATCH 1/3] add Web3AuthNetwork --- .../xcschemes/SingleFactorAuthTests.xcscheme | 53 +++++++++++ .../SingleFactorAuthArgs.swift | 92 ++++++++++++++++--- Tests/SingleFactorAuthTests/AquaTest.swift | 2 +- Tests/SingleFactorAuthTests/CyanTest.swift | 2 +- .../SingleFactorAuthTests.swift | 2 +- 5 files changed, 137 insertions(+), 14 deletions(-) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme new file mode 100644 index 0000000..9107091 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift index 2c787ca..ccecead 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift @@ -3,20 +3,20 @@ import FetchNodeDetails import TorusUtils public class SingleFactorAuthArgs { - public static let SIGNER_MAP: [TorusNetwork: String] = [ - TorusNetwork.sapphire(SapphireNetwork.SAPPHIRE_MAINNET): "https://signer.tor.us", - TorusNetwork.sapphire(SapphireNetwork.SAPPHIRE_DEVNET): "https://signer.tor.us", - TorusNetwork.legacy(LegacyNetwork.MAINNET): "https://signer.tor.us", - TorusNetwork.legacy(LegacyNetwork.TESTNET): "https://signer.tor.us", - TorusNetwork.legacy(LegacyNetwork.CYAN): "https://signer-polygon.tor.us", - TorusNetwork.legacy(LegacyNetwork.AQUA): "https://signer-polygon.tor.us", + public static let SIGNER_MAP: [Web3AuthNetwork: String] = [ + Web3AuthNetwork.SAPPHIRE_MAINNET: "https://signer.tor.us", + Web3AuthNetwork.SAPPHIRE_DEVNET: "https://signer.tor.us", + Web3AuthNetwork.MAINNET: "https://signer.tor.us", + Web3AuthNetwork.TESTNET: "https://signer.tor.us", + Web3AuthNetwork.CYAN: "https://signer-polygon.tor.us", + Web3AuthNetwork.AQUA: "https://signer-polygon.tor.us", ] - private var network: TorusNetwork + private var network: Web3AuthNetwork private var networkUrl: String private var web3AuthClientId: String - public init(web3AuthClientId: String, network: TorusNetwork, networkUrl: String = "") { + public init(web3AuthClientId: String, network: Web3AuthNetwork, networkUrl: String = "") { self.network = network self.networkUrl = networkUrl self.web3AuthClientId = web3AuthClientId @@ -27,14 +27,84 @@ public class SingleFactorAuthArgs { } public func getNetwork() -> TorusNetwork { - return network + return network.network } public func getSignerUrl() -> String? { return SingleFactorAuthArgs.SIGNER_MAP[network] } - public func setNetwork(network: TorusNetwork) { + public func setNetwork(network: Web3AuthNetwork) { self.network = network } } + +public enum Web3AuthNetwork : Equatable, Hashable { + case SAPPHIRE_DEVNET + case SAPPHIRE_MAINNET + case MAINNET + case TESTNET + case CYAN + case AQUA + case CELESTE + case CUSTOM(path: String) + + public var path: String { + switch self { + case .SAPPHIRE_DEVNET: + return "sapphire_devnet" + case .SAPPHIRE_MAINNET: + return "sapphire_mainnet" + case .MAINNET: + return "mainnet" + case .TESTNET: + return "goerli" + case .CYAN, .AQUA, .CELESTE: + return "polygon-mainnet" + case let .CUSTOM(path): + return path + } + } + + public var name: String { + switch self { + case .SAPPHIRE_DEVNET: + return "sapphire_devnet" + case .SAPPHIRE_MAINNET: + return "sapphire_mainnet" + case .MAINNET: + return "mainnet" + case .TESTNET: + return "testnet" + case .CYAN : + return "cyan" + case .AQUA : + return "aqua" + case .CELESTE: + return "celeste" + case .CUSTOM(_): + return "custom" + } + } + + public var network: 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) + case .CUSTOM(path: let path): + return .legacy(.CUSTOM(path: path)) + } + } +} diff --git a/Tests/SingleFactorAuthTests/AquaTest.swift b/Tests/SingleFactorAuthTests/AquaTest.swift index bf597ae..7f0197f 100644 --- a/Tests/SingleFactorAuthTests/AquaTest.swift +++ b/Tests/SingleFactorAuthTests/AquaTest.swift @@ -14,7 +14,7 @@ final class AquaTest: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.AQUA)) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.AQUA) singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } diff --git a/Tests/SingleFactorAuthTests/CyanTest.swift b/Tests/SingleFactorAuthTests/CyanTest.swift index 138b499..c2d924d 100644 --- a/Tests/SingleFactorAuthTests/CyanTest.swift +++ b/Tests/SingleFactorAuthTests/CyanTest.swift @@ -14,7 +14,7 @@ final class CyanTest: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.CYAN)) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.CYAN) singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } diff --git a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift index ec9f955..81d39b1 100644 --- a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift +++ b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift @@ -14,7 +14,7 @@ final class SingleFactorAuthTests: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.TESTNET)) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.TESTNET) singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } From 6200742502d07618e5b91758e20096fa2ae2ef0c Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Thu, 4 Apr 2024 11:04:56 +0530 Subject: [PATCH 2/3] remove test xcsheme --- .../xcschemes/SingleFactorAuthTests.xcscheme | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme deleted file mode 100644 index 9107091..0000000 --- a/.swiftpm/xcode/xcshareddata/xcschemes/SingleFactorAuthTests.xcscheme +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - From 7ecf3777eebb986ae8f7c13618c426ee8b2f1458 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Thu, 4 Apr 2024 11:12:30 +0530 Subject: [PATCH 3/3] imporve usage of network --- Sources/SingleFactorAuth/SingleFactorAuth.swift | 4 ++-- Sources/SingleFactorAuth/SingleFactorAuthArgs.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/SingleFactorAuth/SingleFactorAuth.swift b/Sources/SingleFactorAuth/SingleFactorAuth.swift index 0d784c6..bd90ee5 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuth.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuth.swift @@ -13,12 +13,12 @@ public class SingleFactorAuth { public init(singleFactorAuthArgs: SingleFactorAuthArgs) { sessionManager = .init() - nodeDetailManager = NodeDetailManager(network: singleFactorAuthArgs.getNetwork()) + nodeDetailManager = NodeDetailManager(network: singleFactorAuthArgs.getNetwork().network) torusUtils = TorusUtils( enableOneKey: true, signerHost: singleFactorAuthArgs.getSignerUrl()! + "/api/sign", allowHost: singleFactorAuthArgs.getSignerUrl()! + "/api/allow", - network: singleFactorAuthArgs.getNetwork(), + network: singleFactorAuthArgs.getNetwork().network, clientId: singleFactorAuthArgs.getWeb3AuthClientId() ) } diff --git a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift index ccecead..e024921 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift @@ -26,8 +26,8 @@ public class SingleFactorAuthArgs { return web3AuthClientId } - public func getNetwork() -> TorusNetwork { - return network.network + public func getNetwork() -> Web3AuthNetwork { + return network } public func getSignerUrl() -> String? {