Electroneum
hw::trezor::protocol::tx Namespace Reference

Classes

class  Signer
 
class  TData
 

Typedefs

using TsxData = messages::electroneum::ElectroneumTransactionInitRequest_ElectroneumTransactionData
 
using ElectroneumTransactionDestinationEntry = messages::electroneum::ElectroneumTransactionDestinationEntry
 
using ElectroneumAccountPublicAddress = messages::electroneum::ElectroneumTransactionDestinationEntry_ElectroneumAccountPublicAddress
 
using ElectroneumTransactionSourceEntry = messages::electroneum::ElectroneumTransactionSourceEntry
 
using ElectroneumMultisigKLRki = messages::electroneum::ElectroneumTransactionSourceEntry_ElectroneumMultisigKLRki
 
using ElectroneumOutputEntry = messages::electroneum::ElectroneumTransactionSourceEntry_ElectroneumOutputEntry
 
using ElectroneumRctKey = messages::electroneum::ElectroneumTransactionSourceEntry_ElectroneumOutputEntry_ElectroneumRctKeyPublic
 
using ElectroneumRsigData = messages::electroneum::ElectroneumTransactionRsigData
 
using tx_construction_data = tools::wallet2::tx_construction_data
 
using unsigned_tx_set = tools::wallet2::unsigned_tx_set
 
typedef boost::variant< rct::rangeSig, rct::Bulletproofrsig_v
 

Functions

void translate_address (ElectroneumAccountPublicAddress *dst, const cryptonote::account_public_address *src)
 
void translate_dst_entry (ElectroneumTransactionDestinationEntry *dst, const cryptonote::tx_destination_entry *src)
 
void translate_src_entry (ElectroneumTransactionSourceEntry *dst, const cryptonote::tx_source_entry *src)
 
void translate_klrki (ElectroneumMultisigKLRki *dst, const rct::multisig_kLRki *src)
 
void translate_rct_key (ElectroneumRctKey *dst, const rct::ctkey *src)
 
std::string hash_addr (const ElectroneumAccountPublicAddress *addr, boost::optional< uint64_t > amount, boost::optional< bool > is_subaddr)
 
std::string hash_addr (const std::string &spend_key, const std::string &view_key, boost::optional< uint64_t > amount, boost::optional< bool > is_subaddr)
 
std::string hash_addr (const ::crypto::public_key *spend_key, const ::crypto::public_key *view_key, boost::optional< uint64_t > amount, boost::optional< bool > is_subaddr)
 
::crypto::secret_key compute_enc_key (const ::crypto::secret_key &private_view_key, const std::string &aux, const std::string &salt)
 
void load_tx_key_data (hw::device_cold::tx_key_data_t &res, const std::string &data)
 
std::shared_ptr< messages::Electroneum::ElectroneumGetTxKeyRequest > get_tx_key (const hw::device_cold::tx_key_data_t &tx_data)
 
void get_tx_key_ack (std::vector<::crypto::secret_key > &tx_keys, const std::string &tx_prefix_hash, const ::crypto::secret_key &view_key_priv, std::shared_ptr< const messages::Electroneum::ElectroneumGetTxKeyAck > ack)
 
void get_tx_key_ack (std::vector<::crypto::secret_key > &tx_keys, const std::string &tx_prefix_hash, const ::crypto::secret_key &view_key_priv, std::shared_ptr< const messages::electroneum::ElectroneumGetTxKeyAck > ack)
 

Typedef Documentation

◆ ElectroneumAccountPublicAddress

using hw::trezor::protocol::tx::ElectroneumAccountPublicAddress = typedef messages::electroneum::ElectroneumTransactionDestinationEntry_ElectroneumAccountPublicAddress

Definition at line 149 of file protocol.hpp.

◆ ElectroneumMultisigKLRki

using hw::trezor::protocol::tx::ElectroneumMultisigKLRki = typedef messages::electroneum::ElectroneumTransactionSourceEntry_ElectroneumMultisigKLRki

Definition at line 151 of file protocol.hpp.

◆ ElectroneumOutputEntry

using hw::trezor::protocol::tx::ElectroneumOutputEntry = typedef messages::electroneum::ElectroneumTransactionSourceEntry_ElectroneumOutputEntry

Definition at line 152 of file protocol.hpp.

◆ ElectroneumRctKey

using hw::trezor::protocol::tx::ElectroneumRctKey = typedef messages::electroneum::ElectroneumTransactionSourceEntry_ElectroneumOutputEntry_ElectroneumRctKeyPublic

Definition at line 153 of file protocol.hpp.

◆ ElectroneumRsigData

using hw::trezor::protocol::tx::ElectroneumRsigData = typedef messages::electroneum::ElectroneumTransactionRsigData

Definition at line 154 of file protocol.hpp.

◆ ElectroneumTransactionDestinationEntry

using hw::trezor::protocol::tx::ElectroneumTransactionDestinationEntry = typedef messages::electroneum::ElectroneumTransactionDestinationEntry

Definition at line 148 of file protocol.hpp.

◆ ElectroneumTransactionSourceEntry

using hw::trezor::protocol::tx::ElectroneumTransactionSourceEntry = typedef messages::electroneum::ElectroneumTransactionSourceEntry

Definition at line 150 of file protocol.hpp.

◆ rsig_v

Definition at line 169 of file protocol.hpp.

◆ TsxData

using hw::trezor::protocol::tx::TsxData = typedef messages::electroneum::ElectroneumTransactionInitRequest_ElectroneumTransactionData

Definition at line 147 of file protocol.hpp.

◆ tx_construction_data

◆ unsigned_tx_set

Function Documentation

◆ compute_enc_key()

crypto::secret_key hw::trezor::protocol::tx::compute_enc_key ( const ::crypto::secret_key private_view_key,
const std::string &  aux,
const std::string &  salt 
)

Definition at line 351 of file protocol.cpp.

352  {
353  uint8_t hash[32];
354  KECCAK_CTX ctx;
356 
357  keccak_init(&ctx);
358  keccak_update(&ctx, (const uint8_t *) private_view_key.data, sizeof(private_view_key.data));
359  if (!aux.empty()){
360  keccak_update(&ctx, (const uint8_t *) aux.data(), aux.size());
361  }
362  keccak_finish(&ctx, hash);
363  keccak(hash, sizeof(hash), hash, sizeof(hash));
364 
365  hmac_keccak_hash(hash, (const uint8_t *) salt.data(), salt.size(), hash, sizeof(hash));
366  memcpy(res.data, hash, sizeof(hash));
367  memwipe(hash, sizeof(hash));
368  return res;
369  }
const char * res
Definition: hmac_keccak.cpp:41
void keccak_finish(KECCAK_CTX *ctx, uint8_t *md)
unsigned char uint8_t
Definition: stdint.h:124
void keccak_init(KECCAK_CTX *ctx)
void * memcpy(void *a, const void *b, size_t c)
void keccak_update(KECCAK_CTX *ctx, const uint8_t *in, size_t inlen)
void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
POD_CLASS hash
Definition: hash.h:50
void * memwipe(void *src, size_t n)
void hmac_keccak_hash(uint8_t *out, const uint8_t *key, size_t keylen, const uint8_t *in, size_t inlen)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tx_key()

std::shared_ptr< messages::electroneum::ElectroneumGetTxKeyRequest > hw::trezor::protocol::tx::get_tx_key ( const hw::device_cold::tx_key_data_t tx_data)

Definition at line 1038 of file protocol.cpp.

1040  {
1041  auto req = std::make_shared<messages::Electroneum::ElectroneumGetTxKeyRequest>();
1042  req->set_salt1(tx_data.salt1);
1043  req->set_salt2(tx_data.salt2);
1044  req->set_tx_enc_keys(tx_data.tx_enc_keys);
1045  req->set_tx_prefix_hash(tx_data.tx_prefix_hash);
1046  req->set_reason(0);
1047 
1048  return req;
1049  }
Here is the caller graph for this function:

◆ get_tx_key_ack() [1/2]

void hw::trezor::protocol::tx::get_tx_key_ack ( std::vector<::crypto::secret_key > &  tx_keys,
const std::string &  tx_prefix_hash,
const ::crypto::secret_key view_key_priv,
std::shared_ptr< const messages::electroneum::ElectroneumGetTxKeyAck >  ack 
)

◆ get_tx_key_ack() [2/2]

void hw::trezor::protocol::tx::get_tx_key_ack ( std::vector<::crypto::secret_key > &  tx_keys,
const std::string &  tx_prefix_hash,
const ::crypto::secret_key view_key_priv,
std::shared_ptr< const messages::Electroneum::ElectroneumGetTxKeyAck >  ack 
)

Definition at line 1051 of file protocol.cpp.

1057  {
1058  auto enc_key = protocol::tx::compute_enc_key(view_key_priv, tx_prefix_hash, ack->salt());
1059  auto & encrypted_keys = ack->has_tx_derivations() ? ack->tx_derivations() : ack->tx_keys();
1060 
1061  const size_t len_ciphertext = encrypted_keys.size(); // IV || keys || TAG
1063 
1064  size_t keys_len = len_ciphertext - crypto::chacha::IV_SIZE - crypto::chacha::TAG_SIZE;
1065  std::unique_ptr<uint8_t[]> plaintext(new uint8_t[keys_len]);
1066 
1068  encrypted_keys.data() + crypto::chacha::IV_SIZE,
1069  len_ciphertext - crypto::chacha::IV_SIZE,
1070  reinterpret_cast<const uint8_t *>(enc_key.data),
1071  reinterpret_cast<const uint8_t *>(encrypted_keys.data()),
1072  reinterpret_cast<char *>(plaintext.get()), &keys_len);
1073 
1074  CHECK_AND_ASSERT_THROW_MES(keys_len % 32 == 0, "Invalid size");
1075  tx_keys.resize(keys_len / 32);
1076 
1077  for(unsigned i = 0; i < keys_len / 32; ++i)
1078  {
1079  memcpy(tx_keys[i].data, plaintext.get() + 32 * i, 32);
1080  }
1081  memwipe(plaintext.get(), keys_len);
1082  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
unsigned char uint8_t
Definition: stdint.h:124
::crypto::secret_key compute_enc_key(const ::crypto::secret_key &private_view_key, const std::string &aux, const std::string &salt)
Definition: protocol.cpp:351
void decrypt(const void *ciphertext, size_t length, const uint8_t *key, const uint8_t *iv, char *plaintext, size_t *plaintext_len)
Definition: protocol.cpp:120
void * memcpy(void *a, const void *b, size_t c)
void * memwipe(void *src, size_t n)
Here is the call graph for this function:

◆ hash_addr() [1/3]

std::string hw::trezor::protocol::tx::hash_addr ( const ElectroneumAccountPublicAddress addr,
boost::optional< uint64_t amount,
boost::optional< bool is_subaddr 
)

Definition at line 317 of file protocol.cpp.

317  {
318  return hash_addr(addr->spend_public_key(), addr->view_public_key(), amount, is_subaddr);
319  }
std::string hash_addr(const ::crypto::public_key *spend_key, const ::crypto::public_key *view_key, boost::optional< uint64_t > amount, boost::optional< bool > is_subaddr)
Definition: protocol.cpp:332
Here is the caller graph for this function:

◆ hash_addr() [2/3]

std::string hw::trezor::protocol::tx::hash_addr ( const std::string &  spend_key,
const std::string &  view_key,
boost::optional< uint64_t amount,
boost::optional< bool is_subaddr 
)

Definition at line 321 of file protocol.cpp.

321  {
322  ::crypto::public_key spend{}, view{};
323  if (spend_key.size() != 32 || view_key.size() != 32){
324  throw std::invalid_argument("Public keys have invalid sizes");
325  }
326 
327  memcpy(spend.data, spend_key.data(), 32);
328  memcpy(view.data, view_key.data(), 32);
329  return hash_addr(&spend, &view, amount, is_subaddr);
330  }
std::string hash_addr(const ::crypto::public_key *spend_key, const ::crypto::public_key *view_key, boost::optional< uint64_t > amount, boost::optional< bool > is_subaddr)
Definition: protocol.cpp:332
POD_CLASS public_key
Definition: crypto.h:76
void * memcpy(void *a, const void *b, size_t c)
Definition: view.h:66
Here is the call graph for this function:

◆ hash_addr() [3/3]

std::string hw::trezor::protocol::tx::hash_addr ( const ::crypto::public_key spend_key,
const ::crypto::public_key view_key,
boost::optional< uint64_t amount,
boost::optional< bool is_subaddr 
)

Definition at line 332 of file protocol.cpp.

332  {
333  char buff[64+8+1];
334  size_t offset = 0;
335 
336  memcpy(buff + offset, spend_key->data, 32); offset += 32;
337  memcpy(buff + offset, view_key->data, 32); offset += 32;
338 
339  if (amount){
340  memcpy(buff + offset, (uint8_t*) &(amount.get()), sizeof(amount.get())); offset += sizeof(amount.get());
341  }
342 
343  if (is_subaddr){
344  buff[offset] = is_subaddr.get();
345  offset += 1;
346  }
347 
348  return std::string(buff, offset);
349  }
::std::string string
Definition: gtest-port.h:1097
unsigned char uint8_t
Definition: stdint.h:124
void * memcpy(void *a, const void *b, size_t c)
Here is the call graph for this function:

◆ load_tx_key_data()

void hw::trezor::protocol::tx::load_tx_key_data ( hw::device_cold::tx_key_data_t res,
const std::string &  data 
)

Definition at line 1007 of file protocol.cpp.

1008  {
1010 
1011  // The contents should be JSON if the wallet follows the new format.
1012  if (json.Parse(data.c_str()).HasParseError())
1013  {
1014  throw std::invalid_argument("Data parsing error");
1015  }
1016  else if(!json.IsObject())
1017  {
1018  throw std::invalid_argument("Data parsing error - not an object");
1019  }
1020 
1021  GET_FIELD_FROM_JSON(json, version, int, Int, true, -1);
1024  GET_STRING_FROM_JSON(json, enc_keys, std::string, true, std::string());
1025  GET_STRING_FROM_JSON(json, tx_prefix_hash, std::string, false, std::string());
1026 
1027  if (field_version != 1)
1028  {
1029  throw std::invalid_argument("Unknown version");
1030  }
1031 
1032  res.salt1 = field_salt1;
1033  res.salt2 = field_salt2;
1034  res.tx_enc_keys = field_enc_keys;
1035  res.tx_prefix_hash = field_tx_prefix_hash;
1036  }
const char * res
Definition: hmac_keccak.cpp:41
#define GET_FIELD_FROM_JSON(json, name, type, jtype, mandatory, def)
Definition: protocol.cpp:51
#define GET_STRING_FROM_JSON(json, name, type, mandatory, def)
Definition: protocol.cpp:48
::std::string string
Definition: gtest-port.h:1097
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2512
version
Supported socks variants.
Definition: socks.h:57
rapidjson::Document json
Definition: transport.cpp:49

◆ translate_address()

void hw::trezor::protocol::tx::translate_address ( ElectroneumAccountPublicAddress dst,
const cryptonote::account_public_address src 
)

Definition at line 272 of file protocol.cpp.

272  {
273  dst->set_view_public_key(key_to_string(src->m_view_public_key));
274  dst->set_spend_public_key(key_to_string(src->m_spend_public_key));
275  }
std::string key_to_string(const ::rct::key &key)
Definition: protocol.cpp:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ translate_dst_entry()

void hw::trezor::protocol::tx::translate_dst_entry ( ElectroneumTransactionDestinationEntry dst,
const cryptonote::tx_destination_entry src 
)

Definition at line 277 of file protocol.cpp.

277  {
278  dst->set_amount(src->amount);
279  dst->set_is_subaddress(src->is_subaddress);
280  dst->set_is_integrated(src->is_integrated);
281  dst->set_original(src->original);
282  translate_address(dst->mutable_addr(), &(src->addr));
283  }
void translate_address(ElectroneumAccountPublicAddress *dst, const cryptonote::account_public_address *src)
Definition: protocol.cpp:272
uint64_t amount
bool is_subaddress
bool is_integrated
account_public_address addr
std::string original
Here is the call graph for this function:
Here is the caller graph for this function:

◆ translate_klrki()

void hw::trezor::protocol::tx::translate_klrki ( ElectroneumMultisigKLRki dst,
const rct::multisig_kLRki src 
)

Definition at line 305 of file protocol.cpp.

305  {
306  dst->set_k(key_to_string(src->k));
307  dst->set_l(key_to_string(src->L));
308  dst->set_r(key_to_string(src->R));
309  dst->set_ki(key_to_string(src->ki));
310  }
std::string key_to_string(const ::rct::key &key)
Definition: protocol.cpp:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ translate_rct_key()

void hw::trezor::protocol::tx::translate_rct_key ( ElectroneumRctKey dst,
const rct::ctkey src 
)

Definition at line 312 of file protocol.cpp.

312  {
313  dst->set_dest(key_to_string(src->dest));
314  dst->set_commitment(key_to_string(src->mask));
315  }
key dest
Definition: rctTypes.h:97
std::string key_to_string(const ::rct::key &key)
Definition: protocol.cpp:92
key mask
Definition: rctTypes.h:98
Here is the call graph for this function:
Here is the caller graph for this function:

◆ translate_src_entry()

void hw::trezor::protocol::tx::translate_src_entry ( ElectroneumTransactionSourceEntry dst,
const cryptonote::tx_source_entry src 
)

Definition at line 285 of file protocol.cpp.

285  {
286  for(auto & cur : src->outputs){
287  auto out = dst->add_outputs();
288  out->set_idx(cur.first);
289  translate_rct_key(out->mutable_key(), &(cur.second));
290  }
291 
292  dst->set_real_output(src->real_output);
293  dst->set_real_out_tx_key(key_to_string(src->real_out_tx_key));
294  for(auto & cur : src->real_out_additional_tx_keys){
295  dst->add_real_out_additional_tx_keys(key_to_string(cur));
296  }
297 
298  dst->set_real_output_in_tx_index(src->real_output_in_tx_index);
299  dst->set_amount(src->amount);
300  dst->set_rct(src->rct);
301  dst->set_mask(key_to_string(src->mask));
302  translate_klrki(dst->mutable_multisig_klrki(), &(src->multisig_kLRki));
303  }
crypto::public_key real_out_tx_key
void translate_klrki(ElectroneumMultisigKLRki *dst, const rct::multisig_kLRki *src)
Definition: protocol.cpp:305
bool rct
uint64_t amount
size_t real_output
void translate_rct_key(ElectroneumRctKey *dst, const rct::ctkey *src)
Definition: protocol.cpp:312
std::string key_to_string(const ::rct::key &key)
Definition: protocol.cpp:92
rct::multisig_kLRki multisig_kLRki
std::vector< crypto::public_key > real_out_additional_tx_keys
size_t real_output_in_tx_index
std::vector< output_entry > outputs
rct::key mask
Here is the call graph for this function:
Here is the caller graph for this function: