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/api/wallet.cpp | |
parent | Merge pull request #7735 (diff) | |
download | monero-1aa1850ba509c83dd19ea6328e161efdbbf62d86.tar.xz |
wallet_api: signMessage: add sign with subaddress
Diffstat (limited to 'src/wallet/api/wallet.cpp')
-rw-r--r-- | src/wallet/api/wallet.cpp | 19 |
1 files changed, 17 insertions, 2 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 |