Skip to content

Commit

Permalink
bugFix: Added default name when external Gaiax credential manifest is…
Browse files Browse the repository at this point in the history
… not provided
  • Loading branch information
bibash28 committed Aug 11, 2023
1 parent b3ab5b0 commit 096057c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class _CredentialsDetailsViewState extends State<CredentialsDetailsView> {
final l10n = context.l10n;
final outputDescriptors =
widget.credentialModel.credentialManifest?.outputDescriptors;

return BlocConsumer<CredentialDetailsCubit, CredentialDetailsState>(
listener: (context, state) {
if (state.status == AppStatus.loading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class EmployeeCredentialWidget extends StatelessWidget {
title = titleDisplayMapping.fallback ?? '';
}

if (title == '') {
title = credentialModel
.credentialPreview.credentialSubjectModel.credentialSubjectType.title;
}

final DisplayMapping? subTitleDisplayMapping = credentialModel
.credentialManifest?.outputDescriptors?.first.display?.subtitle;

Expand Down
6 changes: 3 additions & 3 deletions lib/oidc4vc/add_oidc4vc_credential.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ Future<void> addOIDC4VCCredential({
credentialFromOIDC4VC['credentialSchema']['id'];
}

final CredentialManifest credentialManifest = await getCredentialManifest(
final CredentialManifest? credentialManifest = await getCredentialManifest(
Dio(),
issuer,
credentialTypeOrId,
oidc4vcType.schemaForType,
);

if (credentialManifest.outputDescriptors?.isNotEmpty ?? false) {
if (credentialManifest?.outputDescriptors?.isNotEmpty ?? false) {
newCredential['credential_manifest'] = CredentialManifest(
credentialManifest.id,
credentialManifest!.id,
credentialManifest.issuedBy,
credentialManifest.outputDescriptors,
credentialManifest.presentationDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,54 @@ import 'package:credential_manifest/credential_manifest.dart';
import 'package:dio/dio.dart';
import 'package:json_path/json_path.dart';

Future<CredentialManifest> getCredentialManifest(
Future<CredentialManifest?> getCredentialManifest(
Dio client,
String baseUrl,
String credentialTypeOrId,
bool schemaForType,
) async {
final dynamic wellKnown = await client.get<String>(
'$baseUrl/.well-known/openid-configuration',
);
final JsonPath credentialManifestPath = JsonPath(
r'$..credential_manifests[?(@.id)]',
);
try {
final dynamic wellKnown = await client.get<String>(
'$baseUrl/.well-known/openid-configuration',
);
final JsonPath credentialManifestPath = JsonPath(
r'$..credential_manifests[?(@.id)]',
);

/// select first credential manifest
final credentialManifestMap = credentialManifestPath
.read(jsonDecode(wellKnown.data as String))
.first
.value as Map<String, dynamic>;
/// select first credential manifest
final credentialManifestMap = credentialManifestPath
.read(jsonDecode(wellKnown.data as String))
.first
.value as Map<String, dynamic>;

/// create credentialManisfest object
final credentialManifest = CredentialManifest.fromJson(
credentialManifestMap,
);
/// create credentialManisfest object
final credentialManifest = CredentialManifest.fromJson(
credentialManifestMap,
);

final String key = schemaForType ? 'schema' : 'id';
final String key = schemaForType ? 'schema' : 'id';

/// select wanted output desciptor
final JsonPath outputDescriptorPath = JsonPath(
// ignore: prefer_interpolation_to_compose_strings
r'$..output_descriptors[?(@.' + key + '=="' + credentialTypeOrId + '")]',
);
/// select wanted output desciptor
final JsonPath outputDescriptorPath = JsonPath(
// ignore: prefer_interpolation_to_compose_strings
r'$..output_descriptors[?(@.' + key + '=="' + credentialTypeOrId + '")]',
);

/// There are some possible issues with this way of filtering :-/
final outputDescriptorList =
outputDescriptorPath.read(jsonDecode(wellKnown.data as String));
if (outputDescriptorList.isNotEmpty) {
final Map<String, dynamic> outputDescriptorMap =
outputDescriptorList.first.value as Map<String, dynamic>;
final OutputDescriptor outputDescriptor =
OutputDescriptor.fromJson(outputDescriptorMap);
final CredentialManifest sanitizedCredentialManifest =
credentialManifest.copyWith(outputDescriptors: [outputDescriptor]);
return sanitizedCredentialManifest;
} else {
return credentialManifest;
/// There are some possible issues with this way of filtering :-/
final outputDescriptorList =
outputDescriptorPath.read(jsonDecode(wellKnown.data as String));
if (outputDescriptorList.isNotEmpty) {
final Map<String, dynamic> outputDescriptorMap =
outputDescriptorList.first.value as Map<String, dynamic>;
final OutputDescriptor outputDescriptor =
OutputDescriptor.fromJson(outputDescriptorMap);
final CredentialManifest sanitizedCredentialManifest =
credentialManifest.copyWith(outputDescriptors: [outputDescriptor]);
return sanitizedCredentialManifest;
} else {
return credentialManifest;
}
} catch (e) {
return null;
}
}

0 comments on commit 096057c

Please sign in to comment.