Files
rippled/include/xrpl/protocol/HashPrefix.h
Bart 1d42c4f6de refactor: Remove unnecessary copyright notices already covered by LICENSE.md (#5929)
Per XLS-0095, we are taking steps to rename ripple(d) to xrpl(d).

This change specifically removes all copyright notices referencing Ripple, XRPLF, and certain affiliated contributors upon mutual agreement, so the notice in the LICENSE.md file applies throughout. Copyright notices referencing external contributions remain as-is. Duplicate verbiage is also removed.
2025-11-04 08:33:42 +00:00

88 lines
2.4 KiB
C++

#ifndef XRPL_PROTOCOL_HASHPREFIX_H_INCLUDED
#define XRPL_PROTOCOL_HASHPREFIX_H_INCLUDED
#include <xrpl/beast/hash/hash_append.h>
#include <cstdint>
namespace ripple {
namespace detail {
constexpr std::uint32_t
make_hash_prefix(char a, char b, char c)
{
return (static_cast<std::uint32_t>(a) << 24) +
(static_cast<std::uint32_t>(b) << 16) +
(static_cast<std::uint32_t>(c) << 8);
}
} // namespace detail
/** Prefix for hashing functions.
These prefixes are inserted before the source material used to generate
various hashes. This is done to put each hash in its own "space." This way,
two different types of objects with the same binary data will produce
different hashes.
Each prefix is a 4-byte value with the last byte set to zero and the first
three bytes formed from the ASCII equivalent of some arbitrary string. For
example "TXN".
@note Hash prefixes are part of the protocol; you cannot, arbitrarily,
change the type or the value of any of these without causing breakage.
*/
enum class HashPrefix : std::uint32_t {
/** transaction plus signature to give transaction ID */
transactionID = detail::make_hash_prefix('T', 'X', 'N'),
/** transaction plus metadata */
txNode = detail::make_hash_prefix('S', 'N', 'D'),
/** account state */
leafNode = detail::make_hash_prefix('M', 'L', 'N'),
/** inner node in V1 tree */
innerNode = detail::make_hash_prefix('M', 'I', 'N'),
/** ledger master data for signing */
ledgerMaster = detail::make_hash_prefix('L', 'W', 'R'),
/** inner transaction to sign */
txSign = detail::make_hash_prefix('S', 'T', 'X'),
/** inner transaction to multi-sign */
txMultiSign = detail::make_hash_prefix('S', 'M', 'T'),
/** validation for signing */
validation = detail::make_hash_prefix('V', 'A', 'L'),
/** proposal for signing */
proposal = detail::make_hash_prefix('P', 'R', 'P'),
/** Manifest */
manifest = detail::make_hash_prefix('M', 'A', 'N'),
/** Payment Channel Claim */
paymentChannelClaim = detail::make_hash_prefix('C', 'L', 'M'),
/** Credentials signature */
credential = detail::make_hash_prefix('C', 'R', 'D'),
/** Batch */
batch = detail::make_hash_prefix('B', 'C', 'H'),
};
template <class Hasher>
void
hash_append(Hasher& h, HashPrefix const& hp) noexcept
{
using beast::hash_append;
hash_append(h, static_cast<std::uint32_t>(hp));
}
} // namespace ripple
#endif