Skip to content

Commit

Permalink
feat(app): Display the typeConstrait to the app when no credentials a…
Browse files Browse the repository at this point in the history
…re found

Signed-off-by: Talwinder kaur <[email protected]>
  • Loading branch information
Talwinder kaur committed Aug 29, 2023
1 parent 8ddb365 commit 21011ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class MainActivity : FlutterActivity() {

"processAuthorizationRequest" -> {
try {
val creds = processAuthorizationRequest(call)
val creds = processAuthorizationRequest(call, result)

result.success(creds)
} catch (e: Exception) {
Expand Down Expand Up @@ -755,8 +755,7 @@ class MainActivity : FlutterActivity() {

for (cred in vcCredentials) {
val parsedVC = Verifiable.parseCredential(cred, opts)
var issuerID = parsedVC.issuerID()
return issuerID
return parsedVC.issuerID()
}
return ""
}
Expand Down Expand Up @@ -802,7 +801,7 @@ class MainActivity : FlutterActivity() {
/**
This method invoke processAuthorizationRequest defined in OpenID4Vp.kt file.
*/
private fun processAuthorizationRequest(call: MethodCall): List<String> {
private fun processAuthorizationRequest(call: MethodCall, result: MethodChannel.Result): List<String> {
val walletSDK = this.walletSDK
?: throw java.lang.Exception("walletSDK not initiated. Call initSDK().")
val authorizationRequest = call.argument<String>("authorizationRequest")
Expand All @@ -821,9 +820,13 @@ class MainActivity : FlutterActivity() {
val matchedReq = openID4VP.getMatchedSubmissionRequirements(
convertToVerifiableCredentialsArray(storedCredentials)
)
return convertVerifiableCredentialsArray(
var resp = convertVerifiableCredentialsArray(
matchedReq.atIndex(0).descriptorAtIndex(0).matchedVCs
)
if (resp.isEmpty()) {
var typeConstraint = matchedReq.atIndex(0).descriptorAtIndex(0).typeConstraint()
result.error("NATIVE_ERR", "No credentials of type $typeConstraint were found", "Required credential $typeConstraint is missing from the wallet");
}
}
return listOf()
}
Expand Down
8 changes: 5 additions & 3 deletions demo/app/ios/Runner/flutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin {
credentials: storedCredentials!))
var resp = convertVerifiableCredentialsArray(arr: matchedReq.atIndex(0)!.descriptor(at:0)!.matchedVCs!)
if (resp.isEmpty) {
var typeConstraint = matchedReq.atIndex(0)!.descriptor(at:0)!.typeConstraint()
return result(FlutterError.init(code: "NATIVE_ERR",
message: "error while process authorization request",
details: "no matching submission requirement is found"))

message: "No credentials of type \(typeConstraint) were found",
details: "Required credential \(typeConstraint) is missing from the wallet"))
}

result(resp)
}
return result(Array<String>())
Expand Down
10 changes: 6 additions & 4 deletions demo/app/lib/scenarios/handle_openid_vp_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:app/services/storage_service.dart';
import 'package:app/views/presentation_preview.dart';
import 'package:app/views/presentation_preview_multi_cred.dart';
import 'package:app/views/presentation_preview_multi_cred_radio.dart';
import 'package:flutter/services.dart';
import 'package:jwt_decode/jwt_decode.dart';

void handleOpenIDVpFlow(BuildContext context, String qrCodeURL) async {
Expand Down Expand Up @@ -42,13 +43,14 @@ void handleOpenIDVpFlow(BuildContext context, String qrCodeURL) async {
}

try {
await walletSDKPlugin.processAuthorizationRequest(authorizationRequest: qrCodeURL, storedCredentials: credentials);
} catch (error) {
var resp = await walletSDKPlugin.processAuthorizationRequest(
authorizationRequest: qrCodeURL, storedCredentials: credentials);
} on PlatformException catch (error) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CustomError(
requestErrorTitleMsg: "No matching credential found", requestErrorSubTitleMsg: error.toString())));
builder: (context) =>
CustomError(requestErrorTitleMsg: error.message!, requestErrorSubTitleMsg: error.details)));
}
// Get the matched VCIDs from the submission request.
var getSubmissionRequest = await walletSDKPlugin.getSubmissionRequirements(storedCredentials: credentials);
Expand Down

0 comments on commit 21011ed

Please sign in to comment.