Implement viewing key storage in the keystore
This commit is contained in:
@@ -12,20 +12,28 @@ uint256 PaymentAddress::GetHash() const {
|
||||
return Hash(ss.begin(), ss.end());
|
||||
}
|
||||
|
||||
uint256 ReceivingKey::pk_enc() {
|
||||
uint256 ReceivingKey::pk_enc() const {
|
||||
return ZCNoteEncryption::generate_pubkey(*this);
|
||||
}
|
||||
|
||||
PaymentAddress ViewingKey::address() const {
|
||||
return PaymentAddress(a_pk, sk_enc.pk_enc());
|
||||
}
|
||||
|
||||
ReceivingKey SpendingKey::receiving_key() const {
|
||||
return ReceivingKey(ZCNoteEncryption::generate_privkey(*this));
|
||||
}
|
||||
|
||||
ViewingKey SpendingKey::viewing_key() const {
|
||||
return ViewingKey(PRF_addr_a_pk(*this), receiving_key());
|
||||
}
|
||||
|
||||
SpendingKey SpendingKey::random() {
|
||||
return SpendingKey(random_uint252());
|
||||
}
|
||||
|
||||
PaymentAddress SpendingKey::address() const {
|
||||
return PaymentAddress(PRF_addr_a_pk(*this), receiving_key().pk_enc());
|
||||
return viewing_key().address();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,9 +40,37 @@ public:
|
||||
|
||||
class ReceivingKey : public uint256 {
|
||||
public:
|
||||
ReceivingKey() { }
|
||||
ReceivingKey(uint256 sk_enc) : uint256(sk_enc) { }
|
||||
|
||||
uint256 pk_enc();
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
class SpendingKey : public uint252 {
|
||||
@@ -53,6 +81,7 @@ public:
|
||||
static SpendingKey random();
|
||||
|
||||
ReceivingKey receiving_key() const;
|
||||
ViewingKey viewing_key() const;
|
||||
PaymentAddress address() const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user