PIVX Core  5.6.99
P2P Digital Currency
address.h
Go to the documentation of this file.
1 // Copyright (c) 2016-2020 The ZCash developers
2 // Copyright (c) 2021 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_SAPLING_ADDRESS_H
7 #define PIVX_SAPLING_ADDRESS_H
8 
9 #include "optional.h"
10 #include "sapling/sapling.h"
11 #include "serialize.h"
12 #include "uint256.h"
13 
14 #include <array>
15 #include <boost/variant.hpp>
16 
17 namespace libzcash {
19 public:
20  friend bool operator==(const InvalidEncoding &a, const InvalidEncoding &b) { return true; }
21  friend bool operator<(const InvalidEncoding &a, const InvalidEncoding &b) { return true; }
22 };
23 
28 
31 public:
32  diversifier_t d = {{0}};
34 
36  SaplingPaymentAddress(const diversifier_t& _d, const uint256& _pk_d) : d(_d), pk_d(_pk_d) { }
37 
39 
41  uint256 GetHash() const;
42 
43  friend inline bool operator==(const SaplingPaymentAddress& a, const SaplingPaymentAddress& b) {
44  return a.d == b.d && a.pk_d == b.pk_d;
45  }
46  friend inline bool operator<(const SaplingPaymentAddress& a, const SaplingPaymentAddress& b) {
47  return (a.d < b.d ||
48  (a.d == b.d && a.pk_d < b.pk_d));
49  }
50 };
51 
53 public:
55  explicit SaplingIncomingViewingKey(uint256 ivk) : uint256(ivk) { }
56 
57  // Can pass in diversifier for Sapling addr
59 };
60 
62 public:
66 
67  SaplingFullViewingKey() : ak(), nk(), ovk() { }
69 
70  SERIALIZE_METHODS(SaplingFullViewingKey, obj) { READWRITE(obj.ak, obj.nk, obj.ovk); }
71 
73  uint256 GetFingerprint() const;
74 
76  bool is_valid() const;
77 
78  friend inline bool operator==(const SaplingFullViewingKey& a, const SaplingFullViewingKey& b) {
79  return a.ak == b.ak && a.nk == b.nk && a.ovk == b.ovk;
80  }
81  friend inline bool operator<(const SaplingFullViewingKey& a, const SaplingFullViewingKey& b) {
82  return (a.ak < b.ak ||
83  (a.ak == b.ak && a.nk < b.nk) ||
84  (a.ak == b.ak && a.nk == b.nk && a.ovk < b.ovk));
85  }
86 };
87 
88 
90 public:
94 
97 
98  SERIALIZE_METHODS(SaplingExpandedSpendingKey, obj) { READWRITE(obj.ask, obj.nsk, obj.ovk); }
99 
101  bool IsNull() { return ask.IsNull() && nsk.IsNull() && ovk.IsNull(); }
102 
103  friend inline bool operator==(const SaplingExpandedSpendingKey& a, const SaplingExpandedSpendingKey& b) {
104  return a.ask == b.ask && a.nsk == b.nsk && a.ovk == b.ovk;
105  }
106  friend inline bool operator<(const SaplingExpandedSpendingKey& a, const SaplingExpandedSpendingKey& b) {
107  return (a.ask < b.ask ||
108  (a.ask == b.ask && a.nsk < b.nsk) ||
109  (a.ask == b.ask && a.nsk == b.nsk && a.ovk < b.ovk));
110  }
111 };
112 
113 class SaplingSpendingKey : public uint256 {
114 public:
116  explicit SaplingSpendingKey(uint256 sk) : uint256(sk) { }
117 
118  static SaplingSpendingKey random();
119 
122 
123  // Can derive Sapling addr from default diversifier
125 };
126 
127 typedef boost::variant<InvalidEncoding, SaplingPaymentAddress> PaymentAddress;
128 
129 }
130 
133 
134 #endif // PIVX_SAPLING_ADDRESS_H
bool IsValidPaymentAddress(const libzcash::PaymentAddress &zaddr)
Check whether a PaymentAddress is not an InvalidEncoding.
Definition: address.cpp:92
bool IsNull() const
Definition: uint256.h:36
friend bool operator==(const InvalidEncoding &a, const InvalidEncoding &b)
Definition: address.h:20
friend bool operator<(const InvalidEncoding &a, const InvalidEncoding &b)
Definition: address.h:21
friend bool operator<(const SaplingExpandedSpendingKey &a, const SaplingExpandedSpendingKey &b)
Definition: address.h:106
friend bool operator==(const SaplingExpandedSpendingKey &a, const SaplingExpandedSpendingKey &b)
Definition: address.h:103
SERIALIZE_METHODS(SaplingExpandedSpendingKey, obj)
Definition: address.h:98
SaplingExpandedSpendingKey(uint256 ask, uint256 nsk, uint256 ovk)
Definition: address.h:96
SaplingFullViewingKey full_viewing_key() const
Definition: address.cpp:29
SaplingIncomingViewingKey in_viewing_key() const
Definition: address.cpp:45
SERIALIZE_METHODS(SaplingFullViewingKey, obj)
Definition: address.h:70
uint256 GetFingerprint() const
Get the fingerprint of this full viewing key (as defined in ZIP 32).
Definition: address.cpp:57
friend bool operator==(const SaplingFullViewingKey &a, const SaplingFullViewingKey &b)
Definition: address.h:78
SaplingFullViewingKey(uint256 ak, uint256 nk, uint256 ovk)
Definition: address.h:68
friend bool operator<(const SaplingFullViewingKey &a, const SaplingFullViewingKey &b)
Definition: address.h:81
SaplingIncomingViewingKey(uint256 ivk)
Definition: address.h:55
Optional< SaplingPaymentAddress > address(diversifier_t d) const
Definition: address.cpp:73
Sapling functions.
Definition: address.h:30
friend bool operator==(const SaplingPaymentAddress &a, const SaplingPaymentAddress &b)
Definition: address.h:43
uint256 GetHash() const
Get the 256-bit SHA256d hash of this payment address.
Definition: address.cpp:23
SERIALIZE_METHODS(SaplingPaymentAddress, obj)
Definition: address.h:38
SaplingPaymentAddress(const diversifier_t &_d, const uint256 &_pk_d)
Definition: address.h:36
friend bool operator<(const SaplingPaymentAddress &a, const SaplingPaymentAddress &b)
Definition: address.h:46
static SaplingSpendingKey random()
Definition: address.cpp:64
SaplingPaymentAddress default_address() const
Definition: address.cpp:83
SaplingFullViewingKey full_viewing_key() const
Definition: address.cpp:41
SaplingSpendingKey(uint256 sk)
Definition: address.h:116
SaplingExpandedSpendingKey expanded_spending_key() const
Definition: address.cpp:37
256-bit opaque blob.
Definition: uint256.h:138
boost::variant< InvalidEncoding, SaplingPaymentAddress > PaymentAddress
Definition: address.h:127
const size_t SerializedSaplingPaymentAddressSize
Definition: address.h:24
const size_t SerializedSaplingSpendingKeySize
Definition: address.h:27
const size_t SerializedSaplingExpandedSpendingKeySize
Definition: address.h:26
const size_t SerializedSaplingFullViewingKeySize
Definition: address.h:25
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
std::array< unsigned char, ZC_DIVERSIFIER_SIZE > diversifier_t
Definition: sapling.h:38
#define READWRITE(...)
Definition: serialize.h:183
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:175