mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
09fd6a8241
Generate Ethereum specific secrets in Ethereum package
63 lines
1.5 KiB
Dart
63 lines
1.5 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'utils/secret_key.dart';
|
|
import 'utils/utils.dart';
|
|
|
|
const configPath = 'tool/.secrets-config.json';
|
|
const ethereumConfigPath = 'tool/.ethereum-secrets-config.json';
|
|
|
|
Future<void> main(List<String> args) async => generateSecretsConfig(args);
|
|
|
|
Future<void> generateSecretsConfig(List<String> args) async {
|
|
final extraInfo = args.fold(<String, dynamic>{}, (Map<String, dynamic> acc, String arg) {
|
|
final parts = arg.split('=');
|
|
final key = normalizeKeyName(parts[0]);
|
|
acc[key] = acc[key] = parts.length > 1 ? parts[1] : 1;
|
|
return acc;
|
|
});
|
|
|
|
final configFile = File(configPath);
|
|
final ethereumConfigFile = File(ethereumConfigPath);
|
|
final secrets = <String, dynamic>{};
|
|
|
|
secrets.addAll(extraInfo);
|
|
secrets.removeWhere((key, dynamic value) {
|
|
if (key.contains('--')) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
if (configFile.existsSync()) {
|
|
if (extraInfo['--force'] == 1) {
|
|
await configFile.delete();
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
SecretKey.base.forEach((sec) {
|
|
if (secrets[sec.name] != null) {
|
|
return;
|
|
}
|
|
|
|
secrets[sec.name] = sec.generate();
|
|
});
|
|
|
|
var secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
|
|
await configFile.writeAsString(secretsJson);
|
|
|
|
secrets.clear();
|
|
SecretKey.ethereumSecrets.forEach((sec) {
|
|
if (secrets[sec.name] != null) {
|
|
return;
|
|
}
|
|
|
|
secrets[sec.name] = sec.generate();
|
|
});
|
|
|
|
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
|
|
|
|
await ethereumConfigFile.writeAsString(secretsJson);
|
|
}
|