Wallet API: all recover options with password

also renamed memo => mnemonic in api method parms
This commit is contained in:
m2049r 2018-01-11 16:12:27 +01:00
parent 35d5aa36c9
commit 939629e837
5 changed files with 110 additions and 12 deletions

View File

@ -457,6 +457,16 @@ bool WalletImpl::recoverFromKeys(const std::string &path,
const std::string &address_string, const std::string &address_string,
const std::string &viewkey_string, const std::string &viewkey_string,
const std::string &spendkey_string) const std::string &spendkey_string)
{
return recoverFromKeysWithPassword(path, "", language, address_string, viewkey_string, spendkey_string);
}
bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
const std::string &password,
const std::string &language,
const std::string &address_string,
const std::string &viewkey_string,
const std::string &spendkey_string)
{ {
cryptonote::address_parse_info info; cryptonote::address_parse_info info;
if(!get_account_address_from_str(info, m_wallet->testnet(), address_string)) if(!get_account_address_from_str(info, m_wallet->testnet(), address_string))
@ -524,12 +534,12 @@ bool WalletImpl::recoverFromKeys(const std::string &path,
try try
{ {
if (has_spendkey) { if (has_spendkey) {
m_wallet->generate(path, "", info.address, spendkey, viewkey); m_wallet->generate(path, password, info.address, spendkey, viewkey);
setSeedLanguage(language); setSeedLanguage(language);
LOG_PRINT_L1("Generated new wallet from keys with seed language: " + language); LOG_PRINT_L1("Generated new wallet from keys with seed language: " + language);
} }
else { else {
m_wallet->generate(path, "", 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");
} }
@ -569,6 +579,11 @@ bool WalletImpl::open(const std::string &path, const std::string &password)
} }
bool WalletImpl::recover(const std::string &path, const std::string &seed) bool WalletImpl::recover(const std::string &path, const std::string &seed)
{
return recover(path, "", seed);
}
bool WalletImpl::recover(const std::string &path, const std::string &password, const std::string &seed)
{ {
clearStatus(); clearStatus();
m_errorString.clear(); m_errorString.clear();
@ -590,7 +605,7 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed)
try { try {
m_wallet->set_seed_language(old_language); m_wallet->set_seed_language(old_language);
m_wallet->generate(path, "", recovery_key, true, false); m_wallet->generate(path, password, recovery_key, true, false);
} catch (const std::exception &e) { } catch (const std::exception &e) {
m_status = Status_Critical; m_status = Status_Critical;

View File

@ -59,7 +59,18 @@ public:
bool createWatchOnly(const std::string &path, const std::string &password, bool createWatchOnly(const std::string &path, const std::string &password,
const std::string &language) const; const std::string &language) const;
bool open(const std::string &path, const std::string &password); bool open(const std::string &path, const std::string &password);
bool recover(const std::string &path,const std::string &password,
const std::string &seed);
bool recoverFromKeysWithPassword(const std::string &path,
const std::string &password,
const std::string &language,
const std::string &address_string,
const std::string &viewkey_string,
const std::string &spendkey_string = "");
// following two methods are deprecated since they create passwordless wallets
// use the two equivalent methods above
bool recover(const std::string &path, const std::string &seed); bool recover(const std::string &path, const std::string &seed);
// deprecated: use recoverFromKeysWithPassword() instead
bool recoverFromKeys(const std::string &path, bool recoverFromKeys(const std::string &path,
const std::string &language, const std::string &language,
const std::string &address_string, const std::string &address_string,

View File

@ -749,7 +749,7 @@ struct WalletManager
* \brief Creates new wallet * \brief Creates new wallet
* \param path Name of wallet file * \param path Name of wallet file
* \param password Password of wallet file * \param password Password of wallet file
* \param language Language to be used to generate electrum seed memo * \param language Language to be used to generate electrum seed mnemonic
* \return Wallet instance (Wallet::status() needs to be called to check if created successfully) * \return Wallet instance (Wallet::status() needs to be called to check if created successfully)
*/ */
virtual Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language, bool testnet = false) = 0; virtual Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language, bool testnet = false) = 0;
@ -763,16 +763,51 @@ struct WalletManager
virtual Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) = 0; virtual Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) = 0;
/*! /*!
* \brief recovers existing wallet using memo (electrum seed) * \brief recovers existing wallet using mnemonic (electrum seed)
* \param path Name of wallet file to be created * \param path Name of wallet file to be created
* \param memo memo (25 words electrum seed) * \param password Password of wallet file
* \param mnemonic mnemonic (25 words electrum seed)
* \param testnet testnet * \param testnet testnet
* \param restoreHeight restore from start height * \param restoreHeight restore from start height
* \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully) * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
*/ */
virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet = false, uint64_t restoreHeight = 0) = 0; virtual Wallet * recoveryWallet(const std::string &path, const std::string &password, const std::string &mnemonic,
bool testnet = false, uint64_t restoreHeight = 0) = 0;
/*! /*!
* \deprecated this method creates a wallet WITHOUT a passphrase, use the alternate recoverWallet() method
* \brief recovers existing wallet using mnemonic (electrum seed)
* \param path Name of wallet file to be created
* \param mnemonic mnemonic (25 words electrum seed)
* \param testnet testnet
* \param restoreHeight restore from start height
* \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
*/
virtual Wallet * recoveryWallet(const std::string &path, const std::string &mnemonic, bool testnet = false, uint64_t restoreHeight = 0) = 0;
/*!
* \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
* \param path Name of wallet file to be created
* \param password Password of wallet file
* \param language language
* \param testnet testnet
* \param restoreHeight restore from start height
* \param addressString public address
* \param viewKeyString view key
* \param spendKeyString spend key (optional)
* \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
*/
virtual Wallet * createWalletFromKeys(const std::string &path,
const std::string &password,
const std::string &language,
bool testnet,
uint64_t restoreHeight,
const std::string &addressString,
const std::string &viewKeyString,
const std::string &spendKeyString = "") = 0;
/*!
* \deprecated this method creates a wallet WITHOUT a passphrase, use createWalletFromKeys(..., password, ...) instead
* \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted * \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
* \param path Name of wallet file to be created * \param path Name of wallet file to be created
* \param language language * \param language language

View File

@ -76,17 +76,39 @@ Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string
return wallet; return wallet;
} }
Wallet *WalletManagerImpl::recoveryWallet(const std::string &path, const std::string &memo, bool testnet, uint64_t restoreHeight) Wallet *WalletManagerImpl::recoveryWallet(const std::string &path, const std::string &mnemonic, bool testnet, uint64_t restoreHeight)
{
return recoveryWallet(path, "", mnemonic, testnet, restoreHeight);
}
Wallet *WalletManagerImpl::createWalletFromKeys(const std::string &path,
const std::string &language,
bool testnet,
uint64_t restoreHeight,
const std::string &addressString,
const std::string &viewKeyString,
const std::string &spendKeyString)
{
return createWalletFromKeys(path, "", language, testnet, restoreHeight,
addressString, viewKeyString, spendKeyString);
}
Wallet *WalletManagerImpl::recoveryWallet(const std::string &path,
const std::string &password,
const std::string &mnemonic,
bool testnet,
uint64_t restoreHeight)
{ {
WalletImpl * wallet = new WalletImpl(testnet); WalletImpl * wallet = new WalletImpl(testnet);
if(restoreHeight > 0){ if(restoreHeight > 0){
wallet->setRefreshFromBlockHeight(restoreHeight); wallet->setRefreshFromBlockHeight(restoreHeight);
} }
wallet->recover(path, memo); wallet->recover(path, password, mnemonic);
return wallet; return wallet;
} }
Wallet *WalletManagerImpl::createWalletFromKeys(const std::string &path, Wallet *WalletManagerImpl::createWalletFromKeys(const std::string &path,
const std::string &password,
const std::string &language, const std::string &language,
bool testnet, bool testnet,
uint64_t restoreHeight, uint64_t restoreHeight,
@ -98,7 +120,7 @@ Wallet *WalletManagerImpl::createWalletFromKeys(const std::string &path,
if(restoreHeight > 0){ if(restoreHeight > 0){
wallet->setRefreshFromBlockHeight(restoreHeight); wallet->setRefreshFromBlockHeight(restoreHeight);
} }
wallet->recoverFromKeys(path, language, addressString, viewKeyString, spendKeyString); wallet->recoverFromKeysWithPassword(path, password, language, addressString, viewKeyString, spendKeyString);
return wallet; return wallet;
} }

View File

@ -40,7 +40,22 @@ public:
Wallet * createWallet(const std::string &path, const std::string &password, Wallet * createWallet(const std::string &path, const std::string &password,
const std::string &language, bool testnet); const std::string &language, bool testnet);
Wallet * openWallet(const std::string &path, const std::string &password, bool testnet); Wallet * openWallet(const std::string &path, const std::string &password, bool testnet);
virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet, uint64_t restoreHeight); virtual Wallet * recoveryWallet(const std::string &path,
const std::string &password,
const std::string &mnemonic,
bool testnet,
uint64_t restoreHeight);
virtual Wallet * createWalletFromKeys(const std::string &path,
const std::string &password,
const std::string &language,
bool testnet,
uint64_t restoreHeight,
const std::string &addressString,
const std::string &viewKeyString,
const std::string &spendKeyString = "");
// next two methods are deprecated - use the above version which allow setting of a password
virtual Wallet * recoveryWallet(const std::string &path, const std::string &mnemonic, bool testnet, uint64_t restoreHeight);
// deprecated: use createWalletFromKeys(..., password, ...) instead
virtual Wallet * createWalletFromKeys(const std::string &path, virtual Wallet * createWalletFromKeys(const std::string &path,
const std::string &language, const std::string &language,
bool testnet, bool testnet,