]>
Commit | Line | Data |
---|---|---|
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 | ||
a6bbb26e | 17 | #include <array> |
45232b19 S |
18 | #include <cstdint> |
19 | #include <string> | |
20 | ||
21 | ||
22 | // Ensure that the two different protocol messages, payment disclosure blobs and transactions, | |
23 | // which are signed with the same key, joinSplitPrivKey, have disjoint encodings such that an | |
24 | // encoding from one context will be rejected in the other. We know that the set of valid | |
25 | // transaction versions is currently ({1..INT32_MAX}) so we will use a negative value for | |
26 | // payment disclosure of -10328976 which in hex is 0xFF626470. Serialization is in little endian | |
27 | // format, so a payment disclosure hex string begins 706462FF, which in ISO-8859-1 is "pdbÿ". | |
28 | #define PAYMENT_DISCLOSURE_PAYLOAD_MAGIC_BYTES -10328976 | |
29 | ||
30 | #define PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL 0 | |
31 | ||
61345ae7 S |
32 | #define PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX "zpd:" |
33 | ||
45232b19 S |
34 | typedef JSOutPoint PaymentDisclosureKey; |
35 | ||
36 | struct PaymentDisclosureInfo { | |
37 | uint8_t version; // 0 = experimental, 1 = first production version, etc. | |
38 | uint256 esk; // zcash/NoteEncryption.cpp | |
39 | uint256 joinSplitPrivKey; // primitives/transaction.h | |
40 | // ed25519 - not tied to implementation e.g. libsodium, see ed25519 rfc | |
41 | ||
e5eab182 | 42 | libzcash::SproutPaymentAddress zaddr; |
45232b19 S |
43 | |
44 | PaymentDisclosureInfo() : version(PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL) { | |
45 | } | |
46 | ||
e5eab182 | 47 | PaymentDisclosureInfo(uint8_t v, uint256 esk, uint256 key, libzcash::SproutPaymentAddress zaddr) : version(v), esk(esk), joinSplitPrivKey(key), zaddr(zaddr) { } |
45232b19 S |
48 | |
49 | ADD_SERIALIZE_METHODS; | |
50 | ||
51 | template <typename Stream, typename Operation> | |
68a1a592 | 52 | inline void SerializationOp(Stream& s, Operation ser_action) { |
45232b19 S |
53 | READWRITE(version); |
54 | READWRITE(esk); | |
55 | READWRITE(joinSplitPrivKey); | |
56 | READWRITE(zaddr); | |
57 | } | |
58 | ||
59 | std::string ToString() const; | |
60 | ||
61 | friend bool operator==(const PaymentDisclosureInfo& a, const PaymentDisclosureInfo& b) { | |
62 | return (a.version == b.version && a.esk == b.esk && a.joinSplitPrivKey == b.joinSplitPrivKey && a.zaddr == b.zaddr); | |
63 | } | |
64 | ||
65 | friend bool operator!=(const PaymentDisclosureInfo& a, const PaymentDisclosureInfo& b) { | |
66 | return !(a == b); | |
67 | } | |
68 | ||
69 | }; | |
70 | ||
71 | ||
72 | struct PaymentDisclosurePayload { | |
73 | int32_t marker = PAYMENT_DISCLOSURE_PAYLOAD_MAGIC_BYTES; // to be disjoint from transaction encoding | |
74 | uint8_t version; // 0 = experimental, 1 = first production version, etc. | |
75 | uint256 esk; // zcash/NoteEncryption.cpp | |
76 | uint256 txid; // primitives/transaction.h | |
6c7930f6 | 77 | uint64_t js; // Index into CTransaction.vjoinsplit |
45232b19 | 78 | uint8_t n; // Index into JSDescription fields of length ZC_NUM_JS_OUTPUTS |
e5eab182 | 79 | libzcash::SproutPaymentAddress zaddr; // zcash/Address.hpp |
45232b19 S |
80 | std::string message; // parameter to RPC call |
81 | ||
82 | ADD_SERIALIZE_METHODS; | |
83 | ||
84 | template <typename Stream, typename Operation> | |
68a1a592 | 85 | inline void SerializationOp(Stream& s, Operation ser_action) { |
45232b19 S |
86 | READWRITE(marker); |
87 | READWRITE(version); | |
88 | READWRITE(esk); | |
89 | READWRITE(txid); | |
90 | READWRITE(js); | |
91 | READWRITE(n); | |
92 | READWRITE(zaddr); | |
93 | READWRITE(message); | |
94 | } | |
95 | ||
96 | std::string ToString() const; | |
97 | ||
98 | friend bool operator==(const PaymentDisclosurePayload& a, const PaymentDisclosurePayload& b) { | |
99 | return ( | |
100 | a.version == b.version && | |
101 | a.esk == b.esk && | |
102 | a.txid == b.txid && | |
103 | a.js == b.js && | |
104 | a.n == b.n && | |
105 | a.zaddr == b.zaddr && | |
106 | a.message == b.message | |
107 | ); | |
108 | } | |
109 | ||
110 | friend bool operator!=(const PaymentDisclosurePayload& a, const PaymentDisclosurePayload& b) { | |
111 | return !(a == b); | |
112 | } | |
113 | }; | |
114 | ||
115 | struct PaymentDisclosure { | |
4fb3d05c JG |
116 | PaymentDisclosurePayload payload; |
117 | std::array<unsigned char, 64> payloadSig; | |
45232b19 S |
118 | // We use boost array because serialize doesn't like char buffer, otherwise we could do: unsigned char payloadSig[64]; |
119 | ||
120 | PaymentDisclosure() {}; | |
a6bbb26e | 121 | PaymentDisclosure(const PaymentDisclosurePayload payload, const std::array<unsigned char, 64> sig) : payload(payload), payloadSig(sig) {}; |
45232b19 S |
122 | PaymentDisclosure(const uint256& joinSplitPubKey, const PaymentDisclosureKey& key, const PaymentDisclosureInfo& info, const std::string& message); |
123 | ||
124 | ADD_SERIALIZE_METHODS; | |
125 | ||
126 | template <typename Stream, typename Operation> | |
68a1a592 | 127 | inline void SerializationOp(Stream& s, Operation ser_action) { |
45232b19 S |
128 | READWRITE(payload); |
129 | READWRITE(payloadSig); | |
130 | } | |
131 | ||
132 | std::string ToString() const; | |
133 | ||
134 | friend bool operator==(const PaymentDisclosure& a, const PaymentDisclosure& b) { | |
135 | return (a.payload == b.payload && a.payloadSig == b.payloadSig); | |
136 | } | |
137 | ||
138 | friend bool operator!=(const PaymentDisclosure& a, const PaymentDisclosure& b) { | |
139 | return !(a == b); | |
140 | } | |
141 | }; | |
142 | ||
143 | ||
144 | ||
145 | typedef std::pair<PaymentDisclosureKey, PaymentDisclosureInfo> PaymentDisclosureKeyInfo; | |
146 | ||
147 | ||
148 | #endif // ZCASH_PAYMENTDISCLOSURE_H |