mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-29 06:38:45 +01:00
Merge branch 'main' into CAKE-272-implement-localization-generation-script
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"salt": "",
|
||||
"keychainSalt": "",
|
||||
"key": "",
|
||||
"walletSalt": "",
|
||||
"shortKey": "",
|
||||
"change_now_api_key": ""
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'dart:io';
|
||||
|
||||
const outputPath = 'android/key.properties';
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
final output = args.fold('', (String acc, String arg) => acc + arg + '\n');
|
||||
final outputFile = File(outputPath);
|
||||
|
||||
if (outputFile.existsSync()) {
|
||||
await outputFile.delete();
|
||||
}
|
||||
|
||||
await outputFile.writeAsString(output);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'generate_secrets_config.dart';
|
||||
import 'import_secrets_config.dart';
|
||||
|
||||
const configPath = 'tool/.secrets-config.json';
|
||||
const outputPath = 'lib/.secrets.g.dart';
|
||||
|
||||
Future<void> main(List<String> args) async => generateSecrets(args);
|
||||
|
||||
Future<void> generateSecrets(List<String> args) async {
|
||||
await generateSecretsConfig(args);
|
||||
await importSecretsConfig();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'utils/secret_key.dart';
|
||||
import 'utils/utils.dart';
|
||||
|
||||
const configPath = 'tool/.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 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();
|
||||
});
|
||||
|
||||
final secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
|
||||
await configFile.writeAsString(secretsJson);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'utils/utils.dart';
|
||||
|
||||
const configPath = 'tool/.secrets-config.json';
|
||||
const outputPath = 'lib/.secrets.g.dart';
|
||||
|
||||
Future<void> main(List<String> args) async => importSecretsConfig();
|
||||
|
||||
Future<void> importSecretsConfig() async {
|
||||
final outputFile = File(outputPath);
|
||||
final input = json.decode(File(configPath).readAsStringSync())
|
||||
as Map<String, dynamic> ??
|
||||
<String, dynamic>{};
|
||||
final output = input.keys
|
||||
.fold('', (String acc, String val) => acc + generateConst(val, input));
|
||||
|
||||
if (outputFile.existsSync()) {
|
||||
await outputFile.delete();
|
||||
}
|
||||
|
||||
await outputFile.writeAsString(output);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
const secretsProdPath = 'tool/.secrets-prod.json';
|
||||
const secretsTestPath = 'tool/.secrets-test.json';
|
||||
const outputPath = 'lib/.secrets.g.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
final inputPath = FileSystemEntity.typeSync(secretsProdPath) !=
|
||||
FileSystemEntityType.notFound
|
||||
? secretsProdPath
|
||||
: secretsTestPath;
|
||||
|
||||
final inoutContent = File(inputPath).readAsStringSync();
|
||||
final config = json.decode(inoutContent) as Map<String, dynamic>;
|
||||
final output =
|
||||
'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"]}\';';
|
||||
|
||||
await File(outputPath).writeAsString(output);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'generate_new_secrets.dart';
|
||||
import 'import_secrets_config.dart';
|
||||
import 'utils/utils.dart';
|
||||
|
||||
const configPath = 'tool/.secrets-config.json';
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
await updateSecretsConfig(args);
|
||||
await importSecretsConfig();
|
||||
}
|
||||
|
||||
Future<void> updateSecretsConfig(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] = parts.length > 1 ? parts[1] : 1;
|
||||
return acc;
|
||||
});
|
||||
|
||||
final configFile = File(configPath);
|
||||
final secrets = <String, dynamic>{};
|
||||
|
||||
secrets.addAll(extraInfo);
|
||||
secrets.removeWhere((key, dynamic value) {
|
||||
if (key.contains('--')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
final fileConfig =
|
||||
json.decode(configFile.readAsStringSync()) as Map<String, dynamic> ??
|
||||
<String, dynamic>{};
|
||||
fileConfig.forEach((key, dynamic value) {
|
||||
if (secrets[key] == null) {
|
||||
secrets[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
final secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
|
||||
await configFile.writeAsString(secretsJson);
|
||||
await generateSecrets(args);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:encrypt/encrypt.dart' as encrypt;
|
||||
import 'package:convert/convert.dart';
|
||||
|
||||
class SecretKey {
|
||||
const SecretKey(this.name, this.generate);
|
||||
|
||||
static final base = [
|
||||
SecretKey('salt', () => hex.encode(encrypt.Key.fromSecureRandom(16).bytes)),
|
||||
SecretKey('keychainSalt',
|
||||
() => hex.encode(encrypt.Key.fromSecureRandom(12).bytes)),
|
||||
SecretKey('key', () => hex.encode(encrypt.Key.fromSecureRandom(16).bytes)),
|
||||
SecretKey(
|
||||
'walletSalt', () => hex.encode(encrypt.Key.fromSecureRandom(4).bytes)),
|
||||
SecretKey(
|
||||
'shortKey', () => hex.encode(encrypt.Key.fromSecureRandom(12).bytes)),
|
||||
SecretKey(
|
||||
'backupSalt', () => hex.encode(encrypt.Key.fromSecureRandom(8).bytes)),
|
||||
SecretKey('backupKeychainSalt',
|
||||
() => hex.encode(encrypt.Key.fromSecureRandom(12).bytes)),
|
||||
SecretKey('changeNowApiKey', () => ''),
|
||||
SecretKey('wyreSecretKey', () => ''),
|
||||
SecretKey('wyreApiKey', () => ''),
|
||||
SecretKey('wyreAccountId', () => ''),
|
||||
];
|
||||
|
||||
final String name;
|
||||
final String Function() generate;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String normalizeKeyName(String key) {
|
||||
final parts = key.split('_');
|
||||
final firstWord = parts.removeAt(0);
|
||||
final capitalized = parts
|
||||
.map((e) => toBeginningOfSentenceCase(e))
|
||||
.fold('', (String acc, String word) => acc + word);
|
||||
return firstWord + capitalized;
|
||||
}
|
||||
|
||||
String generateConst(String name, Map<String, dynamic> config) =>
|
||||
'const $name = \'${config["$name"]}\';\n';
|
||||
Reference in New Issue
Block a user