Skip to content

Commit

Permalink
Merge pull request #61 from torusresearch/fix/merging-issue
Browse files Browse the repository at this point in the history
fix: merging issue
  • Loading branch information
himanshuchawla009 authored Aug 28, 2023
2 parents aabd0e7 + d9160ed commit 716b5f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions Sources/CustomAuth/CustomAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ open class CustomAuth {
/// - browserType: Indicates the way to open the browser for login flow. Use `.external` for opening system safari, or `.asWebAuthSession` for opening an in-app ASwebAuthenticationSession.
/// - modalPresentationStyle: Indicates the UIModalPresentationStyle for the popup.
/// - Returns: A promise that resolve with a Dictionary that contain at least `privateKey` and `publicAddress` field..
open func triggerLogin(controller: UIViewController? = nil, browserType: URLOpenerTypes = .asWebAuthSession, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> [String: Any] {
open func triggerLogin(controller: UIViewController? = nil, browserType: URLOpenerTypes = .asWebAuthSession, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKey {
os_log("triggerLogin called with %@ %@", log: getTorusLogger(log: CASDKLogger.core, type: .info), type: .info, browserType.rawValue, modalPresentationStyle.rawValue)
// Set browser
authorizeURLHandler = browserType
Expand All @@ -103,7 +103,7 @@ open class CustomAuth {
}
}

open func handleSingleLogins(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> [String: Any] {
open func handleSingleLogins(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKey {
if let subVerifier = subVerifierDetails.first {
let loginURL = subVerifier.getLoginURL()
await openURL(url: loginURL, view: controller, modalPresentationStyle: modalPresentationStyle)
Expand Down Expand Up @@ -144,7 +144,7 @@ open class CustomAuth {
throw CASDKError.unknownError
}

open func handleSingleIdVerifier(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> [String: Any] {
open func handleSingleIdVerifier(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKey {
if let subVerifier = subVerifierDetails.first {
let loginURL = subVerifier.getLoginURL()
await MainActor.run(body: {
Expand Down Expand Up @@ -186,12 +186,12 @@ open class CustomAuth {

}

func handleAndAggregateVerifier(controller: UIViewController?) async throws -> [String: Any] {
func handleAndAggregateVerifier(controller: UIViewController?) async throws -> TorusKey {
// TODO: implement verifier
throw CASDKError.methodUnavailable
}

func handleOrAggregateVerifier(controller: UIViewController?) async throws -> [String: Any] {
func handleOrAggregateVerifier(controller: UIViewController?) async throws -> TorusKey {
// TODO: implement verifier
throw CASDKError.methodUnavailable
}
Expand All @@ -210,7 +210,7 @@ open class CustomAuth {
do {
let nodeDetails = try await nodeDetailManager.getNodeDetails(verifier: verifier, verifierID: verifierId)
// retrieveShares internall checks if network is legacy and calls getPublicAddress if required.
let responseFromRetrieveShares : TorusKey = responseFromRetrieveShares = try await torusUtils.retrieveShares(endpoints: nodeDetails.torusNodeEndpoints, torusNodePubs: nodeDetails.torusNodePub, indexes: nodeDetails.torusIndexes, verifier: verifier, verifierParams: verifierParams, idToken: idToken, extraParams: extraParams)
let responseFromRetrieveShares : TorusKey = try await torusUtils.retrieveShares(endpoints: nodeDetails.torusNodeEndpoints, torusNodePubs: nodeDetails.torusNodePub, indexes: nodeDetails.torusIndexes, verifier: verifier, verifierParams: verifierParams, idToken: idToken, extraParams: extraParams)

return responseFromRetrieveShares
} catch {
Expand Down
12 changes: 6 additions & 6 deletions Tests/CustomAuthTests/CustomAuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ final class MockSDKTest: XCTestCase {
let nodeDetails = try await CustomAuth.getNodeDetailsFromContract(verifier: expectedVerifier, verfierID: expectedVerfierId)
let data = try await CustomAuth.getTorusKey(verifier: expectedVerifier, verifierId: expectedVerfierId, idToken: fakeData.generateVerifier())
let mockTorusUtils = CustomAuth.torusUtils as! MockAbstractTorusUtils
let FinalKeyData = data["finalKeyData"] as! [String: Any]
let FinalKeyData = data.finalKeyData!
print(FinalKeyData)
XCTAssertEqual(mockTorusUtils.retrieveShares_input["endpoints"] as? [String], nodeDetails.getTorusNodeEndpoints())
XCTAssertEqual(mockTorusUtils.retrieveShares_input["verifierIdentifier"] as? String, expectedVerifier)
XCTAssertEqual(mockTorusUtils.retrieveShares_input["verifierId"] as? String, expectedVerfierId)
XCTAssertEqual(FinalKeyData["privKey"] as! String, expectedPrivateKey)
XCTAssertEqual(FinalKeyData["evmAddress"] as! String, expectedPublicAddress)
XCTAssertEqual(FinalKeyData.privKey, expectedPrivateKey)
XCTAssertEqual(FinalKeyData.evmAddress, expectedPublicAddress)
expectation.fulfill()
} catch {
XCTFail(error.localizedDescription)
Expand Down Expand Up @@ -71,13 +71,13 @@ final class MockSDKTest: XCTestCase {
let nodeDetails = try await CustomAuth.getNodeDetailsFromContract(verifier: expectedVerifier, verfierID: expectedVerfierId)
let data = try await CustomAuth.getAggregateTorusKey(verifier: expectedVerifier, verifierId: expectedVerfierId, idToken: fakeData.generateVerifier(), subVerifierDetails: subVerifier[0])
print("Data", data)
let FinalKeyData = data["finalKeyData"] as! [String: Any]
let FinalKeyData = data.finalKeyData!
let mockTorusUtils = CustomAuth.torusUtils as! MockAbstractTorusUtils
XCTAssertEqual(mockTorusUtils.retrieveShares_input["endpoints"] as? [String], nodeDetails.getTorusNodeEndpoints())
XCTAssertEqual(mockTorusUtils.retrieveShares_input["verifierIdentifier"] as? String, expectedVerifier)
XCTAssertEqual(mockTorusUtils.retrieveShares_input["verifierId"] as? String, expectedVerfierId)
XCTAssertEqual(FinalKeyData["privKey"] as! String, expectedPrivateKey)
XCTAssertEqual(FinalKeyData["evmAddress"] as! String, expectedPublicAddress)
XCTAssertEqual(FinalKeyData.privKey, expectedPrivateKey)
XCTAssertEqual(FinalKeyData.evmAddress, expectedPublicAddress)
expectation.fulfill()
} catch {
XCTFail(error.localizedDescription)
Expand Down
8 changes: 4 additions & 4 deletions Tests/CustomAuthTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class IntegrationTests: XCTestCase {
let jwt = try! generateIdToken(email: email)
do {
let data = try await IntegrationTests.sdk?.getTorusKey(verifier: TORUS_TEST_VERIFIER, verifierId: email, idToken: jwt)
let finalKeyDataDict = data?["finalKeyData"] as? [String: Any]
let evmAddress = finalKeyDataDict!["evmAddress"] as? String
let finalKeyDataDict = data!.finalKeyData!
let evmAddress = finalKeyDataDict.evmAddress
XCTAssertEqual(evmAddress, "0x8AA6C8ddCD868873120aA265Fc63E3a2180375BA")
exp1.fulfill()
} catch {
Expand Down Expand Up @@ -73,8 +73,8 @@ final class IntegrationTests: XCTestCase {
let jwt = try! generateIdToken(email: TORUS_TEST_EMAIL)
do {
let data = try await sdk.getTorusKey(verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: jwt)
let finalKeyDataDict = data["finalKeyData"] as? [String: Any]
let evmAddress = finalKeyDataDict!["evmAddress"] as? String
let finalKeyDataDict = data.finalKeyData!
let evmAddress = finalKeyDataDict.evmAddress
XCTAssertEqual(evmAddress, "0x4924F91F5d6701dDd41042D94832bB17B76F316F")
exp1.fulfill()
} catch {
Expand Down

0 comments on commit 716b5f8

Please sign in to comment.