Skip to content

Commit

Permalink
Revert "fix: Get credential supported data based on oidc4vci draft type
Browse files Browse the repository at this point in the history
#2655 (#2656)"

This reverts commit 0265f48.
  • Loading branch information
hawkbee1 committed May 21, 2024
1 parent aff3077 commit a327469
Showing 1 changed file with 62 additions and 67 deletions.
129 changes: 62 additions & 67 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ class OIDC4VC {
await getCredentialData(
openIdConfiguration: openIdConfiguration,
credential: credential,
oidc4vciDraftType: oidc4vciDraftType,
);

final credentialResponseData = <dynamic>[];
Expand Down Expand Up @@ -1014,7 +1013,6 @@ class OIDC4VC {
getCredentialData({
required OpenIdConfiguration openIdConfiguration,
required dynamic credential,
required OIDC4VCIDraftType oidc4vciDraftType,
}) async {
String? credentialType;
List<String>? types;
Expand All @@ -1034,90 +1032,87 @@ class OIDC4VC {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

if (oidc4vciDraftType == OIDC4VCIDraftType.draft13) {
if (openIdConfiguration.credentialConfigurationsSupported != null) {
// draft 13 case
if (credentialType.startsWith('https://api.preprod.ebsi.eu')) {
format = 'jwt_vc';
types = [];
} else if (openIdConfiguration.credentialsSupported != null) {
final credentialsSupported = JsonPath(r'$..credentials_supported')
.read(jsonDecode(jsonEncode(openIdConfiguration)))
.first
.value;

final credentialsSupported =
JsonPath(r'$..credential_configurations_supported')
.read(jsonDecode(jsonEncode(openIdConfiguration)))
.first
.value;
if (credentialsSupported is! List<dynamic>) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

if (credentialsSupported is! Map<String, dynamic>) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}
final credentialSupported = credentialsSupported
.where(
(dynamic e) =>
e is Map<String, dynamic> &&
((e.containsKey('scope') &&
e['scope'].toString() == credentialType) ||
(e.containsKey('id') &&
e['id'].toString() == credentialType) ||
e.containsKey('types') &&
e['types'] is List<dynamic> &&
(e['types'] as List<dynamic>).contains(credentialType)),
)
.firstOrNull;

final credentialSupportedMapEntry = credentialsSupported.entries.where(
(entry) {
final dynamic ele = entry.key;
if (credentialSupported == null ||
credentialSupported is! Map<String, dynamic>) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

if (ele == credentialType) return true;
types = (credentialSupported['types'] as List<dynamic>)
.map((e) => e.toString())
.toList();
format = credentialSupported['format'].toString();
} else if (openIdConfiguration.credentialConfigurationsSupported != null) {
// draft 13 case

return false;
},
).firstOrNull;
final credentialsSupported =
JsonPath(r'$..credential_configurations_supported')
.read(jsonDecode(jsonEncode(openIdConfiguration)))
.first
.value;

if (credentialSupportedMapEntry == null) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}
if (credentialsSupported is! Map<String, dynamic>) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

final credentialSupported = credentialSupportedMapEntry.value;
final credentialSupportedMapEntry = credentialsSupported.entries.where(
(entry) {
final dynamic ele = entry.key;

format = credentialSupported['format'].toString();
if (ele == credentialType) return true;

if (credentialSupported is Map<String, dynamic>) {
if (credentialSupported.containsKey('credential_definition')) {
credentialDefinition = credentialSupported['credential_definition']
as Map<String, dynamic>;
}
return false;
},
).firstOrNull;

if (credentialSupported.containsKey('vct')) {
vct = credentialSupported['vct'].toString();
}
}
} else {
if (credentialSupportedMapEntry == null) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}
} else {
if (openIdConfiguration.credentialsSupported != null) {
final credentialsSupported = JsonPath(r'$..credentials_supported')
.read(jsonDecode(jsonEncode(openIdConfiguration)))
.first
.value;

if (credentialsSupported is! List<dynamic>) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}
final credentialSupported = credentialSupportedMapEntry.value;

final credentialSupported = credentialsSupported
.where(
(dynamic e) =>
e is Map<String, dynamic> &&
((e.containsKey('scope') &&
e['scope'].toString() == credentialType) ||
(e.containsKey('id') &&
e['id'].toString() == credentialType) ||
e.containsKey('types') &&
e['types'] is List<dynamic> &&
(e['types'] as List<dynamic>)
.contains(credentialType)),
)
.firstOrNull;
format = credentialSupported['format'].toString();

if (credentialSupported == null ||
credentialSupported is! Map<String, dynamic>) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
if (credentialSupported is Map<String, dynamic>) {
if (credentialSupported.containsKey('credential_definition')) {
credentialDefinition = credentialSupported['credential_definition']
as Map<String, dynamic>;
}

types = (credentialSupported['types'] as List<dynamic>)
.map((e) => e.toString())
.toList();
format = credentialSupported['format'].toString();
} else {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
if (credentialSupported.containsKey('vct')) {
vct = credentialSupported['vct'].toString();
}
}
} else {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

return (credentialType, types, credentialDefinition, vct, format);
}

Expand Down

0 comments on commit a327469

Please sign in to comment.