Example #1
0
bool IsStealthAddress(const std::string& encodedAddress)
{
    data_chunk raw;
    
    if (!DecodeBase58(encodedAddress, raw))
    {
        //printf("IsStealthAddress DecodeBase58 falied.\n");
        return false;
    };
    
    if (!VerifyChecksum(raw))
    {
        //printf("IsStealthAddress verify_checksum falied.\n");
        return false;
    };
    
    if (raw.size() < 1 + 1 + 33 + 1 + 33 + 1 + 1 + 4)
    {
        //printf("IsStealthAddress too few bytes provided.\n");
        return false;
    };
    
    
    uint8_t* p = &raw[0];
    uint8_t version = *p++;
    
    if (version != stealth_version_byte)
    {
        //printf("IsStealthAddress version mismatch 0x%x != 0x%x.\n", version, stealth_version_byte);
        return false;
    };
    
    return true;
};
Example #2
0
static void Base58Decode(benchmark::State& state)
{
    const char* addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem";
    std::vector<unsigned char> vch;
    while (state.KeepRunning()) {
        DecodeBase58(addr, vch);
    }
}
Example #3
0
std::string DecodeBase58(const char* psz)
{
		std::vector<unsigned char>  vchRet;
		std::string stBuf;
    if(DecodeBase58(psz, vchRet)) {
	    stBuf.assign(vchRet.begin(),vchRet.end());
	    return stBuf;
 		 }
 		 return stBuf;
}
bool DecodeBase58Check(const char *psz, std::vector<uint8_t> &vchRet) {
    if (!DecodeBase58(psz, vchRet) || (vchRet.size() < 4)) {
        vchRet.clear();
        return false;
    }
    // re-calculate the checksum, insure it matches the included 4-byte checksum
    uint256 hash = Hash(vchRet.begin(), vchRet.end() - 4);
    if (memcmp(&hash, &vchRet.end()[-4], 4) != 0) {
        vchRet.clear();
        return false;
    }
    vchRet.resize(vchRet.size() - 4);
    return true;
}
Example #5
0
std::string DecodeBase58(const char* psz)
{
    std::vector<unsigned char> vch;
    DecodeBase58(psz, vch);
    std::stringstream ss;
    ss << std::hex;

    for (unsigned int i = 0; i < vch.size(); i++) {
        unsigned char* c = &vch[i];
        ss << setw(2) << setfill('0') << (int)c[0];
    }

    return ss.str();
}
Example #6
0
bool CStealthAddress::SetEncoded(const std::string& encodedAddress)
{
    data_chunk raw;
    
    if (!DecodeBase58(encodedAddress, raw))
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded DecodeBase58 falied.\n");
        return false;
    };
    
    if (!VerifyChecksum(raw))
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded verify_checksum falied.\n");
        return false;
    };
    
    if (raw.size() < 1 + 1 + 33 + 1 + 33 + 1 + 1 + 4)
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded() too few bytes provided.\n");
        return false;
    };
    
    
    uint8_t* p = &raw[0];
    uint8_t version = *p++;
    
    if (version != stealth_version_byte)
    {
        printf("CStealthAddress::SetEncoded version mismatch 0x%x != 0x%x.\n", version, stealth_version_byte);
        return false;
    };
    
    options = *p++;
    
    scan_pubkey.resize(33);
    memcpy(&scan_pubkey[0], p, 33);
    p += 33;
    //uint8_t spend_pubkeys = *p++;
    p++;
    
    spend_pubkey.resize(33);
    memcpy(&spend_pubkey[0], p, 33);
    
    return true;
};
Example #7
0
 bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet)
 {
     if (!DecodeBase58(psz, vchRet) ||
         (vchRet.size() < 4)) {
         vchRet.clear();
         return false;
     }
     // re-calculate the checksum, ensure it matches the included 4-byte checksum
     uint256 hash = doubleSha256(reinterpret_cast<const char*>(vchRet.data()), vchRet.size() - 4);
     if (memcmp(&hash, &vchRet.end()[-4], 4) != 0) {
         vchRet.clear();
         return false;
     }
     vchRet.resize(vchRet.size() - 4);
     return true;
 }
Example #8
0
// Decode a base58-encoded string psz that includes a checksum, into byte vector vchRet
// returns true if decoding is successful
bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet)
{
    if (!DecodeBase58(psz, vchRet))
        return false;
    if (vchRet.size() < 4)
    {
        vchRet.clear();
        return false;
    }
    uint256 hash = Hash(vchRet.begin(), vchRet.end()-4);
    if (memcmp(&hash, &vchRet.end()[-4], 4) != 0)
    {
        vchRet.clear();
        return false;
    }
    vchRet.resize(vchRet.size()-4);
    return true;
}
Example #9
0
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet) {
    return DecodeBase58(str.c_str(), vchRet);
}
bool DecodeBase58(const std::string &str, std::vector<uint8_t> &vchRet) {
    return DecodeBase58(str.c_str(), vchRet);
}
// stealth addresses have the ticker suffix
bool IsStealthAddress(const std::string& qualAddress)
{
    std::string encodedAddress;

#if USE_QUALIFIED_ADDRESSES
    int nColor;
    if (!SplitQualifiedAddress(qualAddress, encodedAddress, nColor, fDebug))
    {
        if (fDebug)
        {
            printf("StealthAddress::IsStealthAddress: could not split address..\n");
        }
        return false;
    }
#else
    encodedAddress = qualAddress;
#endif

    data_chunk raw;
    
    if (!DecodeBase58(encodedAddress, raw))
    {
        if (fDebug)
        {
            printf("IsStealthAddress: DecodeBase58 falied.\n");
        }
        return false;
    };
    
    if (!VerifyChecksum(raw))
    {
        if (fDebug)
        {
            printf("IsStealthAddress: verify_checksum falied.\n");
        }
        return false;
    };
    
    if (raw.size() < N_COLOR_BYTES + 1 + 1 + 33 + 1 + 33 + 1 + 1 + 4)
    {
        if (fDebug)
        {
            printf("IsStealthAddress: too few bytes provided.\n");
        }
        return false;
    };
    
    
    uint8_t* p = &raw[0];
    int nColor = 0;
    for (int i = 0; i < N_COLOR_BYTES; ++i)
    {
         nColor += pow(256, (int) i) * ((int) *p);
         ++p;
    }

    if (!CheckColor(nColor))
    {
        if (fDebug)
        {
            printf("IsStealthAddress: Invalid currency %d.\n", nColor);
        }
    }

    uint8_t version = *p++;
    
    if (version != stealth_version_byte)
    {
        if (fDebug)
        {
            printf("IsStealthAddress version mismatch 0x%x != 0x%x.\n", version, stealth_version_byte);
        }
        return false;
    };
    
    return true;
};
// color information is stored strting in the second byte so that
// addresses for different colors have distinct starting sequences
bool CStealthAddress::SetEncoded(const std::string& encodedAddress)
{

    data_chunk raw;
    
    if (!DecodeBase58(encodedAddress, raw))
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded DecodeBase58 falied.\n");
        return false;
    };
    
    if (!VerifyChecksum(raw))
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded verify_checksum falied.\n");
        return false;
    };

    size_t nRawSize = raw.size();
    
    // see CStealthAddress::Encoded()
    // Put color first so that stealth addresses of different currencies look different
    // N_COLOR_BYTES, 1-version, 1-options, 33-scan_pubkey, 1-#spend_pubkeys,
    // 33-spend_pubkey, 1-#sigs, 1-?, 4 checksum
    if (nRawSize < N_COLOR_BYTES + 1 + 1 + 33 + 1 + 33 + 1 + 1 + 4)
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded() too few bytes provided.\n");
        return false;
    };

    uint8_t* p = &raw[0];
 
    // Stealth addresses store color as a simple index little bytes first.
    this->nColor = 0;
    for (int i = 0; i < N_COLOR_BYTES; ++i)
    {
         this->nColor += pow(256, (int) i) * ((int) *p);
         ++p;
    }

    if (!CheckColor(nColor))
    {
        printf("CStealthAddress::SetEncoded(): Color %d is not valid (1...%d).\n",
                                                             this->nColor, N_COLORS);
    }

    uint8_t version = *p++;
   
    if (version != stealth_version_byte)
    {
        printf("CStealthAddress::SetEncoded version mismatch 0x%x != 0x%x.\n", version, stealth_version_byte);
        return false;
    };

    options = *p++;
    
    scan_pubkey.resize(33);
    memcpy(&scan_pubkey[0], p, 33);
    p += 33;
    //uint8_t spend_pubkeys = *p++;
    p++;
    
    spend_pubkey.resize(33);
    memcpy(&spend_pubkey[0], p, 33);

    return true;
};