Skip to content

Commit

Permalink
SD-JWT: present credential laking display #2826
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Aug 13, 2024
1 parent a79e13a commit 5b23eb6
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,11 @@ class _CredentialsDetailsViewState extends State<CredentialsDetailsView> {

/// selective disclouse data - _sd
/// and normal data too
if (containClaims) ...[
DisplaySelectiveDisclosure(
credentialModel: widget.credentialModel,
claims: null,
showVertically: showVerticalDescription,
),
],
DisplaySelectiveDisclosure(
credentialModel: widget.credentialModel,
claims: null,
showVertically: showVerticalDescription,
),

// /// normal claims data
// if (widget.credentialModel.credentialSupported !=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ class SelectiveDisclosureCubit extends Cubit<SelectiveDisclosureState> {
index = selectiveDisclosure.disclosureFromJWT
.indexWhere((entry) => entry == threeDotValue);
} else if (claimsKey != null) {
index =
selectiveDisclosure.disclosureToContent.entries.toList().indexWhere(
(entry) => entry.value.toString().contains(claimsKey),
);
index = selectiveDisclosure.disclosureListToContent.entries
.toList()
.indexWhere(
(entry) => entry.value.toString().contains(claimsKey),
);
}

if (index == null || index == -1) {
Expand Down
94 changes: 62 additions & 32 deletions lib/selective_disclosure/selective_disclosure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ import 'package:altme/app/app.dart';
import 'package:altme/dashboard/home/tab_bar/credentials/models/credential_model/credential_model.dart';
import 'package:altme/selective_disclosure/selective_disclosure.dart';
import 'package:json_path/json_path.dart';
import 'package:jwt_decode/jwt_decode.dart';
import 'package:oidc4vc/oidc4vc.dart';
export 'model/model.dart';

class SelectiveDisclosure {
SelectiveDisclosure(this.credentialModel);
final CredentialModel credentialModel;

Map<String, dynamic> get payload {
final encryptedValues = credentialModel.jwt
?.split('~')
.where((element) => element.isNotEmpty)
.toList();

final encryptedPayload = encryptedValues!.first;
return decodePayload(
jwtDecode: JWTDecode(),
token: encryptedPayload,
);
}

Map<String, dynamic> get claims {
final credentialSupported = credentialModel.credentialSupported;

Expand Down Expand Up @@ -52,7 +66,7 @@ class SelectiveDisclosure {

Map<String, dynamic> get extractedValuesFromJwt {
final extractedValues = <String, dynamic>{};
for (final element in disclosureToContent.entries.toList()) {
for (final element in disclosureListToContent.entries.toList()) {
try {
final lisString = jsonDecode(element.value.toString());
if (lisString is List) {
Expand Down Expand Up @@ -100,23 +114,10 @@ class SelectiveDisclosure {
return [];
}

Map<String, dynamic> get disclosureToContent {
Map<String, dynamic> get disclosureListToContent {
final data = <String, dynamic>{};

for (var element in disclosureFromJWT) {
try {
while (element.length % 4 != 0) {
element += '=';
}

final decryptedData = utf8.decode(base64Decode(element));

if (decryptedData.isNotEmpty) {
data[element] = decryptedData;
}
} catch (e) {
//
}
for (final element in disclosureFromJWT) {
data[element] = disclosureToContent(element);
}

return data;
Expand All @@ -126,28 +127,42 @@ class SelectiveDisclosure {
final data = <String, dynamic>{};

for (final element in contents) {
try {
final sh256Hash = OIDC4VC().sh256HashOfContent(element);
final lisString = jsonDecode(element);
if (lisString is List) {
if (lisString.length == 3) {
/// '["Qg_O64zqAxe412a108iroA", "phone_number", "+81-80-1234-5678"]'
data[sh256Hash] = {lisString[1]: lisString[2]};
} else if (lisString.length == 2) {
/// '["Qg_O64zqAxe412a108iroA", "DE']
data[sh256Hash] = {lisString[0]: lisString[1]};
}
data.addAll(contentOfSh256Hash(element));
}
return data;
}

Map<String, dynamic> contentOfSh256Hash(
String element,
) {
final data = <String, dynamic>{};
try {
final sh256Hash = OIDC4VC().sh256HashOfContent(element);
// print('element: $element');
final lisString = jsonDecode(element);
if (lisString is List) {
if (lisString.length == 3) {
/// '["Qg_O64zqAxe412a108iroA", "phone_number", "+81-80-1234-5678"]'
data[sh256Hash] = {
lisString[1]: lisString[2],
};
} else if (lisString.length == 2) {
/// '["Qg_O64zqAxe412a108iroA", "DE']
data[sh256Hash] = {
lisString[0]: lisString[1],
};
}
} catch (e) {
//
}
return data;
} catch (e) {
//
return data;
}
return data;
}

List<String> get contents {
final contents = <String>[];
for (final element in disclosureToContent.entries.toList()) {
for (final element in disclosureListToContent.entries.toList()) {
contents.add(element.value.toString());
}
return contents;
Expand Down Expand Up @@ -260,4 +275,19 @@ class SelectiveDisclosure {

return value;
}

String disclosureToContent(String element) {
String encryptedData = element;
try {
while (encryptedData.length % 4 != 0) {
encryptedData += '=';
}

final decryptedData = utf8.decode(base64Decode(encryptedData));
return decryptedData;
} catch (e) {
return '';
//
}
}
}
Loading

0 comments on commit 5b23eb6

Please sign in to comment.