diff options
author | tobtoht <thotbot@protonmail.com> | 2021-06-04 18:07:31 +0200 |
---|---|---|
committer | tobtoht <thotbot@protonmail.com> | 2021-06-04 18:16:10 +0200 |
commit | 1aa1850ba509c83dd19ea6328e161efdbbf62d86 (patch) | |
tree | b73958763aa78a46c497c143a45456f51520ce39 /src/wallet | |
parent | Merge pull request #7735 (diff) | |
download | monero-1aa1850ba509c83dd19ea6328e161efdbbf62d86.tar.xz |
wallet_api: signMessage: add sign with subaddress
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/api/wallet.cpp | 19 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 2 | ||||
-rw-r--r-- | src/wallet/api/wallet2_api.h | 2 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index db3049f9e..fdc328342 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -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) { - return m_wallet->sign(message, tools::wallet2::sign_with_spend_key); + 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 diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index ce2d7d7e4..c6568157a 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -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; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index e34332734..6e9ca7f40 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -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) |