Skip to content

Commit

Permalink
feat: Added pin code page for issunace of hedera
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Aug 19, 2023
1 parent 98b06b9 commit c4774f5
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export 'search/search.dart';
export 'select_network_fee_bottom_sheet/select_network_fee_bottom_sheet.dart';
export 'self_issued_credential_button/self_issued_credential_button.dart';
export 'src/src.dart';
export 'user_pin/user_pin.dart';
export 'wert/wert.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
const Oidc4vcCredentialPickPage({
super.key,
required this.credentials,
required this.userPin,
});

final List<dynamic> credentials;
final String? userPin;

static Route<dynamic> route({
required List<dynamic> credentials,
required String? userPin,
}) =>
MaterialPageRoute<void>(
builder: (context) => Oidc4vcCredentialPickPage(
credentials: credentials,
userPin: userPin,
),
settings: const RouteSettings(name: '/Oidc4vcCredentialPickPage'),
);
Expand All @@ -26,7 +30,10 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => Oidc4vcCredentialPickCubit(),
child: Oidc4vcCredentialPickView(credentials: credentials),
child: Oidc4vcCredentialPickView(
credentials: credentials,
userPin: userPin,
),
);
}
}
Expand All @@ -35,9 +42,11 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
const Oidc4vcCredentialPickView({
super.key,
required this.credentials,
required this.userPin,
});

final List<dynamic> credentials;
final String? userPin;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -73,9 +82,10 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
creds.add(credentials[i]);
}

context
.read<QRCodeScanCubit>()
.addCredentialsInLoop(creds);
context.read<QRCodeScanCubit>().addCredentialsInLoop(
credentials: creds,
userPin: userPin,
);
},
text: l10n.proceed,
),
Expand Down
98 changes: 90 additions & 8 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 @@ -242,6 +242,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
return;
}
}
} else {
emit(state.acceptHost(isRequestVerified: true));
}
} catch (e) {
log.e(e);
Expand Down Expand Up @@ -281,19 +283,17 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
if (oidc4vcType.isEnabled &&
state.uri.toString().startsWith(oidc4vcType.offerPrefix)) {
currentOIIDC4VCType = oidc4vcType;
break;
}
}

if (currentOIIDC4VCType != null) {
/// issuer side (oidc4VCI)
await initiateOIDC4VCCredentialIssuance(
await startOIDC4VCCredentialIssuance(
scannedResponse: state.uri.toString(),
credentialsCubit: credentialsCubit,
oidc4vcType: currentOIIDC4VCType,
didKitProvider: didKitProvider,
currentOIIDC4VCType: currentOIIDC4VCType,
qrCodeScanCubit: qrCodeScanCubit,
secureStorageProvider: getSecureStorage,
dioClient: dioClient,
);
return;
Expand Down Expand Up @@ -499,6 +499,77 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}
}

Future<void> startOIDC4VCCredentialIssuance({
required String scannedResponse,
required OIDC4VCType currentOIIDC4VCType,
required QRCodeScanCubit qrCodeScanCubit,
required DioClient dioClient,
}) async {
switch (currentOIIDC4VCType) {
case OIDC4VCType.DEFAULT:
case OIDC4VCType.HEDERA:
final dynamic credentialOfferJson = await getCredentialOfferJson(
scannedResponse: scannedResponse,
dioClient: dioClient,
);
if (credentialOfferJson == null) break;

final dynamic userPinRequired = credentialOfferJson['grants']
['urn:ietf:params:oauth:grant-type:pre-authorized_code']
['user_pin_required'];

if (userPinRequired == null) break;

if (userPinRequired is bool && userPinRequired) {
emit(
state.copyWith(
qrScanStatus: QrScanStatus.success,
route: UserPinPage.route(
onCancel: () {
goBack();
},
onProceed: (String userPin) async {
await initiateOIDC4VCCredentialIssuance(
scannedResponse: scannedResponse,
credentialsCubit: credentialsCubit,
oidc4vcType: currentOIIDC4VCType,
didKitProvider: didKitProvider,
qrCodeScanCubit: qrCodeScanCubit,
secureStorageProvider: getSecureStorage,
dioClient: dioClient,
userPin: userPin,
);
},
),
),
);
} else {
break;
}

return;

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

case OIDC4VCType.EBSIV3:
case OIDC4VCType.JWTVC:
throw Exception();
}

await initiateOIDC4VCCredentialIssuance(
scannedResponse: scannedResponse,
credentialsCubit: credentialsCubit,
oidc4vcType: currentOIIDC4VCType,
didKitProvider: didKitProvider,
qrCodeScanCubit: qrCodeScanCubit,
secureStorageProvider: getSecureStorage,
dioClient: dioClient,
userPin: null,
);
}

Future<bool> isVCPresentable(
PresentationDefinition? presentationDefinition,
) async {
Expand Down Expand Up @@ -527,11 +598,17 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
return true;
}

void navigateToOidc4vcCredentialPickPage(List<dynamic> credentials) {
void navigateToOidc4vcCredentialPickPage({
required List<dynamic> credentials,
required String? userPin,
}) {
emit(
state.copyWith(
qrScanStatus: QrScanStatus.success,
route: Oidc4vcCredentialPickPage.route(credentials: credentials),
route: Oidc4vcCredentialPickPage.route(
credentials: credentials,
userPin: userPin,
),
),
);
}
Expand Down Expand Up @@ -727,13 +804,17 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}
}

Future<void> addCredentialsInLoop(List<dynamic> credentials) async {
Future<void> addCredentialsInLoop({
required List<dynamic> credentials,
required String? userPin,
}) async {
try {
OIDC4VCType? currentOIIDC4VCType;
for (final oidc4vcType in OIDC4VCType.values) {
if (oidc4vcType.isEnabled &&
state.uri.toString().startsWith(oidc4vcType.offerPrefix)) {
currentOIIDC4VCType = oidc4vcType;
break;
}
}

Expand All @@ -753,6 +834,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
credentialType: credentialType.toString(),
isLastCall: i + 1 == credentials.length,
dioClient: DioClient('', Dio()),
userPin: userPin,
);
}
oidc4vc.resetNonceAndAccessToken();
Expand Down
1 change: 1 addition & 0 deletions lib/dashboard/user_pin/user_pin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'view/user_pin_page.dart';
Loading

0 comments on commit c4774f5

Please sign in to comment.