CWA-164 | added biometric authentication

Oleksandr Sobol committed Jan 21, 2020 at 19:51 UTC 71bdfb3e5bfaeb4033281a9485e296c48f33a4cc
19 files changed +116 -13
android/app/src/main/AndroidManifest.xml
+1
@@ -7,6 +7,7 @@
7 FlutterApplication and put your custom class here. -->
8
9 <uses-permission android:name="android.permission.INTERNET"/>
10 + <uses-permission android:name="android.permission.USE_FINGERPRINT"/>
11
12 <application
13 android:name="io.flutter.app.FlutterApplication"
android/app/src/main/java/com/cakewallet/cake_wallet/MainActivity.java
+2 -2
@@ -1,10 +1,10 @@
1 package com.cakewallet.cake_wallet;
2
3 import android.os.Bundle;
4 -import io.flutter.app.FlutterActivity;
4 +import io.flutter.app.FlutterFragmentActivity;
5 import io.flutter.plugins.GeneratedPluginRegistrant;
6
7 -public class MainActivity extends FlutterActivity {
7 +public class MainActivity extends FlutterFragmentActivity {
8 @Override
9 protected void onCreate(Bundle savedInstanceState) {
10 super.onCreate(savedInstanceState);
lib/generated/i18n.dart
+21
@@ -38,6 +38,7 @@ class S implements WidgetsLocalizations {
38 String get authenticated => "Authenticated";
39 String get authentication => "Authentication";
40 String get available_balance => "Available Balance";
41 + String get biometric_auth_reason => "Scan your fingerprint to authenticate";
42 String get cancel => "Cancel";
43 String get change => "Change";
44 String get change_currency => "Change Currency";
@@ -315,6 +316,8 @@ class $de extends S {
316 @override
317 String get hidden_balance => "Verstecktes Gleichgewicht";
318 @override
319 + String get biometric_auth_reason => "Scannen Sie Ihren Fingerabdruck zur Authentifizierung";
320 + @override
321 String get transaction_sent => "Transaktion gesendet!";
322 @override
323 String get password => "Passwort";
@@ -861,6 +864,8 @@ class $hi extends S {
864 @override
865 String get hidden_balance => "छिपा हुआ संतुलन";
866 @override
867 + String get biometric_auth_reason => "प्रमाणित करने के लिए अपने फ़िंगरप्रिंट को स्कैन करें";
868 + @override
869 String get transaction_sent => "भेजा गया लेन-देन";
870 @override
871 String get password => "पारण शब्द";
@@ -1407,6 +1412,8 @@ class $ru extends S {
1412 @override
1413 String get hidden_balance => "Скрытый баланс";
1414 @override
1415 + String get biometric_auth_reason => "Отсканируйте свой отпечаток пальца для аутентификации";
1416 + @override
1417 String get transaction_sent => "Tранзакция отправлена!";
1418 @override
1419 String get password => "Password";
@@ -1953,6 +1960,8 @@ class $ko extends S {
1960 @override
1961 String get hidden_balance => "숨겨진 균형";
1962 @override
1963 + String get biometric_auth_reason => "지문을 스캔하여 인증";
1964 + @override
1965 String get transaction_sent => "거래가 전송되었습니다!";
1966 @override
1967 String get password => "암호";
@@ -2499,6 +2508,8 @@ class $pt extends S {
2508 @override
2509 String get hidden_balance => "Saldo escondido";
2510 @override
2511 + String get biometric_auth_reason => "Digitalize sua impressão digital para autenticar";
2512 + @override
2513 String get transaction_sent => "Transação enviada!";
2514 @override
2515 String get password => "Senha";
@@ -3045,6 +3056,8 @@ class $ja extends S {
3056 @override
3057 String get hidden_balance => "隠れたバランス";
3058 @override
3059 + String get biometric_auth_reason => "प指紋をスキャンして認証する";
3060 + @override
3061 String get transaction_sent => "トランザクションが送信されました!";
3062 @override
3063 String get password => "パスワード";
@@ -3595,6 +3608,8 @@ class $pl extends S {
3608 @override
3609 String get hidden_balance => "Ukryta równowaga";
3610 @override
3611 + String get biometric_auth_reason => "Zeskanuj swój odcisk palca, aby go uwierzytelnić";
3612 + @override
3613 String get transaction_sent => "Transakcja wysłana!";
3614 @override
3615 String get password => "Hasło";
@@ -4141,6 +4156,8 @@ class $es extends S {
4156 @override
4157 String get hidden_balance => "Balance oculto";
4158 @override
4159 + String get biometric_auth_reason => "Escanee su huella digital para autenticar";
4160 + @override
4161 String get transaction_sent => "Transacción enviada!";
4162 @override
4163 String get password => "Contraseña";
@@ -4687,6 +4704,8 @@ class $nl extends S {
4704 @override
4705 String get hidden_balance => "Verborgen balans";
4706 @override
4707 + String get biometric_auth_reason => "Scan uw vingerafdruk om te verifiëren";
4708 + @override
4709 String get transaction_sent => "Transactie verzonden!";
4710 @override
4711 String get password => "Wachtwoord";
@@ -5233,6 +5252,8 @@ class $zh extends S {
5252 @override
5253 String get hidden_balance => "隐藏余额";
5254 @override
5255 + String get biometric_auth_reason => "掃描指紋以進行身份驗證";
5256 + @override
5257 String get transaction_sent => "交易已发送";
5258 @override
5259 String get password => "密码";
lib/src/domain/common/biometric_auth.dart new
+24
@@ -0,0 +1,24 @@
1 +import 'package:local_auth/local_auth.dart';
2 +import 'package:flutter/services.dart';
3 +import 'package:cake_wallet/generated/i18n.dart';
4 +
5 +class BiometricAuth {
6 +
7 + Future<bool> isAuthenticated() async {
8 + final LocalAuthentication _localAuth = LocalAuthentication();
9 +
10 + try {
11 + return await _localAuth.authenticateWithBiometrics(
12 + localizedReason: S.current.biometric_auth_reason,
13 + useErrorDialogs: true,
14 + stickyAuth: false
15 + );
16 + } on PlatformException
17 + catch(e) {
18 + print(e);
19 + }
20 +
21 + return false;
22 + }
23 +
24 +}
\ No newline at end of file
lib/src/screens/auth/auth_page.dart
+22
@@ -6,6 +6,8 @@ import 'package:cake_wallet/generated/i18n.dart';
6 import 'package:cake_wallet/src/stores/auth/auth_state.dart';
7 import 'package:cake_wallet/src/stores/auth/auth_store.dart';
8 import 'package:cake_wallet/src/screens/pin_code/pin_code.dart';
9 +import 'package:cake_wallet/src/stores/settings/settings_store.dart';
10 +import 'package:cake_wallet/src/domain/common/biometric_auth.dart';
11
12 typedef OnAuthenticationFinished = void Function(bool, AuthPageState);
13
@@ -33,6 +35,26 @@ class AuthPageState extends State<AuthPage> {
35 @override
36 Widget build(BuildContext context) {
37 final authStore = Provider.of<AuthStore>(context);
38 + final settingsStore = Provider.of<SettingsStore>(context);
39 +
40 + if (settingsStore.allowBiometricalAuthentication) {
41 + WidgetsBinding.instance.addPostFrameCallback((_) {
42 + final biometricAuth = BiometricAuth();
43 + biometricAuth.isAuthenticated().then(
44 + (isAuth) {
45 + if (isAuth) {
46 + authStore.biometricAuth();
47 + _key.currentState.showSnackBar(
48 + SnackBar(
49 + content: Text(S.of(context).authenticated),
50 + backgroundColor: Colors.green,
51 + ),
52 + );
53 + }
54 + }
55 + );
56 + });
57 + }
58
59 reaction((_) => authStore.state, (AuthState state) {
60 if (state is AuthenticatedSuccessfully) {
lib/src/stores/auth/auth_store.dart
+5
@@ -91,4 +91,9 @@ abstract class AuthStoreBase with Store {
91
92 return Duration(milliseconds: timeout);
93 }
94 +
95 + @action
96 + void biometricAuth() {
97 + state = AuthenticatedSuccessfully();
98 + }
99 }
pubspec.lock
+7
@@ -406,6 +406,13 @@ packages:
406 url: "https://pub.dartlang.org"
407 source: hosted
408 version: "0.3.19"
409 + local_auth:
410 + dependency: "direct main"
411 + description:
412 + name: local_auth
413 + url: "https://pub.dartlang.org"
414 + source: hosted
415 + version: "0.6.1"
416 logging:
417 dependency: transitive
418 description:
pubspec.yaml
+1
@@ -45,6 +45,7 @@ dependencies:
45 path: ./cw_monero
46 hive: ^1.2.0
47 hive_flutter: ^0.2.1
48 + local_auth: ^0.6.1
49
50 # The following adds the Cupertino Icons font to your application.
51 # Use with the CupertinoIcons class for iOS style icons.
res/values/strings_de.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "Einfügen",
337 "restore_from_seed_placeholder" : "Bitte geben Sie hier Ihren Code ein",
338 "add_new_word" : "Neues Wort hinzufügen",
339 - "incorrect_seed" : "Der eingegebene Text ist ungültig."
339 + "incorrect_seed" : "Der eingegebene Text ist ungültig.",
340 +
341 + "biometric_auth_reason" : "Scannen Sie Ihren Fingerabdruck zur Authentifizierung"
342 }
\ No newline at end of file
res/values/strings_en.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "Paste",
337 "restore_from_seed_placeholder" : "Please enter or paste your seed here",
338 "add_new_word" : "Add new word",
339 - "incorrect_seed" : "The text entered is not valid."
339 + "incorrect_seed" : "The text entered is not valid.",
340 +
341 + "biometric_auth_reason" : "Scan your fingerprint to authenticate"
342 }
\ No newline at end of file
res/values/strings_es.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "Pegar",
337 "restore_from_seed_placeholder" : "Ingrese o pegue su frase de código aquí",
338 "add_new_word" : "Agregar palabra nueva",
339 - "incorrect_seed" : "El texto ingresado no es válido."
339 + "incorrect_seed" : "El texto ingresado no es válido.",
340 +
341 + "biometric_auth_reason" : "Escanee su huella digital para autenticar"
342 }
\ No newline at end of file
res/values/strings_hi.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "पेस्ट करें",
337 "restore_from_seed_placeholder" : "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें",
338 "add_new_word" : "नया शब्द जोड़ें",
339 - "incorrect_seed" : "दर्ज किया गया पाठ मान्य नहीं है।"
339 + "incorrect_seed" : "दर्ज किया गया पाठ मान्य नहीं है।",
340 +
341 + "biometric_auth_reason" : "प्रमाणित करने के लिए अपने फ़िंगरप्रिंट को स्कैन करें"
342 }
\ No newline at end of file
res/values/strings_ja.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "ペースト",
337 "restore_from_seed_placeholder" : "ここにコードフレーズを入力または貼り付けてください",
338 "add_new_word" : "新しい単語を追加",
339 - "incorrect_seed" : "入力されたテキストは無効です。"
339 + "incorrect_seed" : "入力されたテキストは無効です。",
340 +
341 + "biometric_auth_reason" : "प指紋をスキャンして認証する"
342 }
\ No newline at end of file
res/values/strings_ko.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "풀",
337 "restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오.",
338 "add_new_word" : "새로운 단어 추가",
339 - "incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다."
339 + "incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다.",
340 +
341 + "biometric_auth_reason" : "지문을 스캔하여 인증"
342 }
\ No newline at end of file
res/values/strings_nl.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "Plakken",
337 "restore_from_seed_placeholder" : "Voer hier uw codefrase in of plak deze",
338 "add_new_word" : "Nieuw woord toevoegen",
339 - "incorrect_seed" : "De ingevoerde tekst is niet geldig."
339 + "incorrect_seed" : "De ingevoerde tekst is niet geldig.",
340 +
341 + "biometric_auth_reason" : "Scan uw vingerafdruk om te verifiëren"
342 }
\ No newline at end of file
res/values/strings_pl.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "Pasta",
337 "restore_from_seed_placeholder" : "Wpisz lub wklej tutaj swoją frazę kodową",
338 "add_new_word" : "Dodaj nowe słowo",
339 - "incorrect_seed" : "Wprowadzony tekst jest nieprawidłowy."
339 + "incorrect_seed" : "Wprowadzony tekst jest nieprawidłowy.",
340 +
341 + "biometric_auth_reason" : "Zeskanuj swój odcisk palca, aby go uwierzytelnić"
342 }
\ No newline at end of file
res/values/strings_pt.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "Colar",
337 "restore_from_seed_placeholder" : "Digite ou cole sua frase de código aqui",
338 "add_new_word" : "Adicionar nova palavra",
339 - "incorrect_seed" : "O texto digitado não é válido."
339 + "incorrect_seed" : "O texto digitado não é válido.",
340 +
341 + "biometric_auth_reason" : "Digitalize sua impressão digital para autenticar"
342 }
res/values/strings_ru.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "Вставить",
337 "restore_from_seed_placeholder" : "Введите или вставте код фразу вашего кошелька",
338 "add_new_word" : "Добавить новое слово",
339 - "incorrect_seed" : "Введенный текст некорректный."
339 + "incorrect_seed" : "Введенный текст некорректный.",
340 +
341 + "biometric_auth_reason" : "Отсканируйте свой отпечаток пальца для аутентификации"
342 }
\ No newline at end of file
res/values/strings_zh.arb
+3 -1
@@ -336,5 +336,7 @@
336 "paste" : "糊",
337 "restore_from_seed_placeholder" : "请在此处输入或粘贴您的代码短语",
338 "add_new_word" : "添加新词",
339 - "incorrect_seed" : "输入的文字无效。"
339 + "incorrect_seed" : "输入的文字无效。",
340 +
341 + "biometric_auth_reason" : "掃描指紋以進行身份驗證"
342 }
\ No newline at end of file