Rename xsk to expsk
xsk will be used for ZIP 32 extended spending keys, so renaming here to reduce confusion.
This commit is contained in:
@@ -28,7 +28,7 @@ TEST(TransactionBuilder, Invoke)
|
|||||||
auto fvk_from = sk_from.full_viewing_key();
|
auto fvk_from = sk_from.full_viewing_key();
|
||||||
|
|
||||||
auto sk = libzcash::SaplingSpendingKey::random();
|
auto sk = libzcash::SaplingSpendingKey::random();
|
||||||
auto xsk = sk.expanded_spending_key();
|
auto expsk = sk.expanded_spending_key();
|
||||||
auto fvk = sk.full_viewing_key();
|
auto fvk = sk.full_viewing_key();
|
||||||
auto ivk = fvk.in_viewing_key();
|
auto ivk = fvk.in_viewing_key();
|
||||||
libzcash::diversifier_t d = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
libzcash::diversifier_t d = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
@@ -69,9 +69,9 @@ TEST(TransactionBuilder, Invoke)
|
|||||||
// Create a Sapling-only transaction
|
// Create a Sapling-only transaction
|
||||||
// 0.0004 z-ZEC in, 0.00025 z-ZEC out, 0.0001 t-ZEC fee, 0.00005 z-ZEC change
|
// 0.0004 z-ZEC in, 0.00025 z-ZEC out, 0.0001 t-ZEC fee, 0.00005 z-ZEC change
|
||||||
auto builder2 = TransactionBuilder(consensusParams, 2);
|
auto builder2 = TransactionBuilder(consensusParams, 2);
|
||||||
ASSERT_TRUE(builder2.AddSaplingSpend(xsk, note, anchor, witness));
|
ASSERT_TRUE(builder2.AddSaplingSpend(expsk, note, anchor, witness));
|
||||||
// Check that trying to add a different anchor fails
|
// Check that trying to add a different anchor fails
|
||||||
ASSERT_FALSE(builder2.AddSaplingSpend(xsk, note, uint256(), witness));
|
ASSERT_FALSE(builder2.AddSaplingSpend(expsk, note, uint256(), witness));
|
||||||
|
|
||||||
builder2.AddSaplingOutput(fvk, pk, 25000, {});
|
builder2.AddSaplingOutput(fvk, pk, 25000, {});
|
||||||
auto maybe_tx2 = builder2.Build();
|
auto maybe_tx2 = builder2.Build();
|
||||||
@@ -130,7 +130,7 @@ TEST(TransactionBuilder, FailsWithNegativeChange)
|
|||||||
|
|
||||||
// Generate dummy Sapling address
|
// Generate dummy Sapling address
|
||||||
auto sk = libzcash::SaplingSpendingKey::random();
|
auto sk = libzcash::SaplingSpendingKey::random();
|
||||||
auto xsk = sk.expanded_spending_key();
|
auto expsk = sk.expanded_spending_key();
|
||||||
auto fvk = sk.full_viewing_key();
|
auto fvk = sk.full_viewing_key();
|
||||||
auto pk = sk.default_address();
|
auto pk = sk.default_address();
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ TEST(TransactionBuilder, FailsWithNegativeChange)
|
|||||||
|
|
||||||
// Fails if there is insufficient input
|
// Fails if there is insufficient input
|
||||||
// 0.0005 t-ZEC out, 0.0001 t-ZEC fee, 0.00059999 z-ZEC in
|
// 0.0005 t-ZEC out, 0.0001 t-ZEC fee, 0.00059999 z-ZEC in
|
||||||
EXPECT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
|
EXPECT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||||
EXPECT_FALSE(static_cast<bool>(builder.Build()));
|
EXPECT_FALSE(static_cast<bool>(builder.Build()));
|
||||||
|
|
||||||
// Succeeds if there is sufficient input
|
// Succeeds if there is sufficient input
|
||||||
@@ -185,7 +185,7 @@ TEST(TransactionBuilder, ChangeOutput)
|
|||||||
|
|
||||||
// Generate dummy Sapling address
|
// Generate dummy Sapling address
|
||||||
auto sk = libzcash::SaplingSpendingKey::random();
|
auto sk = libzcash::SaplingSpendingKey::random();
|
||||||
auto xsk = sk.expanded_spending_key();
|
auto expsk = sk.expanded_spending_key();
|
||||||
auto pk = sk.default_address();
|
auto pk = sk.default_address();
|
||||||
|
|
||||||
// Generate dummy Sapling note
|
// Generate dummy Sapling note
|
||||||
@@ -220,7 +220,7 @@ TEST(TransactionBuilder, ChangeOutput)
|
|||||||
{
|
{
|
||||||
auto builder = TransactionBuilder(consensusParams, 1, &keystore);
|
auto builder = TransactionBuilder(consensusParams, 1, &keystore);
|
||||||
builder.AddTransparentInput(COutPoint(), scriptPubKey, 25000);
|
builder.AddTransparentInput(COutPoint(), scriptPubKey, 25000);
|
||||||
ASSERT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
|
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||||
auto maybe_tx = builder.Build();
|
auto maybe_tx = builder.Build();
|
||||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||||
auto tx = maybe_tx.get();
|
auto tx = maybe_tx.get();
|
||||||
@@ -282,7 +282,7 @@ TEST(TransactionBuilder, SetFee)
|
|||||||
|
|
||||||
// Generate dummy Sapling address
|
// Generate dummy Sapling address
|
||||||
auto sk = libzcash::SaplingSpendingKey::random();
|
auto sk = libzcash::SaplingSpendingKey::random();
|
||||||
auto xsk = sk.expanded_spending_key();
|
auto expsk = sk.expanded_spending_key();
|
||||||
auto fvk = sk.full_viewing_key();
|
auto fvk = sk.full_viewing_key();
|
||||||
auto pk = sk.default_address();
|
auto pk = sk.default_address();
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ TEST(TransactionBuilder, SetFee)
|
|||||||
// Default fee
|
// Default fee
|
||||||
{
|
{
|
||||||
auto builder = TransactionBuilder(consensusParams, 1);
|
auto builder = TransactionBuilder(consensusParams, 1);
|
||||||
ASSERT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
|
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||||
auto maybe_tx = builder.Build();
|
auto maybe_tx = builder.Build();
|
||||||
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
ASSERT_EQ(static_cast<bool>(maybe_tx), true);
|
||||||
@@ -314,7 +314,7 @@ TEST(TransactionBuilder, SetFee)
|
|||||||
// Configured fee
|
// Configured fee
|
||||||
{
|
{
|
||||||
auto builder = TransactionBuilder(consensusParams, 1);
|
auto builder = TransactionBuilder(consensusParams, 1);
|
||||||
ASSERT_TRUE(builder.AddSaplingSpend(xsk, note, anchor, witness));
|
ASSERT_TRUE(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||||
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
builder.AddSaplingOutput(fvk, pk, 25000, {});
|
||||||
builder.SetFee(20000);
|
builder.SetFee(20000);
|
||||||
auto maybe_tx = builder.Build();
|
auto maybe_tx = builder.Build();
|
||||||
|
|||||||
@@ -12,10 +12,10 @@
|
|||||||
#include <librustzcash.h>
|
#include <librustzcash.h>
|
||||||
|
|
||||||
SpendDescriptionInfo::SpendDescriptionInfo(
|
SpendDescriptionInfo::SpendDescriptionInfo(
|
||||||
libzcash::SaplingExpandedSpendingKey xsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness) : xsk(xsk), note(note), anchor(anchor), witness(witness)
|
ZCSaplingIncrementalWitness witness) : expsk(expsk), note(note), anchor(anchor), witness(witness)
|
||||||
{
|
{
|
||||||
librustzcash_sapling_generate_r(alpha.begin());
|
librustzcash_sapling_generate_r(alpha.begin());
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ TransactionBuilder::TransactionBuilder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TransactionBuilder::AddSaplingSpend(
|
bool TransactionBuilder::AddSaplingSpend(
|
||||||
libzcash::SaplingExpandedSpendingKey xsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness)
|
ZCSaplingIncrementalWitness witness)
|
||||||
@@ -41,7 +41,7 @@ bool TransactionBuilder::AddSaplingSpend(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spends.emplace_back(xsk, note, anchor, witness);
|
spends.emplace_back(expsk, note, anchor, witness);
|
||||||
mtx.valueBalance += note.value();
|
mtx.valueBalance += note.value();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
|
|||||||
// tChangeAddr has already been validated.
|
// tChangeAddr has already been validated.
|
||||||
assert(AddTransparentOutput(tChangeAddr.value(), change));
|
assert(AddTransparentOutput(tChangeAddr.value(), change));
|
||||||
} else if (!spends.empty()) {
|
} else if (!spends.empty()) {
|
||||||
auto fvk = spends[0].xsk.full_viewing_key();
|
auto fvk = spends[0].expsk.full_viewing_key();
|
||||||
auto note = spends[0].note;
|
auto note = spends[0].note;
|
||||||
libzcash::SaplingPaymentAddress changeAddr(note.d, note.pk_d);
|
libzcash::SaplingPaymentAddress changeAddr(note.d, note.pk_d);
|
||||||
AddSaplingOutput(fvk, changeAddr, change, {});
|
AddSaplingOutput(fvk, changeAddr, change, {});
|
||||||
@@ -150,7 +150,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
|
|||||||
for (auto spend : spends) {
|
for (auto spend : spends) {
|
||||||
auto cm = spend.note.cm();
|
auto cm = spend.note.cm();
|
||||||
auto nf = spend.note.nullifier(
|
auto nf = spend.note.nullifier(
|
||||||
spend.xsk.full_viewing_key(), spend.witness.position());
|
spend.expsk.full_viewing_key(), spend.witness.position());
|
||||||
if (!(cm && nf)) {
|
if (!(cm && nf)) {
|
||||||
librustzcash_sapling_proving_ctx_free(ctx);
|
librustzcash_sapling_proving_ctx_free(ctx);
|
||||||
return boost::none;
|
return boost::none;
|
||||||
@@ -163,8 +163,8 @@ boost::optional<CTransaction> TransactionBuilder::Build()
|
|||||||
SpendDescription sdesc;
|
SpendDescription sdesc;
|
||||||
if (!librustzcash_sapling_spend_proof(
|
if (!librustzcash_sapling_spend_proof(
|
||||||
ctx,
|
ctx,
|
||||||
spend.xsk.full_viewing_key().ak.begin(),
|
spend.expsk.full_viewing_key().ak.begin(),
|
||||||
spend.xsk.nsk.begin(),
|
spend.expsk.nsk.begin(),
|
||||||
spend.note.d.data(),
|
spend.note.d.data(),
|
||||||
spend.note.r.begin(),
|
spend.note.r.begin(),
|
||||||
spend.alpha.begin(),
|
spend.alpha.begin(),
|
||||||
@@ -247,7 +247,7 @@ boost::optional<CTransaction> TransactionBuilder::Build()
|
|||||||
// Create Sapling spendAuth and binding signatures
|
// Create Sapling spendAuth and binding signatures
|
||||||
for (size_t i = 0; i < spends.size(); i++) {
|
for (size_t i = 0; i < spends.size(); i++) {
|
||||||
librustzcash_sapling_spend_sig(
|
librustzcash_sapling_spend_sig(
|
||||||
spends[i].xsk.ask.begin(),
|
spends[i].expsk.ask.begin(),
|
||||||
spends[i].alpha.begin(),
|
spends[i].alpha.begin(),
|
||||||
dataToBeSigned.begin(),
|
dataToBeSigned.begin(),
|
||||||
mtx.vShieldedSpend[i].spendAuthSig.data());
|
mtx.vShieldedSpend[i].spendAuthSig.data());
|
||||||
|
|||||||
@@ -19,14 +19,14 @@
|
|||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
struct SpendDescriptionInfo {
|
struct SpendDescriptionInfo {
|
||||||
libzcash::SaplingExpandedSpendingKey xsk;
|
libzcash::SaplingExpandedSpendingKey expsk;
|
||||||
libzcash::SaplingNote note;
|
libzcash::SaplingNote note;
|
||||||
uint256 alpha;
|
uint256 alpha;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
ZCSaplingIncrementalWitness witness;
|
ZCSaplingIncrementalWitness witness;
|
||||||
|
|
||||||
SpendDescriptionInfo(
|
SpendDescriptionInfo(
|
||||||
libzcash::SaplingExpandedSpendingKey xsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness);
|
ZCSaplingIncrementalWitness witness);
|
||||||
@@ -76,7 +76,7 @@ public:
|
|||||||
// Returns false if the anchor does not match the anchor used by
|
// Returns false if the anchor does not match the anchor used by
|
||||||
// previously-added Sapling spends.
|
// previously-added Sapling spends.
|
||||||
bool AddSaplingSpend(
|
bool AddSaplingSpend(
|
||||||
libzcash::SaplingExpandedSpendingKey xsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness);
|
ZCSaplingIncrementalWitness witness);
|
||||||
|
|||||||
Reference in New Issue
Block a user