PIVX Core  5.6.99
P2P Digital Currency
address.cpp
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 #include "sapling/address.h"
7 
8 #include "hash.h"
10 #include "sapling/prf.h"
11 #include "sapling/sapling_util.h"
12 #include "streams.h"
13 
14 #include <librustzcash.h>
15 
16 const unsigned char ZCASH_SAPLING_FVFP_PERSONALIZATION[crypto_generichash_blake2b_PERSONALBYTES] =
17  {'Z', 'c', 'a', 's', 'h', 'S', 'a', 'p', 'l', 'i', 'n', 'g', 'F', 'V', 'F', 'P'};
18 
19 namespace libzcash {
20 
21 
24  CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
25  ss << *this;
26  return Hash(ss.begin(), ss.end());
27 }
28 
30  uint256 ak;
31  uint256 nk;
34  return SaplingFullViewingKey(ak, nk, ovk);
35 }
36 
38  return SaplingExpandedSpendingKey(PRF_ask(*this), PRF_nsk(*this), PRF_ovk(*this));
39 }
40 
43 }
44 
46  uint256 ivk;
48  return SaplingIncomingViewingKey(ivk);
49 }
50 
52  uint256 ivk;
54  return !ivk.IsNull();
55 }
56 
59  ss << *this;
60  return ss.GetHash();
61 }
62 
63 
65  while (true) {
67  if (sk.full_viewing_key().is_valid()) {
68  return sk;
69  }
70  }
71 }
72 
74  uint256 pk_d;
75  if (librustzcash_check_diversifier(d.data())) {
76  librustzcash_ivk_to_pkd(this->begin(), d.data(), pk_d.begin());
77  return SaplingPaymentAddress(d, pk_d);
78  } else {
79  return nullopt;
80  }
81 }
82 
84  // Iterates within default_diversifier to ensure a valid address is returned
86  assert(addrOpt != nullopt);
87  return addrOpt.value();
88 }
89 
90 }
91 
93  return zaddr.which() != 0;
94 }
const unsigned char ZCASH_SAPLING_FVFP_PERSONALIZATION[crypto_generichash_blake2b_PERSONALBYTES]
Definition: address.cpp:16
bool IsValidPaymentAddress(const libzcash::PaymentAddress &zaddr)
Check whether a PaymentAddress is not an InvalidEncoding.
Definition: address.cpp:92
A writer stream (for serialization) that computes a 256-bit BLAKE2b hash.
Definition: hash.h:298
uint256 GetHash()
Definition: hash.h:321
const_iterator end() const
Definition: streams.h:163
const_iterator begin() const
Definition: streams.h:161
bool IsNull() const
Definition: uint256.h:36
unsigned char * begin()
Definition: uint256.h:63
SaplingFullViewingKey full_viewing_key() const
Definition: address.cpp:29
SaplingIncomingViewingKey in_viewing_key() const
Definition: address.cpp:45
uint256 GetFingerprint() const
Get the fingerprint of this full viewing key (as defined in ZIP 32).
Definition: address.cpp:57
Optional< SaplingPaymentAddress > address(diversifier_t d) const
Definition: address.cpp:73
Sapling functions.
Definition: address.h:30
uint256 GetHash() const
Get the 256-bit SHA256d hash of this payment address.
Definition: address.cpp:23
static SaplingSpendingKey random()
Definition: address.cpp:64
SaplingPaymentAddress default_address() const
Definition: address.cpp:83
SaplingFullViewingKey full_viewing_key() const
Definition: address.cpp:41
SaplingExpandedSpendingKey expanded_spending_key() const
Definition: address.cpp:37
256-bit opaque blob.
Definition: uint256.h:138
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
Definition: hash.h:173
bool librustzcash_check_diversifier(const unsigned char *diversifier)
void librustzcash_crh_ivk(const unsigned char *ak, const unsigned char *nk, unsigned char *result)
void librustzcash_ask_to_ak(const unsigned char *ask, unsigned char *result)
void librustzcash_nsk_to_nk(const unsigned char *nsk, unsigned char *result)
bool librustzcash_ivk_to_pkd(const unsigned char *ivk, const unsigned char *diversifier, unsigned char *result)
boost::variant< InvalidEncoding, SaplingPaymentAddress > PaymentAddress
Definition: address.h:127
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
uint256 PRF_ovk(const uint256 &sk)
Definition: prf.cpp:50
uint256 PRF_ask(const uint256 &sk)
Sapling functions.
Definition: prf.cpp:34
uint256 PRF_nsk(const uint256 &sk)
Definition: prf.cpp:42
std::array< unsigned char, 11 > default_diversifier(const uint256 &sk)
Definition: prf.cpp:58
std::array< unsigned char, ZC_DIVERSIFIER_SIZE > diversifier_t
Definition: sapling.h:38
uint256 random_uint256()
@ SER_NETWORK
Definition: serialize.h:174
@ SER_GETHASH
Definition: serialize.h:176