Add diversifier_index_t::ToTransparentChildIndex
This commit is contained in:
parent
6e6359229a
commit
cfee863644
|
@ -72,6 +72,15 @@ uint256 ovkForShieldingFromTaddr(HDSeed& seed) {
|
||||||
|
|
||||||
namespace libzcash {
|
namespace libzcash {
|
||||||
|
|
||||||
|
std::optional<unsigned int> diversifier_index_t::ToTransparentChildIndex() const {
|
||||||
|
// ensure that the diversifier index is small enough for a t-addr
|
||||||
|
if (MAX_TRANSPARENT_CHILD_IDX < *this) {
|
||||||
|
return std::nullopt;
|
||||||
|
} else {
|
||||||
|
return (unsigned int) GetUint64(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Transparent
|
// Transparent
|
||||||
//
|
//
|
||||||
|
@ -336,8 +345,8 @@ std::optional<ZcashdUnifiedAddress> ZcashdUnifiedFullViewingKey::Address(diversi
|
||||||
ZcashdUnifiedAddress ua;
|
ZcashdUnifiedAddress ua;
|
||||||
|
|
||||||
if (transparentKey.has_value()) {
|
if (transparentKey.has_value()) {
|
||||||
// ensure that the diversifier index is small enough for a t-addr
|
auto childIndex = j.ToTransparentChildIndex();
|
||||||
if (MAX_TRANSPARENT_CHILD_IDX < j) return std::nullopt;
|
if (!childIndex.has_value()) return std::nullopt;
|
||||||
|
|
||||||
CExtPubKey changeKey;
|
CExtPubKey changeKey;
|
||||||
if (!transparentKey.value().Derive(changeKey, 0)) {
|
if (!transparentKey.value().Derive(changeKey, 0)) {
|
||||||
|
@ -345,8 +354,7 @@ std::optional<ZcashdUnifiedAddress> ZcashdUnifiedFullViewingKey::Address(diversi
|
||||||
}
|
}
|
||||||
|
|
||||||
CExtPubKey childKey;
|
CExtPubKey childKey;
|
||||||
unsigned int childIndex = (unsigned int) j.GetUint64(0);
|
if (changeKey.Derive(childKey, childIndex.value())) {
|
||||||
if (changeKey.Derive(childKey, childIndex)) {
|
|
||||||
ua.transparentKey = childKey.pubkey;
|
ua.transparentKey = childKey.pubkey;
|
||||||
} else {
|
} else {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
|
@ -195,6 +195,8 @@ public:
|
||||||
return false; //overflow
|
return false; //overflow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<unsigned int> ToTransparentChildIndex() const;
|
||||||
|
|
||||||
friend bool operator<(const diversifier_index_t& a, const diversifier_index_t& b) {
|
friend bool operator<(const diversifier_index_t& a, const diversifier_index_t& b) {
|
||||||
for (int i = 10; i >= 0; i--) {
|
for (int i = 10; i >= 0; i--) {
|
||||||
if (a.data[i] == b.data[i]) {
|
if (a.data[i] == b.data[i]) {
|
||||||
|
|
Loading…
Reference in New Issue