Skip to content

Commit

Permalink
feat: Use different format for emailpass #3066
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Nov 7, 2024
1 parent 4cbbdac commit 9cf9aed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,17 @@ extension CredentialSubjectTypeExtension on CredentialSubjectType {

final discoverCardsOptions = profileSetting.discoverCardsOptions;

var format = VCFormatType.ldpVc.urlValue;
final isEmailPass = this == CredentialSubjectType.emailPass;

var format = VCFormatType.ldpVc.urlValue(isEmailPass: isEmailPass);

if (vcFormatType == VCFormatType.auto && discoverCardsOptions != null) {
format = discoverCardsOptions.vcFormatTypeForAuto(
credentialSubjectType: this,
vcFormatType: assignedVCFormatType,
);
} else {
format = vcFormatType.urlValue;
format = vcFormatType.urlValue(isEmailPass: isEmailPass);
}

switch (this) {
Expand Down
15 changes: 10 additions & 5 deletions lib/dashboard/profile/models/profile_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,14 @@ class DiscoverCardsOptions extends Equatable {
required CredentialSubjectType credentialSubjectType,
required VCFormatType vcFormatType,
}) {
final ldpVcValue = VCFormatType.ldpVc.urlValue;
final jwtVcJsonValue = VCFormatType.jwtVcJson.urlValue;
final vcSdJWTValue = VCFormatType.vcSdJWT.urlValue;
final isEmailPass =
credentialSubjectType == CredentialSubjectType.emailPass;

final ldpVcValue = VCFormatType.ldpVc.urlValue(isEmailPass: isEmailPass);
final jwtVcJsonValue =
VCFormatType.jwtVcJson.urlValue(isEmailPass: isEmailPass);
final vcSdJWTValue =
VCFormatType.vcSdJWT.urlValue(isEmailPass: isEmailPass);

final isLdpVc = vcFormatType == VCFormatType.ldpVc;
final isJwtVcJson = vcFormatType == VCFormatType.jwtVcJson;
Expand Down Expand Up @@ -416,10 +421,10 @@ class DiscoverCardsOptions extends Equatable {
case CredentialSubjectType.identityCredential:
case CredentialSubjectType.eudiPid:
case CredentialSubjectType.pid:
return VCFormatType.ldpVc.urlValue;
return VCFormatType.ldpVc.urlValue(isEmailPass: isEmailPass);
}

return VCFormatType.ldpVc.urlValue;
return VCFormatType.ldpVc.urlValue(isEmailPass: isEmailPass);
}

@override
Expand Down
9 changes: 7 additions & 2 deletions packages/oidc4vc/lib/src/vc_format_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension VCFormatTypeX on VCFormatType {
}
}

String get urlValue {
String urlValue({required bool isEmailPass}) {
switch (this) {
case VCFormatType.ldpVc:
return 'ldp_vc';
Expand All @@ -44,7 +44,12 @@ extension VCFormatTypeX on VCFormatType {
case VCFormatType.jwtVcJsonLd:
return 'jwt_vc_json-ld';
case VCFormatType.vcSdJWT:
return 'vcsd-jwt';
if (isEmailPass) {
return 'vc_sd_jwt';
} else {
return 'vcsd-jwt';
}

case VCFormatType.auto:
return 'auto';
}
Expand Down
22 changes: 17 additions & 5 deletions packages/oidc4vc/test/src/vc_format_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ void main() {
});

test('urlValue', () {
expect(VCFormatType.ldpVc.urlValue, 'ldp_vc');
expect(VCFormatType.jwtVc.urlValue, 'jwt_vc');
expect(VCFormatType.jwtVcJson.urlValue, 'jwt_vc_json');
expect(VCFormatType.jwtVcJsonLd.urlValue, 'jwt_vc_json-ld');
expect(VCFormatType.vcSdJWT.urlValue, 'vcsd-jwt');
expect(VCFormatType.ldpVc.urlValue(isEmailPass: true), 'ldp_vc');
expect(VCFormatType.ldpVc.urlValue(isEmailPass: false), 'ldp_vc');
expect(VCFormatType.jwtVc.urlValue(isEmailPass: true), 'jwt_vc');
expect(VCFormatType.jwtVc.urlValue(isEmailPass: false), 'jwt_vc');
expect(VCFormatType.jwtVcJson.urlValue(isEmailPass: true), 'jwt_vc_json');
expect(
VCFormatType.jwtVcJson.urlValue(isEmailPass: false), 'jwt_vc_json');
expect(
VCFormatType.jwtVcJsonLd.urlValue(isEmailPass: true),
'jwt_vc_json-ld',
);
expect(
VCFormatType.jwtVcJsonLd.urlValue(isEmailPass: false),
'jwt_vc_json-ld',
);
expect(VCFormatType.vcSdJWT.urlValue(isEmailPass: true), 'vc_sd_jwt');
expect(VCFormatType.vcSdJWT.urlValue(isEmailPass: false), 'vcsd-jwt');
});

test('supportCryptoCredential', () {
Expand Down

0 comments on commit 9cf9aed

Please sign in to comment.