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