Skip to content

Commit

Permalink
feat: Presentation for test12 HAIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Mar 13, 2024
1 parent 6e01f73 commit 8c11a61
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1449,14 +1449,21 @@ Future<(String?, String?, String?, String?)> getClientDetails({

case ClientAuthentication.clientSecretJwt:
if (profileCubit.state.model.walletType != WalletType.enterprise) {
throw Exception();
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'Please switch to enterprise account',
},
);
}

final walletAttestationData = await profileCubit.secureStorageProvider
.get(SecureStorageKeys.walletAttestationData);

if (walletAttestationData == null) {
throw Exception();
}

final iat = (DateTime.now().millisecondsSinceEpoch / 1000).round();
final nbf = iat - 10;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:altme/dashboard/home/tab_bar/credentials/credential.dart';
import 'package:credential_manifest/credential_manifest.dart';

List<CredentialModel> getCredentialsFromFilterList({
List<CredentialModel> getCredentialsFromFilterList({
required List<Field> filterList,
required List<CredentialModel> credentialList,
}) {
Expand Down
18 changes: 16 additions & 2 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,14 @@ class ScanCubit extends Cubit<ScanState> {

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

if (ldpVp) {
vpFormat = 'ldp_vp';
} else if (jwtVp) {
vpFormat = 'jwt_vp';
} else if (vcSdJwt) {
vpFormat = 'vc+sd-jwt';
}
} else {
if (clientMetaData == null) {
Expand All @@ -692,6 +695,8 @@ class ScanCubit extends Cubit<ScanState> {
vpFormat = 'ldp_vp';
} else if (vpFormats.containsKey('jwt_vp')) {
vpFormat = 'jwt_vp';
} else if (vpFormats.containsKey('vc+sd-jwt')) {
vpFormat = 'vc+sd-jwt';
}
}

Expand Down Expand Up @@ -807,13 +812,17 @@ class ScanCubit extends Cubit<ScanState> {

bool presentLdpVc = false;
bool presentJwtVc = false;
bool presentVcSdJwt = false;

if (presentationDefinition.format != null) {
/// ldp_vc
presentLdpVc = presentationDefinition.format?.ldpVc != null;

/// jwt_vc
presentJwtVc = presentationDefinition.format?.jwtVc != null;

/// vc+sd-jwt
presentVcSdJwt = presentationDefinition.format?.vcSdJwt != null;
} else {
if (clientMetaData == null) {
throw ResponseMessage(
Expand All @@ -831,6 +840,9 @@ class ScanCubit extends Cubit<ScanState> {

/// jwt_vc
presentJwtVc = vpFormats.containsKey('jwt_vc');

/// vc+sd-jwt
presentVcSdJwt = vpFormats.containsKey('vc+sd-jwt');
}

final customOidc4vcProfile =
Expand All @@ -842,9 +854,11 @@ class ScanCubit extends Cubit<ScanState> {
presentLdpVc = true;
} else if (!presentJwtVc && vcFormatType == VCFormatType.jwtVc) {
presentJwtVc = true;
} else if (!presentJwtVc && vcFormatType == VCFormatType.vcSdJWT) {
presentVcSdJwt = true;
}

if (!presentLdpVc && !presentJwtVc) {
if (!presentLdpVc && !presentJwtVc && !presentVcSdJwt) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
Expand Down Expand Up @@ -875,7 +889,7 @@ class ScanCubit extends Cubit<ScanState> {
privateKey,
);
return vpToken;
} else if (presentJwtVc) {
} else if (presentJwtVc || presentVcSdJwt) {
final credentialList =
credentialsToBePresented.map((e) => jsonEncode(e.toJson())).toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ List<String> getTextsFromCredential(
) {
final textList = <String>[];
try {
final fieldsPath = JsonPath(jsonPath.replaceAll('.vc', ''));
final fieldsPath = JsonPath(jsonPath.replaceAll(RegExp(r'\.vc(?=\.)'), ''));
fieldsPath.read(data).forEach((a) {
final dynamic value = a.value;
if (value is String) {
Expand Down
3 changes: 3 additions & 0 deletions packages/credential_manifest/lib/src/models/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Format {
this.jwtVc,
this.ldpVp,
this.ldpVc,
this.vcSdJwt,
});

factory Format.fromJson(Map<String, dynamic> json) => _$FormatFromJson(json);
Expand All @@ -22,6 +23,8 @@ class Format {
FormatType? ldpVp;
@JsonKey(name: 'ldp_vc')
FormatType? ldpVc;
@JsonKey(name: 'vc+sd-jwt')
FormatType? vcSdJwt;

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

0 comments on commit 8c11a61

Please sign in to comment.