Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ AC_ARG_ENABLE([wallet],
[enable_wallet=$enableval],
[enable_wallet=yes])

# Enable stealth
AC_ARG_ENABLE([stealth],
[AS_HELP_STRING([--enable-stealth],
[enable stealth (default is no)])],
[enable_stealth=$enableval],
[enable_stealth=no])

# Enable i2psam
AC_ARG_ENABLE([i2psam],
[AS_HELP_STRING([--enable-i2psam],
Expand Down Expand Up @@ -204,6 +211,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
fi
CPPFLAGS="$CPPFLAGS -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"


AC_ARG_WITH([utils],
[AS_HELP_STRING([--with-utils],
[build anoncoin-cli anoncoin-tx (default=yes)])],
Expand Down Expand Up @@ -798,6 +806,15 @@ else
AC_MSG_RESULT(no)
fi

dnl enable stealth
AC_MSG_CHECKING([if stealth module should be included])
if test x$enable_stealth != xno; then
AC_MSG_RESULT(yes)
AC_DEFINE_UNQUOTED([ENABLE_STEALTH],[1],[Define to 1 to enable stealth address functions])
else
AC_MSG_RESULT(no)
fi

dnl enable i2psam
AC_MSG_CHECKING([if i2psam module should be included])
if test x$enable_i2psam != xno; then
Expand Down Expand Up @@ -909,6 +926,7 @@ AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
AM_CONDITIONAL([ENABLE_STEALTH],[test x$enable_stealth = xno])
AM_CONDITIONAL([ENABLE_I2PSAM],[test x$enable_i2psam = xyes])
AM_CONDITIONAL([ENABLE_TESTS],[test x$use_tests = xyes])
AM_CONDITIONAL([ENABLE_QT],[test x$anoncoin_enable_qt = xyes])
Expand Down
16 changes: 13 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ EXTRA_LIBRARIES = \
libanoncoin_server.a \
libanoncoin_cli.a \
libanoncoin_scrypt.a

if ENABLE_WALLET
ANONCOIN_INCLUDES += $(BDB_CPPFLAGS)
EXTRA_LIBRARIES += libanoncoin_wallet.a
endif

if ENABLE_I2PSAM
EXTRA_LIBRARIES += libanoncoin_i2pnet.a
endif
Expand Down Expand Up @@ -126,12 +128,14 @@ ANONCOIN_CORE_H = \
rpcclient.h \
rpcprotocol.h \
rpcserver.h \
rpcstealth.h \
script.h \
script_error.h \
scrypt.h \
serialize.h \
sigcache.h \
sign.h \
stealth.h \
streams.h \
sync.h \
threadsafety.h \
Expand Down Expand Up @@ -201,7 +205,9 @@ libanoncoin_wallet_a_SOURCES = \
db.cpp \
crypter.cpp \
rpcdump.cpp \
rpcstealth.cpp \
rpcwallet.cpp \
stealth.cpp \
wallet.cpp \
walletdb.cpp \
$(ANONCOIN_CORE_H)
Expand Down Expand Up @@ -316,18 +322,22 @@ anoncoind_LDADD = \
$(LIBANONCOIN_UNIVALUE) \
$(LIBANONCOIN_UTIL) \
$(LIBANONCOIN_CRYPTO) \
$(LIBANONCOIN_SCRYPT) \
$(LIBLEVELDB) \
$(LIBMEMENV)
$(LIBANONCOIN_SCRYPT)

if ENABLE_WALLET
anoncoind_LDADD += libanoncoin_wallet.a
endif

if ENABLE_I2PSAM
anoncoind_LDADD += libanoncoin_i2pnet.a
endif

anoncoind_LDADD += \
$(LIBLEVELDB) \
$(LIBMEMENV)

anoncoind_SOURCES = anoncoind.cpp

if TARGET_WINDOWS
anoncoind_SOURCES += anoncoind-res.rc
endif
Expand Down
16 changes: 0 additions & 16 deletions src/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,6 @@ int CBase58Data::CompareTo(const CBase58Data& b58) const
return 0;
}

namespace
{
class CAnoncoinAddressVisitor : public boost::static_visitor<bool>
{
private:
CAnoncoinAddress* addr;
public:
CAnoncoinAddressVisitor(CAnoncoinAddress* addrIn) : addr(addrIn) {}

bool operator()(const CKeyID& id) const { return addr->Set(id); }
bool operator()(const CScriptID& id) const { return addr->Set(id); }
bool operator()(const CNoDestination& no) const { return false; }
};

} // anon namespace

bool CAnoncoinAddress::Set(const CKeyID& id)
{
SetData(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS), &id, 20);
Expand Down
27 changes: 27 additions & 0 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "key.h"
#include "script.h"

#ifdef ENABLE_STEALTH
#include "stealth.h"
#endif

#include <string>
#include <vector>

Expand Down Expand Up @@ -99,6 +103,20 @@ class CBase58Data
* Script-hash-addresses have version 5 (or 196 testnet).
* The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
*/
#ifdef ENABLE_STEALTH
class CAnoncoinAddress;
class CAnoncoinAddressVisitor : public boost::static_visitor<bool> {
private:
CAnoncoinAddress *addr;
public:
CAnoncoinAddressVisitor(CAnoncoinAddress *addrIn) : addr(addrIn) { }
bool operator()(const CKeyID &id) const;
bool operator()(const CScriptID &id) const;
bool operator()(const CStealthAddress &stxAddr) const;
bool operator()(const CNoDestination &no) const;
};
#endif

class CAnoncoinAddress : public CBase58Data {
public:
bool Set(const CKeyID &id);
Expand All @@ -117,6 +135,15 @@ class CAnoncoinAddress : public CBase58Data {
bool IsScript() const;
};

#ifdef ENABLE_STEALTH

bool inline CAnoncoinAddressVisitor::operator()(const CKeyID &id) const { return addr->Set(id); }
bool inline CAnoncoinAddressVisitor::operator()(const CScriptID &id) const { return addr->Set(id); }
bool inline CAnoncoinAddressVisitor::operator()(const CStealthAddress &stxAddr) const { return false; }
bool inline CAnoncoinAddressVisitor::operator()(const CNoDestination &id) const { return false; }

#endif

/**
* A base58-encoded secret key
*/
Expand Down
11 changes: 5 additions & 6 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class CMainParams : public CChainParams {
// Because the prefix bytes are attached to a base256 encoding (ie, binary) of known width, they affect the leading cinquantoctal digit of the corresponding base58
// representation of the same number. The 23 below, is why mainnet pay-to-pubkey txouts always start with the letter A
base58Prefixes[PUBKEY_ADDRESS] = {23}; // the pay-to-pubkey prefix byte
base58Prefixes[SCRIPT_ADDRESS] = {5}; // the pay-to-script-hash prefix byte
base58Prefixes[SCRIPT_ADDRESS] = {15}; // the pay-to-script-hash prefix byte
base58Prefixes[SECRET_KEY] = {151}; // Anoncoin secret keys are the Public Key + 128
// What we have here are the same as Bitcoin values, and explained below as follows:
// The four-byte prefixes correspond to cinquantoctal prefixes 'xpub' and 'xprv' on mainnet and 'tpub' and 'tprv' on testnet.
Expand All @@ -182,7 +182,7 @@ class CMainParams : public CChainParams {
#else

base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,23);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,15);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,151);
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
Expand Down Expand Up @@ -294,14 +294,13 @@ class CTestNetParams : public CMainParams {

#ifdef NO_PREHISTORIC_COMPILER
base58Prefixes[PUBKEY_ADDRESS] = {111}; // Anoncoin v8 compatible testnet Public keys use this value
base58Prefixes[SCRIPT_ADDRESS] = {196};
base58Prefixes[SECRET_KEY] = {239}; // Anoncoin testnet secret keys start with the same prefix as the Public Key + 128
base58Prefixes[SCRIPT_ADDRESS] = {50};
base58Prefixes[SECRET_KEY] = {211}; // Anoncoin testnet secret keys start with the same prefix as the Public Key + 128
base58Prefixes[EXT_PUBLIC_KEY] = {0x04,0x35,0x87,0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04,0x35,0x83,0x94};
#else

base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,50);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
Expand Down
10 changes: 7 additions & 3 deletions src/crypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned
class CCryptoKeyStore : public CBasicKeyStore
{
private:
CryptedKeyMap mapCryptedKeys;

CKeyingMaterial vMasterKey;

// if fUseCrypto is true, mapKeys must be empty
// if fUseCrypto is false, vMasterKey must be empty
Expand All @@ -128,6 +125,9 @@ class CCryptoKeyStore : public CBasicKeyStore
protected:
bool SetCrypted();

CryptedKeyMap mapCryptedKeys;
CKeyingMaterial vMasterKey;

// will encrypt previously unencrypted keys
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);

Expand Down Expand Up @@ -157,6 +157,10 @@ class CCryptoKeyStore : public CBasicKeyStore

bool Lock();

CryptedKeyMap getCryptedKeysMap() {
return mapCryptedKeys;
}

virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
bool HaveKey(const CKeyID &address) const
Expand Down
6 changes: 4 additions & 2 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void CDBEnv::EnvShutdown()
LogPrintf("CDBEnv::EnvShutdown: Error %d shutting down database environment: %s\n", ret, DbEnv::strerror(ret));
if (!fMockDb)
#ifndef USING_PRE_HISTORIC_COMPILER
DbEnv(0).remove(strPath.c_str(), 0);
DbEnv((u_int32_t)0).remove(strPath.c_str(), 0);
#else
DbEnv((u_int32_t)0).remove(strPath.c_str(), 0);
#endif
Expand All @@ -60,6 +60,7 @@ void CDBEnv::Reset()

CDBEnv::CDBEnv() : dbenv(NULL)
{
LogPrintf("Reset triggered.");
Reset();
}

Expand Down Expand Up @@ -89,8 +90,9 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());

unsigned int nEnvFlags = 0;
if (GetBoolArg("-privdb", true))
if (GetBoolArg("-privdb", true)) {
nEnvFlags |= DB_PRIVATE;
}

dbenv->set_lg_dir(pathLogDir.string().c_str());
dbenv->set_cachesize(0, 0x100000, 1); // 1 MiB should be enough for just the wallet
Expand Down
4 changes: 4 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ using namespace std;
CWallet* pwalletMain = NULL;
#endif
bool fFeeEstimatesInitialized = false;
bool fEnforceCanonical;

#ifdef WIN32
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
Expand Down Expand Up @@ -343,6 +344,7 @@ std::string HelpMessage(HelpMessageMode hmm)
strUsage += " -wallet=<file> " + _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), "wallet.dat") + "\n";
strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n";
strUsage += " -zapwallettxes " + _("Clear list of wallet transactions (diagnostic tool; implies -rescan)") + "\n";
strUsage += " -enforcecanonical " + _("Enforce transaction scripts to use canonical PUSH operators (default: 1)") + "\n" +
#endif

strUsage += "\n" + _("Debugging/Testing options:") + "\n";
Expand Down Expand Up @@ -668,6 +670,8 @@ bool AppInit2(boost::thread_group& threadGroup)
LogPrintf("AppInit2 : parameter interaction: -zapwallettxes=1 -> setting -rescan=1\n");
}

fEnforceCanonical = GetBoolArg("-enforcecanonical", true);

// Make sure enough file descriptors are available
int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1);
nMaxConnections = GetArg("-maxconnections", 125);
Expand Down
34 changes: 33 additions & 1 deletion src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
#include <stdexcept>
#include <vector>

#include <openssl/ec.h> // for EC_KEY definition

// secp160k1
// const unsigned int PRIVATE_KEY_SIZE = 192;
// const unsigned int PUBLIC_KEY_SIZE = 41;
// const unsigned int SIGNATURE_SIZE = 48;
//
// secp192k1
// const unsigned int PRIVATE_KEY_SIZE = 222;
// const unsigned int PUBLIC_KEY_SIZE = 49;
// const unsigned int SIGNATURE_SIZE = 57;
//
// secp224k1
// const unsigned int PRIVATE_KEY_SIZE = 250;
// const unsigned int PUBLIC_KEY_SIZE = 57;
// const unsigned int SIGNATURE_SIZE = 66;
//
// secp256k1:
// const unsigned int PRIVATE_KEY_SIZE = 279;
// const unsigned int PUBLIC_KEY_SIZE = 65;
Expand Down Expand Up @@ -161,12 +178,22 @@ class CPubKey {

// Derive BIP32 child pubkey.
bool Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const;


#ifdef ENABLE_STEALTH
// Return the key as a vector of uint8_t
std::vector<uint8_t> Raw() { return std::vector<uint8_t>(begin(), end()); }
#endif
};


// secure_allocator is defined in allocators.h
// CPrivKey is a serialized private key, with all parameters included (279 bytes)
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
#ifdef ENABLE_STEALTH
// CSecret is a serialization of just the secret parameter (32 bytes)
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CSecret;
#endif

/** An encapsulated private key. */
class CKey {
Expand Down Expand Up @@ -235,7 +262,12 @@ class CKey {

// Sets the secret for the key
void SetSecret(const unsigned char vchIn[32], bool fCompressed = false);

#ifdef ENABLE_STEALTH
// Construct a key from a byte vector.
void SetSecret(const std::vector<unsigned char> &vch, bool compressed) {
Set(vch.begin(), vch.end(), compressed);
}
#endif
// Initialize from a CPrivKey (serialized OpenSSL private key data).
bool SetPrivKey(const CPrivKey &vchPrivKey, bool fCompressed);

Expand Down
5 changes: 5 additions & 0 deletions src/keystore.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ class CScript;
* * CNoDestination: no destination set
* * CKeyID: TX_PUBKEYHASH destination
* * CScriptID: TX_SCRIPTHASH destination
* * CStealthAddress: A Stealth address
* A CTxDestination is the internal data type encoded in a CAnoncoinAddress
*/
#ifdef ENABLE_STEALTH
typedef boost::variant<CNoDestination, CKeyID, CScriptID, CStealthAddress> CTxDestination;
#else
typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
#endif

/** A virtual base class for key stores */
class CKeyStore
Expand Down
Loading