Created
May 9, 2018 07:13
-
-
Save narodnik/e76907bcadca4a969b914a95b51c4da9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
// Generate new random secret keys | |
bc::secret_list secrets; | |
for (size_t i = 0; i < 8; ++i) | |
secrets.push_back(new_key()); | |
// Create two rings from the first 4 and last 4 keys | |
auto ring0 = extract_public_keys( | |
secrets.begin(), secrets.begin() + 4); | |
auto ring1 = extract_public_keys( | |
secrets.begin() + 4, secrets.end()); | |
BITCOIN_ASSERT(ring0.size() == 4); | |
BITCOIN_ASSERT(ring1.size() == 4); | |
const bc::key_rings rings{ring0, ring1}; | |
// Randomly choose two secret keys which exist in both rings | |
// So one key from first 4, and one from last 4 | |
bc::secret_list secret_keys; | |
secret_keys.push_back(secrets[random_int(0, 3)]); | |
secret_keys.push_back(secrets[random_int(4, 7)]); | |
BITCOIN_ASSERT(secret_keys.size() == 2); | |
BITCOIN_ASSERT(is_secret_in_ring(secret_keys[0], ring0)); | |
BITCOIN_ASSERT(is_secret_in_ring(secret_keys[1], ring1)); | |
std::string message = "hello world!"; | |
bc::data_chunk message_data = bc::to_chunk(message); | |
bc::ring_signature signature; | |
bool rc = bc::sign(signature, secret_keys, rings, message_data); | |
bool result = bc::verify(rings, message_data, signature); | |
BITCOIN_ASSERT(result); | |
std::cout << "OK" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment