mirror of
https://github.com/monero-project/monero.git
synced 2024-12-14 20:36:31 +02:00
use deterministic viewkey if not supplied
This commit is contained in:
parent
8a7b3ff138
commit
4764929ecb
@ -554,18 +554,26 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse view secret key
|
// parse view secret key
|
||||||
|
bool has_viewkey = true;
|
||||||
|
crypto::secret_key viewkey;
|
||||||
if (viewkey_string.empty()) {
|
if (viewkey_string.empty()) {
|
||||||
setStatusError(tr("No view key supplied, cancelled"));
|
if(has_spendkey) {
|
||||||
|
has_viewkey = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setStatusError(tr("Neither view key nor spend key supplied, cancelled"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(has_viewkey) {
|
||||||
cryptonote::blobdata viewkey_data;
|
cryptonote::blobdata viewkey_data;
|
||||||
if(!epee::string_tools::parse_hexstr_to_binbuff(viewkey_string, viewkey_data) || viewkey_data.size() != sizeof(crypto::secret_key))
|
if(!epee::string_tools::parse_hexstr_to_binbuff(viewkey_string, viewkey_data) || viewkey_data.size() != sizeof(crypto::secret_key))
|
||||||
{
|
{
|
||||||
setStatusError(tr("failed to parse secret view key"));
|
setStatusError(tr("failed to parse secret view key"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
crypto::secret_key viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
|
viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
|
||||||
|
}
|
||||||
// check the spend and view keys match the given address
|
// check the spend and view keys match the given address
|
||||||
crypto::public_key pkey;
|
crypto::public_key pkey;
|
||||||
if(has_spendkey) {
|
if(has_spendkey) {
|
||||||
@ -578,6 +586,7 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(has_viewkey) {
|
||||||
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
|
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
|
||||||
setStatusError(tr("failed to verify secret view key"));
|
setStatusError(tr("failed to verify secret view key"));
|
||||||
return false;
|
return false;
|
||||||
@ -586,18 +595,23 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
|
|||||||
setStatusError(tr("view key does not match address"));
|
setStatusError(tr("view key does not match address"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (has_spendkey) {
|
if (has_spendkey && has_viewkey) {
|
||||||
m_wallet->generate(path, password, info.address, spendkey, viewkey);
|
m_wallet->generate(path, password, info.address, spendkey, viewkey);
|
||||||
setSeedLanguage(language);
|
LOG_PRINT_L1("Generated new wallet from spend key and view key");
|
||||||
LOG_PRINT_L1("Generated new wallet from keys with seed language: " + language);
|
|
||||||
}
|
}
|
||||||
else {
|
if(!has_spendkey && has_viewkey) {
|
||||||
m_wallet->generate(path, password, info.address, viewkey);
|
m_wallet->generate(path, password, info.address, viewkey);
|
||||||
LOG_PRINT_L1("Generated new view only wallet from keys");
|
LOG_PRINT_L1("Generated new view only wallet from keys");
|
||||||
}
|
}
|
||||||
|
if(has_spendkey && !has_viewkey) {
|
||||||
|
m_wallet->generate(path, password, spendkey, true, false, false);
|
||||||
|
setSeedLanguage(language);
|
||||||
|
LOG_PRINT_L1("Generated deterministic wallet from spend key with seed language: " + language);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user