Skip to content

Commit

Permalink
Sd jwt : if there is no cnf in the sd jwt payload
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Sep 12, 2024
1 parent 74b69f6 commit 74a58b3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,24 @@ class SelectiveDisclosureCubit extends Cubit<SelectiveDisclosureState> {
);
}

if (index == null || index == -1) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'Issue with the dislosure of jwt.',
},
);
}

final bool isSelected = state.selectedSDIndexInJWT.contains(index);

late List<int> selected;

if (isSelected) {
/// deSelecting the credential
selected = List<int>.from(state.selectedSDIndexInJWT)
..removeWhere((element) => element == index);
} else {
/// selecting the credential
selected = [
...state.selectedSDIndexInJWT,
...[index],
];
if (!(index == null || index == -1)) {
final bool isSelected = state.selectedSDIndexInJWT.contains(index);

late List<int> selected;

if (isSelected) {
/// deSelecting the credential
selected = List<int>.from(state.selectedSDIndexInJWT)
..removeWhere((element) => element == index);
} else {
/// selecting the credential
selected = [
...state.selectedSDIndexInJWT,
...[index],
];
}
emit(state.copyWith(selectedSDIndexInJWT: selected));
}
emit(state.copyWith(selectedSDIndexInJWT: selected));
}

void disclosureAction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,17 @@ class _SelectiveDisclosurePickViewState
'sd_hash': sdHash,
};

/// sign and get token
final jwtToken = profileCubit.oidc4vc.generateToken(
payload: payload,
tokenParameters: tokenParameters,
ignoreProofHeaderType: true,
);

newJwt = '$newJwt$jwtToken';
// If there no cnf in the payload, then no need to add signature
if (payload['cnf'] != null) {
/// sign and get token
final jwtToken = profileCubit.oidc4vc.generateToken(
payload: payload,
tokenParameters: tokenParameters,
ignoreProofHeaderType: true,
);

newJwt = '$newJwt$jwtToken';
}

final CredentialModel newModel = widget.credentialToBePresented
.copyWith(selectiveDisclosureJwt: newJwt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,16 @@ class SelectiveDisclosureDisplayMap {
} else {
final isCompulsary = limitDisclosure == 'required';

final bool isDisabled = isCompulsary;
if (!isDisabled && isPresentation && parentKeyId != null) {}
bool isDisabled = isCompulsary;
final index = SelectiveDisclosure(credentialModel)
.disclosureListToContent
.entries
.toList()
.indexWhere(
(entry) => entry.value.toString().contains(element.key.toString()),
);
if (index == -1) isDisabled = true;
// if (!isDisabled && isPresentation && parentKeyId != null) {}
builtMap[element.key.toString()] = {
'mapKey': element.key.toString(),
'claimKey': element.key.toString(),
Expand Down Expand Up @@ -266,6 +274,15 @@ class SelectiveDisclosureDisplayMap {
});
}
}
final indexInDisclosure = SelectiveDisclosure(credentialModel)
.disclosureListToContent
.entries
.toList()
.indexWhere(
(entry) => entry.value.toString().contains(claimKey),
);
if (indexInDisclosure == -1) isDisabled = true;

if (!(isDisabled && isPresentation)) {
final listElement = {
'mapKey': mapKey,
Expand Down

0 comments on commit 74a58b3

Please sign in to comment.