Skip to content

Commit

Permalink
refactor: remove hybridaggregatelogin and reddithandler
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Sep 10, 2024
1 parent 045d57c commit 735257e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "18b632e2194394e0c1a608ed933754bf428e89a5fb32ba332befd79edc99e5f5",
"pins" : [
{
"identity" : "bigint",
Expand All @@ -19,21 +20,21 @@
}
},
{
"identity" : "fetch-node-details-swift",
"identity" : "customauth-swift-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/fetch-node-details-swift",
"location" : "https://github.com/torusresearch/customauth-swift-sdk/",
"state" : {
"revision" : "4bd96c33ba8d02d9e27190c5c7cedf09cfdfd656",
"version" : "6.0.3"
"branch" : "features_update",
"revision" : "045d57c57c1bfcc5fa951dd510e6f840c5af8d88"
}
},
{
"identity" : "jwt-kit",
"identity" : "fetch-node-details-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/jwt-kit.git",
"location" : "https://github.com/torusresearch/fetch-node-details-swift",
"state" : {
"revision" : "c2595b9ad7f512d7f334830b4df1fed6e917946a",
"version" : "4.13.4"
"revision" : "4bd96c33ba8d02d9e27190c5c7cedf09cfdfd656",
"version" : "6.0.3"
}
},
{
Expand All @@ -45,15 +46,6 @@
"version" : "3.1.0"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "9f95b4d033a4edd3814b48608db3f2ca90c7218b",
"version" : "3.7.0"
}
},
{
"identity" : "torus-utils-swift",
"kind" : "remoteSourceControl",
Expand All @@ -64,5 +56,5 @@
}
}
],
"version" : 2
"version" : 3
}

This file was deleted.

This file was deleted.

63 changes: 0 additions & 63 deletions Sources/CustomAuth/CustomAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,69 +149,6 @@ 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
}
if args.aggregateLoginParams.subVerifierDetailsArray.count == 1 && args.aggregateLoginParams.aggregateVerifierType == AggregateVerifierType.single_id_verifier {
throw CASDKError.invalidParameters
}

let loginHandler = try HandlerFactory.createHandler(params: CreateHandlerParams(typeOfLogin: args.singleLogin.typeOfLogin, verifier: args.singleLogin.verifier, clientId: args.singleLogin.clientId, urlScheme: config.urlScheme, redirectURL: args.singleLogin.redirectURL, jwtParams: args.singleLogin.jwtParams, customState: args.singleLogin.customState))

var loginParams: LoginWindowResponse
if args.singleLogin.hash != nil && args.singleLogin.queryParams != nil {
let (error, hashParams, instanceParams) = try handleRedirectParameters(hash: args.singleLogin.hash!, queryParameters: args.singleLogin.queryParams!)
if !error.isEmpty {
throw CASDKError.redirectParamsError(msg: error)
}
loginParams = LoginWindowResponse(accessToken: hashParams.params["access_token"], idToken: hashParams.params["idToken"], ref: hashParams.params["ref"] ?? "", extraParams: hashParams.params["extra_params"], extraParamsPassed: hashParams.params["extra_params_passed"]!, state: instanceParams)
} else {
loginParams = try await loginHandler.handleLoginWindow(popupFeatures: config.popupFeatures)
}

let userInfo = try await loginHandler.getUserInfo(params: loginParams, storageServerUrl: nil)

let verifyParams: VerifierParams = VerifierParams(verifier_id: userInfo.verifierId)

let torusKey = try await getTorusKey(verifier: userInfo.verifier, verifier_id: userInfo.verifierId, verifierParams: verifyParams, idToken: loginParams.idToken!)

let returnedInfo = UserInfo(email: userInfo.email, name: userInfo.name, profileImage: userInfo.profileImage, aggregateVerifier: userInfo.aggregateVerifier, verifier: userInfo.verifier, verifierId: userInfo.verifierId, typeOfLogin: userInfo.typeOfLogin, ref: userInfo.ref, // extraVerifierParams: userInfo.extraVerifierParams,
accessToken: loginParams.accessToken, idToken: loginParams.idToken, extraParams: loginParams.extraParams, extraParamsPassed: loginParams.extraParamsPassed, state: loginParams.state)

var subVerifierIds: [String] = []
var aggregateVerifierParams: [VerifyParams] = []
var aggregateIdTokenSeeds: [String] = []
var aggregateVerifierId: String = ""
for i in 0 ..< args.aggregateLoginParams.subVerifierDetailsArray.count {
let sub = args.aggregateLoginParams.subVerifierDetailsArray[i]
aggregateVerifierParams.append(VerifyParams(verifier_id: userInfo.verifierId, idtoken: loginParams.idToken!))
aggregateIdTokenSeeds.append(loginParams.idToken ?? loginParams.accessToken!)
subVerifierIds.append(sub.verifier)
aggregateVerifierId = userInfo.verifierId
}
aggregateIdTokenSeeds.sort()
let joined = aggregateIdTokenSeeds.joined(separator: "\u{29}").data(using: .utf8)!
let aggregateIdToken = try keccak256(data: joined)
let aggregateParams: VerifierParams = VerifierParams(verifier_id: aggregateVerifierId, extended_verifier_id: nil, sub_verifier_ids: subVerifierIds, verify_params: aggregateVerifierParams)

let aggregateTorusKey = try await getTorusKey(verifier: args.aggregateLoginParams.verifierIdentifier, verifier_id: aggregateVerifierId, verifierParams: aggregateParams, idToken: String(data: aggregateIdToken, encoding: .utf8)!)

let aggregateResponse = TorusAggregateVerifierResponse(userInfo: returnedInfo, loginResponse: loginParams)

let aggregateLogin = TorusAggregateLoginResponse(torusAggregateVerifierResponse: [aggregateResponse], torusKey: torusKey)

return TorusHybridAggregateLoginResponse(singleLogin: aggregateLogin, aggregateLogins: [aggregateTorusKey])
}

/// Retrieves the key details
///
/// - Parameters:
Expand Down
6 changes: 0 additions & 6 deletions Sources/CustomAuth/Handlers/HandlerFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ internal class HandlerFactory {
case .discord:
return try DiscordLoginHandler(clientId: params.clientId, verifier: params.verifier, urlScheme: params.urlScheme, redirectURL: params.redirectURL, typeOfLogin: params.typeOfLogin, jwtParams: params.jwtParams, customState: params.customState)
case .reddit: break
/* reddit deprecated implicit flow
if idToken != nil || accessToken != nil {
return try MockLoginHandler(clientId: params.clientId, verifier: params.verifier, urlScheme: params.urlScheme, redirectURL: params.redirectURL, typeOfLogin: params.typeOfLogin, jwtParams: params.jwtParams, customState: params.customState)
}
return try RedditLoginHandler(clientId: params.clientId, verifier: params.verifier, urlScheme: params.urlScheme, redirectURL: params.redirectURL, typeOfLogin: params.typeOfLogin, jwtParams: params.jwtParams, customState: params.customState)
*/
case .apple: break
case .github: break
case .linkedin: break
Expand Down
58 changes: 0 additions & 58 deletions Sources/CustomAuth/Handlers/RedditLoginHandler.swift

This file was deleted.

0 comments on commit 735257e

Please sign in to comment.