Skip to content

Commit

Permalink
feat: Update presentation definition logic - consider field.optional,…
Browse files Browse the repository at this point in the history
… one path must be satisfied, all fields should be satisfied #3012 #2882
  • Loading branch information
bibash28 committed Nov 14, 2024
1 parent 3e725bc commit 40a4237
Showing 1 changed file with 58 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,76 @@ List<CredentialModel> getCredentialsFromFilterList({
final selectedCredential = <CredentialModel>[];

for (final credential in credentialList) {
bool allConditionsSatisfied = false;
fieldLoop:
for (final field in filterList) {
for (final path in field.path) {
final credentialData = createJsonByDecryptingSDValues(
encryptedJson: credential.data,
selectiveDisclosure: SelectiveDisclosure(credential),
);
/// if optional not need to compute
if (field.optional) {
allConditionsSatisfied = true;
} else {
pathLoop:
for (final path in field.path) {
final credentialData = createJsonByDecryptingSDValues(
encryptedJson: credential.data,
selectiveDisclosure: SelectiveDisclosure(credential),
);

final searchList = getTextsFromCredential(path, credentialData);
if (searchList.isNotEmpty) {
/// remove unmatched credential
searchList.removeWhere(
(searchParameter) {
String? pattern;
final searchList = getTextsFromCredential(path, credentialData);
if (searchList.isNotEmpty) {
/// remove unmatched credential
searchList.removeWhere(
(searchParameter) {
final filter = field.filter;

if (field.filter == null) {
//ascs case
return false;
} else if (field.filter?.pattern != null) {
pattern = field.filter!.pattern;
} else if (field.filter?.contains?.containsConst != null) {
pattern = field.filter?.contains?.containsConst;
} else if (field.filter?.containsConst != null) {
pattern = field.filter?.containsConst;
} else {
/// sd-jwt vc bool case
if (searchParameter == 'true') return false;
}
/// condition matched - no further filtration needed
if (filter == null) return false;

if (pattern == null) {
return false;
} else if (pattern.endsWith(r'$')) {
final RegExp regEx = RegExp(pattern);
final Match? match = regEx.firstMatch(searchParameter);
String? pattern = filter.pattern;
if (pattern != null) {
pattern = filter.pattern;
} else if (filter.contains?.containsConst != null) {
pattern = filter.contains?.containsConst;
} else if (filter.containsConst != null) {
pattern = filter.containsConst;
} else {
/// sd-jwt vc bool case
if (searchParameter == 'true') return false;
}

if (match != null) return false;
} else {
if (searchParameter == pattern) return false;
}
if (pattern == null) {
return false;
} else if (pattern.endsWith(r'$')) {
final RegExp regEx = RegExp(pattern);
final Match? match = regEx.firstMatch(searchParameter);

return true;
},
);
}
if (match != null) return false;
} else {
if (searchParameter == pattern) return false;
}

/// if [searchList] is not empty we mark this credential as
/// a valid candidate
if (searchList.isNotEmpty) {
selectedCredential.add(credential);
} else {
return true;
},
);
}

/// if [searchList] is not empty we mark this credential as
/// a valid candidate
if (searchList.isNotEmpty) {
allConditionsSatisfied = true;
break pathLoop;
} else {
allConditionsSatisfied = false;
}
}
// if one field is not satisfied then condition is not satisfied
if (!allConditionsSatisfied) {
break fieldLoop;
}
}
}
if (allConditionsSatisfied) {
selectedCredential.add(credential);
}
}

final credentials = selectedCredential.toSet().toList();
Expand Down

0 comments on commit 40a4237

Please sign in to comment.