From 49cf707d2ced72698cd44c6f4f3f64072c2fc308 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 1 Mar 2017 11:20:42 -0800 Subject: [PATCH] Add Base58 encoding of viewing keys --- src/base58.cpp | 8 ++++++++ src/base58.h | 11 +++++++++++ src/chainparams.cpp | 4 ++++ src/chainparams.h | 1 + src/zcash/Address.hpp | 1 + 5 files changed, 25 insertions(+) diff --git a/src/base58.cpp b/src/base58.cpp index 2fd2475fe..09977ea35 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -365,6 +365,14 @@ template libzcash::PaymentAddress CZCEncoding::Get() const; +// Explicit instantiations for libzcash::ViewingKey +template bool CZCEncoding::Set(const libzcash::ViewingKey& vk); +template libzcash::ViewingKey CZCEncoding::Get() const; + // Explicit instantiations for libzcash::SpendingKey template bool CZCEncoding { +protected: + std::string PrependName(const std::string& s) const { return "viewing key" + s; } + +public: + CZCViewingKey() {} + + CZCViewingKey(const std::string& strViewingKey) { SetString(strViewingKey.c_str(), 3); } + CZCViewingKey(const libzcash::ViewingKey& vk) { Set(vk); } +}; + class CZCSpendingKey : public CZCEncoding { protected: std::string PrependName(const std::string& s) const { return "spending key" + s; } diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 034eee6b2..23544f488 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -110,6 +110,8 @@ public: base58Prefixes[EXT_SECRET_KEY] = {0x04,0x88,0xAD,0xE4}; // guarantees the first 2 characters, when base58 encoded, are "zc" base58Prefixes[ZCPAYMENT_ADDRRESS] = {0x16,0x9A}; + // guarantees the first 4 characters, when base58 encoded, are "ZiVK" + base58Prefixes[ZCVIEWING_KEY] = {0xA8,0xAB,0xD3}; // guarantees the first 2 characters, when base58 encoded, are "SK" base58Prefixes[ZCSPENDING_KEY] = {0xAB,0x36}; @@ -241,6 +243,8 @@ public: base58Prefixes[EXT_SECRET_KEY] = {0x04,0x35,0x83,0x94}; // guarantees the first 2 characters, when base58 encoded, are "zt" base58Prefixes[ZCPAYMENT_ADDRRESS] = {0x16,0xB6}; + // guarantees the first 4 characters, when base58 encoded, are "ZiVt" + base58Prefixes[ZCVIEWING_KEY] = {0xA8,0xAC,0x0C}; // guarantees the first 2 characters, when base58 encoded, are "ST" base58Prefixes[ZCSPENDING_KEY] = {0xAC,0x08}; diff --git a/src/chainparams.h b/src/chainparams.h index a1de7b493..0de8d01b5 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -44,6 +44,7 @@ public: ZCPAYMENT_ADDRRESS, ZCSPENDING_KEY, + ZCVIEWING_KEY, MAX_BASE58_TYPES }; diff --git a/src/zcash/Address.hpp b/src/zcash/Address.hpp index 4287fee4f..2dbe10a60 100644 --- a/src/zcash/Address.hpp +++ b/src/zcash/Address.hpp @@ -8,6 +8,7 @@ namespace libzcash { const size_t SerializedPaymentAddressSize = 64; +const size_t SerializedViewingKeySize = 64; const size_t SerializedSpendingKeySize = 32; class PaymentAddress {