Skip to content

Commit

Permalink
feat: Added credential as array of object #1817 and version update
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Aug 22, 2023
1 parent def4eff commit 65e886e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 25 deletions.
28 changes: 28 additions & 0 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,31 @@ OIDC4VCType? getOIDC4VCTypeForIssuance(String url) {
}
return null;
}

(String, List<String>?, String?) getCredentialData({
required List<dynamic> credentials,
OIDC4VCType? oidc4vcType,
}) {
late String credential;
late List<String> credentialSupported;
late String format;

for (final cred in credentials) {
if (cred is String) {
credential = cred;
if (oidc4vcType != null) {
credentialSupported = oidc4vcType.credentialSupported;
format = oidc4vcType.issuerVcType;
}
} else if (cred is Map<String, dynamic>) {
credentialSupported =
(cred['types'] as List<dynamic>).map((e) => e.toString()).toList();
credential = credentialSupported.last;
format = cred['format'].toString();
} else {
throw Exception();
}
}

return (credential, credentialSupported, format);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,8 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
: () {
if (state.isEmpty) return;

final creds = <dynamic>[];

for (final i in state) {
creds.add(credentials[i]);
}

context.read<QRCodeScanCubit>().addCredentialsInLoop(
credentials: creds,
credentials: credentials,
userPin: userPin,
);
},
Expand All @@ -96,8 +90,12 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
...List.generate(
credentials.length,
(index) {
final (credential, _, _) = getCredentialData(
credentials: credentials,
);

final CredentialSubjectType credentialSubjectType =
getCredTypeFromName(credentials[index].toString()) ??
getCredTypeFromName(credential) ??
CredentialSubjectType.defaultCredential;

final DiscoverDummyCredential discoverDummyCredential =
Expand All @@ -122,7 +120,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
credentialPreview: Credential(
'dummy1',
['dummy2'],
[credentials[index].toString()],
[credential],
'dummy4',
'dummy5',
'',
Expand Down
13 changes: 10 additions & 3 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 @@ -539,9 +539,9 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {

case OIDC4VCType.GAIAX:
case OIDC4VCType.EBSIV2:
case OIDC4VCType.EBSIV3:
break;

case OIDC4VCType.EBSIV3:
case OIDC4VCType.JWTVC:
throw Exception();
}
Expand Down Expand Up @@ -805,18 +805,25 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {

for (int i = 0; i < credentials.length; i++) {
emit(state.loading());
final credentialType = credentials[i];

final (credential, credentialSupported, format) = getCredentialData(
credentials: credentials,
oidc4vcType: currentOIIDC4VCTypeForIssuance,
);

await getAndAddCredential(
scannedResponse: state.uri.toString(),
credentialsCubit: credentialsCubit,
oidc4vc: oidc4vc,
oidc4vcType: currentOIIDC4VCTypeForIssuance,
didKitProvider: didKitProvider,
secureStorageProvider: getSecureStorage,
credentialType: credentialType.toString(),
credentialType: credential,
isLastCall: i + 1 == credentials.length,
dioClient: DioClient('', Dio()),
userPin: userPin,
credentialSupported: credentialSupported!,
format: format!,
);
}
oidc4vc.resetNonceAndAccessToken();
Expand Down
24 changes: 14 additions & 10 deletions lib/oidc4vc/initiate_oidv4vc_credential_issuance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,31 @@ Future<void> initiateOIDC4VCCredentialIssuance({
}) async {
final Uri uriFromScannedResponse = Uri.parse(scannedResponse);

late dynamic credentialType;
late dynamic credentials;

switch (oidc4vcType) {
case OIDC4VCType.DEFAULT:
case OIDC4VCType.HEDERA:
case OIDC4VCType.EBSIV3:
final dynamic credentialOfferJson = await getCredentialOfferJson(
scannedResponse: scannedResponse,
dioClient: dioClient,
);
if (credentialOfferJson == null) throw Exception();

credentialType = credentialOfferJson['credentials'];
credentials = credentialOfferJson['credentials'];

case OIDC4VCType.GAIAX:
case OIDC4VCType.EBSIV2:
credentialType =
uriFromScannedResponse.queryParameters['credential_type'];
credentials = uriFromScannedResponse.queryParameters['credential_type'];

case OIDC4VCType.EBSIV3:
case OIDC4VCType.JWTVC:
break;
}

if (credentialType is List<dynamic>) {
if (credentials is List<dynamic>) {
qrCodeScanCubit.navigateToOidc4vcCredentialPickPage(
credentials: credentialType,
credentials: credentials,
userPin: userPin,
);
} else {
Expand All @@ -57,11 +56,13 @@ Future<void> initiateOIDC4VCCredentialIssuance({
oidc4vc: oidc4vc,
didKitProvider: didKitProvider,
credentialsCubit: credentialsCubit,
credentialType: credentialType.toString(),
credentialType: credentials.toString(),
secureStorageProvider: secureStorageProvider,
isLastCall: true,
dioClient: dioClient,
userPin: userPin,
credentialSupported: oidc4vcType.credentialSupported,
format: oidc4vcType.issuerVcType,
);
oidc4vc.resetNonceAndAccessToken();
qrCodeScanCubit.goBack();
Expand All @@ -79,6 +80,8 @@ Future<void> getAndAddCredential({
required bool isLastCall,
required DioClient dioClient,
required String? userPin,
required List<String> credentialSupported,
required String format,
}) async {
final Uri uriFromScannedResponse = Uri.parse(scannedResponse);

Expand All @@ -88,6 +91,7 @@ Future<void> getAndAddCredential({
switch (oidc4vcType) {
case OIDC4VCType.DEFAULT:
case OIDC4VCType.HEDERA:
case OIDC4VCType.EBSIV3:
final dynamic credentialOfferJson = await getCredentialOfferJson(
scannedResponse: scannedResponse,
dioClient: dioClient,
Expand All @@ -106,7 +110,6 @@ Future<void> getAndAddCredential({
preAuthorizedCode =
uriFromScannedResponse.queryParameters['pre-authorized_code'];

case OIDC4VCType.EBSIV3:
case OIDC4VCType.JWTVC:
throw Exception();
}
Expand Down Expand Up @@ -134,9 +137,10 @@ Future<void> getAndAddCredential({
kid: kid,
credentialRequestUri: uriFromScannedResponse,
privateKey: privateKey,
credentialSupportedTypes: oidc4vcType.credentialSupported,
credentialSupportedTypes: credentialSupported,
indexValue: oidc4vcType.indexValue,
userPin: userPin,
format: format,
);

await addOIDC4VCCredential(
Expand Down
2 changes: 1 addition & 1 deletion lib/splash/bloclisteners/blocklisteners.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ final qrCodeBlocListener = BlocListener<QRCodeScanCubit, QRCodeScanState>(
switch (currentOIIDC4VCTypeForIssuance) {
case OIDC4VCType.DEFAULT:
case OIDC4VCType.HEDERA:
case OIDC4VCType.EBSIV3:
final dynamic credentialOfferJson =
await getCredentialOfferJson(
scannedResponse: state.uri!.toString(),
Expand All @@ -282,7 +283,6 @@ final qrCodeBlocListener = BlocListener<QRCodeScanCubit, QRCodeScanState>(
case OIDC4VCType.EBSIV2:
subtitle = state.uri!.queryParameters['issuer'].toString();

case OIDC4VCType.EBSIV3:
case OIDC4VCType.JWTVC:
throw Exception();
}
Expand Down
5 changes: 4 additions & 1 deletion packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class OIDC4VC {
required String kid,
required Uri credentialRequestUri,
required List<String> credentialSupportedTypes,
required String format,
required int indexValue,
String? preAuthorizedCode,
String? mnemonic,
Expand Down Expand Up @@ -246,6 +247,7 @@ class OIDC4VC {
openidConfigurationResponse: openidConfigurationResponse,
credentialType: credentialType,
credentialSupportedTypes: credentialSupportedTypes,
format: format,
);

/// sign proof
Expand Down Expand Up @@ -420,6 +422,7 @@ class OIDC4VC {
required Response<Map<String, dynamic>> openidConfigurationResponse,
required String credentialType,
required List<String> credentialSupportedTypes,
required String format,
}) async {
final vcJwt = await getIssuerJwt(issuerTokenParameters, nonce);

Expand All @@ -438,7 +441,7 @@ class OIDC4VC {
final credentialData = <String, dynamic>{
'type': credentialType,
'types': credentialSupportedTypes,
'format': oidc4vcModel.issuerVcType,
'format': format,
'proof': {
'proof_type': 'jwt',
'jwt': vcJwt,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: altme
description: AltMe Flutter App
version: 1.20.2+249
version: 1.20.3+250
publish_to: none

environment:
Expand Down

0 comments on commit 65e886e

Please sign in to comment.