Skip to content

Commit

Permalink
refactore: Correct vp value for GAIX-X #2036
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Nov 1, 2023
1 parent 930ff65 commit 34b7847
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:credential_manifest/credential_manifest.dart';

PresentationDefinition applySubmissionRequirements(
PresentationDefinition presentationDefinition) {
PresentationDefinition presentationDefinition,
) {
if (presentationDefinition.submissionRequirements != null) {
/// https://identity.foundation/presentation-exchange/#presentation-definition-extensions
final inputDescriptors = List.of(presentationDefinition.inputDescriptors);
Expand Down
12 changes: 6 additions & 6 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 @@ -586,7 +586,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

/// contain id_token but may or may not contain vp_token
if (hasIDToken(responseType.toString())) {
if (hasIDToken(responseType)) {
final scope = state.uri!.queryParameters['scope'];
if (scope == null || scope != 'openid') {
throw ResponseMessage(
Expand All @@ -600,7 +600,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

/// contain vp_token but may or may not contain id_token
if (hasVPToken(responseType.toString())) {
if (hasVPToken(responseType)) {
if (!keys.contains('nonce')) {
throw ResponseMessage(
data: {
Expand Down Expand Up @@ -651,7 +651,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

/// contain vp_token or id_token
if (hasIDTokenOrVPToken(responseType.toString())) {
if (hasIDTokenOrVPToken(responseType)) {
if (isSecurityHigh &&
redirectUri != null &&
isClientIdUrl &&
Expand All @@ -666,12 +666,12 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

log.i('responseType - $responseType');
if (isIDTokenOnly(responseType.toString())) {
if (isIDTokenOnly(responseType)) {
/// verifier side (siopv2)
await completeSiopV2Flow(redirectUri: redirectUri!);
} else if (isVPTokenOnly(responseType.toString()) ||
isIDTokenAndVPToken(responseType.toString())) {
} else if (isVPTokenOnly(responseType) ||
isIDTokenAndVPToken(responseType)) {
/// responseType == 'vp_token' => verifier side (oidc4vp)
///
/// responseType == 'id_token vp_token' => verifier side (oidc4vp)
Expand Down
35 changes: 24 additions & 11 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,28 @@ class ScanCubit extends Cubit<ScanState> {

final inputDescriptors = <Map<String, dynamic>>[];

final presentLdpVc = presentationDefinition.format?.ldpVc != null;
final presentJwtVc = presentationDefinition.format?.jwtVc != null;
final ldpVc = presentationDefinition.format?.ldpVc != null;
final jwtVc = presentationDefinition.format?.jwtVc != null;

String? format;
String? vcFormat;

if (presentLdpVc) {
format = 'ldp_vc';
} else if (presentJwtVc) {
format = 'jwt_vc';
if (ldpVc) {
vcFormat = 'ldp_vc';
} else if (jwtVc) {
vcFormat = 'jwt_vc';
} else {
throw Exception();
}

final ldpVp = presentationDefinition.format?.ldpVp != null;
final jwtVp = presentationDefinition.format?.jwtVp != null;

String? vpFormat;

if (ldpVp) {
vpFormat = 'ldp_vp';
} else if (jwtVp) {
vpFormat = 'jwt_vp';
} else {
throw Exception();
}
Expand All @@ -636,11 +649,11 @@ class ScanCubit extends Cubit<ScanState> {

inputDescriptors.add({
'id': descriptor.id,
'format': 'jwt_vp',
'format': vpFormat,
'path': r'$',
'path_nested': {
'id': descriptor.id,
'format': format,
'format': vcFormat,
'path': r'$.verifiableCredential',
},
});
Expand All @@ -664,11 +677,11 @@ class ScanCubit extends Cubit<ScanState> {

inputDescriptors.add({
'id': descriptor.id,
'format': 'jwt_vp',
'format': vpFormat,
'path': r'$',
'path_nested': {
'id': descriptor.id,
'format': format,
'format': vcFormat,
// ignore: prefer_interpolation_to_compose_strings
'path': r'$.verifiableCredential[' + i.toString() + ']',
},
Expand Down

0 comments on commit 34b7847

Please sign in to comment.