Skip to content

Commit

Permalink
feat: Update to Interop event verifier fails #2651
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed May 10, 2024
1 parent c9c6d20 commit 164d760
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 97 deletions.
17 changes: 11 additions & 6 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Future<bool> isCredentialAvaialble({
credential
.credentialPreview.credentialSubjectModel.credentialSubjectType;

final matchFormat = vcFormatType.value == credential.format;
final matchFormat = vcFormatType.vcValue == credential.format;
if (matchSubjectType && matchFormat) {
return true;
}
Expand Down Expand Up @@ -972,7 +972,12 @@ Future<Map<String, dynamic>?> getClientMetada({
return null;
}
} catch (e) {
return null;
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'Client metaData is invalid',
},
);
}
}

Expand Down Expand Up @@ -1841,10 +1846,10 @@ List<String> getStringCredentialsForToken({
}

/// create list of supported formats
if (presentLdpVc) supportingFormats.add(VCFormatType.ldpVc.value);
if (presentJwtVc) supportingFormats.add(VCFormatType.jwtVc.value);
if (presentJwtVcJson) supportingFormats.add(VCFormatType.jwtVcJson.value);
if (presentVcSdJwt) supportingFormats.add(VCFormatType.jwtVcJson.value);
if (presentLdpVc) supportingFormats.add(VCFormatType.ldpVc.vcValue);
if (presentJwtVc) supportingFormats.add(VCFormatType.jwtVc.vcValue);
if (presentJwtVcJson) supportingFormats.add(VCFormatType.jwtVcJson.vcValue);
if (presentVcSdJwt) supportingFormats.add(VCFormatType.jwtVcJson.vcValue);

/// make sure only one of all are true
if (presentLdpVc && vcFormatType == VCFormatType.ldpVc) {
Expand Down
2 changes: 1 addition & 1 deletion lib/credentials/cubit/credentials_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ class CredentialsCubit extends Cubit<CredentialsState> {

//get current wallet address
} else {
if (vcFormatType.value == credential.getFormat) {
if (vcFormatType.vcValue == credential.getFormat) {
/// do not add if format matched
/// there can be same credentials with different format
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/credentials/cubit/credentials_helper_function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Future<CredentialModel> _createCredential({
data: jsonLd,
shareLink: '',
jwt: jwt,
format: customOidc4vcProfile.vcFormatType.value,
format: customOidc4vcProfile.vcFormatType.vcValue,
credentialPreview: Credential.fromJson(jsonLd),
credentialManifest: credentialManifest,
activities: [Activity(acquisitionAt: dateTime)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class VCFormatWidget extends StatelessWidget {
),
),
title: Text(
vcFormatType.formattedString,
vcFormatType.vcValue,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/dashboard/home/home/cubit/home_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class HomeCubit extends Cubit<HomeState> {
final Map<String, dynamic> newCredential =
Map<String, dynamic>.from(credential);
newCredential['credentialPreview'] = credential;
newCredential['format'] = vcFormatType.value;
newCredential['format'] = vcFormatType.vcValue;
final CredentialManifest credentialManifest =
await getCredentialManifestFromAltMe(
oidc4vc: oidc4vc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class HomeCredentialCategoryList extends StatelessWidget {
}

/// do not load the credential if vc format is different
if (customOidc4vcProfile.vcFormatType.value !=
if (customOidc4vcProfile.vcFormatType.vcValue !=
element.getFormat) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ List<CredentialModel> filterCredenialListByFormat({
(CredentialModel credentialModel) {
/// remove ldpVc
if (presentLdpVc) {
return credentialModel.format != VCFormatType.ldpVc.value;
return credentialModel.format != VCFormatType.ldpVc.vcValue;
}

/// remove jwtVc
if (presentJwtVc) {
return credentialModel.format != VCFormatType.jwtVc.value;
return credentialModel.format != VCFormatType.jwtVc.vcValue;
}

/// remove JwtVcJson
if (presentJwtVcJson) {
return credentialModel.format != VCFormatType.jwtVcJson.value;
return credentialModel.format != VCFormatType.jwtVcJson.vcValue;
}

/// remove vcSdJwt
if (presentVcSdJwt) {
return credentialModel.format != VCFormatType.vcSdJWT.value;
return credentialModel.format != VCFormatType.vcSdJWT.vcValue;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ List<CredentialModel> getCredentialsFromFilterList({
pattern = field.filter!.pattern;
} else if (field.filter?.contains?.containsConst != null) {
pattern = field.filter?.contains?.containsConst;
} else if (field.filter?.containsConst != null) {
pattern = field.filter?.containsConst;
} else {
/// sd-jwt vc bool case
if (searchParameter == 'true') return false;
Expand Down
34 changes: 17 additions & 17 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 @@ -935,22 +935,16 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
client: client,
uri: state.uri!,
);
if (clientMetaData == null) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'Client metaData is invalid',
},
);
}

if (!clientMetaData.containsKey('vp_formats')) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'Format is missing.',
},
);
if (clientMetaData != null) {
if (!clientMetaData.containsKey('vp_formats')) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'Format is missing.',
},
);
}
}
}

Expand Down Expand Up @@ -998,8 +992,14 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
shareLink: 'shareLink',
data: const {},
jwt: null,
format: profileCubit.state.model.profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile.vcFormatType.value,
format: profileCubit
.state
.model
.profileSetting
.selfSovereignIdentityOptions
.customOidc4vcProfile
.vcFormatType
.vcValue,
credentialManifest: credentialManifest,
);

Expand Down
12 changes: 6 additions & 6 deletions lib/oidc4vc/add_oidc4vc_credential.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ Future<void> addOIDC4VCCredential({
}) async {
late Map<String, dynamic> credentialFromOIDC4VC;

if (format == VCFormatType.jwtVc.value ||
format == VCFormatType.jwtVcJson.value ||
format == VCFormatType.vcSdJWT.value) {
if (format == VCFormatType.jwtVc.vcValue ||
format == VCFormatType.jwtVcJson.vcValue ||
format == VCFormatType.vcSdJWT.vcValue) {
//jwt_vc
final data = encodedCredentialFromOIDC4VC['credential'] as String;

final jsonContent = jwtDecode.parseJwt(data);

if (format == VCFormatType.vcSdJWT.value) {
if (format == VCFormatType.vcSdJWT.vcValue) {
final sdAlg = jsonContent['_sd_alg'];

if (sdAlg == null || sdAlg != 'sha-256') {
Expand All @@ -48,7 +48,7 @@ Future<void> addOIDC4VCCredential({
credentialFromOIDC4VC = jsonContent['vc'] as Map<String, dynamic>;
}

if (format == VCFormatType.vcSdJWT.value) {
if (format == VCFormatType.vcSdJWT.vcValue) {
/// type
if (!credentialFromOIDC4VC.containsKey('type')) {
credentialFromOIDC4VC['type'] = [credentialType];
Expand Down Expand Up @@ -115,7 +115,7 @@ Future<void> addOIDC4VCCredential({
// }

credentialFromOIDC4VC['jwt'] = data;
} else if (format == VCFormatType.ldpVc.value) {
} else if (format == VCFormatType.ldpVc.vcValue) {
//ldp_vc

final data = encodedCredentialFromOIDC4VC['credential'];
Expand Down
72 changes: 28 additions & 44 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ class ScanCubit extends Cubit<ScanState> {
} else {
for (final item in credentialsToBePresented) {
final presentationId = 'urn:uuid:${const Uuid().v4()}';
/// proof is done with a creation date 20 seconds in the past to avoid
/// proof check to fail because of time difference on server

/// proof is done with a creation date 20 seconds in the past to avoid
/// proof check to fail because of time difference on server
final options = jsonEncode({
'verificationMethod': kid,
Expand Down Expand Up @@ -355,7 +356,7 @@ class ScanCubit extends Cubit<ScanState> {
final presentationId = 'urn:uuid:${const Uuid().v4()}';

/// proof is done with a creation date 20 seconds in the past to avoid
/// proof check to fail because of time difference on server
/// proof check to fail because of time difference on server
final options = jsonEncode({
'verificationMethod': kid,
'proofPurpose': 'assertionMethod',
Expand Down Expand Up @@ -760,49 +761,33 @@ class ScanCubit extends Cubit<ScanState> {
}
} else {
if (clientMetaData == null) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'Client metaData is invalid',
},
);
}

final vpFormats = clientMetaData['vp_formats'] as Map<String, dynamic>;

if (vpFormats.containsKey('ldp_vc')) {
vcFormat = 'ldp_vc';
} else if (vpFormats.containsKey('jwt_vc')) {
vcFormat = 'jwt_vc';
} else if (vpFormats.containsKey('jwt_vc_json')) {
vcFormat = 'jwt_vc_json';
}
final vcFormatType = profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile.vcFormatType;
vcFormat = vcFormatType.vcValue;
vpFormat = vcFormatType.vpValue;
} else {
final vpFormats = clientMetaData['vp_formats'] as Map<String, dynamic>;

if (vpFormats.containsKey('ldp_vc')) {
vcFormat = 'ldp_vc';
} else if (vpFormats.containsKey('jwt_vc')) {
vcFormat = 'jwt_vc';
} else if (vpFormats.containsKey('jwt_vc_json')) {
vcFormat = 'jwt_vc_json';
}

if (vpFormats.containsKey('ldp_vp')) {
vpFormat = 'ldp_vp';
} else if (vpFormats.containsKey('jwt_vp')) {
vpFormat = 'jwt_vp';
} else if (vpFormats.containsKey('jwt_vp_json')) {
vpFormat = 'jwt_vp_json';
} else if (vpFormats.containsKey('vc+sd-jwt')) {
vpFormat = 'vc+sd-jwt';
if (vpFormats.containsKey('ldp_vp')) {
vpFormat = 'ldp_vp';
} else if (vpFormats.containsKey('jwt_vp')) {
vpFormat = 'jwt_vp';
} else if (vpFormats.containsKey('jwt_vp_json')) {
vpFormat = 'jwt_vp_json';
} else if (vpFormats.containsKey('vc+sd-jwt')) {
vpFormat = 'vc+sd-jwt';
}
}
}

final vcFormatType = profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile.vcFormatType;

vcFormat ??= vcFormatType.value;

if (vpFormat == null) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'VC format is missing.',
},
);
}

for (int i = 0; i < credentialsToBePresented.length; i++) {
for (final InputDescriptor inputDescriptor
in presentationDefinition.inputDescriptors) {
Expand Down Expand Up @@ -905,9 +890,8 @@ class ScanCubit extends Cubit<ScanState> {
);

if (presentLdpVc) {

/// proof is done with a creation date 20 seconds in the past to avoid
/// proof check to fail because of time difference on server
/// proof check to fail because of time difference on server
final options = jsonEncode({
'verificationMethod': kid,
'proofPurpose': 'assertionMethod',
Expand Down
2 changes: 1 addition & 1 deletion lib/selective_disclosure/selective_disclosure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SelectiveDisclosure {
}

String? get getPicture {
if (credentialModel.format.toString() != VCFormatType.vcSdJWT.value) {
if (credentialModel.format.toString() != VCFormatType.vcSdJWT.vcValue) {
return null;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/credential_manifest/lib/src/models/filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class Filter {
required this.type,
this.pattern,
this.contains,
this.containsConst,
});
factory Filter.fromJson(Map<String, dynamic> json) => _$FilterFromJson(json);

final String type;
final String? pattern;
final Contains? contains;
@JsonKey(name: 'const')
String? containsConst;

Map<String, dynamic> toJson() => _$FilterToJson(this);
}
Loading

0 comments on commit 164d760

Please sign in to comment.