Skip to content

Commit

Permalink
refactor: Handled credential manifest for with id for others and with…
Browse files Browse the repository at this point in the history
… outputdescriptor schema for EBSIV2
  • Loading branch information
bibash28 committed Aug 15, 2023
1 parent 4d72f5b commit 47ee271
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/app/shared/enum/type/oidc4vc_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ enum OIDC4VCType {
'RS256'
],
subjectSyntaxTypesSupported: ['did:key', 'did:pkh'],
schemaForType: true,
schemaForType: false,
publicJWKNeeded: true,
serviceDocumentation:
'''WORK IN PROGRESS EON project. last release of the specs.\n'''
Expand Down
14 changes: 7 additions & 7 deletions lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
return;
}

if (state.uri.toString().startsWith('openid-vc://') ||
uri.toString().startsWith('openid-hedera://')) {
if (state.uri.toString().startsWith('openid-vc://?') ||
uri.toString().startsWith('openid-hedera://?')) {
if (responseType == 'id_token') {
/// verifier side (siopv2) with request uri as value
await launchSiopV2WithRequestUriAsValueFlow();
Expand Down Expand Up @@ -307,9 +307,9 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
// ),
// ),
// );
} else if (state.uri.toString().startsWith('openid://') ||
state.uri.toString().startsWith('openid-vc://') ||
state.uri.toString().startsWith('openid-hedera://')) {
} else if (state.uri.toString().startsWith('openid://?') ||
state.uri.toString().startsWith('openid-vc://?') ||
state.uri.toString().startsWith('openid-hedera://?')) {
/// verifier side (siopv2 oidc4vc) with request_uri
await launchOIDC4VPAndSiopV2RequestAsURIFlow();
Expand Down Expand Up @@ -371,13 +371,13 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

/// verifier side (OIDC4VP And siopv2) with request_uri
if (state.uri.toString().startsWith('openid://')) {
if (state.uri.toString().startsWith('openid://?')) {
await launchOIDC4VPAndSiopV2WithRequestUriFlow(state.uri);
return;
}

/// verifier side (siopv2) with request_uri
if (state.uri.toString().startsWith('openid-vc://')) {
if (state.uri.toString().startsWith('openid-vc://?')) {
await launchSiopV2WithRequestUriFlow();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class ScanCubit extends Cubit<ScanState> {
return;
}

if (uri.toString().startsWith('openid-vc://') ||
uri.toString().startsWith('openid-hedera://')) {
if (uri.toString().startsWith('openid-vc://?') ||
uri.toString().startsWith('openid-hedera://?')) {
if (responseType == 'id_token') {
/// verifier side (siopv2) with request uri as value
throw Exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,48 @@ Future<CredentialManifest?> getCredentialManifest(
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>;

/// create credentialManisfest object
final credentialManifest = CredentialManifest.fromJson(
credentialManifestMap,
);
if (schemaForType) {
final JsonPath credentialManifestPath =
JsonPath(r'$..credential_manifests');

final String key = schemaForType ? 'schema' : 'id';
final credentialManifestsMap = credentialManifestPath
.read(jsonDecode(wellKnown.data as String))
.first
.value as List;

/// select wanted output desciptor
final JsonPath outputDescriptorPath = JsonPath(
// ignore: prefer_interpolation_to_compose_strings
r'$..output_descriptors[?(@.' + key + '=="' + credentialTypeOrId + '")]',
);
for (final map in credentialManifestsMap) {
final credentialManifest = CredentialManifest.fromJson(
map as Map<String, dynamic>,
);
if (credentialManifest.outputDescriptors != null) {
for (final outputDescriptor
in credentialManifest.outputDescriptors!) {
if (outputDescriptor.schema == credentialTypeOrId) {
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;
return null;
} else {
final JsonPath credentialManifestPath = JsonPath(
// ignore: prefer_interpolation_to_compose_strings
r'$..credential_manifests[?(@.id=="' + credentialTypeOrId + '")]',
);

/// 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,
);

return credentialManifest;
}
} catch (e) {
Expand Down

0 comments on commit 47ee271

Please sign in to comment.