Exemple #1
0
std::string encode_privkey(const PrivateKey &privkey) {
	uint8_t bytes[34];
	bytes[0] = 0x80;
	mpn_to_bytes(bytes + 1, privkey.d, 32);
	if (privkey.flags == PrivateKey::Flags::NONE) {
		return base58check_encode(bytes, sizeof bytes - 1);
	}
	bytes[33] = static_cast<uint8_t>(privkey.flags);
	return base58check_encode(bytes, sizeof bytes);
}
Exemple #2
0
END_TEST

START_TEST (test_base58checkencoding)
{
	uint8_t encoding[37] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55};
	const uint8_t str1[] = {0xc4,0xc5,0xd7,0x91,0xfc,0xb4,0x65,0x4a,0x1e,0xf5,0xe0,0x3f,0xe0,0xad,0x3d,0x9c,0x59,0x8f,0x98,0x27};
	const uint8_t encoding1[] = "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T";

	base58check_encode (encoding, 0, str1);
	mu_assert (memcmp (encoding, encoding1, sizeof(encoding1)) == 0, "base58check_encode should correctly encode the test strings.");

	memmove (encoding, str1, 20);
	base58check_encode (encoding, 0, encoding);
	mu_assert (memcmp (encoding, encoding1, sizeof(encoding1)) == 0, "base58check_encode should correctly encode the test strings, even if the src and dst point to the same memory.");
}
Exemple #3
0
/*
 * Create an output address.
 */
static void make_output_addr(uint8_t *hsh160, uint8_t prefix, char *addr)
{
    char tmp[1 + 20];
    tmp[0] = prefix;
    memcpy(tmp+1, hsh160, 20);
    base58check_encode(addr, 35, tmp, sizeof(tmp));
}