2017-11-23 11:20:20 -08:00
|
|
|
#ifndef ZC_ADDRESS_H_
|
|
|
|
#define ZC_ADDRESS_H_
|
2016-05-04 17:25:42 -07:00
|
|
|
|
|
|
|
#include "uint256.h"
|
2016-05-16 08:50:31 -07:00
|
|
|
#include "uint252.h"
|
2016-05-04 17:25:42 -07:00
|
|
|
#include "serialize.h"
|
|
|
|
|
|
|
|
namespace libzcash {
|
|
|
|
|
2016-08-16 03:55:06 -07:00
|
|
|
const size_t SerializedPaymentAddressSize = 64;
|
2017-03-01 11:20:42 -08:00
|
|
|
const size_t SerializedViewingKeySize = 64;
|
2016-08-16 03:55:06 -07:00
|
|
|
const size_t SerializedSpendingKeySize = 32;
|
|
|
|
|
2016-05-04 17:25:42 -07:00
|
|
|
class PaymentAddress {
|
|
|
|
public:
|
|
|
|
uint256 a_pk;
|
|
|
|
uint256 pk_enc;
|
|
|
|
|
|
|
|
PaymentAddress() : a_pk(), pk_enc() { }
|
|
|
|
PaymentAddress(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, int nType, int nVersion) {
|
|
|
|
READWRITE(a_pk);
|
|
|
|
READWRITE(pk_enc);
|
|
|
|
}
|
2016-08-08 18:34:58 -07:00
|
|
|
|
2016-08-09 22:47:13 -07:00
|
|
|
//! Get the 256-bit SHA256d hash of this payment address.
|
|
|
|
uint256 GetHash() const;
|
|
|
|
|
2016-08-31 16:38:43 -07:00
|
|
|
friend inline bool operator==(const PaymentAddress& a, const PaymentAddress& b) {
|
|
|
|
return a.a_pk == b.a_pk && a.pk_enc == b.pk_enc;
|
|
|
|
}
|
|
|
|
friend inline bool operator<(const PaymentAddress& a, const PaymentAddress& b) {
|
|
|
|
return (a.a_pk < b.a_pk ||
|
|
|
|
(a.a_pk == b.a_pk && a.pk_enc < b.pk_enc));
|
|
|
|
}
|
2016-05-04 17:25:42 -07:00
|
|
|
};
|
|
|
|
|
2017-02-23 10:27:41 -08:00
|
|
|
class ReceivingKey : public uint256 {
|
2016-05-04 17:25:42 -07:00
|
|
|
public:
|
2017-02-23 19:01:00 -08:00
|
|
|
ReceivingKey() { }
|
2017-02-23 10:27:41 -08:00
|
|
|
ReceivingKey(uint256 sk_enc) : uint256(sk_enc) { }
|
2016-05-04 17:25:42 -07:00
|
|
|
|
2017-02-23 19:01:00 -08:00
|
|
|
uint256 pk_enc() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ViewingKey {
|
|
|
|
public:
|
|
|
|
uint256 a_pk;
|
|
|
|
ReceivingKey sk_enc;
|
|
|
|
|
|
|
|
ViewingKey() : a_pk(), sk_enc() { }
|
|
|
|
ViewingKey(uint256 a_pk, ReceivingKey sk_enc) : a_pk(a_pk), sk_enc(sk_enc) { }
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(a_pk);
|
|
|
|
READWRITE(sk_enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
PaymentAddress address() const;
|
|
|
|
|
|
|
|
friend inline bool operator==(const ViewingKey& a, const ViewingKey& b) {
|
|
|
|
return a.a_pk == b.a_pk && a.sk_enc == b.sk_enc;
|
|
|
|
}
|
|
|
|
friend inline bool operator<(const ViewingKey& a, const ViewingKey& b) {
|
|
|
|
return (a.a_pk < b.a_pk ||
|
|
|
|
(a.a_pk == b.a_pk && a.sk_enc < b.sk_enc));
|
|
|
|
}
|
2016-05-04 17:25:42 -07:00
|
|
|
};
|
|
|
|
|
2016-05-16 08:50:31 -07:00
|
|
|
class SpendingKey : public uint252 {
|
2016-05-04 17:25:42 -07:00
|
|
|
public:
|
2016-05-16 08:50:31 -07:00
|
|
|
SpendingKey() : uint252() { }
|
|
|
|
SpendingKey(uint252 a_sk) : uint252(a_sk) { }
|
2016-05-04 17:25:42 -07:00
|
|
|
|
|
|
|
static SpendingKey random();
|
|
|
|
|
2017-02-23 10:27:41 -08:00
|
|
|
ReceivingKey receiving_key() const;
|
2017-02-23 19:01:00 -08:00
|
|
|
ViewingKey viewing_key() const;
|
2016-08-08 18:34:58 -07:00
|
|
|
PaymentAddress address() const;
|
2016-05-04 17:25:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-23 11:20:20 -08:00
|
|
|
#endif // ZC_ADDRESS_H_
|