desprout
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||||
|
// Copyright (c) 2019-2020 The Hush developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -26,83 +27,6 @@
|
|||||||
|
|
||||||
#include "librustzcash.h"
|
#include "librustzcash.h"
|
||||||
|
|
||||||
JSDescription::JSDescription(
|
|
||||||
ZCJoinSplit& params,
|
|
||||||
const uint256& joinSplitPubKey,
|
|
||||||
const uint256& anchor,
|
|
||||||
const std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
|
|
||||||
const std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
|
|
||||||
CAmount vpub_old,
|
|
||||||
CAmount vpub_new,
|
|
||||||
bool computeProof,
|
|
||||||
uint256 *esk // payment disclosure
|
|
||||||
) : vpub_old(vpub_old), vpub_new(vpub_new), anchor(anchor)
|
|
||||||
{
|
|
||||||
std::array<libzcash::SproutNote, ZC_NUM_JS_OUTPUTS> notes;
|
|
||||||
|
|
||||||
proof = params.prove(
|
|
||||||
inputs,
|
|
||||||
outputs,
|
|
||||||
notes,
|
|
||||||
ciphertexts,
|
|
||||||
ephemeralKey,
|
|
||||||
joinSplitPubKey,
|
|
||||||
randomSeed,
|
|
||||||
macs,
|
|
||||||
nullifiers,
|
|
||||||
commitments,
|
|
||||||
vpub_old,
|
|
||||||
vpub_new,
|
|
||||||
anchor,
|
|
||||||
computeProof,
|
|
||||||
esk // payment disclosure
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSDescription JSDescription::Randomized(
|
|
||||||
ZCJoinSplit& params,
|
|
||||||
const uint256& joinSplitPubKey,
|
|
||||||
const uint256& anchor,
|
|
||||||
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
|
|
||||||
std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
|
|
||||||
std::array<size_t, ZC_NUM_JS_INPUTS>& inputMap,
|
|
||||||
std::array<size_t, ZC_NUM_JS_OUTPUTS>& outputMap,
|
|
||||||
CAmount vpub_old,
|
|
||||||
CAmount vpub_new,
|
|
||||||
bool computeProof,
|
|
||||||
uint256 *esk, // payment disclosure
|
|
||||||
std::function<int(int)> gen
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Randomize the order of the inputs and outputs
|
|
||||||
inputMap = {0, 1};
|
|
||||||
outputMap = {0, 1};
|
|
||||||
|
|
||||||
assert(gen);
|
|
||||||
|
|
||||||
MappedShuffle(inputs.begin(), inputMap.begin(), ZC_NUM_JS_INPUTS, gen);
|
|
||||||
MappedShuffle(outputs.begin(), outputMap.begin(), ZC_NUM_JS_OUTPUTS, gen);
|
|
||||||
|
|
||||||
return JSDescription(
|
|
||||||
params, joinSplitPubKey, anchor, inputs, outputs,
|
|
||||||
vpub_old, vpub_new, computeProof,
|
|
||||||
esk // payment disclosure
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JSDescription::Verify(
|
|
||||||
ZCJoinSplit& params,
|
|
||||||
libzcash::ProofVerifier& verifier,
|
|
||||||
const uint256& joinSplitPubKey
|
|
||||||
) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint256 JSDescription::h_sig(ZCJoinSplit& params, const uint256& joinSplitPubKey) const
|
|
||||||
{
|
|
||||||
return params.h_sig(randomSeed, nullifiers, joinSplitPubKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string COutPoint::ToString() const
|
std::string COutPoint::ToString() const
|
||||||
{
|
{
|
||||||
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
|
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
|
||||||
|
|||||||
@@ -46,19 +46,6 @@ typedef std::tuple<std::string, CAmount, std::string> SendManyRecipient;
|
|||||||
// Input UTXO is a tuple (quadruple) of txid, vout, amount, coinbase)
|
// Input UTXO is a tuple (quadruple) of txid, vout, amount, coinbase)
|
||||||
typedef std::tuple<uint256, int, CAmount, bool, CTxDestination> SendManyInputUTXO;
|
typedef std::tuple<uint256, int, CAmount, bool, CTxDestination> SendManyInputUTXO;
|
||||||
|
|
||||||
// Input JSOP is a tuple of JSOutpoint, note and amount
|
|
||||||
typedef std::tuple<JSOutPoint, SproutNote, CAmount> SendManyInputJSOP;
|
|
||||||
|
|
||||||
// Package of info which is passed to perform_joinsplit methods.
|
|
||||||
struct AsyncJoinSplitInfo
|
|
||||||
{
|
|
||||||
std::vector<JSInput> vjsin;
|
|
||||||
std::vector<JSOutput> vjsout;
|
|
||||||
std::vector<SproutNote> notes;
|
|
||||||
CAmount vpub_old = 0;
|
|
||||||
CAmount vpub_new = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// A struct to help us track the witness and anchor for a given JSOutPoint
|
// A struct to help us track the witness and anchor for a given JSOutPoint
|
||||||
struct WitnessAnchorData {
|
struct WitnessAnchorData {
|
||||||
boost::optional<SproutWitness> witness;
|
boost::optional<SproutWitness> witness;
|
||||||
@@ -115,7 +102,7 @@ private:
|
|||||||
std::vector<SendManyRecipient> t_outputs_;
|
std::vector<SendManyRecipient> t_outputs_;
|
||||||
std::vector<SendManyRecipient> z_outputs_;
|
std::vector<SendManyRecipient> z_outputs_;
|
||||||
std::vector<SendManyInputUTXO> t_inputs_;
|
std::vector<SendManyInputUTXO> t_inputs_;
|
||||||
std::vector<SendManyInputJSOP> z_sprout_inputs_;
|
//std::vector<SendManyInputJSOP> z_sprout_inputs_;
|
||||||
std::vector<SaplingNoteEntry> z_sapling_inputs_;
|
std::vector<SaplingNoteEntry> z_sapling_inputs_;
|
||||||
|
|
||||||
TransactionBuilder builder_;
|
TransactionBuilder builder_;
|
||||||
@@ -128,18 +115,6 @@ private:
|
|||||||
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s);
|
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s);
|
||||||
bool main_impl();
|
bool main_impl();
|
||||||
|
|
||||||
// JoinSplit without any input notes to spend
|
|
||||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &);
|
|
||||||
|
|
||||||
// JoinSplit with input notes to spend (JSOutPoints))
|
|
||||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &, std::vector<JSOutPoint> & );
|
|
||||||
|
|
||||||
// JoinSplit where you have the witnesses and anchor
|
|
||||||
UniValue perform_joinsplit(
|
|
||||||
AsyncJoinSplitInfo & info,
|
|
||||||
std::vector<boost::optional < SproutWitness>> witnesses,
|
|
||||||
uint256 anchor);
|
|
||||||
|
|
||||||
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -185,22 +160,6 @@ public:
|
|||||||
return delegate->main_impl();
|
return delegate->main_impl();
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &info) {
|
|
||||||
return delegate->perform_joinsplit(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &info, std::vector<JSOutPoint> &v ) {
|
|
||||||
return delegate->perform_joinsplit(info, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
UniValue perform_joinsplit(
|
|
||||||
AsyncJoinSplitInfo & info,
|
|
||||||
std::vector<boost::optional < SproutWitness>> witnesses,
|
|
||||||
uint256 anchor)
|
|
||||||
{
|
|
||||||
return delegate->perform_joinsplit(info, witnesses, anchor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sign_send_raw_transaction(UniValue obj) {
|
void sign_send_raw_transaction(UniValue obj) {
|
||||||
delegate->sign_send_raw_transaction(obj);
|
delegate->sign_send_raw_transaction(obj);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,37 @@ public:
|
|||||||
uint256 pk_enc() const;
|
uint256 pk_enc() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: wallet.dat format depends on this
|
||||||
|
class SproutPaymentAddress {
|
||||||
|
public:
|
||||||
|
uint256 a_pk;
|
||||||
|
uint256 pk_enc;
|
||||||
|
|
||||||
|
SproutPaymentAddress() : a_pk(), pk_enc() { }
|
||||||
|
SproutPaymentAddress(uint256 a_pk, uint256 pk_enc) : a_pk(a_pk), pk_enc(pk_enc) { }
|
||||||
|
|
||||||
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
template <typename Stream, typename Operation>
|
||||||
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||||
|
READWRITE(a_pk);
|
||||||
|
READWRITE(pk_enc);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Get the 256-bit SHA256d hash of this payment address.
|
||||||
|
uint256 GetHash() const;
|
||||||
|
|
||||||
|
friend inline bool operator==(const SproutPaymentAddress& a, const SproutPaymentAddress& b) {
|
||||||
|
return a.a_pk == b.a_pk && a.pk_enc == b.pk_enc;
|
||||||
|
}
|
||||||
|
friend inline bool operator<(const SproutPaymentAddress& a, const SproutPaymentAddress& b) {
|
||||||
|
return (a.a_pk < b.a_pk ||
|
||||||
|
(a.a_pk == b.a_pk && a.pk_enc < b.pk_enc));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//! Sapling functions.
|
//! Sapling functions.
|
||||||
class SaplingPaymentAddress {
|
class SaplingPaymentAddress {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user