Delete Payment Disclosures
This code will be "experimental" forever, only supports Sprout, and is a piece of shit. Deleting with fire. Sapling viewing keys are the replacement, which already exist.
This commit is contained in:
@@ -133,9 +133,6 @@ saplingNoteInputs_(saplingNoteInputs), recipient_(recipient), fee_(fee), context
|
||||
// Lock UTXOs
|
||||
lock_utxos();
|
||||
lock_notes();
|
||||
|
||||
// Enable payment disclosure if requested
|
||||
paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", true);
|
||||
}
|
||||
|
||||
AsyncRPCOperation_mergetoaddress::~AsyncRPCOperation_mergetoaddress()
|
||||
@@ -210,25 +207,10 @@ void AsyncRPCOperation_mergetoaddress::main()
|
||||
|
||||
unlock_utxos(); // clean up
|
||||
unlock_notes(); // clean up
|
||||
|
||||
// !!! Payment disclosure START
|
||||
if (success && paymentDisclosureMode && paymentDisclosureData_.size() > 0) {
|
||||
uint256 txidhash = tx_.GetHash();
|
||||
std::shared_ptr<PaymentDisclosureDB> db = PaymentDisclosureDB::sharedInstance();
|
||||
for (PaymentDisclosureKeyInfo p : paymentDisclosureData_) {
|
||||
p.first.hash = txidhash;
|
||||
if (!db->Put(p.first, p.second)) {
|
||||
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
|
||||
} else {
|
||||
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
// !!! Payment disclosure END
|
||||
}
|
||||
|
||||
// Notes:
|
||||
// 1. #1359 Currently there is no limit set on the number of joinsplits, so size of tx could be invalid.
|
||||
// 1. #1359 Currently there is no limit set on the number of inputs+outputs, so size of tx could be invalid.
|
||||
// 2. #1277 Spendable notes are not locked, so an operation running in parallel could also try to use them.
|
||||
bool AsyncRPCOperation_mergetoaddress::main_impl()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Copyright (c) 2019-2020 The Hush developers
|
||||
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -22,7 +24,6 @@
|
||||
|
||||
#include "amount.h"
|
||||
#include "asyncrpcoperation.h"
|
||||
#include "paymentdisclosure.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "transaction_builder.h"
|
||||
#include "wallet.h"
|
||||
@@ -93,8 +94,6 @@ public:
|
||||
|
||||
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
||||
|
||||
bool paymentDisclosureMode = true; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
|
||||
private:
|
||||
friend class TEST_FRIEND_AsyncRPCOperation_mergetoaddress; // class for unit testing
|
||||
|
||||
@@ -148,8 +147,6 @@ private:
|
||||
|
||||
void unlock_notes();
|
||||
|
||||
// payment disclosure!
|
||||
std::vector<PaymentDisclosureKeyInfo> paymentDisclosureData_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -211,25 +211,10 @@ void AsyncRPCOperation_sendmany::main() {
|
||||
s += strprintf(", error=%s)\n", getErrorMessage());
|
||||
}
|
||||
LogPrintf("%s",s);
|
||||
|
||||
// !!! Payment disclosure START
|
||||
if (success && paymentDisclosureMode && paymentDisclosureData_.size()>0) {
|
||||
uint256 txidhash = tx_.GetHash();
|
||||
std::shared_ptr<PaymentDisclosureDB> db = PaymentDisclosureDB::sharedInstance();
|
||||
for (PaymentDisclosureKeyInfo p : paymentDisclosureData_) {
|
||||
p.first.hash = txidhash;
|
||||
if (!db->Put(p.first, p.second)) {
|
||||
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
|
||||
} else {
|
||||
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
// !!! Payment disclosure END
|
||||
}
|
||||
|
||||
// Notes:
|
||||
// 1. #1159 Currently there is no limit set on the number of joinsplits, so size of tx could be invalid.
|
||||
// 1. #1159 Currently there is no limit set on the number of shielded spends, so size of tx could be invalid.
|
||||
// 2. #1360 Note selection is not optimal
|
||||
// 3. #1277 Spendable notes are not locked, so an operation running in parallel could also try to use them
|
||||
bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Copyright (c) 2016 The Zcash developers
|
||||
// Copyright (c) 2019-2020 The Hush developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -27,7 +28,6 @@
|
||||
#include "zcash/JoinSplit.hpp"
|
||||
#include "zcash/Address.hpp"
|
||||
#include "wallet.h"
|
||||
#include "paymentdisclosure.h"
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
@@ -90,8 +90,6 @@ public:
|
||||
|
||||
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
||||
|
||||
bool paymentDisclosureMode = true; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
|
||||
private:
|
||||
friend class TEST_FRIEND_AsyncRPCOperation_sendmany; // class for unit testing
|
||||
|
||||
@@ -143,9 +141,6 @@ private:
|
||||
uint256 anchor);
|
||||
|
||||
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
||||
|
||||
// payment disclosure!
|
||||
std::vector<PaymentDisclosureKeyInfo> paymentDisclosureData_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -48,9 +48,6 @@
|
||||
|
||||
#include "asyncrpcoperation_shieldcoinbase.h"
|
||||
|
||||
#include "paymentdisclosure.h"
|
||||
#include "paymentdisclosuredb.h"
|
||||
|
||||
using namespace libzcash;
|
||||
extern uint64_t ASSETCHAINS_TIMELOCKGTE;
|
||||
|
||||
@@ -108,8 +105,6 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
|
||||
// Lock UTXOs
|
||||
lock_utxos();
|
||||
|
||||
// Enable payment disclosure if requested
|
||||
paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", true);
|
||||
}
|
||||
|
||||
AsyncRPCOperation_shieldcoinbase::~AsyncRPCOperation_shieldcoinbase() {
|
||||
@@ -181,20 +176,6 @@ void AsyncRPCOperation_shieldcoinbase::main() {
|
||||
|
||||
unlock_utxos(); // clean up
|
||||
|
||||
// !!! Payment disclosure START
|
||||
if (success && paymentDisclosureMode && paymentDisclosureData_.size()>0) {
|
||||
uint256 txidhash = tx_.GetHash();
|
||||
std::shared_ptr<PaymentDisclosureDB> db = PaymentDisclosureDB::sharedInstance();
|
||||
for (PaymentDisclosureKeyInfo p : paymentDisclosureData_) {
|
||||
p.first.hash = txidhash;
|
||||
if (!db->Put(p.first, p.second)) {
|
||||
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
|
||||
} else {
|
||||
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
// !!! Payment disclosure END
|
||||
}
|
||||
|
||||
bool AsyncRPCOperation_shieldcoinbase::main_impl() {
|
||||
|
||||
@@ -34,8 +34,6 @@
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
#include "paymentdisclosure.h"
|
||||
|
||||
// Default transaction fee if caller does not specify one.
|
||||
#define SHIELD_COINBASE_DEFAULT_MINERS_FEE 10000
|
||||
|
||||
@@ -81,8 +79,6 @@ public:
|
||||
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
||||
bool cheatSpend = false; // set when this is shielding a cheating coinbase
|
||||
|
||||
bool paymentDisclosureMode = true; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
|
||||
private:
|
||||
friend class ShieldToAddress;
|
||||
friend class TEST_FRIEND_AsyncRPCOperation_shieldcoinbase; // class for unit testing
|
||||
@@ -110,9 +106,6 @@ private:
|
||||
void lock_utxos();
|
||||
|
||||
void unlock_utxos();
|
||||
|
||||
// payment disclosure!
|
||||
std::vector<PaymentDisclosureKeyInfo> paymentDisclosureData_;
|
||||
};
|
||||
|
||||
class ShieldToAddress : public boost::static_visitor<bool>
|
||||
|
||||
@@ -1,324 +0,0 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Copyright (c) 2019-2020 The Hush developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright © 2014-2019 The SuperNET Developers. *
|
||||
* *
|
||||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
|
||||
* the top-level directory of this distribution for the individual copyright *
|
||||
* holder information and the developer policies on copyright and licensing. *
|
||||
* *
|
||||
* Unless otherwise agreed in a custom licensing agreement, no part of the *
|
||||
* SuperNET software, including this file may be copied, modified, propagated *
|
||||
* or distributed except according to the terms contained in the LICENSE file *
|
||||
* *
|
||||
* Removal or modification of this copyright notice is prohibited. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "rpc/server.h"
|
||||
#include "init.h"
|
||||
#include "key_io.h"
|
||||
#include "main.h"
|
||||
#include "script/script.h"
|
||||
#include "script/standard.h"
|
||||
#include "sync.h"
|
||||
#include "util.h"
|
||||
#include "utiltime.h"
|
||||
#include "wallet.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
#include "paymentdisclosure.h"
|
||||
#include "paymentdisclosuredb.h"
|
||||
|
||||
#include "zcash/Note.hpp"
|
||||
#include "zcash/NoteEncryption.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace libzcash;
|
||||
|
||||
// Function declaration for function implemented in wallet/rpcwallet.cpp
|
||||
bool EnsureWalletIsAvailable(bool avoidException);
|
||||
|
||||
/**
|
||||
* RPC call to generate a payment disclosure
|
||||
*/
|
||||
UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
string enableArg = "paymentdisclosure";
|
||||
auto fEnablePaymentDisclosure = fExperimentalMode && GetBoolArg("-" + enableArg, true);
|
||||
string strPaymentDisclosureDisabledMsg = "";
|
||||
if (!fEnablePaymentDisclosure) {
|
||||
strPaymentDisclosureDisabledMsg = experimentalDisabledHelpMsg("z_getpaymentdisclosure", enableArg);
|
||||
}
|
||||
|
||||
if (fHelp || params.size() < 3 || params.size() > 4 )
|
||||
throw runtime_error(
|
||||
"z_getpaymentdisclosure \"txid\" \"js_index\" \"output_index\" (\"message\") \n"
|
||||
"\nGenerate a payment disclosure for a given joinsplit output.\n"
|
||||
"\nEXPERIMENTAL FEATURE\n"
|
||||
+ strPaymentDisclosureDisabledMsg +
|
||||
"\nArguments:\n"
|
||||
"1. \"txid\" (string, required) \n"
|
||||
"2. \"js_index\" (string, required) \n"
|
||||
"3. \"output_index\" (string, required) \n"
|
||||
"4. \"message\" (string, optional) \n"
|
||||
"\nResult:\n"
|
||||
"\"paymentdisclosure\" (string) Hex data string, with \"zpd:\" prefix.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_getpaymentdisclosure", "96f12882450429324d5f3b48630e3168220e49ab7b0f066e5c2935a6b88bb0f2 0 0 \"refund\"")
|
||||
+ HelpExampleRpc("z_getpaymentdisclosure", "\"96f12882450429324d5f3b48630e3168220e49ab7b0f066e5c2935a6b88bb0f2\", 0, 0, \"refund\"")
|
||||
);
|
||||
|
||||
if (!fEnablePaymentDisclosure) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: payment disclosure is disabled.");
|
||||
}
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
EnsureWalletIsUnlocked();
|
||||
|
||||
// Check wallet knows about txid
|
||||
string txid = params[0].get_str();
|
||||
uint256 hash;
|
||||
hash.SetHex(txid);
|
||||
|
||||
CTransaction tx;
|
||||
uint256 hashBlock;
|
||||
|
||||
// Check txid has been seen
|
||||
if (!GetTransaction(hash, tx, hashBlock, true)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
|
||||
}
|
||||
|
||||
// Check tx has been confirmed
|
||||
if (hashBlock.IsNull()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Transaction has not been confirmed yet");
|
||||
}
|
||||
|
||||
// Check is mine
|
||||
if (!pwalletMain->mapWallet.count(hash)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Transaction does not belong to the wallet");
|
||||
}
|
||||
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
|
||||
|
||||
// Check if shielded tx
|
||||
if (wtx.vjoinsplit.empty()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Transaction is not a shielded transaction");
|
||||
}
|
||||
|
||||
// Check js_index
|
||||
int js_index = params[1].get_int();
|
||||
if (js_index < 0 || js_index >= wtx.vjoinsplit.size()) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid js_index");
|
||||
}
|
||||
|
||||
// Check output_index
|
||||
int output_index = params[2].get_int();
|
||||
if (output_index < 0 || output_index >= ZC_NUM_JS_OUTPUTS) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid output_index");
|
||||
}
|
||||
|
||||
// Get message if it exists
|
||||
string msg;
|
||||
if (params.size() == 4) {
|
||||
msg = params[3].get_str();
|
||||
}
|
||||
|
||||
// Create PaymentDisclosureKey
|
||||
PaymentDisclosureKey key = {hash, (size_t)js_index, (uint8_t)output_index };
|
||||
|
||||
// TODO: In future, perhaps init the DB in init.cpp
|
||||
shared_ptr<PaymentDisclosureDB> db = PaymentDisclosureDB::sharedInstance();
|
||||
PaymentDisclosureInfo info;
|
||||
if (!db->Get(key, info)) {
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Could not find payment disclosure info for the given joinsplit output");
|
||||
}
|
||||
|
||||
PaymentDisclosure pd( wtx.joinSplitPubKey, key, info, msg );
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << pd;
|
||||
string strHex = HexStr(ss.begin(), ss.end());
|
||||
return PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX + strHex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* RPC call to validate a payment disclosure data blob.
|
||||
*/
|
||||
UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
string enableArg = "paymentdisclosure";
|
||||
auto fEnablePaymentDisclosure = fExperimentalMode && GetBoolArg("-" + enableArg, true);
|
||||
string strPaymentDisclosureDisabledMsg = "";
|
||||
if (!fEnablePaymentDisclosure) {
|
||||
strPaymentDisclosureDisabledMsg = experimentalDisabledHelpMsg("z_validatepaymentdisclosure", enableArg);
|
||||
}
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"z_validatepaymentdisclosure \"paymentdisclosure\"\n"
|
||||
"\nValidates a payment disclosure.\n"
|
||||
"\nEXPERIMENTAL FEATURE\n"
|
||||
+ strPaymentDisclosureDisabledMsg +
|
||||
"\nArguments:\n"
|
||||
"1. \"paymentdisclosure\" (string, required) Hex data string, with \"zpd:\" prefix.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_validatepaymentdisclosure", "\"zpd:706462ff004c561a0447ba2ec51184e6c204...\"")
|
||||
+ HelpExampleRpc("z_validatepaymentdisclosure", "\"zpd:706462ff004c561a0447ba2ec51184e6c204...\"")
|
||||
);
|
||||
|
||||
if (!fEnablePaymentDisclosure) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: payment disclosure is disabled.");
|
||||
}
|
||||
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: payment disclosures not implemented for Sapling yet");
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
EnsureWalletIsUnlocked();
|
||||
|
||||
// Verify the payment disclosure input begins with "zpd:" prefix.
|
||||
string strInput = params[0].get_str();
|
||||
size_t pos = strInput.find(PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX);
|
||||
if (pos != 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, payment disclosure prefix not found.");
|
||||
}
|
||||
string hexInput = strInput.substr(strlen(PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX));
|
||||
if (!IsHex(hexInput))
|
||||
{
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected payment disclosure data in hexadecimal format.");
|
||||
}
|
||||
|
||||
// Unserialize the payment disclosure data into an object
|
||||
PaymentDisclosure pd;
|
||||
CDataStream ss(ParseHex(hexInput), SER_NETWORK, PROTOCOL_VERSION);
|
||||
try {
|
||||
ss >> pd;
|
||||
// too much data is ignored, but if not enough data, exception of type ios_base::failure is thrown,
|
||||
// CBaseDataStream::read(): end of data: iostream error
|
||||
} catch (const std::exception &e) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, payment disclosure data is malformed.");
|
||||
}
|
||||
|
||||
if (pd.payload.marker != PAYMENT_DISCLOSURE_PAYLOAD_MAGIC_BYTES) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, payment disclosure marker not found.");
|
||||
}
|
||||
|
||||
if (pd.payload.version != PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Payment disclosure version is unsupported.");
|
||||
}
|
||||
|
||||
uint256 hash = pd.payload.txid;
|
||||
CTransaction tx;
|
||||
uint256 hashBlock;
|
||||
// Check if we have seen the transaction
|
||||
if (!GetTransaction(hash, tx, hashBlock, true)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
|
||||
}
|
||||
|
||||
// Check if the transaction has been confirmed
|
||||
if (hashBlock.IsNull()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Transaction has not been confirmed yet");
|
||||
}
|
||||
|
||||
// Check if shielded tx
|
||||
if (tx.vjoinsplit.empty()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Transaction is not a shielded transaction");
|
||||
}
|
||||
|
||||
UniValue errs(UniValue::VARR);
|
||||
UniValue o(UniValue::VOBJ);
|
||||
o.push_back(Pair("txid", pd.payload.txid.ToString()));
|
||||
|
||||
// Check js_index
|
||||
if (pd.payload.js >= tx.vjoinsplit.size()) {
|
||||
errs.push_back("Payment disclosure refers to an invalid joinsplit index");
|
||||
}
|
||||
o.push_back(Pair("jsIndex", pd.payload.js));
|
||||
|
||||
if (pd.payload.n < 0 || pd.payload.n >= ZC_NUM_JS_OUTPUTS) {
|
||||
errs.push_back("Payment disclosure refers to an invalid output index");
|
||||
}
|
||||
o.push_back(Pair("outputIndex", pd.payload.n));
|
||||
o.push_back(Pair("version", pd.payload.version));
|
||||
o.push_back(Pair("onetimePrivKey", pd.payload.esk.ToString()));
|
||||
o.push_back(Pair("message", pd.payload.message));
|
||||
o.push_back(Pair("joinSplitPubKey", tx.joinSplitPubKey.ToString()));
|
||||
|
||||
// Verify the payment disclosure was signed using the same key as the transaction i.e. the joinSplitPrivKey.
|
||||
uint256 dataToBeSigned = SerializeHash(pd.payload, SER_GETHASH, 0);
|
||||
bool sigVerified = (crypto_sign_verify_detached(pd.payloadSig.data(),
|
||||
dataToBeSigned.begin(), 32,
|
||||
tx.joinSplitPubKey.begin()) == 0);
|
||||
o.push_back(Pair("signatureVerified", sigVerified));
|
||||
if (!sigVerified) {
|
||||
errs.push_back("Payment disclosure signature does not match transaction signature");
|
||||
}
|
||||
|
||||
/*
|
||||
// Check the payment address is valid
|
||||
PaymentAddress zaddr = pd.payload.zaddr;
|
||||
{
|
||||
o.push_back(Pair("paymentAddress", EncodePaymentAddress(zaddr)));
|
||||
|
||||
try {
|
||||
// Decrypt the note to get value and memo field
|
||||
JSDescription jsdesc = tx.vjoinsplit[pd.payload.js];
|
||||
uint256 h_sig = jsdesc.h_sig(*pzcashParams, tx.joinSplitPubKey);
|
||||
|
||||
ZCPaymentDisclosureNoteDecryption decrypter;
|
||||
|
||||
ZCNoteEncryption::Ciphertext ciphertext = jsdesc.ciphertexts[pd.payload.n];
|
||||
|
||||
uint256 pk_enc = zaddr.pk_enc;
|
||||
auto plaintext = decrypter.decryptWithEsk(ciphertext, pk_enc, pd.payload.esk, h_sig, pd.payload.n);
|
||||
|
||||
CDataStream ssPlain(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssPlain << plaintext;
|
||||
SproutNotePlaintext npt;
|
||||
ssPlain >> npt;
|
||||
|
||||
string memoHexString = HexStr(npt.memo().data(), npt.memo().data() + npt.memo().size());
|
||||
o.push_back(Pair("memo", memoHexString));
|
||||
o.push_back(Pair("value", ValueFromAmount(npt.value())));
|
||||
|
||||
// Check the blockchain commitment matches decrypted note commitment
|
||||
uint256 cm_blockchain = jsdesc.commitments[pd.payload.n];
|
||||
SproutNote note = npt.note(zaddr);
|
||||
uint256 cm_decrypted = note.cm();
|
||||
bool cm_match = (cm_decrypted == cm_blockchain);
|
||||
o.push_back(Pair("commitmentMatch", cm_match));
|
||||
if (!cm_match) {
|
||||
errs.push_back("Commitment derived from payment disclosure does not match blockchain commitment");
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
errs.push_back(string("Error while decrypting payment disclosure note: ") + string(e.what()) );
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool isValid = errs.empty();
|
||||
o.push_back(Pair("valid", isValid));
|
||||
if (!isValid) {
|
||||
o.push_back(Pair("errors", errs));
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
Reference in New Issue
Block a user