From ca4b78a06c1245a839c406e5fbcb50cb4ef3c373 Mon Sep 17 00:00:00 2001 From: milan Date: Thu, 9 May 2024 15:42:30 +0530 Subject: [PATCH] Fix #24: filter logic updated with limited_disclosures parameter --- .../models/InputDescriptors.kt | 1 + .../services/issue/IssueService.kt | 32 +++++++++++-------- .../verification/VerificationService.kt | 19 +++++++++-- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/InputDescriptors.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/InputDescriptors.kt index 1908ac9..f0c10cd 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/InputDescriptors.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/InputDescriptors.kt @@ -11,6 +11,7 @@ data class InputDescriptors( data class Constraints( + @SerializedName("limit_disclosure") var limitDisclosure: String? = null, @SerializedName("fields") var fields: ArrayList? = null ) diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt index 0ad3634..de6f056 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt @@ -435,24 +435,30 @@ class IssueService : IssueServiceInterface { when (credentialsSupported) { is JSONObject -> { - val credentialSupported = credentialsSupported.getJSONObject(type ?: "") - format = credentialSupported.getString("format") + try { + val credentialSupported = credentialsSupported.getJSONObject(type ?: "") + format = credentialSupported.getString("format") + } catch (e: Exception) { + } } is JSONArray -> { - for (i in 0 until credentialsSupported.length()) { - val jsonObject: JSONObject = credentialsSupported.getJSONObject(i) - - // Get the "types" JSONArray - val typesArray = jsonObject.getJSONArray("types") - - // Check if the string is present in the "types" array - for (j in 0 until typesArray.length()) { - if (typesArray.getString(j) == type) { - format = jsonObject.getString("format") - break + try { + for (i in 0 until credentialsSupported.length()) { + val jsonObject: JSONObject = credentialsSupported.getJSONObject(i) + + // Get the "types" JSONArray + val typesArray = jsonObject.getJSONArray("types") + + // Check if the string is present in the "types" array + for (j in 0 until typesArray.length()) { + if (typesArray.getString(j) == type) { + format = jsonObject.getString("format") + break + } } } + } catch (e: Exception) { } } diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt index b1c8f4f..13f03dc 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt @@ -82,7 +82,7 @@ class VerificationService : VerificationServiceInterface { ) return json - }else{ + } else { return null } } else { @@ -194,10 +194,25 @@ class VerificationService : VerificationServiceInterface { * Returns all the list of credentials matching for all input descriptors */ override suspend fun filterCredentials( - credentialList: List, + allCredentialList: List, presentationDefinition: PresentationDefinition ): List> { //list of credentials matched for all input descriptors + + val credentialList: ArrayList = arrayListOf() + for (item in allCredentialList) { + if (presentationDefinition.inputDescriptors?.get(0)?.constraints?.limitDisclosure != null && item?.contains( + "~" + ) == true + ) + credentialList.add(item) + else if (presentationDefinition.inputDescriptors?.get(0)?.constraints?.limitDisclosure == null && item?.contains( + "~" + ) != true + ) + credentialList.add(item) + } + val response: MutableList> = mutableListOf() var processedCredentials: List = mutableListOf()