Skip to content

Commit

Permalink
feat(app): Support for schemas when credential not found
Browse files Browse the repository at this point in the history
Signed-off-by: Talwinder kaur <[email protected]>
  • Loading branch information
Talwinder kaur committed Aug 29, 2023
1 parent 2b18a86 commit 3f30355
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,10 @@ class MainActivity : FlutterActivity() {
/**
This method invoke processAuthorizationRequest defined in OpenID4Vp.kt file.
*/
private fun processAuthorizationRequest(call: MethodCall, result: MethodChannel.Result): 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 @@ -820,14 +823,38 @@ class MainActivity : FlutterActivity() {
val matchedReq = openID4VP.getMatchedSubmissionRequirements(
convertToVerifiableCredentialsArray(storedCredentials)
)
var resp = 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");
if (typeConstraint.isEmpty()) {
var schemas = matchedReq.atIndex(0).descriptorAtIndex(0).schemas()
var schemaList = mutableListOf<Any>()
for (i in 0..schemas.length()) {
val schemasResp: MutableMap<String, Any> = mutableMapOf()
if (schemas.atIndex(i) != null) {
schemasResp["required"] = schemas.atIndex(i).required()
schemasResp["uri"] = schemas.atIndex(i).uri()
schemaList.addAll(listOf(schemasResp))
}
}

result.error(
"NATIVE_ERR",
"No credentials conforming to the following schemas were found",
"$schemaList"
);
}
result.error(
"NATIVE_ERR",
"No credentials of type $typeConstraint were found",
"Required credential $typeConstraint is missing from the wallet"
);
}

return resp

}
return listOf()
}
Expand Down
20 changes: 20 additions & 0 deletions demo/app/ios/Runner/flutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin {
var resp = convertVerifiableCredentialsArray(arr: matchedReq.atIndex(0)!.descriptor(at:0)!.matchedVCs!)
if (resp.isEmpty) {
var typeConstraint = matchedReq.atIndex(0)!.descriptor(at:0)!.typeConstraint()
if typeConstraint == "" {
var schemas = matchedReq.atIndex(0)!.descriptor(at:0)!.schemas()
var schemaList:[Any] = []
if let schemas = schemas {
var schemasResp : [String: Any] = [:]
for index in 0..<schemas.length() {
if let schema = schemas.atIndex(index) {
schemasResp["required"] = schema.required()
schemasResp["uri"] = schema.uri()
}

schemaList.append(schemasResp)
}

return result(FlutterError.init(code: "NATIVE_ERR",
message: "No credentials conforming to the following schemas were found",
details: "\(schemaList)"))

}
}
return result(FlutterError.init(code: "NATIVE_ERR",
message: "No credentials of type \(typeConstraint) were found",
details: "Required credential \(typeConstraint) is missing from the wallet"))
Expand Down
4 changes: 2 additions & 2 deletions demo/app/lib/scenarios/handle_openid_vp_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void handleOpenIDVpFlow(BuildContext context, String qrCodeURL) async {
storedCredentials = await storageService.retrieveCredentials(username!);
log("stored credentials -> $storedCredentials");

credentials = storedCredentials.map((e) => e.value.rawCredential).toList();
credentials = storedCredentials.map((e) => e.value.rawCredential).toList();
if (credentials.isEmpty) {
log("credentials is empty now $credentials");
Navigator.push(
Expand All @@ -43,7 +43,7 @@ void handleOpenIDVpFlow(BuildContext context, String qrCodeURL) async {
}

try {
var resp = await walletSDKPlugin.processAuthorizationRequest(
await walletSDKPlugin.processAuthorizationRequest(
authorizationRequest: qrCodeURL, storedCredentials: credentials);
} on PlatformException catch (error) {
Navigator.push(
Expand Down

0 comments on commit 3f30355

Please sign in to comment.