cake_wallet/lib/core/seed_validator.dart

41 lines
1.4 KiB
Dart
Raw Normal View History

2021-12-24 12:37:24 +00:00
import 'package:cake_wallet/bitcoin/bitcoin.dart';
2022-03-30 15:57:04 +00:00
import 'package:cake_wallet/haven/haven.dart';
2020-06-20 07:10:00 +00:00
import 'package:cake_wallet/core/validator.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/mnemonic_item.dart';
2021-12-24 12:37:24 +00:00
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/monero/monero.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/utils/language_list.dart';
2020-06-20 07:10:00 +00:00
class SeedValidator extends Validator<MnemonicItem> {
2022-10-12 17:09:57 +00:00
SeedValidator({required this.type, required this.language})
: _words = getWordList(type: type, language: language),
super(errorMessage: 'Wrong seed mnemonic');
2020-06-20 07:10:00 +00:00
final WalletType type;
final String language;
final List<String> _words;
2022-10-12 17:09:57 +00:00
static List<String> getWordList({required WalletType type, required String language}) {
2020-06-20 07:10:00 +00:00
switch (type) {
case WalletType.bitcoin:
return getBitcoinWordList(language);
2021-05-07 18:59:03 +00:00
case WalletType.litecoin:
return getBitcoinWordList(language);
2020-06-20 07:10:00 +00:00
case WalletType.monero:
2022-10-12 17:09:57 +00:00
return monero!.getMoneroWordList(language);
2022-03-30 15:57:04 +00:00
case WalletType.haven:
2022-10-12 17:09:57 +00:00
return haven!.getMoneroWordList(language);
2020-06-20 07:10:00 +00:00
default:
return [];
}
}
static List<String> getBitcoinWordList(String language) {
2020-09-21 11:50:26 +00:00
assert(language.toLowerCase() == LanguageList.english.toLowerCase());
2022-10-12 17:09:57 +00:00
return bitcoin!.getWordList();
2020-06-20 07:10:00 +00:00
}
@override
2022-10-12 17:09:57 +00:00
bool isValid(MnemonicItem? value) => _words.contains(value?.text);
2020-06-20 07:10:00 +00:00
}