peerplays_migrated/libraries/chain/include/graphene/chain/protocol/memo.hpp
2015-07-31 11:00:01 -04:00

72 lines
2.7 KiB
C++

#pragma once
#include <graphene/chain/protocol/types.hpp>
namespace graphene { namespace chain {
/**
* @brief defines the keys used to derive the shared secret
*
* Because account authorities and keys can change at any time, each memo must
* capture the specific keys used to derive the shared secret. In order to read
* the cipher message you will need one of the two private keys.
*
* If @ref from == @ref to and @ref from == 0 then no encryption is used, the memo is public.
* If @ref from == @ref to and @ref from != 0 then invalid memo data
*
* The reason we include *both* keys is to allow the wallet to
* rebuild the data for any transfer, including the memo, from the
* user's private keys and the contents of the blockchain --
* regardless of whether the user is the sender or receiver.
*/
struct memo_data
{
public_key_type from;
public_key_type to;
/**
* 64 bit nonce format:
* [ 8 bits | 56 bits ]
* [ entropy | timestamp ]
* Timestamp is number of microseconds since the epoch
* Entropy is a byte taken from the hash of a new private key
*
* This format is not mandated or verified; it is chosen to ensure uniqueness of key-IV pairs only. This should
* be unique with high probability as long as the generating host has a high-resolution clock OR a strong source
* of entropy for generating private keys.
*/
uint64_t nonce;
/**
* This field contains the AES encrypted packed @ref memo_message
*/
vector<char> message;
/// @note custom_nonce is for debugging only; do not set to a nonzero value in production
void set_message(const fc::ecc::private_key& priv,
const fc::ecc::public_key& pub, const string& msg, uint64_t custom_nonce = 0);
std::string get_message(const fc::ecc::private_key& priv,
const fc::ecc::public_key& pub)const;
};
/**
* @brief defines a message and checksum to enable validation of successful decryption
*
* When encrypting/decrypting a checksum is required to determine whether or not
* decryption was successful.
*/
struct memo_message
{
memo_message(){}
memo_message( uint32_t checksum, const std::string& text )
:checksum(checksum),text(text){}
uint32_t checksum = 0;
std::string text;
string serialize() const;
static memo_message deserialize(const string& serial);
};
} } // namespace graphene::chain
FC_REFLECT( graphene::chain::memo_message, (checksum)(text) )
FC_REFLECT( graphene::chain::memo_data, (from)(to)(nonce)(message) )