xrpld
Loading...
Searching...
No Matches
tokens.h
1#pragma once
2
3#include <xrpl/protocol/detail/token_errors.h>
4
5#include <cstddef>
6#include <cstdint>
7#include <expected>
8#include <optional>
9#include <span>
10#include <string>
11#include <string_view>
12#include <system_error>
13
14namespace xrpl {
15
16template <class T>
17using B58Result = std::expected<T, std::error_code>;
18
19enum class TokenType : std::uint8_t {
20 None = 1, // unused
26 FamilyGenerator = 41, // unused
28};
29
30template <class T>
31[[nodiscard]] std::optional<T>
33
34template <class T>
35[[nodiscard]] std::optional<T>
37
50[[nodiscard]] std::string
51encodeBase58Token(TokenType type, void const* token, std::size_t size);
52
53[[nodiscard]] std::string
55
56namespace b58_ref {
57// The reference version does not use gcc extensions (int128 in particular)
58[[nodiscard]] std::string
59encodeBase58Token(TokenType type, void const* token, std::size_t size);
60
61[[nodiscard]] std::string
63
64namespace detail {
65// Expose detail functions for unit tests only
67encodeBase58(void const* message, std::size_t size, void* temp, std::size_t tempSize);
68
71} // namespace detail
72} // namespace b58_ref
73
74#ifndef _MSC_VER
75namespace b58_fast {
76// Use the fast version (10-15x faster) is using gcc extensions (int128 in
77// particular)
80 TokenType tokenType,
83
86
87// This interface matches the old interface, but requires additional allocation
88[[nodiscard]] std::string
89encodeBase58Token(TokenType type, void const* token, std::size_t size);
90
91// This interface matches the old interface, but requires additional allocation
92[[nodiscard]] std::string
94
95namespace detail {
96// Expose detail functions for unit tests only
99
101b58ToB256Be(std::string_view input, std::span<std::uint8_t> out);
102} // namespace detail
103
104} // namespace b58_fast
105#endif // _MSC_VER
106} // namespace xrpl
std::string decodeBase58(std::string const &s)
Definition tokens.cpp:252
std::string encodeBase58(void const *message, std::size_t size, void *temp, std::size_t tempSize)
Definition tokens.cpp:205
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Definition tokens.cpp:300
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition tokens.cpp:323
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::expected< T, std::error_code > B58Result
Definition tokens.h:17
TokenType
Definition tokens.h:19
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Encode data in Base58Check format using XRPL alphabet.
Definition tokens.cpp:181
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition tokens.cpp:191