| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "cryptonote_basic.h" |
| 34 |
#include "crypto/crypto.h" |
| 35 |
#include "serialization/keyvalue_serialization.h" |
| 36 |
|
| 37 |
namespace cryptonote |
| 38 |
{ |
| 39 |
|
| 40 |
struct account_keys |
| 41 |
{ |
| 42 |
account_public_address m_account_address; |
| 43 |
crypto::secret_key m_spend_secret_key; |
| 44 |
crypto::secret_key m_view_secret_key; |
| 45 |
std::vector<crypto::secret_key> m_multisig_keys; |
| 46 |
hw::device *m_device = &hw::get_device("default"); |
| 47 |
crypto::chacha_iv m_encryption_iv; |
| 48 |
|
| 49 |
BEGIN_KV_SERIALIZE_MAP() |
| 50 |
KV_SERIALIZE(m_account_address) |
| 51 |
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_secret_key) |
| 52 |
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_secret_key) |
| 53 |
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_multisig_keys) |
| 54 |
const crypto::chacha_iv default_iv{{0, 0, 0, 0, 0, 0, 0, 0}}; |
| 55 |
KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(m_encryption_iv, default_iv) |
| 56 |
END_KV_SERIALIZE_MAP() |
| 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 |
|
| 63 |
hw::device& get_device() const ; |
| 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 |
|
| 73 |
class account_base |
| 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 ) |
| 108 |
{ |
| 109 |
a & m_keys; |
| 110 |
a & m_creation_timestamp; |
| 111 |
} |
| 112 |
|
| 113 |
BEGIN_KV_SERIALIZE_MAP() |
| 114 |
KV_SERIALIZE(m_keys) |
| 115 |
KV_SERIALIZE(m_creation_timestamp) |
| 116 |
END_KV_SERIALIZE_MAP() |
| 117 |
|
| 118 |
private: |
| 119 |
void set_null(); |
| 120 |
account_keys m_keys; |
| 121 |
uint64_t m_creation_timestamp; |
| 122 |
}; |
| 123 |
} |