BTCP-Rebase/src/zcash/Note.hpp

78 lines
2.0 KiB
C++

// Copyright (c) 2018 The Bitcoin Private developers
// Copyright (c) 2016 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_ZCASH_NOTE_H
#define BITCOIN_ZCASH_NOTE_H
#include "uint256.h"
#include "Zcash.h"
#include "Address.hpp"
#include "NoteEncryption.hpp"
#include <array>
namespace libzcash {
class Note {
public:
uint256 a_pk;
uint64_t value;
uint256 rho;
uint256 r;
Note(uint256 a_pk, uint64_t value, uint256 rho, uint256 r)
: a_pk(a_pk), value(value), rho(rho), r(r) {}
Note();
uint256 cm() const;
uint256 nullifier(const SpendingKey& a_sk) const;
};
class NotePlaintext {
public:
uint64_t value = 0;
uint256 rho;
uint256 r;
std::array<unsigned char, ZC_MEMO_SIZE> memo;
NotePlaintext() {}
NotePlaintext(const Note& note, std::array<unsigned char, ZC_MEMO_SIZE> memo);
Note note(const PaymentAddress& addr) const;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
unsigned char leadingByte = 0x00;
READWRITE(leadingByte);
if (leadingByte != 0x00) {
throw std::ios_base::failure("lead byte of NotePlaintext is not recognized");
}
READWRITE(value);
READWRITE(rho);
READWRITE(r);
READWRITE(memo);
}
static NotePlaintext decrypt(const ZCNoteDecryption& decryptor,
const ZCNoteDecryption::Ciphertext& ciphertext,
const uint256& ephemeralKey,
const uint256& h_sig,
unsigned char nonce
);
ZCNoteEncryption::Ciphertext encrypt(ZCNoteEncryption& encryptor,
const uint256& pk_enc
) const;
};
}
#endif // BITCOIN_ZCASH_NOTE_H