mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
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:
parent
4b4d8a4840
commit
d933743a72
3 changed files with 40 additions and 49 deletions
|
@ -37,8 +37,7 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
|
|||
spendKey = '',
|
||||
wif = '',
|
||||
address = '',
|
||||
super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel,
|
||||
type: type, isRecovery: true);
|
||||
super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel, type: type, isRecovery: true);
|
||||
|
||||
@observable
|
||||
int height;
|
||||
|
@ -58,13 +57,10 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
|
|||
bool get hasRestorationHeight => type == WalletType.monero || type == WalletType.wownero;
|
||||
|
||||
@override
|
||||
WalletCredentials getCredentialsFromRestoredWallet(
|
||||
dynamic options, RestoredWallet restoreWallet) {
|
||||
Future<WalletCredentials> getWalletCredentialsFromQRCredentials(
|
||||
RestoredWallet restoreWallet) async {
|
||||
final password = generateWalletPassword();
|
||||
|
||||
DerivationInfo? derivationInfo;
|
||||
derivationInfo ??= getDefaultCreateDerivation();
|
||||
|
||||
switch (restoreWallet.restoreMode) {
|
||||
case WalletRestoreMode.keys:
|
||||
switch (restoreWallet.type) {
|
||||
|
@ -116,12 +112,13 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
|
|||
);
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.litecoin:
|
||||
final derivationInfo = (await getDerivationInfoFromQRCredentials(restoreWallet)).first;
|
||||
return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
||||
name: name,
|
||||
mnemonic: restoreWallet.mnemonicSeed ?? '',
|
||||
password: password,
|
||||
passphrase: restoreWallet.passphrase,
|
||||
derivationType: derivationInfo!.derivationType!,
|
||||
derivationType: derivationInfo.derivationType!,
|
||||
derivationPath: derivationInfo.derivationPath!,
|
||||
);
|
||||
case WalletType.bitcoinCash:
|
||||
|
@ -139,11 +136,13 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
|
|||
passphrase: restoreWallet.passphrase,
|
||||
);
|
||||
case WalletType.nano:
|
||||
final derivationInfo =
|
||||
(await getDerivationInfoFromQRCredentials(restoreWallet)).first;
|
||||
return nano!.createNanoRestoreWalletFromSeedCredentials(
|
||||
name: name,
|
||||
mnemonic: restoreWallet.mnemonicSeed ?? '',
|
||||
password: password,
|
||||
derivationType: derivationInfo!.derivationType!,
|
||||
derivationType: derivationInfo.derivationType!,
|
||||
passphrase: restoreWallet.passphrase,
|
||||
);
|
||||
case WalletType.polygon:
|
||||
|
@ -183,8 +182,8 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
|
|||
}
|
||||
|
||||
@override
|
||||
Future<WalletBase> processFromRestoredWallet(
|
||||
WalletCredentials credentials, RestoredWallet restoreWallet) async {
|
||||
Future<WalletBase> processFromRestoredWallet(WalletCredentials credentials,
|
||||
RestoredWallet restoreWallet) async {
|
||||
try {
|
||||
switch (restoreWallet.restoreMode) {
|
||||
case WalletRestoreMode.keys:
|
||||
|
|
|
@ -142,6 +142,10 @@ class WalletRestoreFromQRCode {
|
|||
return WalletRestoreMode.seed;
|
||||
}
|
||||
|
||||
if ((type == WalletType.monero || type == WalletType.wownero)) {
|
||||
return WalletRestoreMode.seed;
|
||||
}
|
||||
|
||||
seedValue.split(' ').forEach((element) {
|
||||
if (!words.contains(element)) {
|
||||
throw Exception(
|
||||
|
|
|
@ -85,21 +85,9 @@ abstract class WalletCreationVMBase with Store {
|
|||
final dirPath = await pathForWalletDir(name: name, type: type);
|
||||
final path = await pathForWallet(name: name, type: type);
|
||||
|
||||
WalletCredentials credentials;
|
||||
if (restoreWallet != null) {
|
||||
if (restoreWallet.restoreMode == WalletRestoreMode.seed &&
|
||||
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 credentials = restoreWallet != null
|
||||
? await getWalletCredentialsFromQRCredentials(restoreWallet)
|
||||
: getCredentials(options);
|
||||
|
||||
final walletInfo = WalletInfo.external(
|
||||
id: WalletBase.idFor(name, type),
|
||||
|
@ -200,36 +188,36 @@ abstract class WalletCreationVMBase with Store {
|
|||
}
|
||||
}
|
||||
|
||||
Future<List<DerivationInfo>> getDerivationInfo(RestoredWallet restoreWallet) async {
|
||||
var list = <DerivationInfo>[];
|
||||
final walletType = restoreWallet.type;
|
||||
var appStore = getIt.get<AppStore>();
|
||||
var node = appStore.settingsStore.getCurrentNode(walletType);
|
||||
Future<List<DerivationInfo>> getDerivationInfoFromQRCredentials(RestoredWallet restoreWallet) async {
|
||||
var list = <DerivationInfo>[];
|
||||
final walletType = restoreWallet.type;
|
||||
var appStore = getIt.get<AppStore>();
|
||||
var node = appStore.settingsStore.getCurrentNode(walletType);
|
||||
|
||||
switch (walletType) {
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.litecoin:
|
||||
return bitcoin!.getDerivationsFromMnemonic(
|
||||
mnemonic: restoreWallet.mnemonicSeed!,
|
||||
node: node,
|
||||
);
|
||||
case WalletType.nano:
|
||||
return nanoUtil!.getDerivationsFromMnemonic(
|
||||
mnemonic: restoreWallet.mnemonicSeed!,
|
||||
node: node,
|
||||
);
|
||||
default:
|
||||
break;
|
||||
switch (walletType) {
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.litecoin:
|
||||
return bitcoin!.getDerivationsFromMnemonic(
|
||||
mnemonic: restoreWallet.mnemonicSeed!,
|
||||
node: node,
|
||||
passphrase: restoreWallet.passphrase,
|
||||
);
|
||||
case WalletType.nano:
|
||||
return nanoUtil!.getDerivationsFromMnemonic(
|
||||
mnemonic: restoreWallet.mnemonicSeed!,
|
||||
node: node,
|
||||
);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
WalletCredentials getCredentials(dynamic options) => throw UnimplementedError();
|
||||
|
||||
Future<WalletBase> process(WalletCredentials credentials) => throw UnimplementedError();
|
||||
|
||||
WalletCredentials getCredentialsFromRestoredWallet(
|
||||
dynamic options, RestoredWallet restoreWallet) =>
|
||||
Future<WalletCredentials> getWalletCredentialsFromQRCredentials(RestoredWallet restoreWallet) async =>
|
||||
throw UnimplementedError();
|
||||
|
||||
Future<WalletBase> processFromRestoredWallet(
|
||||
|
|
Loading…
Reference in a new issue