rippled
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 <boost/optional.hpp>
24 #include <cstdint>
25 #include <string>
26 
27 namespace ripple {
28 
29 enum class TokenType : std::uint8_t {
30  None = 1, // unused
31  NodePublic = 28,
32  NodePrivate = 32,
33  AccountID = 0,
34  AccountPublic = 35,
35  AccountSecret = 34,
36  FamilyGenerator = 41, // unused
37  FamilySeed = 33
38 };
39 
40 template <class T>
41 boost::optional<T>
42 parseBase58(std::string const& s);
43 
44 template <class T>
45 boost::optional<T>
46 parseBase58(TokenType type, std::string const& s);
47 
48 template <class T>
49 boost::optional<T>
50 parseHex(std::string const& s);
51 
52 template <class T>
53 boost::optional<T>
55 
56 // Facilities for converting Ripple tokens
57 // to and from their human readable strings
58 
59 /* Base-58 encode a Ripple Token
60 
61  Ripple Tokens have a one-byte prefx indicating
62  the type of token, followed by the data for the
63  token, and finally a 4-byte checksum.
64 
65  Tokens include the following:
66 
67  Wallet Seed
68  Account Public Key
69  Account ID
70 
71  @param type A single byte representing the TokenType
72  @param token A pointer to storage of not
73  less than 2*(size+6) bytes
74  @param size the size of the token buffer in bytes
75 */
77 base58EncodeToken(TokenType type, void const* token, std::size_t size);
78 
79 /* Base-58 encode a Bitcoin Token
80  *
81  * provided here for symmetry, but should never be needed
82  * except for testing.
83  *
84  * @see base58EncodeToken for format description.
85  *
86  */
88 base58EncodeTokenBitcoin(TokenType type, void const* token, std::size_t size);
89 
97 
110 
111 } // namespace ripple
112 
113 #endif
std::string
STL class.
ripple::base58EncodeToken
std::string base58EncodeToken(TokenType type, void const *token, std::size_t size)
Definition: tokens.cpp:182
ripple::TokenType::FamilyGenerator
@ FamilyGenerator
ripple::parseHex
boost::optional< AccountID > parseHex(std::string const &s)
Parse AccountID from hexadecimal string.
Definition: AccountID.cpp:75
ripple::TokenType::None
@ None
ripple::base_uint
Definition: base_uint.h:63
ripple::TokenType::FamilySeed
@ FamilySeed
ripple::TokenType
TokenType
Definition: tokens.h:29
cstdint
std::uint8_t
ripple::base58EncodeTokenBitcoin
std::string base58EncodeTokenBitcoin(TokenType type, void const *token, std::size_t size)
Definition: tokens.cpp:188
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::TokenType::AccountSecret
@ AccountSecret
ripple::parseHexOrBase58
boost::optional< AccountID > parseHexOrBase58(std::string const &s)
Parse AccountID from hex or checked base58 string.
Definition: AccountID.cpp:87
ripple::decodeBase58Token
static std::string decodeBase58Token(std::string const &s, TokenType type, InverseArray const &inv)
Definition: tokens.cpp:256
ripple::TokenType::AccountPublic
@ AccountPublic
ripple::TokenType::NodePublic
@ NodePublic
std::size_t
ripple::decodeBase58TokenBitcoin
std::string decodeBase58TokenBitcoin(std::string const &s, TokenType type)
Decode a Base58 token using Bitcoin alphabet.
Definition: tokens.cpp:313
ripple::parseBase58
boost::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:36
ripple::TokenType::NodePrivate
@ NodePrivate
string