mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-19 05:00:42 +00:00
std::ranges::transform/all_of come from <algorithm>, which is already included. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
32 lines
940 B
C++
32 lines
940 B
C++
#include <xrpl/telemetry/Redaction.h>
|
|
|
|
#include <xrpl/basics/Slice.h>
|
|
#include <xrpl/basics/base_uint.h>
|
|
#include <xrpl/protocol/digest.h>
|
|
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace xrpl::telemetry {
|
|
|
|
std::string
|
|
redactAccount(std::string_view addr)
|
|
{
|
|
// Empty in, empty out: nothing to hash and no token to emit.
|
|
if (addr.empty())
|
|
return {};
|
|
|
|
// sha512Half yields a uint256; to_string renders it as uppercase hex.
|
|
// Keep the first 16 chars (64 bits) — enough to correlate spans while
|
|
// staying non-reversible — and lowercase them for a stable token.
|
|
auto const digest = sha512Half(Slice(addr.data(), addr.size()));
|
|
std::string token = to_string(digest).substr(0, 16);
|
|
std::ranges::transform(
|
|
token, token.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
|
return token;
|
|
}
|
|
|
|
} // namespace xrpl::telemetry
|