Monero
account.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30 
31 #pragma once
32 
33 #include "cryptonote_basic.h"
34 #include "crypto/crypto.h"
36 
37 namespace cryptonote
38 {
39 
40  struct account_keys
41  {
45  std::vector<crypto::secret_key> m_multisig_keys;
47  crypto::chacha_iv m_encryption_iv;
48 
54  const crypto::chacha_iv default_iv{{0, 0, 0, 0, 0, 0, 0, 0}};
57 
58  void encrypt(const crypto::chacha_key &key);
59  void decrypt(const crypto::chacha_key &key);
60  void encrypt_viewkey(const crypto::chacha_key &key);
61  void decrypt_viewkey(const crypto::chacha_key &key);
62 
64  void set_device( hw::device &hwdev) ;
65 
66  private:
67  void xor_with_key_stream(const crypto::chacha_key &key);
68  };
69 
70  /************************************************************************/
71  /* */
72  /************************************************************************/
74  {
75  public:
76  account_base();
77  crypto::secret_key generate(const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false, bool two_random = false);
78  void create_from_device(const std::string &device_name);
79  void create_from_device(hw::device &hwdev);
80  void create_from_keys(const cryptonote::account_public_address& address, const crypto::secret_key& spendkey, const crypto::secret_key& viewkey);
81  void create_from_viewkey(const cryptonote::account_public_address& address, const crypto::secret_key& viewkey);
82  bool make_multisig(const crypto::secret_key &view_secret_key, const crypto::secret_key &spend_secret_key, const crypto::public_key &spend_public_key, const std::vector<crypto::secret_key> &multisig_keys);
83  const account_keys& get_keys() const;
84  std::string get_public_address_str(network_type nettype) const;
85  std::string get_public_integrated_address_str(const crypto::hash8 &payment_id, network_type nettype) const;
86 
87  hw::device& get_device() const {return m_keys.get_device();}
88  void set_device( hw::device &hwdev) {m_keys.set_device(hwdev);}
89  void deinit();
90 
91  uint64_t get_createtime() const { return m_creation_timestamp; }
92  void set_createtime(uint64_t val) { m_creation_timestamp = val; }
93 
94  bool load(const std::string& file_path);
95  bool store(const std::string& file_path);
96 
97  void forget_spend_key();
98  void set_spend_key(const crypto::secret_key& spend_secret_key);
99  const std::vector<crypto::secret_key> &get_multisig_keys() const { return m_keys.m_multisig_keys; }
100 
101  void encrypt_keys(const crypto::chacha_key &key) { m_keys.encrypt(key); }
102  void decrypt_keys(const crypto::chacha_key &key) { m_keys.decrypt(key); }
103  void encrypt_viewkey(const crypto::chacha_key &key) { m_keys.encrypt_viewkey(key); }
104  void decrypt_viewkey(const crypto::chacha_key &key) { m_keys.decrypt_viewkey(key); }
105 
106  template <class t_archive>
107  inline void serialize(t_archive &a, const unsigned int /*ver*/)
108  {
109  a & m_keys;
110  a & m_creation_timestamp;
111  }
112 
114  KV_SERIALIZE(m_keys)
115  KV_SERIALIZE(m_creation_timestamp)
117 
118  private:
119  void set_null();
120  account_keys m_keys;
121  uint64_t m_creation_timestamp;
122  };
123 }
void encrypt_viewkey(const crypto::chacha_key &key)
Definition: account.cpp:114
void decrypt_viewkey(const crypto::chacha_key &key)
Definition: account.cpp:124
::std::string string
Definition: gtest-port.h:1097
void generate(randomx::Program &p, uint32_t nonce)
Definition: perf-simulation.cpp:62
const char * key
Definition: hmac_keccak.cpp:40
crypto namespace.
Definition: crypto.cpp:60
#define KV_SERIALIZE(varialble)
Definition: keyvalue_serialization.h:120
const crypto::chacha_iv default_iv
Definition: account.h:54
void encrypt_keys(const crypto::chacha_key &key)
Definition: account.h:101
Definition: minissdpd.c:75
Holds cryptonote related classes and helpers.
Definition: blockchain_db.cpp:44
crypto::chacha_iv m_encryption_iv
Definition: account.h:47
void decrypt_keys(const crypto::chacha_key &key)
Definition: account.h:102
hw::device & get_device() const
Definition: account.h:87
Definition: account.h:73
device & get_device(const std::string &device_descriptor)
Definition: device.cpp:95
void serialize(t_archive &a, const unsigned int)
Definition: account.h:107
unsigned __int64 uint64_t
Definition: stdint.h:136
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble)
Definition: keyvalue_serialization.h:124
void load(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
Definition: unordered_containers_boost_serialization.h:54
Definition: device.cpp:38
Definition: device.hpp:87
hw::device * m_device
Definition: account.h:46
Definition: account.h:40
void set_createtime(uint64_t val)
Definition: account.h:92
void encrypt(const crypto::chacha_key &key)
Definition: account.cpp:103
POD_CLASS public_key
Definition: crypto.h:61
crypto::secret_key spendkey
Definition: cold-outputs.cpp:44
void set_device(hw::device &hwdev)
Definition: account.h:88
crypto::secret_key m_view_secret_key
Definition: account.h:44
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
account_public_address m_account_address
Definition: account.h:42
network_type
Definition: cryptonote_config.h:301
uint32_t address
Definition: getifaddr.c:269
Definition: cryptonote_basic.h:511
POD_CLASS hash8
Definition: hash.h:52
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble)
Definition: keyvalue_serialization.h:123
void xor_with_key_stream(const crypto::chacha_key &key)
Definition: account.cpp:87
crypto::secret_key m_spend_secret_key
Definition: account.h:43
void set_device(hw::device &hwdev)
Definition: account.cpp:60
std::vector< crypto::secret_key > m_multisig_keys
Definition: account.h:45
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(varialble, def)
Definition: keyvalue_serialization.h:122
void decrypt(const crypto::chacha_key &key)
Definition: account.cpp:109
#define END_KV_SERIALIZE_MAP()
Definition: keyvalue_serialization.h:118
uint64_t get_createtime() const
Definition: account.h:91
const std::vector< crypto::secret_key > & get_multisig_keys() const
Definition: account.h:99
#define const
Definition: ipfrdr.c:80
hw::device & get_device() const
Definition: account.cpp:56
#define BEGIN_KV_SERIALIZE_MAP()
Definition: keyvalue_serialization.h:43
void encrypt_viewkey(const crypto::chacha_key &key)
Definition: account.h:103
void decrypt_viewkey(const crypto::chacha_key &key)
Definition: account.h:104