cake_wallet/lib/core/seed_validator.dart

75 lines
2.5 KiB
Dart
Raw Normal View History

2020-11-30 17:17:44 +00:00
import 'package:cake_wallet/bitcoin/bitcoin_mnemonic.dart' as bitcoin_electrum;
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';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/monero/mnemonics/chinese_simplified.dart';
import 'package:cake_wallet/monero/mnemonics/dutch.dart';
import 'package:cake_wallet/monero/mnemonics/english.dart';
import 'package:cake_wallet/monero/mnemonics/german.dart';
import 'package:cake_wallet/monero/mnemonics/japanese.dart';
import 'package:cake_wallet/monero/mnemonics/portuguese.dart';
import 'package:cake_wallet/monero/mnemonics/russian.dart';
import 'package:cake_wallet/monero/mnemonics/spanish.dart';
import 'package:cake_wallet/utils/language_list.dart';
2020-06-20 07:10:00 +00:00
class SeedValidator extends Validator<MnemonicItem> {
SeedValidator({this.type, this.language})
: _words = getWordList(type: type, language: language);
final WalletType type;
final String language;
final List<String> _words;
static List<String> getWordList({WalletType type, String language}) {
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:
return getMoneroWordList(language);
default:
return [];
}
}
static List<String> getMoneroWordList(String language) {
switch (language) {
2020-09-21 11:50:26 +00:00
case LanguageList.english:
2020-06-20 07:10:00 +00:00
return EnglishMnemonics.words;
break;
2020-09-21 11:50:26 +00:00
case LanguageList.chineseSimplified:
2020-06-20 07:10:00 +00:00
return ChineseSimplifiedMnemonics.words;
break;
2020-09-21 11:50:26 +00:00
case LanguageList.dutch:
2020-06-20 07:10:00 +00:00
return DutchMnemonics.words;
break;
2020-09-21 11:50:26 +00:00
case LanguageList.german:
2020-06-20 07:10:00 +00:00
return GermanMnemonics.words;
break;
2020-09-21 11:50:26 +00:00
case LanguageList.japanese:
2020-06-20 07:10:00 +00:00
return JapaneseMnemonics.words;
break;
2020-09-21 11:50:26 +00:00
case LanguageList.portuguese:
2020-06-20 07:10:00 +00:00
return PortugueseMnemonics.words;
break;
2020-09-21 11:50:26 +00:00
case LanguageList.russian:
2020-06-20 07:10:00 +00:00
return RussianMnemonics.words;
break;
2020-09-21 11:50:26 +00:00
case LanguageList.spanish:
2020-06-20 07:10:00 +00:00
return SpanishMnemonics.words;
break;
default:
return EnglishMnemonics.words;
}
}
static List<String> getBitcoinWordList(String language) {
2020-09-21 11:50:26 +00:00
assert(language.toLowerCase() == LanguageList.english.toLowerCase());
2020-11-30 17:17:44 +00:00
return bitcoin_electrum.englishWordlist;
2020-06-20 07:10:00 +00:00
}
@override
bool isValid(MnemonicItem value) => _words.contains(value.text);
}