Changed monero dependencies path for android. Changed scripts for generation of secrets.
M committed
Mar 16, 2021 at 15:20 UTC
db751673027115de43c37bef4b1f36523c2c378c
16 files changed
+246
-71
.gitignore
+1
@@ -87,6 +87,7 @@ cw_monero/cw_monero/android/.cxx/
87
android/key.properties
88
89
**/tool/.secrets-prod.json
90
+**/tool/.secrets-config.json
91
**/lib/.secrets.g.dart
92
93
vendor/
cw_monero/android/CMakeLists.txt
+48
-37
@@ -17,7 +17,7 @@ set(EXTERNAL_LIBS_DIR ${CMAKE_SOURCE_DIR}/../ios/External/android)
17
18
add_library(sodium STATIC IMPORTED)
19
set_target_properties(sodium PROPERTIES IMPORTED_LOCATION
20
- ${EXTERNAL_LIBS_DIR}/libsodium/lib/${ANDROID_ABI}/libsodium.a)
20
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libsodium.a)
21
22
############
23
# OpenSSL
@@ -25,11 +25,11 @@ set_target_properties(sodium PROPERTIES IMPORTED_LOCATION
25
26
add_library(crypto STATIC IMPORTED)
27
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION
28
- ${EXTERNAL_LIBS_DIR}/openssl/lib/${ANDROID_ABI}/libcrypto.a)
28
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libcrypto.a)
29
30
add_library(ssl STATIC IMPORTED)
31
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION
32
- ${EXTERNAL_LIBS_DIR}/openssl/lib/${ANDROID_ABI}/libssl.a)
32
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libssl.a)
33
34
############
35
# Boost
@@ -37,39 +37,39 @@ set_target_properties(ssl PROPERTIES IMPORTED_LOCATION
37
38
add_library(boost_chrono STATIC IMPORTED)
39
set_target_properties(boost_chrono PROPERTIES IMPORTED_LOCATION
40
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_chrono.a)
40
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_chrono.a)
41
42
add_library(boost_date_time STATIC IMPORTED)
43
set_target_properties(boost_date_time PROPERTIES IMPORTED_LOCATION
44
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_date_time.a)
44
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_date_time.a)
45
46
add_library(boost_filesystem STATIC IMPORTED)
47
set_target_properties(boost_filesystem PROPERTIES IMPORTED_LOCATION
48
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_filesystem.a)
48
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_filesystem.a)
49
50
add_library(boost_program_options STATIC IMPORTED)
51
set_target_properties(boost_program_options PROPERTIES IMPORTED_LOCATION
52
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_program_options.a)
52
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_program_options.a)
53
54
add_library(boost_regex STATIC IMPORTED)
55
set_target_properties(boost_regex PROPERTIES IMPORTED_LOCATION
56
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_regex.a)
56
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_regex.a)
57
58
add_library(boost_serialization STATIC IMPORTED)
59
set_target_properties(boost_serialization PROPERTIES IMPORTED_LOCATION
60
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_serialization.a)
60
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_serialization.a)
61
62
add_library(boost_system STATIC IMPORTED)
63
set_target_properties(boost_system PROPERTIES IMPORTED_LOCATION
64
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_system.a)
64
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_system.a)
65
66
add_library(boost_thread STATIC IMPORTED)
67
set_target_properties(boost_thread PROPERTIES IMPORTED_LOCATION
68
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_thread.a)
68
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_thread.a)
69
70
add_library(boost_wserialization STATIC IMPORTED)
71
set_target_properties(boost_wserialization PROPERTIES IMPORTED_LOCATION
72
- ${EXTERNAL_LIBS_DIR}/boost/lib/${ANDROID_ABI}/libboost_wserialization.a)
72
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/libboost_wserialization.a)
73
74
#############
75
# Monero
@@ -77,101 +77,111 @@ set_target_properties(boost_wserialization PROPERTIES IMPORTED_LOCATION
77
78
add_library(wallet_api STATIC IMPORTED)
79
set_target_properties(wallet_api PROPERTIES IMPORTED_LOCATION
80
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libwallet_api.a)
80
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libwallet_api.a)
81
82
add_library(wallet STATIC IMPORTED)
83
set_target_properties(wallet PROPERTIES IMPORTED_LOCATION
84
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libwallet.a)
84
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libwallet.a)
85
86
add_library(cryptonote_core STATIC IMPORTED)
87
set_target_properties(cryptonote_core PROPERTIES IMPORTED_LOCATION
88
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libcryptonote_core.a)
88
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libcryptonote_core.a)
89
90
add_library(cryptonote_basic STATIC IMPORTED)
91
set_target_properties(cryptonote_basic PROPERTIES IMPORTED_LOCATION
92
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libcryptonote_basic.a)
92
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libcryptonote_basic.a)
93
94
add_library(mnemonics STATIC IMPORTED)
95
set_target_properties(mnemonics PROPERTIES IMPORTED_LOCATION
96
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libmnemonics.a)
96
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libmnemonics.a)
97
98
add_library(common STATIC IMPORTED)
99
set_target_properties(common PROPERTIES IMPORTED_LOCATION
100
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libcommon.a)
100
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libcommon.a)
101
102
add_library(cncrypto STATIC IMPORTED)
103
set_target_properties(cncrypto PROPERTIES IMPORTED_LOCATION
104
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libcncrypto.a)
104
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libcncrypto.a)
105
106
add_library(ringct STATIC IMPORTED)
107
set_target_properties(ringct PROPERTIES IMPORTED_LOCATION
108
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libringct.a)
108
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libringct.a)
109
110
add_library(ringct_basic STATIC IMPORTED)
111
set_target_properties(ringct_basic PROPERTIES IMPORTED_LOCATION
112
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libringct_basic.a)
112
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libringct_basic.a)
113
114
add_library(blockchain_db STATIC IMPORTED)
115
set_target_properties(blockchain_db PROPERTIES IMPORTED_LOCATION
116
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libblockchain_db.a)
116
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libblockchain_db.a)
117
118
add_library(lmdb STATIC IMPORTED)
119
set_target_properties(lmdb PROPERTIES IMPORTED_LOCATION
120
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/liblmdb.a)
120
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/liblmdb.a)
121
122
add_library(easylogging STATIC IMPORTED)
123
set_target_properties(easylogging PROPERTIES IMPORTED_LOCATION
124
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libeasylogging.a)
124
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libeasylogging.a)
125
126
add_library(unbound STATIC IMPORTED)
127
set_target_properties(unbound PROPERTIES IMPORTED_LOCATION
128
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libunbound.a)
128
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libunbound.a)
129
130
add_library(epee STATIC IMPORTED)
131
set_target_properties(epee PROPERTIES IMPORTED_LOCATION
132
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libepee.a)
132
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libepee.a)
133
134
add_library(blocks STATIC IMPORTED)
135
set_target_properties(blocks PROPERTIES IMPORTED_LOCATION
136
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libblocks.a)
136
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libblocks.a)
137
138
add_library(checkpoints STATIC IMPORTED)
139
set_target_properties(checkpoints PROPERTIES IMPORTED_LOCATION
140
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libcheckpoints.a)
140
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libcheckpoints.a)
141
142
add_library(device STATIC IMPORTED)
143
set_target_properties(device PROPERTIES IMPORTED_LOCATION
144
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libdevice.a)
144
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libdevice.a)
145
146
add_library(device_trezor STATIC IMPORTED)
147
set_target_properties(device_trezor PROPERTIES IMPORTED_LOCATION
148
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libdevice_trezor.a)
148
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libdevice_trezor.a)
149
150
add_library(multisig STATIC IMPORTED)
151
set_target_properties(multisig PROPERTIES IMPORTED_LOCATION
152
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libmultisig.a)
152
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libmultisig.a)
153
154
add_library(version STATIC IMPORTED)
155
set_target_properties(version PROPERTIES IMPORTED_LOCATION
156
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libversion.a)
156
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libversion.a)
157
158
add_library(net STATIC IMPORTED)
159
set_target_properties(net PROPERTIES IMPORTED_LOCATION
160
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libnet.a)
160
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libnet.a)
161
162
add_library(hardforks STATIC IMPORTED)
163
set_target_properties(hardforks PROPERTIES IMPORTED_LOCATION
164
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/libhardforks.a)
164
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libhardforks.a)
165
166
add_library(randomx STATIC IMPORTED)
167
set_target_properties(randomx PROPERTIES IMPORTED_LOCATION
168
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/librandomx.a)
168
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/librandomx.a)
169
170
add_library(rpc_base STATIC IMPORTED)
171
set_target_properties(rpc_base PROPERTIES IMPORTED_LOCATION
172
- ${EXTERNAL_LIBS_DIR}/monero/lib/${ANDROID_ABI}/librpc_base.a)
172
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/librpc_base.a)
173
174
-include_directories( ${EXTERNAL_LIBS_DIR}/monero/include )
174
+add_library(wallet-crypto STATIC IMPORTED)
175
+set_target_properties(wallet-crypto PROPERTIES IMPORTED_LOCATION
176
+ ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/lib/monero/libwallet-crypto.a)
177
+
178
+set(WALLET_CRYPTO "")
179
+
180
+if(${ANDROID_ABI} STREQUAL "x86_64")
181
+ set(WALLET_CRYPTO "wallet-crypto")
182
+endif()
183
+
184
+include_directories( ${EXTERNAL_LIBS_DIR}/${ANDROID_ABI}/include )
185
186
target_link_libraries( cw_monero
187
@@ -199,6 +209,7 @@ target_link_libraries( cw_monero
209
randomx
210
hardforks
211
rpc_base
212
+ ${WALLET_CRYPTO}
213
214
boost_chrono
215
boost_date_time
cw_monero/ios/Classes/monero_api.cpp
+1
-1
@@ -6,7 +6,7 @@
6
#include <unistd.h>
7
#include "thread"
8
#include "CwWalletListener.h"
9
-#include "../External/android/monero/include/wallet2_api.h"
9
+#include "../External/android/x86/include/wallet2_api.h"
10
11
using namespace std::chrono_literals;
12
lib/di.dart
+9
-3
@@ -104,6 +104,7 @@ import 'package:cake_wallet/store/templates/send_template_store.dart';
104
import 'package:cake_wallet/store/templates/exchange_template_store.dart';
105
import 'package:cake_wallet/entities/template.dart';
106
import 'package:cake_wallet/exchange/exchange_template.dart';
107
+import 'package:cake_wallet/.secrets.g.dart' as secrets;
108
109
final getIt = GetIt.instance;
110
@@ -134,10 +135,14 @@ Future setup(
135
136
if (!_isSetupFinished) {
137
getIt.registerSingletonAsync<SharedPreferences>(
137
- () => SharedPreferences.getInstance());
138
+ () => SharedPreferences.getInstance());
139
}
140
140
- final settingsStore = await SettingsStoreBase.load(nodeSource: _nodeSource);
141
+ final isBitcoinBuyEnabled = (secrets.wyreSecretKey?.isNotEmpty ?? false) &&
142
+ (secrets.wyreApiKey?.isNotEmpty ?? false) &&
143
+ (secrets.wyreAccountId?.isNotEmpty ?? false);
144
+ final settingsStore = await SettingsStoreBase.load(
145
+ nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled);
146
147
if (_isSetupFinished) {
148
return;
@@ -219,7 +224,8 @@ Future setup(
224
appStore: getIt.get<AppStore>(),
225
tradesStore: getIt.get<TradesStore>(),
226
tradeFilterStore: getIt.get<TradeFilterStore>(),
222
- transactionFilterStore: getIt.get<TransactionFilterStore>()));
227
+ transactionFilterStore: getIt.get<TransactionFilterStore>(),
228
+ settingsStore: settingsStore));
229
230
getIt.registerFactory<AuthService>(() => AuthService(
231
secureStorage: getIt.get<FlutterSecureStorage>(),
lib/exchange/changenow/changenow_exchange_provider.dart
+1
-1
@@ -25,7 +25,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
25
.toList());
26
27
static const apiUri = 'https://changenow.io/api/v1';
28
- static const apiKey = secrets.change_now_api_key;
28
+ static const apiKey = secrets.changeNowApiKey;
29
static const _exchangeAmountUriSufix = '/exchange-amount/';
30
static const _transactionsUriSufix = '/transactions/';
31
static const _minAmountUriSufix = '/min-amount/';
lib/store/settings_store.dart
+5
@@ -38,6 +38,7 @@ abstract class SettingsStoreBase with Store {
38
@required Map<WalletType, Node> nodes,
39
@required TransactionPriority initialBitcoinTransactionPriority,
40
@required TransactionPriority initialMoneroTransactionPriority,
41
+ @required this.isBitcoinBuyEnabled,
42
this.actionlistDisplayMode}) {
43
fiatCurrency = initialFiatCurrency;
44
balanceDisplayMode = initialBalanceDisplayMode;
@@ -144,8 +145,11 @@ abstract class SettingsStoreBase with Store {
145
146
Node getCurrentNode(WalletType walletType) => nodes[walletType];
147
148
+ bool isBitcoinBuyEnabled;
149
+
150
static Future<SettingsStore> load(
151
{@required Box<Node> nodeSource,
152
+ @required bool isBitcoinBuyEnabled,
153
FiatCurrency initialFiatCurrency = FiatCurrency.usd,
154
MoneroTransactionPriority initialMoneroTransactionPriority =
155
MoneroTransactionPriority.slow,
@@ -212,6 +216,7 @@ abstract class SettingsStoreBase with Store {
216
WalletType.bitcoin: bitcoinElectrumServer
217
},
218
appVersion: packageInfo.version,
219
+ isBitcoinBuyEnabled: isBitcoinBuyEnabled,
220
initialFiatCurrency: currentFiatCurrency,
221
initialBalanceDisplayMode: currentBalanceDisplayMode,
222
initialSaveRecipientAddress: shouldSaveRecipientAddress,
lib/view_model/dashboard/dashboard_view_model.dart
+7
-1
@@ -13,6 +13,7 @@ import 'package:cake_wallet/entities/transaction_direction.dart';
13
import 'package:cake_wallet/entities/transaction_info.dart';
14
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
15
import 'package:cake_wallet/exchange/trade.dart';
16
+import 'package:cake_wallet/store/settings_store.dart';
17
import 'package:cake_wallet/utils/mobx.dart';
18
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
19
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
@@ -41,7 +42,8 @@ abstract class DashboardViewModelBase with Store {
42
this.appStore,
43
this.tradesStore,
44
this.tradeFilterStore,
44
- this.transactionFilterStore}) {
45
+ this.transactionFilterStore,
46
+ this.settingsStore}) {
47
filterItems = {
48
S.current.transactions: [
49
FilterItem(
@@ -193,6 +195,8 @@ abstract class DashboardViewModelBase with Store {
195
196
AppStore appStore;
197
198
+ SettingsStore settingsStore;
199
+
200
TradesStore tradesStore;
201
202
TradeFilterStore tradeFilterStore;
@@ -201,6 +205,8 @@ abstract class DashboardViewModelBase with Store {
205
206
Map<String, List<FilterItem>> filterItems;
207
208
+ bool get isBuyEnabled => settingsStore.isBitcoinBuyEnabled;
209
+
210
ReactionDisposer _reaction;
211
212
ReactionDisposer _onMoneroAccountChangeReaction;
lib/view_model/settings/settings_view_model.dart
+2
@@ -188,6 +188,8 @@ abstract class SettingsViewModelBase with Store {
188
@computed
189
ThemeBase get theme => _settingsStore.currentTheme;
190
191
+ bool get isBitcoinBuyEnabled => _settingsStore.isBitcoinBuyEnabled;
192
+
193
final Map<String, String> itemHeaders;
194
List<List<SettingsListItem>> sections;
195
final SettingsStore _settingsStore;
tool/.secrets-test.json
deleted
-8
@@ -1,8 +0,0 @@
1
-{
2
- "salt": "",
3
- "keychainSalt": "",
4
- "key": "",
5
- "walletSalt": "",
6
- "shortKey": "",
7
- "change_now_api_key": ""
8
-}
\ No newline at end of file
tool/generate_new_secrets.dart
new
+12
@@ -0,0 +1,12 @@
1
+import 'generate_secrets_config.dart';
2
+import 'import_secrets_config.dart';
3
+
4
+const configPath = 'tool/.secrets-config.json';
5
+const outputPath = 'lib/.secrets.g.dart';
6
+
7
+Future<void> main(List<String> args) async => generateSecrets(args);
8
+
9
+Future<void> generateSecrets(List<String> args) async {
10
+ await generateSecretsConfig(args);
11
+ await importSecretsConfig();
12
+}
\ No newline at end of file
tool/generate_secrets_config.dart
new
+49
@@ -0,0 +1,49 @@
1
+import 'dart:convert';
2
+import 'dart:io';
3
+import 'utils/secret_key.dart';
4
+import 'utils/utils.dart';
5
+
6
+const configPath = 'tool/.secrets-config.json';
7
+
8
+Future<void> main(List<String> args) async => generateSecretsConfig(args);
9
+
10
+Future<void> generateSecretsConfig(List<String> args) async {
11
+ final extraInfo =
12
+ args.fold(<String, dynamic>{}, (Map<String, dynamic> acc, String arg) {
13
+ final parts = arg.split('=');
14
+ final key = normalizeKeyName(parts[0]);
15
+ acc[key] = acc[key] = parts.length > 1 ? parts[1] : 1;
16
+ return acc;
17
+ });
18
+
19
+ final configFile = File(configPath);
20
+ final secrets = <String, dynamic>{};
21
+
22
+ secrets.addAll(extraInfo);
23
+ secrets.removeWhere((key, dynamic value) {
24
+ if (key.contains('--')) {
25
+ return true;
26
+ }
27
+
28
+ return false;
29
+ });
30
+
31
+ if (configFile.existsSync()) {
32
+ if (extraInfo['--force'] == 1) {
33
+ await configFile.delete();
34
+ } else {
35
+ return;
36
+ }
37
+ }
38
+
39
+ SecretKey.base.forEach((sec) {
40
+ if (secrets[sec.name] != null) {
41
+ return;
42
+ }
43
+
44
+ secrets[sec.name] = sec.generate();
45
+ });
46
+
47
+ final secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
48
+ await configFile.writeAsString(secretsJson);
49
+}
tool/import_secrets_config.dart
new
+23
@@ -0,0 +1,23 @@
1
+import 'dart:convert';
2
+import 'dart:io';
3
+import 'utils/utils.dart';
4
+
5
+const configPath = 'tool/.secrets-config.json';
6
+const outputPath = 'lib/.secrets.g.dart';
7
+
8
+Future<void> main(List<String> args) async => importSecretsConfig();
9
+
10
+Future<void> importSecretsConfig() async {
11
+ final outputFile = File(outputPath);
12
+ final input = json.decode(File(configPath).readAsStringSync())
13
+ as Map<String, dynamic> ??
14
+ <String, dynamic>{};
15
+ final output = input.keys
16
+ .fold('', (String acc, String val) => acc + generateConst(val, input));
17
+
18
+ if (outputFile.existsSync()) {
19
+ await outputFile.delete();
20
+ }
21
+
22
+ await outputFile.writeAsString(output);
23
+}
tool/secrets.dart
deleted
-20
@@ -1,20 +0,0 @@
1
-import 'dart:convert';
2
-import 'dart:io';
3
-
4
-const secretsProdPath = 'tool/.secrets-prod.json';
5
-const secretsTestPath = 'tool/.secrets-test.json';
6
-const outputPath = 'lib/.secrets.g.dart';
7
-
8
-Future<void> main() async {
9
- final inputPath = FileSystemEntity.typeSync(secretsProdPath) !=
10
- FileSystemEntityType.notFound
11
- ? secretsProdPath
12
- : secretsTestPath;
13
-
14
- final inoutContent = File(inputPath).readAsStringSync();
15
- final config = json.decode(inoutContent) as Map<String, dynamic>;
16
- final output =
17
- 'const salt = \'${config["salt"]}\';const keychainSalt = \'${config["keychainSalt"]}\';\nconst key = \'${config["key"]}\';\nconst walletSalt = \'${config["walletSalt"]}\';\nconst shortKey = \'${config["shortKey"]}\';\nconst change_now_api_key = \'${config["change_now_api_key"]}\';';
18
-
19
- await File(outputPath).writeAsString(output);
20
-}
tool/update_secrets.dart
new
+47
@@ -0,0 +1,47 @@
1
+import 'dart:convert';
2
+import 'dart:io';
3
+import 'generate_new_secrets.dart';
4
+import 'import_secrets_config.dart';
5
+import 'utils/utils.dart';
6
+
7
+const configPath = 'tool/.secrets-config.json';
8
+
9
+Future<void> main(List<String> args) async {
10
+ await updateSecretsConfig(args);
11
+ await importSecretsConfig();
12
+}
13
+
14
+Future<void> updateSecretsConfig(List<String> args) async {
15
+ final extraInfo =
16
+ args.fold(<String, dynamic>{}, (Map<String, dynamic> acc, String arg) {
17
+ final parts = arg.split('=');
18
+ final key = normalizeKeyName(parts[0]);
19
+ acc[key] = parts.length > 1 ? parts[1] : 1;
20
+ return acc;
21
+ });
22
+
23
+ final configFile = File(configPath);
24
+ final secrets = <String, dynamic>{};
25
+
26
+ secrets.addAll(extraInfo);
27
+ secrets.removeWhere((key, dynamic value) {
28
+ if (key.contains('--')) {
29
+ return true;
30
+ }
31
+
32
+ return false;
33
+ });
34
+
35
+ final fileConfig =
36
+ json.decode(configFile.readAsStringSync()) as Map<String, dynamic> ??
37
+ <String, dynamic>{};
38
+ fileConfig.forEach((key, dynamic value) {
39
+ if (secrets[key] == null) {
40
+ secrets[key] = value;
41
+ }
42
+ });
43
+
44
+ final secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
45
+ await configFile.writeAsString(secretsJson);
46
+ await generateSecrets(args);
47
+}
tool/utils/secret_key.dart
new
+28
@@ -0,0 +1,28 @@
1
+import 'package:encrypt/encrypt.dart' as encrypt;
2
+import 'package:convert/convert.dart';
3
+
4
+class SecretKey {
5
+ const SecretKey(this.name, this.generate);
6
+
7
+ static final base = [
8
+ SecretKey('salt', () => hex.encode(encrypt.Key.fromSecureRandom(16).bytes)),
9
+ SecretKey('keychainSalt',
10
+ () => hex.encode(encrypt.Key.fromSecureRandom(12).bytes)),
11
+ SecretKey('key', () => hex.encode(encrypt.Key.fromSecureRandom(16).bytes)),
12
+ SecretKey(
13
+ 'walletSalt', () => hex.encode(encrypt.Key.fromSecureRandom(4).bytes)),
14
+ SecretKey(
15
+ 'shortKey', () => hex.encode(encrypt.Key.fromSecureRandom(12).bytes)),
16
+ SecretKey(
17
+ 'backupSalt', () => hex.encode(encrypt.Key.fromSecureRandom(8).bytes)),
18
+ SecretKey('backupKeychainSalt',
19
+ () => hex.encode(encrypt.Key.fromSecureRandom(12).bytes)),
20
+ SecretKey('changeNowApiKey', () => ''),
21
+ SecretKey('wyreSecretKey', () => ''),
22
+ SecretKey('wyreApiKey', () => ''),
23
+ SecretKey('wyreAccountId', () => ''),
24
+ ];
25
+
26
+ final String name;
27
+ final String Function() generate;
28
+}
tool/utils/utils.dart
new
+13
@@ -0,0 +1,13 @@
1
+import 'package:intl/intl.dart';
2
+
3
+String normalizeKeyName(String key) {
4
+ final parts = key.split('_');
5
+ final firstWord = parts.removeAt(0);
6
+ final capitalized = parts
7
+ .map((e) => toBeginningOfSentenceCase(e))
8
+ .fold('', (String acc, String word) => acc + word);
9
+ return firstWord + capitalized;
10
+}
11
+
12
+String generateConst(String name, Map<String, dynamic> config) =>
13
+ 'const $name = \'${config["$name"]}\';\n';
\ No newline at end of file