Skip to content

Commit

Permalink
Merge pull request #6 from Web3Auth/fix/ios-issue
Browse files Browse the repository at this point in the history
Fix iOS issue
  • Loading branch information
chaitanyapotti authored Mar 15, 2024
2 parents 4e11711 + a0105eb commit 02e6cb3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class _MyAppState extends State<MyApp> {
_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 {
Expand Down
16 changes: 14 additions & 2 deletions ios/Classes/SingleFactorAuthFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -85,6 +86,7 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
)

do {

let torusKeyCF = try await singleFactorAuth?.getKey(
loginParams: loginParams
)
Expand All @@ -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: [
Expand Down Expand Up @@ -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 {
Expand All @@ -150,5 +162,5 @@ struct getTorusKeyParams: Codable {
var verifier: String
var verifierId: String
var idToken: String
var aggregateVerifier: String
var aggregateVerifier: String?
}
7 changes: 7 additions & 0 deletions lib/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions lib/single_factor_auth_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 02e6cb3

Please sign in to comment.