]> Git Repo - VerusCoin.git/blame - src/paymentdisclosure.h
Merge branch 'dev' into assetchain-conf
[VerusCoin.git] / src / paymentdisclosure.h
CommitLineData
45232b19
S
1// Copyright (c) 2017 The Zcash developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef ZCASH_PAYMENTDISCLOSURE_H
6#define ZCASH_PAYMENTDISCLOSURE_H
7
8#include "uint256.h"
9#include "clientversion.h"
10#include "serialize.h"
11#include "streams.h"
12#include "version.h"
13
14// For JSOutPoint
15#include "wallet/wallet.h"
16
17#include <cstdint>
18#include <string>
19
20
21// Ensure that the two different protocol messages, payment disclosure blobs and transactions,
22// which are signed with the same key, joinSplitPrivKey, have disjoint encodings such that an
23// encoding from one context will be rejected in the other. We know that the set of valid
24// transaction versions is currently ({1..INT32_MAX}) so we will use a negative value for
25// payment disclosure of -10328976 which in hex is 0xFF626470. Serialization is in little endian
26// format, so a payment disclosure hex string begins 706462FF, which in ISO-8859-1 is "pdbÿ".
27#define PAYMENT_DISCLOSURE_PAYLOAD_MAGIC_BYTES -10328976
28
29#define PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL 0
30
61345ae7
S
31#define PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX "zpd:"
32
45232b19
S
33typedef JSOutPoint PaymentDisclosureKey;
34
35struct PaymentDisclosureInfo {
36 uint8_t version; // 0 = experimental, 1 = first production version, etc.
37 uint256 esk; // zcash/NoteEncryption.cpp
38 uint256 joinSplitPrivKey; // primitives/transaction.h
39 // ed25519 - not tied to implementation e.g. libsodium, see ed25519 rfc
40
41 libzcash::PaymentAddress zaddr;
42
43 PaymentDisclosureInfo() : version(PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL) {
44 }
45
46 PaymentDisclosureInfo(uint8_t v, uint256 esk, uint256 key, libzcash::PaymentAddress zaddr) : version(v), esk(esk), joinSplitPrivKey(key), zaddr(zaddr) { }
47
48 ADD_SERIALIZE_METHODS;
49
50 template <typename Stream, typename Operation>
51 inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
52 READWRITE(version);
53 READWRITE(esk);
54 READWRITE(joinSplitPrivKey);
55 READWRITE(zaddr);
56 }
57
58 std::string ToString() const;
59
60 friend bool operator==(const PaymentDisclosureInfo& a, const PaymentDisclosureInfo& b) {
61 return (a.version == b.version && a.esk == b.esk && a.joinSplitPrivKey == b.joinSplitPrivKey && a.zaddr == b.zaddr);
62 }
63
64 friend bool operator!=(const PaymentDisclosureInfo& a, const PaymentDisclosureInfo& b) {
65 return !(a == b);
66 }
67
68};
69
70
71struct PaymentDisclosurePayload {
72 int32_t marker = PAYMENT_DISCLOSURE_PAYLOAD_MAGIC_BYTES; // to be disjoint from transaction encoding
73 uint8_t version; // 0 = experimental, 1 = first production version, etc.
74 uint256 esk; // zcash/NoteEncryption.cpp
75 uint256 txid; // primitives/transaction.h
d6d312f9 76 #ifdef __LP64__
77 uint64_t js;
78 #else
45232b19 79 size_t js; // Index into CTransaction.vjoinsplit
d6d312f9 80 #endif
45232b19
S
81 uint8_t n; // Index into JSDescription fields of length ZC_NUM_JS_OUTPUTS
82 libzcash::PaymentAddress zaddr; // zcash/Address.hpp
83 std::string message; // parameter to RPC call
84
85 ADD_SERIALIZE_METHODS;
86
87 template <typename Stream, typename Operation>
88 inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
89 READWRITE(marker);
90 READWRITE(version);
91 READWRITE(esk);
92 READWRITE(txid);
93 READWRITE(js);
94 READWRITE(n);
95 READWRITE(zaddr);
96 READWRITE(message);
97 }
98
99 std::string ToString() const;
100
101 friend bool operator==(const PaymentDisclosurePayload& a, const PaymentDisclosurePayload& b) {
102 return (
103 a.version == b.version &&
104 a.esk == b.esk &&
105 a.txid == b.txid &&
106 a.js == b.js &&
107 a.n == b.n &&
108 a.zaddr == b.zaddr &&
109 a.message == b.message
110 );
111 }
112
113 friend bool operator!=(const PaymentDisclosurePayload& a, const PaymentDisclosurePayload& b) {
114 return !(a == b);
115 }
116};
117
118struct PaymentDisclosure {
119 PaymentDisclosurePayload payload;
120 boost::array<unsigned char, 64> payloadSig;
121 // We use boost array because serialize doesn't like char buffer, otherwise we could do: unsigned char payloadSig[64];
122
123 PaymentDisclosure() {};
124 PaymentDisclosure(const PaymentDisclosurePayload payload, const boost::array<unsigned char, 64> sig) : payload(payload), payloadSig(sig) {};
125 PaymentDisclosure(const uint256& joinSplitPubKey, const PaymentDisclosureKey& key, const PaymentDisclosureInfo& info, const std::string& message);
126
127 ADD_SERIALIZE_METHODS;
128
129 template <typename Stream, typename Operation>
130 inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
131 READWRITE(payload);
132 READWRITE(payloadSig);
133 }
134
135 std::string ToString() const;
136
137 friend bool operator==(const PaymentDisclosure& a, const PaymentDisclosure& b) {
138 return (a.payload == b.payload && a.payloadSig == b.payloadSig);
139 }
140
141 friend bool operator!=(const PaymentDisclosure& a, const PaymentDisclosure& b) {
142 return !(a == b);
143 }
144};
145
146
147
148typedef std::pair<PaymentDisclosureKey, PaymentDisclosureInfo> PaymentDisclosureKeyInfo;
149
150
151#endif // ZCASH_PAYMENTDISCLOSURE_H
This page took 0.05851 seconds and 4 git commands to generate.