Add libzcash::AccountId type.

This commit is contained in:
Kris Nuttycombe 2021-11-18 17:40:20 -07:00
parent 9202b127d0
commit 8f5591a9c1
4 changed files with 14 additions and 12 deletions

View File

@ -431,7 +431,7 @@ ZcashdUnifiedSpendingKey CWallet::GenerateNewUnifiedSpendingKey() {
} }
} }
std::optional<libzcash::ZcashdUnifiedSpendingKey> CWallet::GenerateUnifiedSpendingKeyForAccount(uint32_t accountId) { std::optional<libzcash::ZcashdUnifiedSpendingKey> CWallet::GenerateUnifiedSpendingKeyForAccount(libzcash::AccountId accountId) {
auto seed = GetMnemonicSeed(); auto seed = GetMnemonicSeed();
if (!seed.has_value()) { if (!seed.has_value()) {
throw std::runtime_error(std::string(__func__) + ": Wallet has no mnemonic HD seed."); throw std::runtime_error(std::string(__func__) + ": Wallet has no mnemonic HD seed.");

View File

@ -1097,7 +1097,7 @@ public:
* Unified keys & addresses * Unified keys & addresses
*/ */
libzcash::ZcashdUnifiedSpendingKey GenerateNewUnifiedSpendingKey(); libzcash::ZcashdUnifiedSpendingKey GenerateNewUnifiedSpendingKey();
std::optional<libzcash::ZcashdUnifiedSpendingKey> GenerateUnifiedSpendingKeyForAccount(uint32_t accountId); std::optional<libzcash::ZcashdUnifiedSpendingKey> GenerateUnifiedSpendingKeyForAccount(libzcash::AccountId accountId);
/** /**
* Increment the next transaction order id * Increment the next transaction order id

View File

@ -85,7 +85,7 @@ std::optional<unsigned int> diversifier_index_t::ToTransparentChildIndex() const
// Transparent // Transparent
// //
std::optional<std::pair<CExtKey, HDKeyPath>> DeriveBip44TransparentAccountKey(const MnemonicSeed& seed, uint32_t bip44CoinType, uint32_t accountId) { std::optional<std::pair<CExtKey, HDKeyPath>> DeriveBip44TransparentAccountKey(const MnemonicSeed& seed, uint32_t bip44CoinType, libzcash::AccountId accountId) {
auto rawSeed = seed.RawSeed(); auto rawSeed = seed.RawSeed();
auto m = CExtKey::Master(rawSeed.data(), rawSeed.size()); auto m = CExtKey::Master(rawSeed.data(), rawSeed.size());
@ -110,7 +110,7 @@ std::optional<std::pair<CExtKey, HDKeyPath>> DeriveBip44TransparentAccountKey(co
std::optional<Bip44AccountChains> Bip44AccountChains::ForAccount( std::optional<Bip44AccountChains> Bip44AccountChains::ForAccount(
const MnemonicSeed& seed, const MnemonicSeed& seed,
uint32_t bip44CoinType, uint32_t bip44CoinType,
uint32_t accountId) { libzcash::AccountId accountId) {
auto accountKeyOpt = DeriveBip44TransparentAccountKey(seed, bip44CoinType, accountId); auto accountKeyOpt = DeriveBip44TransparentAccountKey(seed, bip44CoinType, accountId);
if (!accountKeyOpt.has_value()) return std::nullopt; if (!accountKeyOpt.has_value()) return std::nullopt;
@ -251,7 +251,7 @@ SaplingExtendedSpendingKey SaplingExtendedSpendingKey::Derive(uint32_t i) const
return xsk_i; return xsk_i;
} }
std::pair<SaplingExtendedSpendingKey, HDKeyPath> SaplingExtendedSpendingKey::ForAccount(const MnemonicSeed& seed, uint32_t bip44CoinType, uint32_t accountId) { std::pair<SaplingExtendedSpendingKey, HDKeyPath> SaplingExtendedSpendingKey::ForAccount(const MnemonicSeed& seed, uint32_t bip44CoinType, libzcash::AccountId accountId) {
auto m = Master(seed); auto m = Master(seed);
// We use a fixed keypath scheme of m/32'/coin_type'/account' // We use a fixed keypath scheme of m/32'/coin_type'/account'
@ -313,7 +313,7 @@ SaplingExtendedFullViewingKey SaplingExtendedSpendingKey::ToXFVK() const
// Unified // Unified
// //
std::optional<std::pair<ZcashdUnifiedSpendingKey, HDKeyPath>> ZcashdUnifiedSpendingKey::ForAccount(const MnemonicSeed& seed, uint32_t bip44CoinType, uint32_t accountId) { std::optional<std::pair<ZcashdUnifiedSpendingKey, HDKeyPath>> ZcashdUnifiedSpendingKey::ForAccount(const MnemonicSeed& seed, uint32_t bip44CoinType, libzcash::AccountId accountId) {
ZcashdUnifiedSpendingKey usk; ZcashdUnifiedSpendingKey usk;
usk.accountId = accountId; usk.accountId = accountId;

View File

@ -165,6 +165,8 @@ uint256 ovkForShieldingFromTaddr(HDSeed& seed);
namespace libzcash { namespace libzcash {
typedef uint32_t AccountId;
/** /**
* 88-bit diversifier index. This would ideally derive from base_uint * 88-bit diversifier index. This would ideally derive from base_uint
* but those values must have bit widths that are multiples of 32. * but those values must have bit widths that are multiples of 32.
@ -290,7 +292,7 @@ struct SaplingExtendedSpendingKey {
} }
static SaplingExtendedSpendingKey Master(const HDSeed& seed); static SaplingExtendedSpendingKey Master(const HDSeed& seed);
static std::pair<SaplingExtendedSpendingKey, HDKeyPath> ForAccount(const MnemonicSeed& seed, uint32_t bip44CoinType, uint32_t accountId); static std::pair<SaplingExtendedSpendingKey, HDKeyPath> ForAccount(const MnemonicSeed& seed, uint32_t bip44CoinType, libzcash::AccountId accountId);
static std::pair<SaplingExtendedSpendingKey, HDKeyPath> Legacy(const MnemonicSeed& seed, uint32_t bip44CoinType, uint32_t addressIndex); static std::pair<SaplingExtendedSpendingKey, HDKeyPath> Legacy(const MnemonicSeed& seed, uint32_t bip44CoinType, uint32_t addressIndex);
@ -363,7 +365,7 @@ public:
class ZcashdUnifiedSpendingKey { class ZcashdUnifiedSpendingKey {
private: private:
uint32_t accountId; libzcash::AccountId accountId;
std::optional<CExtKey> transparentKey; std::optional<CExtKey> transparentKey;
std::optional<SaplingExtendedSpendingKey> saplingKey; std::optional<SaplingExtendedSpendingKey> saplingKey;
@ -372,7 +374,7 @@ public:
static std::optional<std::pair<ZcashdUnifiedSpendingKey, HDKeyPath>> ForAccount( static std::optional<std::pair<ZcashdUnifiedSpendingKey, HDKeyPath>> ForAccount(
const MnemonicSeed& mnemonic, const MnemonicSeed& mnemonic,
uint32_t bip44CoinType, uint32_t bip44CoinType,
uint32_t accountId); libzcash::AccountId accountId);
const std::optional<CExtKey>& GetTransparentKey() const { const std::optional<CExtKey>& GetTransparentKey() const {
return transparentKey; return transparentKey;
@ -390,18 +392,18 @@ std::optional<unsigned long> ParseHDKeypathAccount(uint32_t purpose, uint32_t co
class Bip44AccountChains { class Bip44AccountChains {
private: private:
uint256 seedFp; uint256 seedFp;
uint32_t accountId; libzcash::AccountId accountId;
uint32_t bip44CoinType; uint32_t bip44CoinType;
CExtKey external; CExtKey external;
CExtKey internal; CExtKey internal;
Bip44AccountChains(uint256 seedFpIn, uint32_t bip44CoinTypeIn, uint32_t accountIdIn, CExtKey externalIn, CExtKey internalIn): Bip44AccountChains(uint256 seedFpIn, uint32_t bip44CoinTypeIn, libzcash::AccountId accountIdIn, CExtKey externalIn, CExtKey internalIn):
seedFp(seedFpIn), accountId(accountIdIn), bip44CoinType(bip44CoinTypeIn), external(externalIn), internal(internalIn) {} seedFp(seedFpIn), accountId(accountIdIn), bip44CoinType(bip44CoinTypeIn), external(externalIn), internal(internalIn) {}
public: public:
static std::optional<Bip44AccountChains> ForAccount( static std::optional<Bip44AccountChains> ForAccount(
const MnemonicSeed& mnemonic, const MnemonicSeed& mnemonic,
uint32_t bip44CoinType, uint32_t bip44CoinType,
uint32_t accountId); libzcash::AccountId accountId);
std::optional<std::pair<CExtKey, HDKeyPath>> DeriveExternal(uint32_t addrIndex); std::optional<std::pair<CExtKey, HDKeyPath>> DeriveExternal(uint32_t addrIndex);
std::optional<std::pair<CExtKey, HDKeyPath>> DeriveInternal(uint32_t addrIndex); std::optional<std::pair<CExtKey, HDKeyPath>> DeriveInternal(uint32_t addrIndex);