Skip to content

Commit

Permalink
feat: verify with biometrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-hades committed Jan 9, 2025
1 parent b1060be commit bea30e4
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 717 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class CreateLocalCredsNotifier extends _$CreateLocalCredsNotifier {
state = await AsyncValue.guard(() async {
final ionIdentity = await ref.read(ionIdentityClientProvider.future);
await ionIdentity.auth.createNewCredentials(
({required onPasskeyFlow, required onPasswordFlow}) => onPasskeyFlow(),
({required onPasskeyFlow, required onPasswordFlow, required onBiometricsFlow}) =>
onPasskeyFlow(),
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ class TwoFAInputStep extends HookConsumerWidget {
.requestRecoveryTwoFaCode(twoFaType, recoveryIdentityKeyName, ({
required OnPasswordFlow<GenerateSignatureResponse> onPasswordFlow,
required OnPasskeyFlow<GenerateSignatureResponse> onPasskeyFlow,
required OnBiometricsFlow<GenerateSignatureResponse>
onBiometricsFlow,
}) {
return ref.read(
verifyUserIdentityProvider(
onGetPassword: onGetPassword,
onPasswordFlow: onPasswordFlow,
onPasskeyFlow: onPasskeyFlow,
onBiometricsFlow: onBiometricsFlow,
localisedReasonForBiometricsDialog:
context.i18n.verify_with_biometrics_title,
).future,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/components/verify_identity/hooks/use_on_get_password.dart';
import 'package:ion/app/features/components/verify_identity/verify_identity_prompt_dialog.dart';
import 'package:ion/app/features/user/providers/user_verify_identity_provider.c.dart';
Expand Down Expand Up @@ -46,12 +47,15 @@ class RiverpodVerifyIdentityRequestBuilder<T, P> extends HookConsumerWidget {
requestWithVerifyIdentity(({
required OnPasswordFlow<P> onPasswordFlow,
required OnPasskeyFlow<P> onPasskeyFlow,
required OnBiometricsFlow<P> onBiometricsFlow,
}) {
return ref.read(
verifyUserIdentityProvider(
onGetPassword: onGetPassword,
onPasswordFlow: onPasswordFlow,
onPasskeyFlow: onPasskeyFlow,
onBiometricsFlow: onBiometricsFlow,
localisedReasonForBiometricsDialog: context.i18n.verify_with_biometrics_title,
).future,
);
});
Expand Down Expand Up @@ -81,13 +85,16 @@ class HookVerifyIdentityRequestBuilder<P> extends HookConsumerWidget {
requestWithVerifyIdentity(({
required OnPasswordFlow<P> onPasswordFlow,
required OnPasskeyFlow<P> onPasskeyFlow,
required OnBiometricsFlow<P> onBiometricsFlow,
}) async {
try {
return await ref.read(
verifyUserIdentityProvider(
onGetPassword: onGetPassword,
onPasswordFlow: onPasswordFlow,
onPasskeyFlow: onPasskeyFlow,
onBiometricsFlow: onBiometricsFlow,
localisedReasonForBiometricsDialog: context.i18n.verify_with_biometrics_title,
).future,
);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ class UserDelegationManager extends _$UserDelegationManager {
.wallets
.generateHashSignatureWithPasskey(mainWallet.id, eventId);
},
onBiometricsFlow: ({required String localisedReason}) {
return ionIdentity(username: currentIdentityKeyName)
.wallets
.generateHashSignatureWithBiometrics(mainWallet.id, eventId, localisedReason);
},
);

final curveName = switch (mainWallet.signingKey.curve) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ AutoDisposeFutureProvider<T> verifyUserIdentityProvider<T>({
required Future<String?> Function() onGetPassword,
required OnPasswordFlow<T> onPasswordFlow,
required OnPasskeyFlow<T> onPasskeyFlow,
required OnBiometricsFlow<T> onBiometricsFlow,
required String localisedReasonForBiometricsDialog,
}) {
return FutureProvider.autoDispose<T>((ref) async {
final username = ref.read(currentIdentityKeyNameSelectorProvider)!;
final ionIdentity = await ref.read(ionIdentityProvider.future);
final isPasswordFlowUser = ionIdentity(username: username).auth.isPasswordFlowUser();
final biometricsState = ionIdentity(username: username).auth.getBiometricsState();

if (isPasswordFlowUser) {
if (biometricsState == BiometricsState.enabled) {
try {
return await onBiometricsFlow(localisedReason: localisedReasonForBiometricsDialog);
// If biometrics flow fails then fallback to password flow
} catch (_) {}
}
final password = await onGetPassword();
if (password != null) {
return onPasswordFlow(password: password);
Expand Down
Loading

0 comments on commit bea30e4

Please sign in to comment.