aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-10-31 14:09:19 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-12-31 08:44:36 +0000
commitd64e5aa71936d86f91d3f45a9da0468f97078409 (patch)
tree1376f2390b9c971f95b9e188d38f899af6a6e84f /src/wallet
parentMerge pull request #6044 (diff)
downloadmonero-d64e5aa71936d86f91d3f45a9da0468f97078409.tar.xz
wallet: allow message sign/verify for subaddresses
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp18
-rw-r--r--src/wallet/wallet2.h2
-rw-r--r--src/wallet/wallet_rpc_server.cpp2
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h6
4 files changed, 23 insertions, 5 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 9b3e7e8b4..48b8bbf7e 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -11777,13 +11777,27 @@ void wallet2::set_account_tag_description(const std::string& tag, const std::str
m_account_tags.first[tag] = description;
}
-std::string wallet2::sign(const std::string &data) const
+std::string wallet2::sign(const std::string &data, cryptonote::subaddress_index index) const
{
crypto::hash hash;
crypto::cn_fast_hash(data.data(), data.size(), hash);
const cryptonote::account_keys &keys = m_account.get_keys();
crypto::signature signature;
- crypto::generate_signature(hash, keys.m_account_address.m_spend_public_key, keys.m_spend_secret_key, signature);
+ crypto::secret_key skey;
+ crypto::public_key pkey;
+ if (index.is_zero())
+ {
+ skey = keys.m_spend_secret_key;
+ pkey = keys.m_account_address.m_spend_public_key;
+ }
+ else
+ {
+ skey = keys.m_spend_secret_key;
+ crypto::secret_key m = m_account.get_device().get_subaddress_secret_key(keys.m_view_secret_key, index);
+ sc_add((unsigned char*)&skey, (unsigned char*)&m, (unsigned char*)&skey);
+ secret_key_to_public_key(skey, pkey);
+ }
+ crypto::generate_signature(hash, pkey, skey, signature);
return std::string("SigV1") + tools::base58::encode(std::string((const char *)&signature, sizeof(signature)));
}
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 640565a4e..38e3afd69 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1182,7 +1182,7 @@ private:
*/
void set_account_tag_description(const std::string& tag, const std::string& description);
- std::string sign(const std::string &data) const;
+ std::string sign(const std::string &data, cryptonote::subaddress_index index = {0, 0}) const;
bool verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const;
/*!
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index ec21b2897..b5b572bc8 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -1943,7 +1943,7 @@ namespace tools
return false;
}
- res.signature = m_wallet->sign(req.data);
+ res.signature = m_wallet->sign(req.data, {req.account_index, req.address_index});
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 0c86f404d..c823417eb 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -1591,9 +1591,13 @@ namespace wallet_rpc
struct request_t
{
std::string data;
+ uint32_t account_index;
+ uint32_t address_index;
BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(data);
+ KV_SERIALIZE(data)
+ KV_SERIALIZE_OPT(account_index, 0u)
+ KV_SERIALIZE_OPT(address_index, 0u)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;