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 2c787ca..e024921 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 @@ -26,7 +26,7 @@ public class SingleFactorAuthArgs { return web3AuthClientId } - public func getNetwork() -> TorusNetwork { + public func getNetwork() -> Web3AuthNetwork { return network } @@ -34,7 +34,77 @@ public class SingleFactorAuthArgs { 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) }