Beispiel #1
0
/*  Base-58 encode a Ripple Token

    Ripple Tokens have a one-byte prefx indicating
    the type of token, followed by the data for the
    token, and finally a 4-byte checksum.

    Tokens include the following:

        Wallet Seed
        Account Public Key
        Account ID
    
    @param temp A pointer to storage of not
                less than 2*(size+6) bytes
*/
std::string
base58EncodeToken (std::uint8_t type,
    void const* token, std::size_t size)
{
    char buf[1024];
    // expanded token includes type + checksum
    auto const expanded = 1 + size + 4;
    // add scratch, log(256) / log(58), rounded up.
    auto const needed = expanded +
        size * (138 / 100 + 1);
    std::unique_ptr<
        char[]> pbuf;
    char* temp;
    if (needed > sizeof(buf))
    {
        pbuf.reset(new char[needed]);
        temp = pbuf.get();
    }
    else
    {
        temp = buf;
    }
    // Lay the data out as
    //      <type><token><checksum>
    temp[0] = type;
    std::memcpy(temp + 1, token, size);
    checksum(temp + 1 + size, temp, 1 + size);
    return encodeBase58(temp, expanded,
        temp + expanded, rippleAlphabet);
}
ByteArray * getStringForVersionChecksumBytes(VersionChecksumBytes * self){
	if (self->cachedString) {
		incrementReferenceCount(self->cachedString);
		return self->cachedString;
	} else {
		reverseBytes(getByteArray(self));

		BigInt bytes;
		BigIntAlloc(&bytes, getByteArray(self)->length);
		bytes.length = getByteArray(self)->length;
		memcpy(bytes.data, getByteArrayData(getByteArray(self)), bytes.length);

		char * string = encodeBase58(bytes.data,bytes.length);

		if (! string){
			return NULL;
		}
		ByteArray * str = createNewByteArrayFromString(string, TRUE, getByteArray(self)->onErrorReceived);
		if (! str) {
			free(string);
			return NULL;
		}
		reverseBytes(getByteArray(self));
		if (self->cacheString) {
			self->cachedString = str;
			incrementReferenceCount(str);
		}

		return str;
	}
}
bool bitcoinAddressToAscii(const uint8_t address[25],char *output,uint32_t maxOutputLen)
{
	bool ret = false;

	ret = encodeBase58(address,25,true,output,maxOutputLen);

	return ret;
}
bool bitcoinCompressedPublicKeyToAscii(const uint8_t input[33], // The 33 bytes long ECDSA public key
							 char *output,				// The output ascii representation.
							 uint32_t maxOutputLen) // convert a binary bitcoin address into ASCII
{
	bool ret = false;

	output[0] = 0;

	uint8_t hash2[25];

	if ( bitcoinCompressedPublicKeyToAddress(input,hash2))
	{
		ret = encodeBase58(hash2,25,true,output,maxOutputLen);
	}
	return ret;
}
bool bitcoinPublicKeyToAscii(const uint8_t input[65], // The 65 bytes long ECDSA public key; first byte will always be 0x4 followed by two 32 byte components
							 char *output,				// The output ascii representation.
							 uint32_t maxOutputLen) // convert a binary bitcoin address into ASCII
{
	bool ret = false;

	output[0] = 0;

	uint8_t hash2[25];

	if ( bitcoinPublicKeyToAddress(input,hash2))
	{
		ret = encodeBase58(hash2,25,true,output,maxOutputLen);
	}
	return ret;
}