From 4d0895714e9734a348446f2f53612f8bf734a182 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Thu, 15 Feb 2024 23:02:44 +0530 Subject: [PATCH] fix iOS issue --- example/lib/main.dart | 2 ++ ios/Classes/SingleFactorAuthFlutterPlugin.swift | 16 ++++++++++++++-- lib/input.dart | 7 +++++++ lib/single_factor_auth_flutter.dart | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 736137e..697070a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -140,6 +140,8 @@ class _MyAppState extends State { _result = "Private Key : ${response.privateKey}"; log(response.publicAddress); }); + } on MissingParamException catch (error) { + log("Missing Param: ${error.paramName}"); } on PrivateKeyNotGeneratedException { log("Private key not generated"); } on UnKnownException { diff --git a/ios/Classes/SingleFactorAuthFlutterPlugin.swift b/ios/Classes/SingleFactorAuthFlutterPlugin.swift index 4296318..f60c546 100644 --- a/ios/Classes/SingleFactorAuthFlutterPlugin.swift +++ b/ios/Classes/SingleFactorAuthFlutterPlugin.swift @@ -76,6 +76,7 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin { guard let data = args?.data(using: .utf8) else { return result(throwKeyNotGeneratedError()) } + let params = try self.decoder.decode(getTorusKeyParams.self, from: data) let loginParams = LoginParams( @@ -85,6 +86,7 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin { ) do { + let torusKeyCF = try await singleFactorAuth?.getKey( loginParams: loginParams ) @@ -105,8 +107,12 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin { let params = try self.decoder.decode(getTorusKeyParams.self, from: data) + guard let aggregateVerifier = params.aggregateVerifier else { + return result(throwParamMissingError(param: "aggregateVerifier")) + } + let loginParams = LoginParams( - verifier: params.aggregateVerifier, + verifier: params.aggregateVerifier!, verifierId: params.verifierId, idToken: params.idToken, subVerifierInfoArray: [ @@ -140,6 +146,12 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin { ) } + public func throwParamMissingError(param: String) -> FlutterError { + return FlutterError( + code: "missing_param", message: param, details: nil + ) + } + } struct InitParams: Codable { @@ -150,5 +162,5 @@ struct getTorusKeyParams: Codable { var verifier: String var verifierId: String var idToken: String - var aggregateVerifier: String + var aggregateVerifier: String? } diff --git a/lib/input.dart b/lib/input.dart index f0f5089..1b4d6c8 100644 --- a/lib/input.dart +++ b/lib/input.dart @@ -39,6 +39,13 @@ class UserCancelledException implements Exception {} class PrivateKeyNotGeneratedException implements Exception {} +class MissingParamException implements Exception { + final String paramName; + + MissingParamException({required this.paramName}); + +} + class UnKnownException implements Exception { final String? message; diff --git a/lib/single_factor_auth_flutter.dart b/lib/single_factor_auth_flutter.dart index 5ed8cc9..e8d4022 100644 --- a/lib/single_factor_auth_flutter.dart +++ b/lib/single_factor_auth_flutter.dart @@ -73,6 +73,8 @@ class SingleFactAuthFlutter { throw UnKnownException(e.message); case "key_not_generated": throw PrivateKeyNotGeneratedException(); + case "missing_param": + throw MissingParamException(paramName: e.message!); default: throw e; }