Electroneum
Loading...
Searching...
No Matches
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
38namespace cryptonote
39{
40
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:
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);
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}
uint64_t get_createtime() const
Definition account.h:95
void finalize_multisig(const crypto::public_key &spend_public_key)
Definition account.cpp:259
void encrypt_viewkey(const crypto::chacha_key &key)
Definition account.h:106
std::string get_public_address_str(network_type nettype) const
Definition account.cpp:269
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)
Definition account.cpp:250
void create_from_viewkey(const cryptonote::account_public_address &address, const crypto::secret_key &viewkey)
Definition account.cpp:243
void serialize(t_archive &a, const unsigned int)
Definition account.h:110
void decrypt_viewkey(const crypto::chacha_key &key)
Definition account.h:107
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
Definition account.cpp:158
void set_device(hw::device &hwdev)
Definition account.h:92
bool store(const std::string &file_path)
void create_from_keys(const cryptonote::account_public_address &address, const crypto::secret_key &spendkey, const crypto::secret_key &viewkey)
Definition account.cpp:189
void encrypt_keys(const crypto::chacha_key &key)
Definition account.h:104
void decrypt_keys(const crypto::chacha_key &key)
Definition account.h:105
void create_from_device(const std::string &device_name)
Definition account.cpp:209
void set_createtime(uint64_t val)
Definition account.h:96
const account_keys & get_keys() const
Definition account.cpp:264
const std::vector< crypto::secret_key > & get_multisig_keys() const
Definition account.h:102
std::string get_public_integrated_address_str(const crypto::hash8 &payment_id, network_type nettype) const
Definition account.cpp:275
bool load(const std::string &file_path)
hw::device & get_device() const
Definition account.h:91
const char * key
#define KV_SERIALIZE(varialble)
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble)
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(varialble, def)
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble)
#define END_KV_SERIALIZE_MAP()
#define BEGIN_KV_SERIALIZE_MAP()
crypto namespace.
Definition crypto.cpp:58
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:82
POD_CLASS hash8
Definition hash.h:53
POD_CLASS public_key
Definition crypto.h:79
Holds cryptonote related classes and helpers.
Definition ban.cpp:40
Definition device.cpp:38
device & get_device(const std::string &device_descriptor)
Definition device.cpp:95
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
unsigned __int64 uint64_t
Definition stdint.h:136
crypto::secret_key m_view_secret_key
Definition account.h:45
hw::device & get_device() const
Definition account.cpp:59
crypto::secret_key m_spend_secret_key
Definition account.h:44
crypto::chacha_iv m_encryption_iv
Definition account.h:48
std::vector< crypto::secret_key > m_multisig_keys
Definition account.h:46
hw::device * m_device
Definition account.h:47
account_public_address m_account_address
Definition account.h:43
void encrypt_viewkey(const crypto::chacha_key &key)
Definition account.cpp:117
const crypto::chacha_iv default_iv
Definition account.h:55
void set_device(hw::device &hwdev)
Definition account.cpp:63
void decrypt_viewkey(const crypto::chacha_key &key)
Definition account.cpp:127
void decrypt(const crypto::chacha_key &key)
Definition account.cpp:112
void encrypt(const crypto::chacha_key &key)
Definition account.cpp:106
const char * address
Definition multisig.cpp:37
const char * spendkey
Definition multisig.cpp:38