Skip to content

Commit

Permalink
Merge pull request #16 from Web3Auth/feat/add-Web3AuthNetwork
Browse files Browse the repository at this point in the history
Add Web3AuthNetwork
  • Loading branch information
himanshuchawla009 authored Apr 4, 2024
2 parents f2f56e8 + 7ecf377 commit 8baa2b8
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Sources/SingleFactorAuth/SingleFactorAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
Expand Down
92 changes: 81 additions & 11 deletions Sources/SingleFactorAuth/SingleFactorAuthArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,15 +26,85 @@ public class SingleFactorAuthArgs {
return web3AuthClientId
}

public func getNetwork() -> TorusNetwork {
public func getNetwork() -> Web3AuthNetwork {
return 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))
}
}
}
2 changes: 1 addition & 1 deletion Tests/SingleFactorAuthTests/AquaTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SingleFactorAuthTests/CyanTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 8baa2b8

Please sign in to comment.