Skip to content

Commit

Permalink
update: visibility and initial inline documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Jul 30, 2024
1 parent b9f81e0 commit 473faf6
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/torus-utils-swift.git",
"state" : {
"revision" : "7788752bed699b3d34e78c2c51174f814d02610b",
"revision" : "303dc2cf41db7c10f769855edad0e717ced2d554",
"version" : "9.0.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Common/State.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public class State: Codable {
internal class State: Codable {
public var customState: TorusGenericContainer?
public var instanceId: String
public var verifier: String
Expand Down
52 changes: 52 additions & 0 deletions Sources/CustomAuth/CustomAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public class CustomAuth {

public let nodeDetailManager: NodeDetailManager

/// Initializes CustomAuth with the provided options
///
/// - Parameters:
/// - params: `CustomAuthArgs`
///
/// - Returns: `CustomAuth`
///
/// - Throws: `CASDKError.invalidCallbackURLScheme`, `TorusUtilError.invalidInput`
public init(config: CustomAuthArgs) throws {
if URL(string: config.urlScheme)?.scheme == nil {
throw CASDKError.invalidCallbackURLScheme
Expand All @@ -37,6 +45,14 @@ public class CustomAuth {
torus.setApiKey(apiKey: config.apiKey ?? "")
}

/// Initiates a login using a single verifier
///
/// - Parameters:
/// - params: `SingleLoginParams`
///
/// - Returns: `TorusLoginResponse`
///
/// - Throws: `CASDKError`, `TorusUtilError`
public func triggerLogin(args: SingleLoginParams) async throws -> TorusLoginResponse {
let loginHandler = try HandlerFactory.createHandler(params: CreateHandlerParams(typeOfLogin: args.typeOfLogin, verifier: args.verifier, clientId: args.clientId, urlScheme: config.urlScheme, redirectURL: args.redirectURL, jwtParams: args.jwtParams, customState: args.customState))

Expand All @@ -62,6 +78,14 @@ public class CustomAuth {
return TorusLoginResponse(singleVerifierResponse: TorusSingleVerifierResponse(userInfo: returnedInfo, loginResponse: loginParams), torusKey: torusKey)
}

/// Initiates a login using a aggregate verifier
///
/// - Parameters:
/// - params: `AggregateLoginParams`
///
/// - Returns: `TorusAggregateLoginResponse`
///
/// - Throws: `CASDKError`, `TorusUtilError`
public func triggerAggregateLogin(args: AggregateLoginParams) async throws -> TorusAggregateLoginResponse {
if args.subVerifierDetailsArray.isEmpty {
throw CASDKError.invalidParameters
Expand Down Expand Up @@ -123,6 +147,14 @@ public class CustomAuth {
return TorusAggregateLoginResponse(torusAggregateVerifierResponse: aggregateVerifierResponses, torusKey: aggregateTorusKey)
}

/// Initiates a login using a hybrid verifier
///
/// - Parameters:
/// - params: `HybridAggregateLoginParams`
///
/// - Returns: `TorusHybridAggregateLoginResponse`
///
/// - Throws: `CASDKError`, `TorusUtilError`
public func triggerHybridAggregateLogin(args: HybridAggregateLoginParams) async throws -> TorusHybridAggregateLoginResponse {
if args.aggregateLoginParams.subVerifierDetailsArray.isEmpty {
throw CASDKError.invalidParameters
Expand Down Expand Up @@ -177,12 +209,32 @@ public class CustomAuth {
return TorusHybridAggregateLoginResponse(singleLogin: aggregateLogin, aggregateLogins: [aggregateTorusKey])
}

/// Retrieves the key details
///
/// - Parameters:
/// - verifier: `String`
/// - verifierParams: `VerifierParams`
/// - idToken: `String`
///
/// - Returns: `TorusKey`
///
/// - Throws: `CASDKError`, `TorusUtilError`, `FetchNodeError`
func getTorusKey(verifier: String, verifierParams: VerifierParams, idToken: String) async throws -> TorusKey {
let nodeDetails = try await nodeDetailManager.getNodeDetails(verifier: verifier, verifierID: verifierParams.verifier_id)

return try await torus.retrieveShares(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: verifier, verifierParams: verifierParams, idToken: idToken)
}

/// Retrieves the aggregate key details
///
/// - Parameters:
/// - verifier: `String`
/// - verifierParams: `VerifierParams`
/// - subVerifierInfoArray: `TorusSubVerifierInfo`
///
/// - Returns: `TorusKey`
///
/// - Throws: `CASDKError`, `TorusUtilError`, `FetchNodeError`
func getAggregateTorusKey(verifier: String, verifierParams: VerifierParams, subVerifierInfoArray: [TorusSubVerifierInfo]) async throws -> TorusKey {
let nodeDetails = try await nodeDetailManager.getNodeDetails(verifier: verifier, verifierID: verifierParams.verifier_id)

Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Extension/Data+extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

extension Data {
internal extension Data {
func toBase64URL() -> String {
var result = base64EncodedString()
result = result.replacingOccurrences(of: "+", with: "-")
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Extension/String+extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

extension String {
internal extension String {
func fromBase64URL() throws -> String {
var base64 = self
base64 = base64.replacingOccurrences(of: "-", with: "+")
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Extension/URLComponents+extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

extension URLComponents {
internal extension URLComponents {
mutating func setQueryItems(with parameters: [String: String]) {
queryItems = parameters.map { URLQueryItem(name: $0.key, value: $0.value) }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Handlers/AuthenticationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AuthenticationServices
import UIKit
#endif

public class AuthenticationManager: NSObject, ASWebAuthenticationPresentationContextProviding {
internal class AuthenticationManager: NSObject, ASWebAuthenticationPresentationContextProviding {
public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
var window: ASPresentationAnchor?
#if os(macOS)
Expand Down
4 changes: 2 additions & 2 deletions Sources/CustomAuth/Handlers/DiscordLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation

class DiscordInfo: Codable {
internal class DiscordInfo: Codable {
public var id: String
public var username: String
public var avatar: String?
public var discriminator: String
public var email: String
}

class DiscordLoginHandler: AbstractLoginHandler {
internal class DiscordLoginHandler: AbstractLoginHandler {
private var response_type: String = "token"
private var scope: String = "identify email"
private var prompt: String = "none"
Expand Down
8 changes: 4 additions & 4 deletions Sources/CustomAuth/Handlers/FacebookLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Foundation

class FacebookPictureData: Codable {
internal class FacebookPictureData: Codable {
public var url: String
}

class FacebookPicture: Codable {
internal class FacebookPicture: Codable {
public var data: FacebookPictureData
}

class FacebookInfo: Codable {
internal class FacebookInfo: Codable {
public var id: String
public var name: String
public var picture: FacebookPicture
public var email: String
}

class FacebookLoginHandler: AbstractLoginHandler {
internal class FacebookLoginHandler: AbstractLoginHandler {
private var response_type: String = "token"
private var scope: String = "public_profile email"

Expand Down
4 changes: 2 additions & 2 deletions Sources/CustomAuth/Handlers/GoogleLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Foundation

class GoogleInfo: Codable {
internal class GoogleInfo: Codable {
public var name: String
public var picture: String
public var email: String
}

class GoogleLoginHandler: AbstractLoginHandler {
internal class GoogleLoginHandler: AbstractLoginHandler {
private var response_type: String = "token id_token"
private var scope: String = "profile email openid"
private var prompt: String = "select_account"
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Handlers/HandlerFactory.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public class HandlerFactory {
internal class HandlerFactory {
static func createHandler(
params: CreateHandlerParams
) throws -> ILoginHandler {
Expand Down
4 changes: 2 additions & 2 deletions Sources/CustomAuth/Handlers/JWTLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import JWTDecode

public class Auth0UserInfo: Codable {
internal class Auth0UserInfo: Codable {
public let picture: String
public let email: String
public let name: String
Expand All @@ -17,7 +17,7 @@ public class Auth0UserInfo: Codable {
}
}

class JWTLoginHandler: AbstractLoginHandler {
internal class JWTLoginHandler: AbstractLoginHandler {
private var response_type: String = "token id_token"
private var scope: String = "openid profile email"
private var prompt: String = "login"
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Handlers/MockLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import JWTDecode

class MockLoginHandler: AbstractLoginHandler {
internal class MockLoginHandler: AbstractLoginHandler {
override public init(clientId: String, verifier: String, urlScheme: String, redirectURL: String, typeOfLogin: LoginType, jwtParams: Auth0ClientOptions? = nil, customState: TorusGenericContainer? = nil) throws {
try super.init(clientId: clientId, verifier: verifier, urlScheme: urlScheme, redirectURL: redirectURL, typeOfLogin: typeOfLogin, jwtParams: jwtParams, customState: customState)
try setFinalUrl()
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import JWTDecode

class PasswordlessLoginHandler: AbstractLoginHandler {
internal class PasswordlessLoginHandler: AbstractLoginHandler {
private var response_type: String = "token id_token"
private var scope: String = "openid profile email"
private var prompt: String = "login"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import curveSecp256k1
#endif

public class AbstractLoginHandler: ILoginHandler {
internal class AbstractLoginHandler: ILoginHandler {
public var clientId: String

public var nonce: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public class CreateHandlerParams: Codable {
internal class CreateHandlerParams: Codable {
public let typeOfLogin: LoginType
public let verifier: String
public let clientId: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Handlers/Protocol/ILoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public protocol ILoginHandler {
internal protocol ILoginHandler {
var clientId: String { get set }
var nonce: String { get set }
var finalUrl: URLComponents { get set }
Expand Down
4 changes: 2 additions & 2 deletions Sources/CustomAuth/Handlers/RedditLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation

class RedditInfo: Codable {
internal class RedditInfo: Codable {
public var name: String
public var icon_image: String?
}

class RedditLoginHandler: AbstractLoginHandler {
internal class RedditLoginHandler: AbstractLoginHandler {
private var response_type: String = "token"
private var scope: String = "identity"

Expand Down
6 changes: 3 additions & 3 deletions Sources/CustomAuth/Handlers/TwitchLoginHandler.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Foundation

class TwitchInfo: Codable {
internal class TwitchInfo: Codable {
public var id: String
public var email: String?
public var display_name: String
public var profile_image_url: String
}

class TwitchRootInfo: Codable {
internal class TwitchRootInfo: Codable {
public var data: [TwitchInfo]
}

class TwitchLoginHandler: AbstractLoginHandler {
internal class TwitchLoginHandler: AbstractLoginHandler {
private var response_type: String = "token"
private var scope: String = "user:read:email"

Expand Down
4 changes: 2 additions & 2 deletions Sources/CustomAuth/Helpers/Common.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

func loginToConnection(loginType: LoginType) -> String {
internal func loginToConnection(loginType: LoginType) -> String {
switch loginType {
case .apple: break
case .google: break
Expand All @@ -19,7 +19,7 @@ func loginToConnection(loginType: LoginType) -> String {
return loginType.rawValue
}

func getVerifierId(
internal func getVerifierId(
userInfo: Auth0UserInfo,
typeOfLogin: LoginType,
verifierIdField: String? = nil,
Expand Down

0 comments on commit 473faf6

Please sign in to comment.