From d9160ed18867be94c1551b32abc424db00a96db5 Mon Sep 17 00:00:00 2001 From: ieow Date: Mon, 28 Aug 2023 17:43:21 +0800 Subject: [PATCH] fix: merging issue --- Sources/CustomAuth/CustomAuth.swift | 12 ++++++------ Tests/CustomAuthTests/CustomAuthTests.swift | 12 ++++++------ Tests/CustomAuthTests/IntegrationTests.swift | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Sources/CustomAuth/CustomAuth.swift b/Sources/CustomAuth/CustomAuth.swift index edea586..480a409 100644 --- a/Sources/CustomAuth/CustomAuth.swift +++ b/Sources/CustomAuth/CustomAuth.swift @@ -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 @@ -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) @@ -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: { @@ -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 } @@ -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 { diff --git a/Tests/CustomAuthTests/CustomAuthTests.swift b/Tests/CustomAuthTests/CustomAuthTests.swift index 5cb4669..0545035 100644 --- a/Tests/CustomAuthTests/CustomAuthTests.swift +++ b/Tests/CustomAuthTests/CustomAuthTests.swift @@ -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) @@ -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) diff --git a/Tests/CustomAuthTests/IntegrationTests.swift b/Tests/CustomAuthTests/IntegrationTests.swift index 2362a84..cda9504 100644 --- a/Tests/CustomAuthTests/IntegrationTests.swift +++ b/Tests/CustomAuthTests/IntegrationTests.swift @@ -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 { @@ -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 {