Skip to content

Commit

Permalink
Check with collective sd values #2552
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Apr 1, 2024
1 parent 084b4bf commit 5c8bbb1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
36 changes: 36 additions & 0 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1759,3 +1759,39 @@ List<String> getStringCredentialsForToken({

return (presentLdpVc, presentJwtVc, presentJwtVcJson, presentVcSdJwt);
}

List<dynamic> collectSdValues(Map<String, dynamic> data) {
final result = <dynamic>[];

if (data.containsKey('_sd') && data is List<dynamic>) {
final sd = data['_sd'];
if (sd is List<dynamic>) {
result.addAll(sd);
}
}

data.forEach((key, value) {
if (key == '_sd') {
final sd = data['_sd'];
if (sd is List<dynamic>) {
result.addAll(sd);
}
} else {
if (value is Map<String, dynamic>) {
result.addAll(collectSdValues(value));
} else if (value is List<dynamic>) {
for (final ele in value) {
if (ele is Map) {
final threeDotValue = ele['...'];

if (threeDotValue != null) {
result.add(threeDotValue);
}
}
}
}
}
});

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,20 @@ class CredentialDetailsCubit extends Cubit<CredentialDetailsState> {
/// sd-jwt
final credentialSupported = item.credentialSupported;
final claims = credentialSupported?['claims'];
final sd = item.data['_sd'];

if (claims != null && sd != null && sd is List<dynamic>) {
final data = item.data;

final listOfSd = collectSdValues(data);

if (claims != null && listOfSd.isNotEmpty) {
final selectiveDisclosure = SelectiveDisclosure(item);
final decryptedDatas = selectiveDisclosure.decryptedDatas;

/// check if sd already contain sh256 hash
for (final element in decryptedDatas) {
final sh256Hash = profileCubit.oidc4vc.sh256HashOfContent(element);

if (!sd.contains(sh256Hash)) {
if (!listOfSd.contains(sh256Hash)) {
emit(
state.copyWith(
credentialStatus: CredentialStatus.invalidSignature,
Expand Down
27 changes: 23 additions & 4 deletions lib/selective_disclosure/selective_disclosure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SelectiveDisclosure {
(String?, bool) getClaimsData({
required String key,
}) {
String? data;
dynamic data;
bool isfromDisclosureOfJWT = false;

final JsonPath dataPath = JsonPath(
Expand All @@ -138,18 +138,37 @@ class SelectiveDisclosure {

try {
final uncryptedDataPath = dataPath.read(extractedValuesFromJwt).first;
data = uncryptedDataPath.value.toString();
data = uncryptedDataPath.value;
isfromDisclosureOfJWT = true;
} catch (e) {
try {
final credentialModelPath = dataPath.read(credentialModel.data).first;
data = credentialModelPath.value.toString();
data = credentialModelPath.value;
isfromDisclosureOfJWT = false;
} catch (e) {
data = null;
}
}

return (data, isfromDisclosureOfJWT);
try {
if (data != null && data is List<dynamic>) {
final value = [];
for (final ele in data) {
if (ele is String) {
value.add(ele);
} else if (ele is Map) {
final threeDotValue = ele['...'];

if (threeDotValue != null) {
// what to do?
}
}
}
data = value.toString();
}
// ignore: empty_catches
} catch (e) {}

return (data.toString(), isfromDisclosureOfJWT);
}
}
1 change: 1 addition & 0 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@ class OIDC4VC {
String getDisclosure(String content) {
final disclosure =
base64Url.encode(utf8.encode(content)).replaceAll('=', '');

return disclosure;
}

Expand Down

0 comments on commit 5c8bbb1

Please sign in to comment.