CWA-164 | added biometric authentication

This commit is contained in:
Oleksandr Sobol 2020-01-21 19:51:37 +02:00
parent 59492a6634
commit 71bdfb3e5b
19 changed files with 116 additions and 13 deletions

View file

@ -7,6 +7,7 @@
FlutterApplication and put your custom class here. --> FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<application <application
android:name="io.flutter.app.FlutterApplication" android:name="io.flutter.app.FlutterApplication"

View file

@ -1,10 +1,10 @@
package com.cakewallet.cake_wallet; package com.cakewallet.cake_wallet;
import android.os.Bundle; import android.os.Bundle;
import io.flutter.app.FlutterActivity; import io.flutter.app.FlutterFragmentActivity;
import io.flutter.plugins.GeneratedPluginRegistrant; import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterFragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

View file

@ -38,6 +38,7 @@ class S implements WidgetsLocalizations {
String get authenticated => "Authenticated"; String get authenticated => "Authenticated";
String get authentication => "Authentication"; String get authentication => "Authentication";
String get available_balance => "Available Balance"; String get available_balance => "Available Balance";
String get biometric_auth_reason => "Scan your fingerprint to authenticate";
String get cancel => "Cancel"; String get cancel => "Cancel";
String get change => "Change"; String get change => "Change";
String get change_currency => "Change Currency"; String get change_currency => "Change Currency";
@ -315,6 +316,8 @@ class $de extends S {
@override @override
String get hidden_balance => "Verstecktes Gleichgewicht"; String get hidden_balance => "Verstecktes Gleichgewicht";
@override @override
String get biometric_auth_reason => "Scannen Sie Ihren Fingerabdruck zur Authentifizierung";
@override
String get transaction_sent => "Transaktion gesendet!"; String get transaction_sent => "Transaktion gesendet!";
@override @override
String get password => "Passwort"; String get password => "Passwort";
@ -861,6 +864,8 @@ class $hi extends S {
@override @override
String get hidden_balance => "छिपा हुआ संतुलन"; String get hidden_balance => "छिपा हुआ संतुलन";
@override @override
String get biometric_auth_reason => "प्रमाणित करने के लिए अपने फ़िंगरप्रिंट को स्कैन करें";
@override
String get transaction_sent => "भेजा गया लेन-देन"; String get transaction_sent => "भेजा गया लेन-देन";
@override @override
String get password => "पारण शब्द"; String get password => "पारण शब्द";
@ -1407,6 +1412,8 @@ class $ru extends S {
@override @override
String get hidden_balance => "Скрытый баланс"; String get hidden_balance => "Скрытый баланс";
@override @override
String get biometric_auth_reason => "Отсканируйте свой отпечаток пальца для аутентификации";
@override
String get transaction_sent => "Tранзакция отправлена!"; String get transaction_sent => "Tранзакция отправлена!";
@override @override
String get password => "Password"; String get password => "Password";
@ -1953,6 +1960,8 @@ class $ko extends S {
@override @override
String get hidden_balance => "숨겨진 균형"; String get hidden_balance => "숨겨진 균형";
@override @override
String get biometric_auth_reason => "지문을 스캔하여 인증";
@override
String get transaction_sent => "거래가 전송되었습니다!"; String get transaction_sent => "거래가 전송되었습니다!";
@override @override
String get password => "암호"; String get password => "암호";
@ -2499,6 +2508,8 @@ class $pt extends S {
@override @override
String get hidden_balance => "Saldo escondido"; String get hidden_balance => "Saldo escondido";
@override @override
String get biometric_auth_reason => "Digitalize sua impressão digital para autenticar";
@override
String get transaction_sent => "Transação enviada!"; String get transaction_sent => "Transação enviada!";
@override @override
String get password => "Senha"; String get password => "Senha";
@ -3045,6 +3056,8 @@ class $ja extends S {
@override @override
String get hidden_balance => "隠れたバランス"; String get hidden_balance => "隠れたバランス";
@override @override
String get biometric_auth_reason => "प指紋をスキャンして認証する";
@override
String get transaction_sent => "トランザクションが送信されました!"; String get transaction_sent => "トランザクションが送信されました!";
@override @override
String get password => "パスワード"; String get password => "パスワード";
@ -3595,6 +3608,8 @@ class $pl extends S {
@override @override
String get hidden_balance => "Ukryta równowaga"; String get hidden_balance => "Ukryta równowaga";
@override @override
String get biometric_auth_reason => "Zeskanuj swój odcisk palca, aby go uwierzytelnić";
@override
String get transaction_sent => "Transakcja wysłana!"; String get transaction_sent => "Transakcja wysłana!";
@override @override
String get password => "Hasło"; String get password => "Hasło";
@ -4141,6 +4156,8 @@ class $es extends S {
@override @override
String get hidden_balance => "Balance oculto"; String get hidden_balance => "Balance oculto";
@override @override
String get biometric_auth_reason => "Escanee su huella digital para autenticar";
@override
String get transaction_sent => "Transacción enviada!"; String get transaction_sent => "Transacción enviada!";
@override @override
String get password => "Contraseña"; String get password => "Contraseña";
@ -4687,6 +4704,8 @@ class $nl extends S {
@override @override
String get hidden_balance => "Verborgen balans"; String get hidden_balance => "Verborgen balans";
@override @override
String get biometric_auth_reason => "Scan uw vingerafdruk om te verifiëren";
@override
String get transaction_sent => "Transactie verzonden!"; String get transaction_sent => "Transactie verzonden!";
@override @override
String get password => "Wachtwoord"; String get password => "Wachtwoord";
@ -5233,6 +5252,8 @@ class $zh extends S {
@override @override
String get hidden_balance => "隐藏余额"; String get hidden_balance => "隐藏余额";
@override @override
String get biometric_auth_reason => "掃描指紋以進行身份驗證";
@override
String get transaction_sent => "交易已发送"; String get transaction_sent => "交易已发送";
@override @override
String get password => "密码"; String get password => "密码";

View file

@ -0,0 +1,24 @@
import 'package:local_auth/local_auth.dart';
import 'package:flutter/services.dart';
import 'package:cake_wallet/generated/i18n.dart';
class BiometricAuth {
Future<bool> isAuthenticated() async {
final LocalAuthentication _localAuth = LocalAuthentication();
try {
return await _localAuth.authenticateWithBiometrics(
localizedReason: S.current.biometric_auth_reason,
useErrorDialogs: true,
stickyAuth: false
);
} on PlatformException
catch(e) {
print(e);
}
return false;
}
}

View file

@ -6,6 +6,8 @@ import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/stores/auth/auth_state.dart'; import 'package:cake_wallet/src/stores/auth/auth_state.dart';
import 'package:cake_wallet/src/stores/auth/auth_store.dart'; import 'package:cake_wallet/src/stores/auth/auth_store.dart';
import 'package:cake_wallet/src/screens/pin_code/pin_code.dart'; import 'package:cake_wallet/src/screens/pin_code/pin_code.dart';
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
import 'package:cake_wallet/src/domain/common/biometric_auth.dart';
typedef OnAuthenticationFinished = void Function(bool, AuthPageState); typedef OnAuthenticationFinished = void Function(bool, AuthPageState);
@ -33,6 +35,26 @@ class AuthPageState extends State<AuthPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final authStore = Provider.of<AuthStore>(context); final authStore = Provider.of<AuthStore>(context);
final settingsStore = Provider.of<SettingsStore>(context);
if (settingsStore.allowBiometricalAuthentication) {
WidgetsBinding.instance.addPostFrameCallback((_) {
final biometricAuth = BiometricAuth();
biometricAuth.isAuthenticated().then(
(isAuth) {
if (isAuth) {
authStore.biometricAuth();
_key.currentState.showSnackBar(
SnackBar(
content: Text(S.of(context).authenticated),
backgroundColor: Colors.green,
),
);
}
}
);
});
}
reaction((_) => authStore.state, (AuthState state) { reaction((_) => authStore.state, (AuthState state) {
if (state is AuthenticatedSuccessfully) { if (state is AuthenticatedSuccessfully) {

View file

@ -91,4 +91,9 @@ abstract class AuthStoreBase with Store {
return Duration(milliseconds: timeout); return Duration(milliseconds: timeout);
} }
@action
void biometricAuth() {
state = AuthenticatedSuccessfully();
}
} }

View file

@ -406,6 +406,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.19" version: "0.3.19"
local_auth:
dependency: "direct main"
description:
name: local_auth
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1"
logging: logging:
dependency: transitive dependency: transitive
description: description:

View file

@ -45,6 +45,7 @@ dependencies:
path: ./cw_monero path: ./cw_monero
hive: ^1.2.0 hive: ^1.2.0
hive_flutter: ^0.2.1 hive_flutter: ^0.2.1
local_auth: ^0.6.1
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.

View file

@ -336,5 +336,7 @@
"paste" : "Einfügen", "paste" : "Einfügen",
"restore_from_seed_placeholder" : "Bitte geben Sie hier Ihren Code ein", "restore_from_seed_placeholder" : "Bitte geben Sie hier Ihren Code ein",
"add_new_word" : "Neues Wort hinzufügen", "add_new_word" : "Neues Wort hinzufügen",
"incorrect_seed" : "Der eingegebene Text ist ungültig." "incorrect_seed" : "Der eingegebene Text ist ungültig.",
"biometric_auth_reason" : "Scannen Sie Ihren Fingerabdruck zur Authentifizierung"
} }

View file

@ -336,5 +336,7 @@
"paste" : "Paste", "paste" : "Paste",
"restore_from_seed_placeholder" : "Please enter or paste your seed here", "restore_from_seed_placeholder" : "Please enter or paste your seed here",
"add_new_word" : "Add new word", "add_new_word" : "Add new word",
"incorrect_seed" : "The text entered is not valid." "incorrect_seed" : "The text entered is not valid.",
"biometric_auth_reason" : "Scan your fingerprint to authenticate"
} }

View file

@ -336,5 +336,7 @@
"paste" : "Pegar", "paste" : "Pegar",
"restore_from_seed_placeholder" : "Ingrese o pegue su frase de código aquí", "restore_from_seed_placeholder" : "Ingrese o pegue su frase de código aquí",
"add_new_word" : "Agregar palabra nueva", "add_new_word" : "Agregar palabra nueva",
"incorrect_seed" : "El texto ingresado no es válido." "incorrect_seed" : "El texto ingresado no es válido.",
"biometric_auth_reason" : "Escanee su huella digital para autenticar"
} }

View file

@ -336,5 +336,7 @@
"paste" : "पेस्ट करें", "paste" : "पेस्ट करें",
"restore_from_seed_placeholder" : "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें", "restore_from_seed_placeholder" : "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें",
"add_new_word" : "नया शब्द जोड़ें", "add_new_word" : "नया शब्द जोड़ें",
"incorrect_seed" : "दर्ज किया गया पाठ मान्य नहीं है।" "incorrect_seed" : "दर्ज किया गया पाठ मान्य नहीं है।",
"biometric_auth_reason" : "प्रमाणित करने के लिए अपने फ़िंगरप्रिंट को स्कैन करें"
} }

View file

@ -336,5 +336,7 @@
"paste" : "ペースト", "paste" : "ペースト",
"restore_from_seed_placeholder" : "ここにコードフレーズを入力または貼り付けてください", "restore_from_seed_placeholder" : "ここにコードフレーズを入力または貼り付けてください",
"add_new_word" : "新しい単語を追加", "add_new_word" : "新しい単語を追加",
"incorrect_seed" : "入力されたテキストは無効です。" "incorrect_seed" : "入力されたテキストは無効です。",
"biometric_auth_reason" : "प指紋をスキャンして認証する"
} }

View file

@ -336,5 +336,7 @@
"paste" : "풀", "paste" : "풀",
"restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오.", "restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오.",
"add_new_word" : "새로운 단어 추가", "add_new_word" : "새로운 단어 추가",
"incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다." "incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다.",
"biometric_auth_reason" : "지문을 스캔하여 인증"
} }

View file

@ -336,5 +336,7 @@
"paste" : "Plakken", "paste" : "Plakken",
"restore_from_seed_placeholder" : "Voer hier uw codefrase in of plak deze", "restore_from_seed_placeholder" : "Voer hier uw codefrase in of plak deze",
"add_new_word" : "Nieuw woord toevoegen", "add_new_word" : "Nieuw woord toevoegen",
"incorrect_seed" : "De ingevoerde tekst is niet geldig." "incorrect_seed" : "De ingevoerde tekst is niet geldig.",
"biometric_auth_reason" : "Scan uw vingerafdruk om te verifiëren"
} }

View file

@ -336,5 +336,7 @@
"paste" : "Pasta", "paste" : "Pasta",
"restore_from_seed_placeholder" : "Wpisz lub wklej tutaj swoją frazę kodową", "restore_from_seed_placeholder" : "Wpisz lub wklej tutaj swoją frazę kodową",
"add_new_word" : "Dodaj nowe słowo", "add_new_word" : "Dodaj nowe słowo",
"incorrect_seed" : "Wprowadzony tekst jest nieprawidłowy." "incorrect_seed" : "Wprowadzony tekst jest nieprawidłowy.",
"biometric_auth_reason" : "Zeskanuj swój odcisk palca, aby go uwierzytelnić"
} }

View file

@ -336,5 +336,7 @@
"paste" : "Colar", "paste" : "Colar",
"restore_from_seed_placeholder" : "Digite ou cole sua frase de código aqui", "restore_from_seed_placeholder" : "Digite ou cole sua frase de código aqui",
"add_new_word" : "Adicionar nova palavra", "add_new_word" : "Adicionar nova palavra",
"incorrect_seed" : "O texto digitado não é válido." "incorrect_seed" : "O texto digitado não é válido.",
"biometric_auth_reason" : "Digitalize sua impressão digital para autenticar"
} }

View file

@ -336,5 +336,7 @@
"paste" : "Вставить", "paste" : "Вставить",
"restore_from_seed_placeholder" : "Введите или вставте код фразу вашего кошелька", "restore_from_seed_placeholder" : "Введите или вставте код фразу вашего кошелька",
"add_new_word" : "Добавить новое слово", "add_new_word" : "Добавить новое слово",
"incorrect_seed" : "Введенный текст некорректный." "incorrect_seed" : "Введенный текст некорректный.",
"biometric_auth_reason" : "Отсканируйте свой отпечаток пальца для аутентификации"
} }

View file

@ -336,5 +336,7 @@
"paste" : "糊", "paste" : "糊",
"restore_from_seed_placeholder" : "请在此处输入或粘贴您的代码短语", "restore_from_seed_placeholder" : "请在此处输入或粘贴您的代码短语",
"add_new_word" : "添加新词", "add_new_word" : "添加新词",
"incorrect_seed" : "输入的文字无效。" "incorrect_seed" : "输入的文字无效。",
"biometric_auth_reason" : "掃描指紋以進行身份驗證"
} }