wallet_api: signMessage: add sign with subaddress

This commit is contained in:
tobtoht 2021-06-04 18:07:31 +02:00
parent 1c8e598172
commit 1aa1850ba5
3 changed files with 19 additions and 4 deletions

View file

@ -2063,9 +2063,24 @@ bool WalletImpl::checkReserveProof(const std::string &address, const std::string
}
}
std::string WalletImpl::signMessage(const std::string &message)
std::string WalletImpl::signMessage(const std::string &message, const std::string &address)
{
if (address.empty()) {
return m_wallet->sign(message, tools::wallet2::sign_with_spend_key);
}
cryptonote::address_parse_info info;
if (!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), address)) {
setStatusError(tr("Failed to parse address"));
return "";
}
auto index = m_wallet->get_subaddress_index(info.address);
if (!index) {
setStatusError(tr("Address doesn't belong to the wallet"));
return "";
}
return m_wallet->sign(message, tools::wallet2::sign_with_spend_key, *index);
}
bool WalletImpl::verifySignedMessage(const std::string &message, const std::string &address, const std::string &signature) const

View file

@ -196,7 +196,7 @@ public:
virtual bool checkSpendProof(const std::string &txid, const std::string &message, const std::string &signature, bool &good) const override;
virtual std::string getReserveProof(bool all, uint32_t account_index, uint64_t amount, const std::string &message) const override;
virtual bool checkReserveProof(const std::string &address, const std::string &message, const std::string &signature, bool &good, uint64_t &total, uint64_t &spent) const override;
virtual std::string signMessage(const std::string &message) override;
virtual std::string signMessage(const std::string &message, const std::string &address) override;
virtual bool verifySignedMessage(const std::string &message, const std::string &address, const std::string &signature) const override;
virtual std::string signMultisigParticipant(const std::string &message) const override;
virtual bool verifyMessageWithPublicKey(const std::string &message, const std::string &publicKey, const std::string &signature) const override;

View file

@ -993,7 +993,7 @@ struct Wallet
* \param message - the message to sign (arbitrary byte data)
* \return the signature
*/
virtual std::string signMessage(const std::string &message) = 0;
virtual std::string signMessage(const std::string &message, const std::string &address = "") = 0;
/*!
* \brief verifySignedMessage - verify a signature matches a given message
* \param message - the message (arbitrary byte data)