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 {
31  None = 1, // unused
32  NodePublic = 28,
33  NodePrivate = 32,
34  AccountID = 0,
35  AccountPublic = 35,
36  AccountSecret = 34,
37  FamilyGenerator = 41, // unused
38  FamilySeed = 33
39 };
40 
41 template <class T>
42 boost::optional<T>
43 parseBase58 (std::string const& s);
44 
45 template<class T>
46 boost::optional<T>
47 parseBase58 (TokenType type, std::string const& s);
48 
49 template <class T>
50 boost::optional<T>
51 parseHex (std::string const& s);
52 
53 template <class T>
54 boost::optional<T>
55 parseHexOrBase58 (std::string const& s);
56 
57 // Facilities for converting Ripple tokens
58 // to and from their human readable strings
59 
60 /* Base-58 encode a Ripple Token
61 
62  Ripple Tokens have a one-byte prefx indicating
63  the type of token, followed by the data for the
64  token, and finally a 4-byte checksum.
65 
66  Tokens include the following:
67 
68  Wallet Seed
69  Account Public Key
70  Account ID
71 
72  @param type A single byte representing the TokenType
73  @param token A pointer to storage of not
74  less than 2*(size+6) bytes
75  @param size the size of the token buffer in bytes
76 */
78 base58EncodeToken (TokenType type, void const* token, std::size_t size);
79 
80 /* Base-58 encode a Bitcoin Token
81  *
82  * provided here for symmetry, but should never be needed
83  * except for testing.
84  *
85  * @see base58EncodeToken for format description.
86  *
87  */
89 base58EncodeTokenBitcoin (TokenType type, void const* token, std::size_t size);
90 
98 
111 
112 } // ripple
113 
114 #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:79
ripple::TokenType::None
@ None
ripple::base_uint
Definition: base_uint.h:65
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:189
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:91
ripple::decodeBase58Token
static std::string decodeBase58Token(std::string const &s, TokenType type, InverseArray const &inv)
Definition: tokens.cpp:264
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:326
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