LNS: Serialize owner if not specified, use subaddress keys if possible

- Also fix a subtle bug that use to always default a the wallet's spend
key in update mappings even if no owner or backup owner was specified
for update.
This commit is contained in:
Doyle 2020-03-13 18:09:47 +11:00
parent 2d8c2ba7ef
commit 28cecfe558
5 changed files with 17 additions and 5 deletions

View File

@ -6515,6 +6515,7 @@ bool simple_wallet::lns_make_update_mapping_signature(const std::vector<std::str
owner.size() ? &owner : nullptr,
backup_owner.size() ? &backup_owner : nullptr,
signature_binary,
m_current_subaddress_account,
&reason))
tools::success_msg_writer() << "signature=" << epee::string_tools::pod_to_hex(signature_binary.ed25519);
else

View File

@ -8446,6 +8446,7 @@ static lns_prepared_args prepare_tx_extra_loki_name_system_values(wallet2 const
std::string const *owner,
std::string const *backup_owner,
bool make_signature,
uint32_t account_index,
std::string *reason)
{
lns_prepared_args result = {};
@ -8508,8 +8509,12 @@ static lns_prepared_args prepare_tx_extra_loki_name_system_values(wallet2 const
if (make_signature)
{
cryptonote::subaddress_index const index = {account_index, 0};
crypto::secret_key skey = wallet.get_account().get_device().get_subaddress_secret_key(wallet.get_account().get_keys().m_view_secret_key, index);;
crypto::public_key pkey = wallet.get_subaddress_spend_public_key(index);
crypto::hash hash = lns::tx_extra_signature_hash(result.encrypted_value.to_span(), owner ? &result.owner : nullptr, backup_owner ? &result.backup_owner : nullptr, result.prev_txid);
result.signature = lns::make_monero_signature(hash, wallet.get_account().get_keys().m_account_address.m_spend_public_key, wallet.get_account().get_keys().m_spend_secret_key);
result.signature = lns::make_monero_signature(hash, pkey, skey);
}
result.prepared = true;
@ -8526,7 +8531,10 @@ std::vector<wallet2::pending_tx> wallet2::lns_create_buy_mapping_tx(lns::mapping
uint32_t account_index,
std::set<uint32_t> subaddr_indices)
{
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, &value, owner, backup_owner, false /*make_signature*/, reason);
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, &value, owner, backup_owner, false /*make_signature*/, account_index, reason);
if (!owner)
prepared_args.owner = lns::make_monero_owner(get_subaddress({account_index, 0}), account_index != 0);
if (!prepared_args)
return {};
@ -8595,7 +8603,7 @@ std::vector<wallet2::pending_tx> wallet2::lns_create_update_mapping_tx(lns::mapp
}
bool make_signature = signature == nullptr;
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, value, owner, backup_owner, make_signature, reason);
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, value, owner, backup_owner, make_signature, account_index, reason);
if (!prepared_args) return {};
if (!make_signature)
@ -8682,9 +8690,10 @@ bool wallet2::lns_make_update_mapping_signature(lns::mapping_type type,
std::string const *owner,
std::string const *backup_owner,
lns::generic_signature &signature,
uint32_t account_index,
std::string *reason)
{
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, tx_priority_unimportant, name, value, owner, backup_owner, true /*make_signature*/, reason);
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, tx_priority_unimportant, name, value, owner, backup_owner, true /*make_signature*/, account_index, reason);
if (!prepared_args) return false;
if (prepared_args.prev_txid == crypto::null_hash)

View File

@ -1547,7 +1547,7 @@ private:
std::vector<wallet2::pending_tx> lns_create_update_mapping_tx(std::string const &type, std::string const &name, std::string const *value, std::string const *owner, std::string const *backup_owner, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
// Generate just the signature required for putting into lns_update_mapping command in the wallet
bool lns_make_update_mapping_signature(lns::mapping_type type, std::string name, std::string const *value, std::string const *owner, std::string const *backup_owner, lns::generic_signature &signature, std::string *reason = nullptr);
bool lns_make_update_mapping_signature(lns::mapping_type type, std::string name, std::string const *value, std::string const *owner, std::string const *backup_owner, lns::generic_signature &signature, uint32_t account_index = 0, std::string *reason = nullptr);
void freeze(size_t idx);
void thaw(size_t idx);

View File

@ -4396,6 +4396,7 @@ namespace tools
req.owner.size() ? &req.owner : nullptr,
req.backup_owner.size() ? &req.backup_owner : nullptr,
signature,
req.account_index,
&reason))
{
er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE;

View File

@ -3012,6 +3012,7 @@ This command is only required if the open wallet is one of the owners of a LNS r
std::string value; // (Optional): The new value that the name maps to via Loki Name Service. If not specified or given the empty string "", then the mapping's value remains unchanged.
std::string owner; // (Optional): The new owner of the mapping. If not specified or given the empty string "", then the mapping's owner remains unchanged.
std::string backup_owner; // (Optional): The new backup owner of the mapping. If not specified or given the empty string "", then the mapping's backup owner remains unchanged.
uint32_t account_index; // (Optional) Use this wallet's subaddress account for generating the signature
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(type);