do not restore deterministic wallet if it's not one (#1676)

* do not restore deterministic wallet if it's not one

* [skip ci] update comment
This commit is contained in:
cyan 2024-09-15 17:48:07 +02:00 committed by GitHub
parent 7bf2fb9dce
commit 417de3669c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 3 deletions

View file

@ -123,7 +123,7 @@ void restoreWalletFromKeysSync(
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
final newWptr = spendKey != ""
var newWptr = (spendKey != "")
? monero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr,
path: path,
@ -149,6 +149,32 @@ void restoreWalletFromKeysSync(
message: monero.Wallet_errorString(newWptr));
}
// CW-712 - Try to restore deterministic wallet first, if the view key doesn't
// match the view key provided
if (spendKey != "") {
final viewKeyRestored = monero.Wallet_secretViewKey(newWptr);
if (viewKey != viewKeyRestored && viewKey != "") {
monero.WalletManager_closeWallet(wmPtr, newWptr, false);
File(path).deleteSync();
File(path+".keys").deleteSync();
newWptr = monero.WalletManager_createWalletFromKeys(
wmPtr,
path: path,
password: password,
restoreHeight: restoreHeight,
addressString: address,
viewKeyString: viewKey,
spendKeyString: spendKey,
nettype: 0,
);
final status = monero.Wallet_status(newWptr);
if (status != 0) {
throw WalletRestoreFromKeysException(
message: monero.Wallet_errorString(newWptr));
}
}
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;

View file

@ -140,7 +140,7 @@ void restoreWalletFromKeysSync(
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
final newWptr = spendKey != ""
var newWptr = (spendKey != "")
? wownero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr,
path: path,
@ -165,7 +165,31 @@ void restoreWalletFromKeysSync(
throw WalletRestoreFromKeysException(
message: wownero.Wallet_errorString(newWptr));
}
// CW-712 - Try to restore deterministic wallet first, if the view key doesn't
// match the view key provided
if (spendKey != "") {
final viewKeyRestored = wownero.Wallet_secretViewKey(newWptr);
if (viewKey != viewKeyRestored && viewKey != "") {
wownero.WalletManager_closeWallet(wmPtr, newWptr, false);
File(path).deleteSync();
File(path+".keys").deleteSync();
newWptr = wownero.WalletManager_createWalletFromKeys(
wmPtr,
path: path,
password: password,
restoreHeight: restoreHeight,
addressString: address,
viewKeyString: viewKey,
spendKeyString: spendKey,
nettype: 0,
);
final status = wownero.Wallet_status(newWptr);
if (status != 0) {
throw WalletRestoreFromKeysException(
message: wownero.Wallet_errorString(newWptr));
}
}
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;