diff --git a/Sources/SingleFactorAuth/SingleFactorAuth.swift b/Sources/SingleFactorAuth/SingleFactorAuth.swift index 599d57c..f4a8058 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuth.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuth.swift @@ -4,7 +4,9 @@ import FetchNodeDetails import Foundation import SessionManager import TorusUtils -import curveSecp256k1 +#if canImport(curveSecp256k1) + import curveSecp256k1 +#endif public class SingleFactorAuth { let nodeDetailManager: NodeDetailManager @@ -13,9 +15,9 @@ public class SingleFactorAuth { public init(singleFactorAuthArgs: SingleFactorAuthArgs) throws { sessionManager = .init() - nodeDetailManager = NodeDetailManager(network: singleFactorAuthArgs.getNetwork().network) - let torusOptions = TorusOptions(clientId: singleFactorAuthArgs.getWeb3AuthClientId(), network: singleFactorAuthArgs.getNetwork().network, enableOneKey: true) - try torusUtils = TorusUtils( params: torusOptions) + nodeDetailManager = NodeDetailManager(network: singleFactorAuthArgs.getNetwork()) + let torusOptions = TorusOptions(clientId: singleFactorAuthArgs.getWeb3AuthClientId(), network: singleFactorAuthArgs.getNetwork(), enableOneKey: true) + try torusUtils = TorusUtils(params: torusOptions) } public func initialize() async throws -> TorusSFAKey { @@ -51,7 +53,7 @@ public class SingleFactorAuth { aggregateIdTokenSeeds.sort() let verifierParams = VerifierParams(verifier_id: loginParams.verifierId, sub_verifier_ids: subVerifierIds, verify_params: verifyParams) - + let aggregateIdToken = try curveSecp256k1.keccak256(data: Data(aggregateIdTokenSeeds.joined(separator: "\u{001d}").utf8)).toHexString() retrieveSharesResponse = try await torusUtils.retrieveShares( @@ -73,10 +75,10 @@ public class SingleFactorAuth { return retrieveSharesResponse } - + public func getKey(loginParams: LoginParams) async throws -> TorusSFAKey { - let torusKey = try await self.getTorusKey(loginParams: loginParams) - + let torusKey = try await getTorusKey(loginParams: loginParams) + let publicAddress = torusKey.finalKeyData.evmAddress let privateKey = torusKey.finalKeyData.privKey diff --git a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift index 32ddd4c..9974c35 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift @@ -1,17 +1,9 @@ import FetchNodeDetails -import TorusUtils -public class SingleFactorAuthArgs { - 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", - ] +public typealias Web3AuthNetwork = TorusNetwork - private var network: Web3AuthNetwork +public class SingleFactorAuthArgs { + private var network: TorusNetwork private var networkUrl: String private var web3AuthClientId: String @@ -20,7 +12,7 @@ public class SingleFactorAuthArgs { self.networkUrl = networkUrl self.web3AuthClientId = web3AuthClientId } - + public func getWeb3AuthClientId() -> String { return web3AuthClientId } @@ -30,50 +22,10 @@ public class SingleFactorAuthArgs { } public func getSignerUrl() -> String? { - return SingleFactorAuthArgs.SIGNER_MAP[network] + return network.signerMap } 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 { - return self.network.path - } - - public var name: String { - return self.network.name - } - - 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 ed70cbc..d677c7c 100644 --- a/Tests/SingleFactorAuthTests/AquaTest.swift +++ b/Tests/SingleFactorAuthTests/AquaTest.swift @@ -1,6 +1,7 @@ import BigInt import JWTKit import XCTest +import FetchNodeDetails @testable import SingleFactorAuth @@ -13,7 +14,7 @@ final class AquaTest: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.AQUA) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: .legacy(.AQUA)) singleFactoreAuth = try! SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } diff --git a/Tests/SingleFactorAuthTests/CyanTest.swift b/Tests/SingleFactorAuthTests/CyanTest.swift index db6728c..bb2e855 100644 --- a/Tests/SingleFactorAuthTests/CyanTest.swift +++ b/Tests/SingleFactorAuthTests/CyanTest.swift @@ -13,7 +13,7 @@ final class CyanTest: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.CYAN) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: .legacy(.CYAN)) singleFactoreAuth = try! SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } diff --git a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift index 6af503d..2f6df02 100644 --- a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift +++ b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift @@ -13,7 +13,7 @@ final class SingleFactorAuthTests: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.TESTNET) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: .legacy(.TESTNET)) singleFactoreAuth = try! SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) }