Add rfc1751 support to NewcoinAddress.

This commit is contained in:
Arthur Britto
2012-04-07 16:14:33 -07:00
parent a7440cb55e
commit b8f1df2a18
2 changed files with 43 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
#include "key.h"
#include "Config.h"
#include "BitcoinUtil.h"
#include "rfc1751.h"
#include "openssl/rand.h"
@@ -438,6 +439,30 @@ BIGNUM* NewcoinAddress::getFamilyPrivateKey() const
return ret;
}
std::string NewcoinAddress::humanFamilySeed1751() const
{
switch (nVersion) {
case VER_NONE:
throw std::runtime_error("unset source");
case VER_FAMILY_SEED:
{
std::string strHuman;
std::string strKey;
uint128 uSeed = getFamilySeed();
strKey.assign(uSeed.begin(), uSeed.end());
key2eng(strHuman, strKey);
return strHuman;
}
default:
throw std::runtime_error("bad source");
}
}
std::string NewcoinAddress::humanFamilySeed() const
{
switch (nVersion) {
@@ -452,6 +477,22 @@ std::string NewcoinAddress::humanFamilySeed() const
}
}
int NewcoinAddress::setFamilySeed1751(const std::string& strHuman1751)
{
std::string strKey;
int iResult = eng2key(strKey, strHuman1751);
if (1 == iResult)
{
std::vector<unsigned char> vch(strKey.begin(), strKey.end());
uint128 uSeed(vch);
setFamilySeed(uSeed);
}
return iResult;
}
bool NewcoinAddress::setFamilySeed(const std::string& strSeed)
{
return SetString(strSeed.c_str(), VER_FAMILY_SEED);

View File

@@ -112,8 +112,10 @@ public:
BIGNUM* getFamilyPrivateKey() const;
std::string humanFamilySeed() const;
std::string humanFamilySeed1751() const;
bool setFamilySeed(const std::string& strSeed);
int setFamilySeed1751(const std::string& strHuman1751);
void setFamilySeed(uint128 hash128);
void setFamilySeedRandom();
};