Cw 772 restore from qr generates different wallet (#1721)

* fix derivation info for QR restoring

* allow all available seed languages for Monero

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii 2024-10-04 22:04:23 +03:00 committed by GitHub
parent 4b4d8a4840
commit d933743a72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 49 deletions

View file

@ -37,8 +37,7 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
spendKey = '', spendKey = '',
wif = '', wif = '',
address = '', address = '',
super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel, super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel, type: type, isRecovery: true);
type: type, isRecovery: true);
@observable @observable
int height; int height;
@ -58,13 +57,10 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
bool get hasRestorationHeight => type == WalletType.monero || type == WalletType.wownero; bool get hasRestorationHeight => type == WalletType.monero || type == WalletType.wownero;
@override @override
WalletCredentials getCredentialsFromRestoredWallet( Future<WalletCredentials> getWalletCredentialsFromQRCredentials(
dynamic options, RestoredWallet restoreWallet) { RestoredWallet restoreWallet) async {
final password = generateWalletPassword(); final password = generateWalletPassword();
DerivationInfo? derivationInfo;
derivationInfo ??= getDefaultCreateDerivation();
switch (restoreWallet.restoreMode) { switch (restoreWallet.restoreMode) {
case WalletRestoreMode.keys: case WalletRestoreMode.keys:
switch (restoreWallet.type) { switch (restoreWallet.type) {
@ -116,12 +112,13 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
); );
case WalletType.bitcoin: case WalletType.bitcoin:
case WalletType.litecoin: case WalletType.litecoin:
final derivationInfo = (await getDerivationInfoFromQRCredentials(restoreWallet)).first;
return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials( return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
name: name, name: name,
mnemonic: restoreWallet.mnemonicSeed ?? '', mnemonic: restoreWallet.mnemonicSeed ?? '',
password: password, password: password,
passphrase: restoreWallet.passphrase, passphrase: restoreWallet.passphrase,
derivationType: derivationInfo!.derivationType!, derivationType: derivationInfo.derivationType!,
derivationPath: derivationInfo.derivationPath!, derivationPath: derivationInfo.derivationPath!,
); );
case WalletType.bitcoinCash: case WalletType.bitcoinCash:
@ -139,11 +136,13 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
passphrase: restoreWallet.passphrase, passphrase: restoreWallet.passphrase,
); );
case WalletType.nano: case WalletType.nano:
final derivationInfo =
(await getDerivationInfoFromQRCredentials(restoreWallet)).first;
return nano!.createNanoRestoreWalletFromSeedCredentials( return nano!.createNanoRestoreWalletFromSeedCredentials(
name: name, name: name,
mnemonic: restoreWallet.mnemonicSeed ?? '', mnemonic: restoreWallet.mnemonicSeed ?? '',
password: password, password: password,
derivationType: derivationInfo!.derivationType!, derivationType: derivationInfo.derivationType!,
passphrase: restoreWallet.passphrase, passphrase: restoreWallet.passphrase,
); );
case WalletType.polygon: case WalletType.polygon:
@ -183,8 +182,8 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
} }
@override @override
Future<WalletBase> processFromRestoredWallet( Future<WalletBase> processFromRestoredWallet(WalletCredentials credentials,
WalletCredentials credentials, RestoredWallet restoreWallet) async { RestoredWallet restoreWallet) async {
try { try {
switch (restoreWallet.restoreMode) { switch (restoreWallet.restoreMode) {
case WalletRestoreMode.keys: case WalletRestoreMode.keys:

View file

@ -142,6 +142,10 @@ class WalletRestoreFromQRCode {
return WalletRestoreMode.seed; return WalletRestoreMode.seed;
} }
if ((type == WalletType.monero || type == WalletType.wownero)) {
return WalletRestoreMode.seed;
}
seedValue.split(' ').forEach((element) { seedValue.split(' ').forEach((element) {
if (!words.contains(element)) { if (!words.contains(element)) {
throw Exception( throw Exception(

View file

@ -85,21 +85,9 @@ abstract class WalletCreationVMBase with Store {
final dirPath = await pathForWalletDir(name: name, type: type); final dirPath = await pathForWalletDir(name: name, type: type);
final path = await pathForWallet(name: name, type: type); final path = await pathForWallet(name: name, type: type);
WalletCredentials credentials; final credentials = restoreWallet != null
if (restoreWallet != null) { ? await getWalletCredentialsFromQRCredentials(restoreWallet)
if (restoreWallet.restoreMode == WalletRestoreMode.seed && : getCredentials(options);
options == null &&
(type == WalletType.nano ||
type == WalletType.bitcoin ||
type == WalletType.litecoin)) {
final derivationInfo = await getDerivationInfo(restoreWallet);
options ??= {};
options["derivationInfo"] = derivationInfo.first;
}
credentials = getCredentialsFromRestoredWallet(options, restoreWallet);
} else {
credentials = getCredentials(options);
}
final walletInfo = WalletInfo.external( final walletInfo = WalletInfo.external(
id: WalletBase.idFor(name, type), id: WalletBase.idFor(name, type),
@ -200,36 +188,36 @@ abstract class WalletCreationVMBase with Store {
} }
} }
Future<List<DerivationInfo>> getDerivationInfo(RestoredWallet restoreWallet) async { Future<List<DerivationInfo>> getDerivationInfoFromQRCredentials(RestoredWallet restoreWallet) async {
var list = <DerivationInfo>[]; var list = <DerivationInfo>[];
final walletType = restoreWallet.type; final walletType = restoreWallet.type;
var appStore = getIt.get<AppStore>(); var appStore = getIt.get<AppStore>();
var node = appStore.settingsStore.getCurrentNode(walletType); var node = appStore.settingsStore.getCurrentNode(walletType);
switch (walletType) { switch (walletType) {
case WalletType.bitcoin: case WalletType.bitcoin:
case WalletType.litecoin: case WalletType.litecoin:
return bitcoin!.getDerivationsFromMnemonic( return bitcoin!.getDerivationsFromMnemonic(
mnemonic: restoreWallet.mnemonicSeed!, mnemonic: restoreWallet.mnemonicSeed!,
node: node, node: node,
); passphrase: restoreWallet.passphrase,
case WalletType.nano: );
return nanoUtil!.getDerivationsFromMnemonic( case WalletType.nano:
mnemonic: restoreWallet.mnemonicSeed!, return nanoUtil!.getDerivationsFromMnemonic(
node: node, mnemonic: restoreWallet.mnemonicSeed!,
); node: node,
default: );
break; default:
break;
}
return list;
} }
return list;
}
WalletCredentials getCredentials(dynamic options) => throw UnimplementedError(); WalletCredentials getCredentials(dynamic options) => throw UnimplementedError();
Future<WalletBase> process(WalletCredentials credentials) => throw UnimplementedError(); Future<WalletBase> process(WalletCredentials credentials) => throw UnimplementedError();
WalletCredentials getCredentialsFromRestoredWallet( Future<WalletCredentials> getWalletCredentialsFromQRCredentials(RestoredWallet restoreWallet) async =>
dynamic options, RestoredWallet restoreWallet) =>
throw UnimplementedError(); throw UnimplementedError();
Future<WalletBase> processFromRestoredWallet( Future<WalletBase> processFromRestoredWallet(