dev
dart 110 lines 3.55 KB
Raw
1 import 'package:cake_wallet/core/secure_storage.dart';
2 import 'package:shared_preferences/shared_preferences.dart';
3
4 enum SecretStoreKey { moneroWalletPassword, pinCodePassword, backupPassword, duressPinCodePassword }
5
6 const moneroWalletPassword = "MONERO_WALLET_PASSWORD";
7 const pinCodePassword = "PIN_CODE_PASSWORD";
8 const backupPassword = "BACKUP_CODE_PASSWORD";
9 const duressPinCodePassword = "DURESS_PIN_CODE_PASSWORD";
10
11 String generateStoreKeyFor({
12 required SecretStoreKey key,
13 String walletName = "",
14 }) {
15 var _key = "";
16
17 switch (key) {
18 case SecretStoreKey.moneroWalletPassword:
19 {
20 _key = moneroWalletPassword + "_" + walletName.toUpperCase();
21 }
22 break;
23
24 case SecretStoreKey.pinCodePassword:
25 {
26 _key = pinCodePassword;
27 }
28 break;
29
30 case SecretStoreKey.backupPassword:
31 {
32 _key = backupPassword;
33 }
34 break;
35
36 case SecretStoreKey.duressPinCodePassword:
37 {
38 _key = duressPinCodePassword;
39 }
40 break;
41
42 default:
43 {}
44 }
45
46 return _key;
47 }
48
49 class SecureKey {
50 static const allowBiometricalAuthenticationKey = 'allow_biometrical_authentication';
51 static const useTOTP2FA = 'use_totp_2fa';
52 static const shouldRequireTOTP2FAForAccessingWallet =
53 'should_require_totp_2fa_for_accessing_wallets';
54 static const shouldRequireTOTP2FAForSendsToContact =
55 'should_require_totp_2fa_for_sends_to_contact';
56 static const shouldRequireTOTP2FAForSendsToNonContact =
57 'should_require_totp_2fa_for_sends_to_non_contact';
58 static const shouldRequireTOTP2FAForSendsToInternalWallets =
59 'should_require_totp_2fa_for_sends_to_internal_wallets';
60 static const shouldRequireTOTP2FAForExchangesToInternalWallets =
61 'should_require_totp_2fa_for_exchanges_to_internal_wallets';
62 static const shouldRequireTOTP2FAForExchangesToExternalWallets =
63 'should_require_totp_2fa_for_exchanges_to_external_wallets';
64 static const shouldRequireTOTP2FAForAddingContacts =
65 'should_require_totp_2fa_for_adding_contacts';
66 static const shouldRequireTOTP2FAForCreatingNewWallets =
67 'should_require_totp_2fa_for_creating_new_wallets';
68 static const shouldRequireTOTP2FAForAllSecurityAndBackupSettings =
69 'should_require_totp_2fa_for_all_security_and_backup_settings';
70 static const selectedCake2FAPreset = 'selected_cake_2fa_preset';
71 static const totpSecretKey = 'totp_secret_key';
72 static const pinTimeOutDuration = 'pin_timeout_duration';
73 static const lastAuthTimeMilliseconds = 'last_auth_time_milliseconds';
74 static const enableDuressPin = 'enable_duress_pin';
75
76 static Future<int?> getInt({
77 required SecureStorage secureStorage,
78 required SharedPreferences sharedPreferences,
79 required String key,
80 }) async {
81 int? value = int.tryParse((await secureStorage.read(key: key) ?? ''));
82 value ??= sharedPreferences.getInt(key);
83 return value;
84 }
85
86 static Future<bool?> getBool({
87 required SecureStorage secureStorage,
88 required SharedPreferences sharedPreferences,
89 required String key,
90 }) async {
91 String? value = (await secureStorage.read(key: key) ?? '');
92 if (value.toLowerCase() == "true") {
93 return true;
94 } else if (value.toLowerCase() == "false") {
95 return false;
96 } else {
97 return sharedPreferences.getBool(key);
98 }
99 }
100
101 static Future<String?> getString({
102 required SecureStorage secureStorage,
103 required SharedPreferences sharedPreferences,
104 required String key,
105 }) async {
106 String? value = await secureStorage.read(key: key);
107 value ??= sharedPreferences.getString(key);
108 return value;
109 }
110 }