2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
2023-08-04 17:01:49 +00:00
|
|
|
import 'package:cake_wallet/ethereum/ethereum.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';
|
2023-10-05 01:09:07 +00:00
|
|
|
import 'package:cake_wallet/nano/nano.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);
|
2023-08-04 17:01:49 +00:00
|
|
|
case WalletType.ethereum:
|
|
|
|
return ethereum!.getEthereumWordList(language);
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
|
|
|
case WalletType.banano:
|
|
|
|
return nano!.getNanoWordList(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
|
|
|
}
|