mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -20,9 +20,11 @@ public:
|
|||||||
typedef boost::shared_ptr<AccountState> pointer;
|
typedef boost::shared_ptr<AccountState> pointer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewcoinAddress mAccountID;
|
NewcoinAddress mAccountID;
|
||||||
SerializedLedgerEntry::pointer mLedgerEntry;
|
NewcoinAddress mAuthorizedKey;
|
||||||
bool mValid;
|
SerializedLedgerEntry::pointer mLedgerEntry;
|
||||||
|
|
||||||
|
bool mValid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AccountState(const NewcoinAddress& AccountID); // For new accounts
|
AccountState(const NewcoinAddress& AccountID); // For new accounts
|
||||||
|
|||||||
@@ -106,16 +106,64 @@ void Application::run()
|
|||||||
//
|
//
|
||||||
mConnectionPool.start();
|
mConnectionPool.start();
|
||||||
|
|
||||||
|
// New stuff.
|
||||||
|
NewcoinAddress rootSeedMaster;
|
||||||
|
NewcoinAddress rootSeedRegular;
|
||||||
|
NewcoinAddress rootGeneratorMaster;
|
||||||
|
NewcoinAddress rootGeneratorRegular;
|
||||||
|
NewcoinAddress reservedPublicRegular;
|
||||||
|
NewcoinAddress reservedPrivateRegular;
|
||||||
|
NewcoinAddress rootAddress;
|
||||||
|
|
||||||
|
rootSeedMaster.setFamilySeed(CKey::PassPhraseToKey("Master passphrase."));
|
||||||
|
rootSeedRegular.setFamilySeed(CKey::PassPhraseToKey("Regular passphrase."));
|
||||||
|
|
||||||
|
std::cerr << "Master seed: " << rootSeedMaster.humanFamilySeed() << std::endl;
|
||||||
|
std::cerr << "Regular seed: " << rootSeedRegular.humanFamilySeed() << std::endl;
|
||||||
|
|
||||||
|
rootGeneratorMaster.setFamilyGenerator(rootSeedMaster);
|
||||||
|
rootGeneratorRegular.setFamilyGenerator(rootSeedRegular);
|
||||||
|
|
||||||
|
std::cerr << "Master generator: " << rootGeneratorMaster.humanFamilyGenerator() << std::endl;
|
||||||
|
std::cerr << "Regular generator: " << rootGeneratorRegular.humanFamilyGenerator() << std::endl;
|
||||||
|
|
||||||
|
rootAddress.setAccountPublic(rootGeneratorMaster, 0);
|
||||||
|
|
||||||
|
std::cerr << "Regular address: " << rootAddress.humanAccountPublic() << std::endl;
|
||||||
|
|
||||||
|
reservedPublicRegular.setAccountPublic(rootGeneratorRegular, -1);
|
||||||
|
reservedPrivateRegular.setAccountPrivate(rootGeneratorRegular, rootSeedRegular, -1);
|
||||||
|
|
||||||
|
std::cerr << "Reserved public regular: " << reservedPublicRegular.humanAccountPublic() << std::endl;
|
||||||
|
std::cerr << "Reserved private regular: " << reservedPrivateRegular.humanAccountPrivate() << std::endl;
|
||||||
|
|
||||||
|
// hash of regular account #reserved public key.
|
||||||
|
uint160 uiGeneratorID = reservedPublicRegular.getAccountID();
|
||||||
|
|
||||||
|
// std::cerr << "uiGeneratorID: " << uiGeneratorID << std::endl;
|
||||||
|
|
||||||
|
// Encrypt with regular account #reserved private key.
|
||||||
|
std::vector<unsigned char> vucGeneratorCipher = reservedPrivateRegular.accountPrivateEncrypt(reservedPublicRegular, rootGeneratorMaster.getFamilyGenerator());
|
||||||
|
|
||||||
|
std::cerr << "Plain: " << strHex(rootGeneratorMaster.getFamilyGenerator()) << std::endl;
|
||||||
|
|
||||||
|
std::cerr << "Cipher: " << strHex(vucGeneratorCipher) << std::endl;
|
||||||
|
|
||||||
|
std::vector<unsigned char> vucGeneratorText = reservedPrivateRegular.accountPrivateDecrypt(reservedPublicRegular, vucGeneratorCipher);
|
||||||
|
|
||||||
|
std::cerr << "Plain: " << strHex(vucGeneratorText) << std::endl;
|
||||||
|
|
||||||
// Temporary root account will be ["This is my payphrase."]:0
|
// Temporary root account will be ["This is my payphrase."]:0
|
||||||
NewcoinAddress rootFamilySeed; // Hold the 128 password.
|
NewcoinAddress rootFamilySeed; // Hold the 128 password.
|
||||||
NewcoinAddress rootFamilyGenerator; // Hold the generator.
|
NewcoinAddress rootFamilyGenerator; // Hold the generator.
|
||||||
NewcoinAddress rootAddress;
|
// NewcoinAddress rootAddress;
|
||||||
|
|
||||||
rootFamilySeed.setFamilySeed(CKey::PassPhraseToKey("This is my payphrase."));
|
rootFamilySeed.setFamilySeed(CKey::PassPhraseToKey("This is my payphrase."));
|
||||||
rootFamilyGenerator.setFamilyGenerator(rootFamilySeed);
|
rootFamilyGenerator.setFamilyGenerator(rootFamilySeed);
|
||||||
rootAddress.setAccountPublic(rootFamilyGenerator, 0);
|
rootAddress.setAccountPublic(rootFamilyGenerator, 0);
|
||||||
std::cerr << "Root account: " << rootAddress.humanAccountID() << std::endl;
|
std::cerr << "Root account: " << rootAddress.humanAccountID() << std::endl;
|
||||||
|
|
||||||
|
|
||||||
Ledger::pointer firstLedger = boost::make_shared<Ledger>(rootAddress, 100000000);
|
Ledger::pointer firstLedger = boost::make_shared<Ledger>(rootAddress, 100000000);
|
||||||
assert(!!firstLedger->getAccountState(rootAddress));
|
assert(!!firstLedger->getAccountState(rootAddress));
|
||||||
firstLedger->updateHash();
|
firstLedger->updateHash();
|
||||||
|
|||||||
24
src/Ledger.h
24
src/Ledger.h
@@ -16,7 +16,6 @@
|
|||||||
#include "BitcoinUtil.h"
|
#include "BitcoinUtil.h"
|
||||||
#include "SHAMap.h"
|
#include "SHAMap.h"
|
||||||
|
|
||||||
|
|
||||||
enum LedgerStateParms
|
enum LedgerStateParms
|
||||||
{
|
{
|
||||||
lepNONE = 0, // no special flags
|
lepNONE = 0, // no special flags
|
||||||
@@ -38,20 +37,19 @@ class Ledger : public boost::enable_shared_from_this<Ledger>
|
|||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<Ledger> pointer;
|
typedef boost::shared_ptr<Ledger> pointer;
|
||||||
|
|
||||||
|
|
||||||
enum TransResult
|
enum TransResult
|
||||||
{
|
{
|
||||||
TR_ERROR =-1,
|
TR_ERROR = -1,
|
||||||
TR_SUCCESS =0,
|
TR_SUCCESS = 0,
|
||||||
TR_NOTFOUND =1,
|
TR_NOTFOUND = 1,
|
||||||
TR_ALREADY =2,
|
TR_ALREADY = 2,
|
||||||
TR_BADTRANS =3, // the transaction itself is corrupt
|
TR_BADTRANS = 3, // the transaction itself is corrupt
|
||||||
TR_BADACCT =4, // one of the accounts is invalid
|
TR_BADACCT = 4, // one of the accounts is invalid
|
||||||
TR_INSUFF =5, // the sending(apply)/receiving(remove) account is broke
|
TR_INSUFF = 5, // the sending(apply)/receiving(remove) account is broke
|
||||||
TR_PASTASEQ =6, // account is past this transaction
|
TR_PASTASEQ = 6, // account is past this transaction
|
||||||
TR_PREASEQ =7, // account is missing transactions before this
|
TR_PREASEQ = 7, // account is missing transactions before this
|
||||||
TR_BADLSEQ =8, // ledger too early
|
TR_BADLSEQ = 8, // ledger too early
|
||||||
TR_TOOSMALL =9, // amount is less than Tx fee
|
TR_TOOSMALL = 9, // amount is less than Tx fee
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ LedgerEntryFormat LedgerFormats[]=
|
|||||||
{ "AccountRoot", ltACCOUNT_ROOT, {
|
{ "AccountRoot", ltACCOUNT_ROOT, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||||
|
{ S_FIELD(AuthorizedKey),STI_VL, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
|
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(Balance), STI_UINT64, SOE_REQUIRED, 0 },
|
{ S_FIELD(Balance), STI_UINT64, SOE_REQUIRED, 0 },
|
||||||
{ S_FIELD(LastReceive), STI_UINT32, SOE_REQUIRED, 0 },
|
{ S_FIELD(LastReceive), STI_UINT32, SOE_REQUIRED, 0 },
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "BitcoinUtil.h"
|
#include "BitcoinUtil.h"
|
||||||
#include "rfc1751.h"
|
#include "rfc1751.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include "openssl/rand.h"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/functional/hash.hpp>
|
#include <boost/functional/hash.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <openssl/rand.h>
|
||||||
|
|
||||||
NewcoinAddress::NewcoinAddress()
|
NewcoinAddress::NewcoinAddress()
|
||||||
{
|
{
|
||||||
@@ -272,7 +272,7 @@ void NewcoinAddress::setAccountPublic(const std::vector<unsigned char>& vPublic)
|
|||||||
|
|
||||||
void NewcoinAddress::setAccountPublic(const NewcoinAddress& generator, int seq)
|
void NewcoinAddress::setAccountPublic(const NewcoinAddress& generator, int seq)
|
||||||
{
|
{
|
||||||
CKey pubkey = CKey(generator, seq);
|
CKey pubkey = CKey(generator, seq+1);
|
||||||
|
|
||||||
setAccountPublic(pubkey.GetPubKey());
|
setAccountPublic(pubkey.GetPubKey());
|
||||||
}
|
}
|
||||||
@@ -281,14 +281,14 @@ void NewcoinAddress::setAccountPublic(const NewcoinAddress& generator, int seq)
|
|||||||
// AccountPrivate
|
// AccountPrivate
|
||||||
//
|
//
|
||||||
|
|
||||||
uint256 NewcoinAddress::getAccountPrivate() const
|
const std::vector<unsigned char>& NewcoinAddress::getAccountPrivate() const
|
||||||
{
|
{
|
||||||
switch (nVersion) {
|
switch (nVersion) {
|
||||||
case VER_NONE:
|
case VER_NONE:
|
||||||
throw std::runtime_error("unset source");
|
throw std::runtime_error("unset source");
|
||||||
|
|
||||||
case VER_ACCOUNT_PRIVATE:
|
case VER_ACCOUNT_PRIVATE:
|
||||||
return uint256(vchData);
|
return vchData;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
|
throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
|
||||||
@@ -324,6 +324,73 @@ void NewcoinAddress::setAccountPrivate(uint256 hash256)
|
|||||||
SetData(VER_ACCOUNT_PRIVATE, hash256.begin(), 32);
|
SetData(VER_ACCOUNT_PRIVATE, hash256.begin(), 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewcoinAddress::setAccountPrivate(const NewcoinAddress& generator, const NewcoinAddress& seed, int seq)
|
||||||
|
{
|
||||||
|
CKey privkey = CKey(generator, seed.getFamilyPrivateKey(), seq+1);
|
||||||
|
|
||||||
|
setAccountPrivate(privkey.GetPrivKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> NewcoinAddress::accountPrivateEncrypt(const NewcoinAddress& naPublicTo, const std::vector<unsigned char>& vucPlainText)
|
||||||
|
{
|
||||||
|
CKey ckPrivate;
|
||||||
|
CKey ckPublic;
|
||||||
|
std::vector<unsigned char> vucCipherText;
|
||||||
|
|
||||||
|
if (!ckPublic.SetPubKey(naPublicTo.getAccountPublic()))
|
||||||
|
{
|
||||||
|
// Bad public key.
|
||||||
|
std::cerr << "accountPrivateEncrypt: Bad public key." << std::endl;
|
||||||
|
}
|
||||||
|
else if (!ckPrivate.SetPrivKey(getAccountPrivate()))
|
||||||
|
{
|
||||||
|
// Bad private key.
|
||||||
|
std::cerr << "accountPrivateEncrypt: Bad private key." << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
vucCipherText = ckPrivate.encryptECIES(ckPublic, vucPlainText);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
nothing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return vucCipherText;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> NewcoinAddress::accountPrivateDecrypt(const NewcoinAddress& naPublicFrom, const std::vector<unsigned char>& vucCipherText)
|
||||||
|
{
|
||||||
|
CKey ckPrivate;
|
||||||
|
CKey ckPublic;
|
||||||
|
std::vector<unsigned char> vucPlainText;
|
||||||
|
|
||||||
|
if (!ckPublic.SetPubKey(naPublicFrom.getAccountPublic()))
|
||||||
|
{
|
||||||
|
// Bad public key.
|
||||||
|
std::cerr << "accountPrivateDecrypt: Bad public key." << std::endl;
|
||||||
|
}
|
||||||
|
else if (!ckPrivate.SetPrivKey(getAccountPrivate()))
|
||||||
|
{
|
||||||
|
// Bad private key.
|
||||||
|
std::cerr << "accountPrivateDecrypt: Bad private key." << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
vucPlainText = ckPrivate.decryptECIES(ckPublic, vucCipherText);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
nothing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return vucPlainText;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Family Generators
|
// Family Generators
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -78,16 +78,24 @@ public:
|
|||||||
//
|
//
|
||||||
// Accounts Private
|
// Accounts Private
|
||||||
//
|
//
|
||||||
uint256 getAccountPrivate() const;
|
const std::vector<unsigned char>& getAccountPrivate() const;
|
||||||
|
|
||||||
std::string humanAccountPrivate() const;
|
std::string humanAccountPrivate() const;
|
||||||
|
|
||||||
bool setAccountPrivate(const std::string& strPrivate);
|
bool setAccountPrivate(const std::string& strPrivate);
|
||||||
void setAccountPrivate(const std::vector<unsigned char>& vPrivate);
|
void setAccountPrivate(const std::vector<unsigned char>& vPrivate);
|
||||||
void setAccountPrivate(uint256 hash256);
|
void setAccountPrivate(uint256 hash256);
|
||||||
|
void setAccountPrivate(const NewcoinAddress& generator, const NewcoinAddress& seed, int seq);
|
||||||
|
|
||||||
|
// Encrypt a message.
|
||||||
|
std::vector<unsigned char> accountPrivateEncrypt(const NewcoinAddress& naPublicTo, const std::vector<unsigned char>& vucPlainText);
|
||||||
|
|
||||||
|
// Decrypt a message.
|
||||||
|
std::vector<unsigned char> accountPrivateDecrypt(const NewcoinAddress& naPublicFrom, const std::vector<unsigned char>& vucCipherText);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Family Generators
|
// Family Generators
|
||||||
|
// Given a seed, hold a generator.
|
||||||
//
|
//
|
||||||
BIGNUM* getFamilyGeneratorBN() const;
|
BIGNUM* getFamilyGeneratorBN() const;
|
||||||
const std::vector<unsigned char>& getFamilyGenerator() const;
|
const std::vector<unsigned char>& getFamilyGenerator() const;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ enum SOE_Field
|
|||||||
sfBorrower, sfLender, sfLimit, sfOfferCurrency, sfLedgerHash,
|
sfBorrower, sfLender, sfLimit, sfOfferCurrency, sfLedgerHash,
|
||||||
sfLastReceive, sfLastTxn, sfNextRate, sfNextRateLgr, sfNextRateExp,
|
sfLastReceive, sfLastTxn, sfNextRate, sfNextRateLgr, sfNextRateExp,
|
||||||
sfNickname, sfMinimumOffer,
|
sfNickname, sfMinimumOffer,
|
||||||
|
sfAuthorizedKey,
|
||||||
|
|
||||||
// test fields
|
// test fields
|
||||||
sfTest1, sfTest2, sfTest3, sfTest4
|
sfTest1, sfTest2, sfTest3, sfTest4
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ void DH_der_gen_hex(std::string& strDer, int iKeyLength)
|
|||||||
|
|
||||||
DH_der_gen(strBuf, iKeyLength);
|
DH_der_gen(strBuf, iKeyLength);
|
||||||
|
|
||||||
strHex(strDer, strBuf);
|
strDer = strHex(strBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
DH* DH_der_load(const std::string& strDer)
|
DH* DH_der_load(const std::string& strDer)
|
||||||
|
|||||||
14
src/utils.h
14
src/utils.h
@@ -36,8 +36,10 @@ std::string strJoin(Iterator first, Iterator last, std::string strSeperator)
|
|||||||
char charHex(int iDigit);
|
char charHex(int iDigit);
|
||||||
|
|
||||||
template<class Iterator>
|
template<class Iterator>
|
||||||
void strHex(std::string& strDst, Iterator first, int iSize)
|
std::string strHex(Iterator first, int iSize)
|
||||||
{
|
{
|
||||||
|
std::string strDst;
|
||||||
|
|
||||||
strDst.resize(iSize*2);
|
strDst.resize(iSize*2);
|
||||||
|
|
||||||
for (int i = 0; i < iSize; i++) {
|
for (int i = 0; i < iSize; i++) {
|
||||||
@@ -46,14 +48,16 @@ void strHex(std::string& strDst, Iterator first, int iSize)
|
|||||||
strDst[i*2] = charHex(c >> 4);
|
strDst[i*2] = charHex(c >> 4);
|
||||||
strDst[i*2+1] = charHex(c & 15);
|
strDst[i*2+1] = charHex(c & 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return strDst;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void strHex(std::string& strDst, const std::string& strSrc) {
|
inline const std::string strHex(const std::string& strSrc) {
|
||||||
strHex(strDst, strSrc.begin(), strSrc.size());
|
return strHex(strSrc.begin(), strSrc.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void strHex(std::string& strDst, const std::vector<unsigned char> vchData) {
|
inline std::string strHex(const std::vector<unsigned char> vchData) {
|
||||||
strHex(strDst, vchData.begin(), vchData.size());
|
return strHex(vchData.begin(), vchData.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
int charUnHex(char cDigit);
|
int charUnHex(char cDigit);
|
||||||
|
|||||||
Reference in New Issue
Block a user