Skip to content

Commit

Permalink
feat: Wallet suspension update #2582
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Apr 15, 2024
1 parent a06010d commit 476f2a2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/dashboard/src/view/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _DashboardViewState extends State<DashboardView> {
if (context.read<ProfileCubit>().state.model.profileType ==
ProfileType.enterprise) {
unawaited(
context.read<EnterpriseCubit>().getWalletAttestationStatus(),
context.read<EnterpriseCubit>().getWalletAttestationBitStatus(),
);
}
});
Expand Down
72 changes: 56 additions & 16 deletions lib/enterprise/cubit/enterprise_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,9 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
'accept': 'application/statuslist+jwt',
};

final customOidc4vcProfile = profileCubit.state.model.profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile;

final response = await client.get(
uri,
headers: headers,
isCachingEnabled: customOidc4vcProfile.statusListCache,
);

final payload = profileCubit.jwtDecode.parseJwt(response.toString());
Expand Down Expand Up @@ -367,22 +363,66 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
return jwtVc;
}

Future<void> getWalletAttestationStatus() async {
Future<void> getWalletAttestationBitStatus() async {
try {
final provider = await profileCubit.secureStorageProvider.get(
SecureStorageKeys.enterpriseWalletProvider,
final walletAttestationData =
await profileCubit.secureStorageProvider.get(
SecureStorageKeys.walletAttestationData,
);

if (provider == null) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'The wallet is not configured yet.',
},
);
}
final jwtVc = walletAttestationData.toString();

final payload = profileCubit.jwtDecode.parseJwt(jwtVc);
final status = payload['status'];

await getWalletAttestationData(provider);
if (status != null && status is Map<String, dynamic>) {
final statusList = status['status_list'];
if (statusList != null && statusList is Map<String, dynamic>) {
final uri = statusList['uri'];
final idx = statusList['idx'];

if (idx != null && idx is int && uri != null && uri is String) {
final headers = {
'Content-Type': 'application/json; charset=UTF-8',
'accept': 'application/statuslist+jwt',
};

final response = await client.get(
uri,
headers: headers,
);

final payload =
profileCubit.jwtDecode.parseJwt(response.toString());

final newStatusList = payload['status_list'];
if (newStatusList != null &&
newStatusList is Map<String, dynamic>) {
final lst = newStatusList['lst'].toString();

final bytes = profileCubit.oidc4vc.getByte(idx);

// '$idx = $bytes X 8 + $posOfBit'
final decompressedBytes =
profileCubit.oidc4vc.decodeAndZlibDecompress(lst);
final byteToCheck = decompressedBytes[bytes];

final posOfBit = profileCubit.oidc4vc.getPositionOfZlibBit(idx);
final bit = profileCubit.oidc4vc
.getBit(byte: byteToCheck, bitPosition: posOfBit);

if (bit == 0) {
// active
} else {
// revoked
throw ResponseMessage(
message: ResponseString.RESPONSE_STRING_theWalletIsSuspended,
);
}
}
}
}
}
} catch (e) {
emitError(e);
}
Expand Down

0 comments on commit 476f2a2

Please sign in to comment.