rippled
Loading...
Searching...
No Matches
tokens.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_TOKENS_H_INCLUDED
21#define RIPPLE_PROTOCOL_TOKENS_H_INCLUDED
22
23#include <xrpl/basics/Expected.h>
24#include <xrpl/basics/contract.h>
25#include <xrpl/protocol/detail/token_errors.h>
26
27#include <cstdint>
28#include <optional>
29#include <span>
30#include <string>
31#include <string_view>
32
33namespace ripple {
34
35template <class T>
37
38enum class TokenType : std::uint8_t {
39 None = 1, // unused
40 NodePublic = 28,
41 NodePrivate = 32,
42 AccountID = 0,
43 AccountPublic = 35,
44 AccountSecret = 34,
45 FamilyGenerator = 41, // unused
46 FamilySeed = 33
47};
48
49template <class T>
50[[nodiscard]] std::optional<T>
52
53template <class T>
54[[nodiscard]] std::optional<T>
56
68[[nodiscard]] std::string
69encodeBase58Token(TokenType type, void const* token, std::size_t size);
70
71[[nodiscard]] std::string
73
74namespace b58_ref {
75// The reference version does not use gcc extensions (int128 in particular)
76[[nodiscard]] std::string
77encodeBase58Token(TokenType type, void const* token, std::size_t size);
78
79[[nodiscard]] std::string
81
82namespace detail {
83// Expose detail functions for unit tests only
86 void const* message,
87 std::size_t size,
88 void* temp,
89 std::size_t temp_size);
90
93} // namespace detail
94} // namespace b58_ref
95
96#ifndef _MSC_VER
97namespace b58_fast {
98// Use the fast version (10-15x faster) is using gcc extensions (int128 in
99// particular)
102 TokenType token_type,
105
108 TokenType type,
111
112// This interface matches the old interface, but requires additional allocation
113[[nodiscard]] std::string
114encodeBase58Token(TokenType type, void const* token, std::size_t size);
115
116// This interface matches the old interface, but requires additional allocation
117[[nodiscard]] std::string
119
120namespace detail {
121// Expose detail functions for unit tests only
123b256_to_b58_be(
126
128b58_to_b256_be(std::string_view input, std::span<std::uint8_t> out);
129} // namespace detail
130
131} // namespace b58_fast
132#endif // _MSC_VER
133} // namespace ripple
134
135#endif
std::string decodeBase58(std::string const &s)
Definition tokens.cpp:275
std::string encodeBase58(void const *message, std::size_t size, void *temp, std::size_t temp_size)
Definition tokens.cpp:223
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Definition tokens.cpp:325
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition tokens.cpp:349
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
TokenType
Definition tokens.h:38
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Encode data in Base58Check format using XRPL alphabet.
Definition tokens.cpp:199
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition tokens.cpp:209