From: Pieter Wuille Date: Mon, 11 Jul 2011 19:48:09 +0000 (+0200) Subject: CBitcoinSecret added (base58 encoded privkey) X-Git-Tag: v0.4.0-unstable~129^2~314^2~2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=15a8590ecf6610387502be14d26657cb154d6201 CBitcoinSecret added (base58 encoded privkey) --- diff --git a/src/base58.h b/src/base58.h index cace423..113fa14 100644 --- a/src/base58.h +++ b/src/base58.h @@ -18,6 +18,7 @@ #include #include #include "bignum.h" +#include "key.h" static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; @@ -257,15 +258,14 @@ public: class CBitcoinAddress : public CBase58Data { public: - bool SetHash160(const uint160& hash160) + void SetHash160(const uint160& hash160) { SetData(fTestNet ? 111 : 0, &hash160, 20); - return true; } - bool SetPubKey(const std::vector& vchPubKey) + void SetPubKey(const std::vector& vchPubKey) { - return SetHash160(Hash160(vchPubKey)); + SetHash160(Hash160(vchPubKey)); } bool IsValid() const @@ -320,4 +320,49 @@ public: } }; +class CBitcoinSecret : public CBase58Data +{ +public: + void SetSecret(const CSecret& vchSecret) + { + SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size()); + } + + CSecret GetSecret() + { + CSecret vchSecret; + vchSecret.resize(vchData.size()); + memcpy(&vchSecret[0], &vchData[0], vchData.size()); + return vchSecret; + } + + bool IsValid() const + { + int nExpectedSize = 32; + bool fExpectTestNet = false; + switch(nVersion) + { + case 128: + break; + + case 239: + fExpectTestNet = true; + break; + + default: + return false; + } + return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize; + } + + CBitcoinSecret(const CSecret& vchSecret) + { + SetSecret(vchSecret); + } + + CBitcoinSecret() + { + } +}; + #endif