src/wallet/wallet.cpp
// Generate a new Sapling spending key and return its public payment address
Generate a new Sapling spending key and return its public payment address
Generate a new Sapling spending key and return its public payment address
SaplingPaymentAddress CWallet::GenerateNewSaplingZKey()
{
    AssertLockHeld(cs_wallet); 
    int64_t nCreationTime = GetTime();
    CKeyMetadata metadata(nCreationTime);
    HDSeed seed;
    if (!GetHDSeed(seed))
        throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): HD seed not found");
    auto m = libzelcash::SaplingExtendedSpendingKey::Master(seed);
    uint32_t bip44CoinType = Params().BIP44CoinType();
    auto m_32h = m.Derive(32 | ZIP32_HARDENED_KEY_LIMIT);
    /coin_type'
    auto m_32h_cth = m_32h.Derive(bip44CoinType | ZIP32_HARDENED_KEY_LIMIT);
    libzelcash::SaplingExtendedSpendingKey xsk;
    do
    {
        xsk = m_32h_cth.Derive(hdChain.saplingAccountCounter | ZIP32_HARDENED_KEY_LIMIT);
        metadata.hdKeypath = "m/32'/" + std::to_string(bip44CoinType) + "'/" + std::to_string(hdChain.saplingAccountCounter) + "'";
        metadata.seedFp = hdChain.seedFp;
        hdChain.saplingAccountCounter++;
    } while (HaveSaplingSpendingKey(xsk.expsk.full_viewing_key()));
    if (fFileBacked && !CWalletDB(strWalletFile).WriteHDChain(hdChain))
        throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): Writing HD chain model failed");
    auto ivk = xsk.expsk.full_viewing_key().in_viewing_key();
    mapSaplingZKeyMetadata[ivk] = metadata;
    auto addr = xsk.DefaultAddress();
    if (!AddSaplingZKey(xsk, addr)) {
        throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): AddSaplingZKey failed");
    }
    return addr;
}
SaplingPaymentAddress CWallet :: GenerateNewSaplingZKey ( ) { AssertLockHeld ( cs_wallet ) ; int64_t nCreationTime = GetTime ( ) ; CKeyMetadata metadata ( nCreationTime ) ; HDSeed seed ; if ( ! GetHDSeed ( seed ) ) throw std :: runtime_error ( " " ) ; auto m = libzelcash :: SaplingExtendedSpendingKey :: Master ( seed ) ; uint32_t bip44CoinType = Params ( ) . BIP44CoinType ( ) ; auto m_32h = m . Derive ( 32 | ZIP32_HARDENED_KEY_LIMIT ) ; auto m_32h_cth = m_32h . Derive ( bip44CoinType | ZIP32_HARDENED_KEY_LIMIT ) ; libzelcash :: SaplingExtendedSpendingKey xsk ; do { xsk = m_32h_cth . Derive ( hdChain . saplingAccountCounter | ZIP32_HARDENED_KEY_LIMIT ) ; metadata . hdKeypath = " " + std :: to_string ( bip44CoinType ) + " " + std :: to_string ( hdChain . saplingAccountCounter ) + " " ; metadata . seedFp = hdChain . seedFp ; hdChain . saplingAccountCounter ++ ; } while ( HaveSaplingSpendingKey ( xsk . expsk . full_viewing_key ( ) ) ) ; if ( fFileBacked && ! CWalletDB ( strWalletFile ) . WriteHDChain ( hdChain ) ) throw std :: runtime_error ( " " ) ; auto ivk = xsk . expsk . full_viewing_key ( ) . in_viewing_key ( ) ; mapSaplingZKeyMetadata [ ivk ] = metadata ; auto addr = xsk . DefaultAddress ( ) ; if ( ! AddSaplingZKey ( xsk , addr ) ) { throw std :: runtime_error ( " " ) ; } return addr ; }
Generate a new Sapling spending key and return its public payment address
Generate a new Sapling spending key and return its public payment address
// mapSaplingZKeyMetadata // Create new metadata // Try to get the seed // We use a fixed keypath scheme of m/32'/coin_type'/account' // Derive m/32' // Derive m/32'/coin_type' // Derive account key at next index, skip keys already known to the wallet // Increment childkey index // Update the chain model in the database // return default sapling payment address.