Revise LNS documenation to reflect actual implementation

This commit is contained in:
Doyle 2020-02-27 14:36:53 +11:00
parent 8c31535955
commit 91036eb2ad
5 changed files with 49 additions and 38 deletions

View File

@ -1497,13 +1497,8 @@ std::vector<mapping_record> name_system_db::get_mappings_by_owners(std::vector<c
// Bind parameters statements
int sql_param_index = 1;
for (size_t i = 0; i < keys.size(); i++)
{
for (auto const &key : keys)
{
sqlite3_bind_blob(statement, sql_param_index++, key.data, sizeof(key), nullptr /*destructor*/);
}
}
assert((sql_param_index - 1) == (static_cast<int>(keys.size() * 2)));
// Execute
sql_run_statement(nettype, lns_sql_type::get_mappings_by_owners, statement, &result);

View File

@ -3396,7 +3396,8 @@ namespace cryptonote
entry.entry_index = request_index;
entry.type = static_cast<uint16_t>(record.type);
entry.owner = epee::string_tools::pod_to_hex(record.owner);
entry.encrypted_value = epee::to_hex::string(epee::span<const uint8_t>(record.encrypted_value.buffer.data(), record.encrypted_value.len));
entry.backup_owner = epee::string_tools::pod_to_hex(record.backup_owner);
entry.encrypted_value = epee::to_hex::string(record.encrypted_value.to_span());
entry.register_height = record.register_height;
entry.txid = epee::string_tools::pod_to_hex(record.txid);
entry.prev_txid = epee::string_tools::pod_to_hex(record.prev_txid);
@ -3449,7 +3450,8 @@ namespace cryptonote
entry.request_index = it->second;
entry.type = static_cast<uint16_t>(record.type);
entry.name_hash = std::move(record.name_hash);
entry.encrypted_value = epee::to_hex::string(epee::span<const uint8_t>(record.encrypted_value.buffer.data(), record.encrypted_value.len));
entry.backup_owner = epee::string_tools::pod_to_hex(record.backup_owner);
entry.encrypted_value = epee::to_hex::string(record.encrypted_value.to_span());
entry.register_height = record.register_height;
entry.txid = epee::string_tools::pod_to_hex(record.txid);
entry.prev_txid = epee::string_tools::pod_to_hex(record.prev_txid);

View File

@ -3481,7 +3481,8 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
{
uint64_t entry_index; // The index in request_entry's `entries` array that was resolved via Loki Name Service.
uint16_t type; // The type of Loki Name Service entry that the owner owns.
std::string owner; // The ed25519 public key that purchased the Loki Name Service entry.
std::string owner; // The public key that purchased the Loki Name Service entry.
std::string backup_owner; // The backup public key that the owner specified when purchasing the Loki Name Service entry.
std::string encrypted_value; // The encrypted value that the name maps to. This value is encrypted using the name (not the hash) as the secret.
uint64_t register_height; // The height that this Loki Name Service entry was purchased on the Blockchain.
std::string txid; // The txid of who purchased the mapping, null hash if not applicable.
@ -3490,6 +3491,7 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
KV_SERIALIZE(entry_index)
KV_SERIALIZE(type)
KV_SERIALIZE(owner)
KV_SERIALIZE(backup_owner)
KV_SERIALIZE(encrypted_value)
KV_SERIALIZE(register_height)
KV_SERIALIZE(txid)
@ -3509,9 +3511,8 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
};
LOKI_RPC_DOC_INTROSPECT
// Get all the name mappings for the queried owner. The owner should be
// a ed25519 public key; by default this is the public key of an ed25519
// keypair derived using the wallet's secret spend key as the seed value.
// Get all the name mappings for the queried owner. The owner can be either a ed25519 public key or Monero style
// public key; by default purchases are owned by the spend public key of the purchasing wallet.
struct COMMAND_RPC_GET_LNS_OWNERS_TO_NAMES
{
static size_t const MAX_REQUEST_ENTRIES = 256;
@ -3528,14 +3529,16 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
uint64_t request_index; // The index in request's `entries` array that was resolved via Loki Name Service.
uint16_t type; // The category the Loki Name Service entry belongs to, currently only Session whose value is 0.
std::string name_hash; // The hash of the name that the owner purchased via Loki Name Service.
std::string backup_owner; // The backup public key specified by the owner that purchased the Loki Name Service entry.
std::string encrypted_value; // The encrypted value that the name maps to. This value is encrypted using the name (not the hash) as the secret.
uint64_t register_height; // The height that this Loki Name Service entry was purchased on the Blockchain.
std::string txid; // The txid of who purchases the mapping, null hash if not applicable
std::string txid; // The txid of who purchases the mapping.
std::string prev_txid; // The previous txid that purchased the mapping, null hash if not applicable.
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(request_index)
KV_SERIALIZE(type)
KV_SERIALIZE(name_hash)
KV_SERIALIZE(backup_owner)
KV_SERIALIZE(encrypted_value)
KV_SERIALIZE(register_height)
KV_SERIALIZE(txid)

View File

@ -6393,19 +6393,22 @@ bool simple_wallet::buy_lns_mapping(const std::vector<std::string>& args)
{
char const OWNER_PREFIX[] = "owner=";
char const BACKUP_OWNER_PREFIX[] = "backup_owner=";
size_t const OWNER_LEN = loki::char_count(OWNER_PREFIX) + (sizeof(crypto::generic_public_key) * 2);
size_t const BACKUP_OWNER_LEN = loki::char_count(BACKUP_OWNER_PREFIX) + (sizeof(crypto::generic_public_key) * 2);
for (auto it = args.begin(); it != args.end(); it++)
for (auto it = local_args.begin(); it != local_args.end();)
{
// Check prefix of argument is <owner>= and extract keys out
if (it->size() == OWNER_LEN && memcmp(it->data(), OWNER_PREFIX, loki::char_count(OWNER_PREFIX)) == 0)
if (it->size() > loki::char_count(OWNER_PREFIX) && memcmp(it->data(), OWNER_PREFIX, loki::char_count(OWNER_PREFIX)) == 0)
{
owner = it->substr(loki::char_count(OWNER_PREFIX), it->size() - loki::char_count(OWNER_PREFIX));
it = local_args.erase(it);
}
else if (it->size() == BACKUP_OWNER_LEN && memcmp(it->data(), BACKUP_OWNER_PREFIX, loki::char_count(BACKUP_OWNER_PREFIX)) == 0)
else if (it->size() > loki::char_count(BACKUP_OWNER_PREFIX) && memcmp(it->data(), BACKUP_OWNER_PREFIX, loki::char_count(BACKUP_OWNER_PREFIX)) == 0)
{
backup_owner = it->substr(loki::char_count(BACKUP_OWNER_PREFIX), it->size() - loki::char_count(BACKUP_OWNER_PREFIX));
it = local_args.erase(it);
}
else
{
it++;
}
}
}
@ -6418,7 +6421,7 @@ bool simple_wallet::buy_lns_mapping(const std::vector<std::string>& args)
if (!parse_lns_name_string(local_args, first_word_index, last_word_index, name))
{
PRINT_USAGE(USAGE_BUY_LNS_MAPPING);
fail_msg_writer() << "lns name didn't start or end with quotation marks (')";
fail_msg_writer() << "lns name didn't start or end with quotation marks (\"), first word in name is=\"" << local_args[first_word_index] << "\"";
return false;
}
@ -6550,6 +6553,7 @@ bool simple_wallet::update_lns_mapping(const std::vector<std::string>& args)
return true;
}
//----------------------------------------------------------------------------------------------------
static char constexpr NULL_KEY_STR[] = "0000000000000000000000000000000000000000000000000000000000000000";
bool simple_wallet::print_lns_name_to_owners(const std::vector<std::string>& args)
{
if (!try_connect_to_daemon())
@ -6625,7 +6629,14 @@ bool simple_wallet::print_lns_name_to_owners(const std::vector<std::string>& arg
}
for (auto const &mapping : response)
tools::msg_writer() << "name=\"" << entry.name << "\", owner=" << mapping.owner << ", type=" << static_cast<lns::mapping_type>(mapping.type) << ", height=" << mapping.register_height;
{
tools::msg_writer() << ", type=" << static_cast<lns::mapping_type>(mapping.type)
<< ", owner=" << mapping.owner
<< ", backup_owner=" << (mapping.backup_owner.size() ? NULL_KEY_STR : mapping.backup_owner)
<< ", height=" << mapping.register_height
<< ", encrypted_value=" << mapping.encrypted_value
<< ", prev_txid=" << mapping.prev_txid;
}
return true;
}
@ -6637,18 +6648,12 @@ bool simple_wallet::print_lns_owners_to_name_hashes(const std::vector<std::strin
boost::optional<std::string> failed;
std::string my_own_ed25519_key;
std::string my_key;
cryptonote::COMMAND_RPC_GET_LNS_OWNERS_TO_NAMES::request request = {};
if (args.size() == 0)
{
// TODO(doyle): I need to make this address visible easily for people, prior
// removed because of wallet encrypting/decrypting the secret keys
SCOPED_WALLET_UNLOCK();
crypto::ed25519_public_key pkey;
crypto::ed25519_secret_key skey;
crypto_sign_ed25519_seed_keypair(pkey.data, skey.data, reinterpret_cast<const unsigned char *>(m_wallet->get_account().get_keys().m_spend_secret_key.data));
my_own_ed25519_key = epee::string_tools::pod_to_hex(pkey);
request.entries.push_back(my_own_ed25519_key);
my_key = epee::string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_spend_public_key);
request.entries.push_back(my_key);
}
else
{
@ -6677,7 +6682,7 @@ bool simple_wallet::print_lns_owners_to_name_hashes(const std::vector<std::strin
for (cryptonote::COMMAND_RPC_GET_LNS_OWNERS_TO_NAMES::response_entry const &entry : entries)
{
std::string const *owner = &my_own_ed25519_key;
std::string const *owner = &my_key;
if (args.size()) // If specified owner to look up, retrieve it
{
try
@ -6691,7 +6696,13 @@ bool simple_wallet::print_lns_owners_to_name_hashes(const std::vector<std::strin
}
}
tools::msg_writer() << "owner=" << *owner << ", type=" << entry.type << ", height=" << entry.register_height << ", name_hash=\"" << entry.name_hash << "\", encrypted_value=" << entry.encrypted_value << ", prev_txid=" << entry.prev_txid;
tools::msg_writer() << "owner=" << *owner
<< ", backup_owner=" << (entry.backup_owner.size() ? NULL_KEY_STR : entry.backup_owner)
<< ", type=" << static_cast<lns::mapping_type>(entry.type)
<< ", height=" << entry.register_height
<< ", name_hash=\"" << entry.name_hash << "\""
<< ", encrypted_value=" << entry.encrypted_value
<< ", prev_txid=" << entry.prev_txid;
}
return true;
}

View File

@ -2870,11 +2870,11 @@ For information on updating & signing, refer to COMMAND_RPC_UPDATE_LNS_MAPPING)"
struct request_t
{
std::string type; // The mapping type, either "blockchain", "lokinet", "session" or if custom, a value between [65-65536] (0-2 map to the predefined mappings listed earlier).
std::string owner; // (Optional): The owner's public key that has authority to update the mapping. It must be a ed25519 public key and is used to verify update transaction signatures.
std::string backup_owner; // (Optional): The owner's wallet spend public key that has authority to update the mapping. It must be a monero style public key and is used to verify update transaction signatures.
std::string type; // The mapping type, currently we only support "session". In future "lokinet" and "blockchain" mappings will be available.
std::string owner; // (Optional): The public key that has authority to update the mapping.
std::string backup_owner; // (Optional): The secondary, backup public key that has authority to update the mapping.
std::string name; // The name to purchase via Loki Name Service
std::string value; // The value that the name maps to via Loki Name Service, (i.e. For wallets: name -> wallet address. For session: display name -> session public key. For Lokinet: name -> domain name).
std::string value; // The value that the name maps to via Loki Name Service, (i.e. For Session: [display name->session public key]. In future, for wallets: [name->wallet address], for Lokinet: [name->domain name]).
uint32_t account_index; // (Optional) Transfer from this account index. (Defaults to 0)
std::set<uint32_t> subaddr_indices; // (Optional) Transfer from this set of subaddresses. (Defaults to 0)
@ -2942,10 +2942,10 @@ Providing the signature is an optional field and if not provided, will default t
struct request_t
{
std::string type; // The mapping type, currently only "session" is supported.
std::string type; // The mapping type, currently we only support "session". In future "lokinet" and "blockchain" mappings will be available.
std::string name; // The name to update via Loki Name Service
std::string value; // The new value that the name maps to via Loki Name Service, (i.e. For session: display name -> session public key).
std::string signature; // (Optional): Signature derived using libsodium generichash on {current txid blob, new value blob} of the mapping to update. By default the hash is signed using the wallet's spend key as an ed25519 keypair, if signature is specified.
std::string value; // The new value that the name maps to via Loki Name Service, (i.e. For Session: [display name->session public key]. In future, for wallets: [name->wallet address], for Lokinet: [name->domain name]).
std::string signature; // (Optional): Signature derived using libsodium generichash on {current txid blob, new value blob} of the mapping to update. By default the hash is signed using the wallet's spend key if signature is not specified.
uint32_t account_index; // (Optional) Transfer from this account index. (Defaults to 0)
std::set<uint32_t> subaddr_indices; // (Optional) Transfer from this set of subaddresses. (Defaults to 0)