mirror of
https://github.com/monero-project/monero.git
synced 2024-12-26 00:59:24 -05:00
Merge pull request #6069
d64e5aa7
wallet: allow message sign/verify for subaddresses (moneromooo-monero)
This commit is contained in:
commit
3b224bb99d
@ -214,7 +214,7 @@ namespace
|
|||||||
const char* USAGE_GET_TX_NOTE("get_tx_note <txid>");
|
const char* USAGE_GET_TX_NOTE("get_tx_note <txid>");
|
||||||
const char* USAGE_GET_DESCRIPTION("get_description");
|
const char* USAGE_GET_DESCRIPTION("get_description");
|
||||||
const char* USAGE_SET_DESCRIPTION("set_description [free text note]");
|
const char* USAGE_SET_DESCRIPTION("set_description [free text note]");
|
||||||
const char* USAGE_SIGN("sign <filename>");
|
const char* USAGE_SIGN("sign [<account_index>,<address_index>] <filename>");
|
||||||
const char* USAGE_VERIFY("verify <filename> <address> <signature>");
|
const char* USAGE_VERIFY("verify <filename> <address> <signature>");
|
||||||
const char* USAGE_EXPORT_KEY_IMAGES("export_key_images [all] <filename>");
|
const char* USAGE_EXPORT_KEY_IMAGES("export_key_images [all] <filename>");
|
||||||
const char* USAGE_IMPORT_KEY_IMAGES("import_key_images <filename>");
|
const char* USAGE_IMPORT_KEY_IMAGES("import_key_images <filename>");
|
||||||
@ -3346,7 +3346,7 @@ simple_wallet::simple_wallet()
|
|||||||
m_cmd_binder.set_handler("sign",
|
m_cmd_binder.set_handler("sign",
|
||||||
boost::bind(&simple_wallet::on_command, this, &simple_wallet::sign, _1),
|
boost::bind(&simple_wallet::on_command, this, &simple_wallet::sign, _1),
|
||||||
tr(USAGE_SIGN),
|
tr(USAGE_SIGN),
|
||||||
tr("Sign the contents of a file."));
|
tr("Sign the contents of a file with the given subaddress (or the main address if not specified)"));
|
||||||
m_cmd_binder.set_handler("verify",
|
m_cmd_binder.set_handler("verify",
|
||||||
boost::bind(&simple_wallet::on_command, this, &simple_wallet::verify, _1),
|
boost::bind(&simple_wallet::on_command, this, &simple_wallet::verify, _1),
|
||||||
tr(USAGE_VERIFY),
|
tr(USAGE_VERIFY),
|
||||||
@ -9572,7 +9572,7 @@ bool simple_wallet::sign(const std::vector<std::string> &args)
|
|||||||
fail_msg_writer() << tr("command not supported by HW wallet");
|
fail_msg_writer() << tr("command not supported by HW wallet");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.size() != 1)
|
if (args.size() != 1 && args.size() != 2)
|
||||||
{
|
{
|
||||||
PRINT_USAGE(USAGE_SIGN);
|
PRINT_USAGE(USAGE_SIGN);
|
||||||
return true;
|
return true;
|
||||||
@ -9588,7 +9588,20 @@ bool simple_wallet::sign(const std::vector<std::string> &args)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string filename = args[0];
|
subaddress_index index{0, 0};
|
||||||
|
if (args.size() == 2)
|
||||||
|
{
|
||||||
|
unsigned int a, b;
|
||||||
|
if (sscanf(args[0].c_str(), "%u,%u", &a, &b) != 2)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << tr("Invalid subaddress index format");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
index.major = a;
|
||||||
|
index.minor = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &filename = args.back();
|
||||||
std::string data;
|
std::string data;
|
||||||
bool r = m_wallet->load_from_file(filename, data);
|
bool r = m_wallet->load_from_file(filename, data);
|
||||||
if (!r)
|
if (!r)
|
||||||
@ -9599,7 +9612,7 @@ bool simple_wallet::sign(const std::vector<std::string> &args)
|
|||||||
|
|
||||||
SCOPED_WALLET_UNLOCK();
|
SCOPED_WALLET_UNLOCK();
|
||||||
|
|
||||||
std::string signature = m_wallet->sign(data);
|
std::string signature = m_wallet->sign(data, index);
|
||||||
success_msg_writer() << signature;
|
success_msg_writer() << signature;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11823,13 +11823,27 @@ void wallet2::set_account_tag_description(const std::string& tag, const std::str
|
|||||||
m_account_tags.first[tag] = description;
|
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::hash hash;
|
||||||
crypto::cn_fast_hash(data.data(), data.size(), hash);
|
crypto::cn_fast_hash(data.data(), data.size(), hash);
|
||||||
const cryptonote::account_keys &keys = m_account.get_keys();
|
const cryptonote::account_keys &keys = m_account.get_keys();
|
||||||
crypto::signature signature;
|
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)));
|
return std::string("SigV1") + tools::base58::encode(std::string((const char *)&signature, sizeof(signature)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1185,7 +1185,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
void set_account_tag_description(const std::string& tag, const std::string& description);
|
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;
|
bool verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1963,7 +1963,7 @@ namespace tools
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.signature = m_wallet->sign(req.data);
|
res.signature = m_wallet->sign(req.data, {req.account_index, req.address_index});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1597,9 +1597,13 @@ namespace wallet_rpc
|
|||||||
struct request_t
|
struct request_t
|
||||||
{
|
{
|
||||||
std::string data;
|
std::string data;
|
||||||
|
uint32_t account_index;
|
||||||
|
uint32_t address_index;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
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()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
typedef epee::misc_utils::struct_init<request_t> request;
|
typedef epee::misc_utils::struct_init<request_t> request;
|
||||||
|
@ -43,7 +43,8 @@ from framework.wallet import Wallet
|
|||||||
class MessageSigningTest():
|
class MessageSigningTest():
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.create()
|
self.create()
|
||||||
self.check_signing()
|
self.check_signing(False)
|
||||||
|
self.check_signing(True)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
print('Creating wallets')
|
print('Creating wallets')
|
||||||
@ -65,20 +66,34 @@ class MessageSigningTest():
|
|||||||
assert res.address == self.address[i]
|
assert res.address == self.address[i]
|
||||||
assert res.seed == seeds[i]
|
assert res.seed == seeds[i]
|
||||||
|
|
||||||
def check_signing(self):
|
def check_signing(self, subaddress):
|
||||||
print('Signing/verifing messages')
|
print('Signing/verifing messages with ' + ('subaddress' if subaddress else 'standard address'))
|
||||||
messages = ['foo', '']
|
messages = ['foo', '']
|
||||||
|
if subaddress:
|
||||||
|
address = []
|
||||||
|
for i in range(2):
|
||||||
|
res = self.wallet[i].create_account()
|
||||||
|
if i == 0:
|
||||||
|
account_index = res.account_index
|
||||||
|
res = self.wallet[i].create_address(account_index = account_index)
|
||||||
|
if i == 0:
|
||||||
|
address_index = res.address_index
|
||||||
|
address.append(res.address)
|
||||||
|
else:
|
||||||
|
address = [self.address[0], self.address[1]]
|
||||||
|
account_index = 0
|
||||||
|
address_index = 0
|
||||||
for message in messages:
|
for message in messages:
|
||||||
res = self.wallet[0].sign(message)
|
res = self.wallet[0].sign(message, account_index = account_index, address_index = address_index)
|
||||||
signature = res.signature
|
signature = res.signature
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
res = self.wallet[i].verify(message, self.address[0], signature)
|
res = self.wallet[i].verify(message, address[0], signature)
|
||||||
assert res.good
|
assert res.good
|
||||||
res = self.wallet[i].verify('different', self.address[0], signature)
|
res = self.wallet[i].verify('different', address[0], signature)
|
||||||
assert not res.good
|
assert not res.good
|
||||||
res = self.wallet[i].verify(message, self.address[1], signature)
|
res = self.wallet[i].verify(message, address[1], signature)
|
||||||
assert not res.good
|
assert not res.good
|
||||||
res = self.wallet[i].verify(message, self.address[0], signature + 'x')
|
res = self.wallet[i].verify(message, address[0], signature + 'x')
|
||||||
assert not res.good
|
assert not res.good
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -706,11 +706,13 @@ class Wallet(object):
|
|||||||
}
|
}
|
||||||
return self.rpc.send_json_rpc_request(check_reserve_proof)
|
return self.rpc.send_json_rpc_request(check_reserve_proof)
|
||||||
|
|
||||||
def sign(self, data):
|
def sign(self, data, account_index = 0, address_index = 0):
|
||||||
sign = {
|
sign = {
|
||||||
'method': 'sign',
|
'method': 'sign',
|
||||||
'params' : {
|
'params' : {
|
||||||
'data': data,
|
'data': data,
|
||||||
|
'account_index': account_index,
|
||||||
|
'address_index': address_index,
|
||||||
},
|
},
|
||||||
'jsonrpc': '2.0',
|
'jsonrpc': '2.0',
|
||||||
'id': '0'
|
'id': '0'
|
||||||
|
Loading…
Reference in New Issue
Block a user