Fixes for validation of monero seed. Add French and Italian seeds validation.

This commit is contained in:
M 2022-01-19 16:25:58 +02:00
parent 2bbd413b12
commit bd2e2ce258
8 changed files with 3372 additions and 30 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -186,6 +186,10 @@ class CWMonero extends Monero {
return RussianMnemonics.words;
case 'spanish':
return SpanishMnemonics.words;
case 'french':
return FrenchMnemonics.words;
case 'italian':
return ItalianMnemonics.words;
default:
return EnglishMnemonics.words;
}

View file

@ -18,7 +18,9 @@ class WalletRestoreFromSeedForm extends StatefulWidget {
@required this.displayBlockHeightSelector,
@required this.type,
this.blockHeightFocusNode,
this.onHeightOrDateEntered})
this.onHeightOrDateEntered,
this.onSeedChange,
this.onLanguageChange})
: super(key: key);
final WalletType type;
@ -26,6 +28,8 @@ class WalletRestoreFromSeedForm extends StatefulWidget {
final bool displayBlockHeightSelector;
final FocusNode blockHeightFocusNode;
final Function(bool) onHeightOrDateEntered;
final void Function(String) onSeedChange;
final void Function(String) onLanguageChange;
@override
WalletRestoreFromSeedFormState createState() =>
@ -62,7 +66,10 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
validator: WalletNameValidator()),
Container(height: 20),
SeedWidget(
key: seedWidgetStateKey, language: language, type: widget.type),
key: seedWidgetStateKey,
language: language,
type: widget.type,
onSeedChange: widget.onSeedChange),
if (widget.displayLanguageSelector)
GestureDetector(
onTap: () async {
@ -98,6 +105,7 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
this.language = language;
seedWidgetStateKey.currentState.changeSeedLanguage(language);
_setLanguageLabel(language);
widget.onLanguageChange?.call(language);
});
}

View file

@ -18,6 +18,7 @@ import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:cake_wallet/core/seed_validator.dart';
class WalletRestorePage extends BasePage {
WalletRestorePage(this.walletRestoreViewModel)
@ -39,8 +40,40 @@ class WalletRestorePage extends BasePage {
type: walletRestoreViewModel.type,
key: walletRestoreFromSeedFormKey,
blockHeightFocusNode: _blockHeightFocusNode,
onHeightOrDateEntered: (value) =>
walletRestoreViewModel.isButtonEnabled = value));
onHeightOrDateEntered: (value) {
if (_isValidSeed()) {
walletRestoreViewModel.isButtonEnabled = value;
}
},
onSeedChange: (String seed) {
final hasHeight = walletRestoreFromSeedFormKey
.currentState
.blockchainHeightKey
.currentState
.restoreHeightController
.text
.isNotEmpty;
if (hasHeight) {
walletRestoreViewModel.isButtonEnabled = _isValidSeed();
}
},
onLanguageChange: (_) {
if (walletRestoreViewModel.hasBlockchainHeightLanguageSelector) {
final hasHeight = walletRestoreFromSeedFormKey
.currentState
.blockchainHeightKey
.currentState
.restoreHeightController
.text
.isNotEmpty;
if (hasHeight) {
walletRestoreViewModel.isButtonEnabled = _isValidSeed();
}
} else {
walletRestoreViewModel.isButtonEnabled = _isValidSeed();
}
}));
break;
case WalletRestoreMode.keys:
_pages.add(WalletRestoreFromKeysFrom(
@ -169,6 +202,31 @@ class WalletRestorePage extends BasePage {
])));
}
bool _isValidSeed() {
final seedWords = walletRestoreFromSeedFormKey
.currentState
.seedWidgetStateKey
.currentState
.text
.split(' ');
if (seedWords.length != walletRestoreViewModel.seedMnemonicLength) {
return false;
}
final words = walletRestoreFromSeedFormKey
.currentState
.seedWidgetStateKey
.currentState
.words
.toSet();
return seedWords
.toSet()
.difference(words)
.toSet()
.isEmpty;
}
Map<String, dynamic> _credentials() {
final credentials = <String, dynamic>{};

View file

@ -12,10 +12,11 @@ import 'package:cake_wallet/generated/i18n.dart';
import 'package:flutter/widgets.dart';
class SeedWidget extends StatefulWidget {
SeedWidget({Key key, this.language, this.type}) : super(key: key);
SeedWidget({Key key, this.language, this.type, this.onSeedChange}) : super(key: key);
final String language;
final WalletType type;
final void Function(String) onSeedChange;
@override
SeedWidgetState createState() => SeedWidgetState(language, type);
@ -52,6 +53,7 @@ class SeedWidgetState extends State<SeedWidget> {
void initState() {
super.initState();
_showPlaceholder = true;
controller.addListener(() => widget.onSeedChange?.call(text));
}
void changeSeedLanguage(String language) {

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/core/mnemonic_length.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
@ -35,17 +36,24 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
_walletCreationService.changeWalletType(type: type);
}
static const moneroSeedMnemonicLength = 25;
static const electrumSeedMnemonicLength = 24;
final List<WalletRestoreMode> availableModes;
final bool hasSeedLanguageSelector;
final bool hasBlockchainHeightLanguageSelector;
final WalletCreationService _walletCreationService;
@observable
WalletRestoreMode mode;
@observable
bool isButtonEnabled;
final List<WalletRestoreMode> availableModes;
final bool hasSeedLanguageSelector;
final bool hasBlockchainHeightLanguageSelector;
final WalletCreationService _walletCreationService;
int get seedMnemonicLength =>
type == WalletType.monero
? moneroSeedMnemonicLength
: electrumSeedMnemonicLength;
@override
WalletCredentials getCredentials(dynamic options) {

View file

@ -143,6 +143,8 @@ import 'package:cw_monero/mnemonics/japanese.dart';
import 'package:cw_monero/mnemonics/russian.dart';
import 'package:cw_monero/mnemonics/spanish.dart';
import 'package:cw_monero/mnemonics/portuguese.dart';
import 'package:cw_monero/mnemonics/french.dart';
import 'package:cw_monero/mnemonics/italian.dart';
""";
const moneroCwPart = "part 'cw_monero.dart';";
const moneroContent = """