rippled
Seed.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_SEED_H_INCLUDED
21 #define RIPPLE_PROTOCOL_SEED_H_INCLUDED
22 
23 #include <ripple/basics/Slice.h>
24 #include <ripple/basics/base_uint.h>
25 #include <ripple/protocol/tokens.h>
26 #include <array>
27 #include <optional>
28 
29 namespace ripple {
30 
32 class Seed
33 {
34 private:
36 
37 public:
39 
40  Seed() = delete;
41 
42  Seed(Seed const&) = default;
43  Seed&
44  operator=(Seed const&) = default;
45 
49  ~Seed();
50 
53  explicit Seed(Slice const& slice);
54  explicit Seed(uint128 const& seed);
57  std::uint8_t const*
58  data() const
59  {
60  return buf_.data();
61  }
62 
64  size() const
65  {
66  return buf_.size();
67  }
68 
70  begin() const noexcept
71  {
72  return buf_.begin();
73  }
74 
76  cbegin() const noexcept
77  {
78  return buf_.cbegin();
79  }
80 
82  end() const noexcept
83  {
84  return buf_.end();
85  }
86 
88  cend() const noexcept
89  {
90  return buf_.cend();
91  }
92 };
93 
94 //------------------------------------------------------------------------------
95 
97 Seed
98 randomSeed();
99 
111 Seed
112 generateSeed(std::string const& passPhrase);
113 
115 template <>
117 parseBase58(std::string const& s);
118 
125 parseGenericSeed(std::string const& str, bool rfc1751 = true);
126 
129 seedAs1751(Seed const& seed);
130 
132 inline std::string
133 toBase58(Seed const& seed)
134 {
135  return encodeBase58Token(TokenType::FamilySeed, seed.data(), seed.size());
136 }
137 
138 } // namespace ripple
139 
140 #endif
ripple::Dir::const_iterator
Definition: Directory.h:49
std::string
STL class.
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
std::array::size
T size(T... args)
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
ripple::Seed::~Seed
~Seed()
Destroy the seed.
Definition: Seed.cpp:37
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::TokenType::FamilySeed
@ FamilySeed
ripple::seedAs1751
std::string seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition: Seed.cpp:128
array
ripple::randomSeed
Seed randomSeed()
Create a seed using secure random numbers.
Definition: Seed.cpp:59
std::uint8_t
ripple::parseGenericSeed
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751)
Attempt to parse a string as a seed.
Definition: Seed.cpp:90
ripple::Seed::buf_
std::array< uint8_t, 16 > buf_
Definition: Seed.h:35
ripple::generateSeed
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition: Seed.cpp:69
ripple::Seed::size
std::size_t size() const
Definition: Seed.h:64
ripple::Seed::Seed
Seed()=delete
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Seed::begin
const_iterator begin() const noexcept
Definition: Seed.h:70
ripple::Seed
Seeds are used to generate deterministic secret keys.
Definition: Seed.h:32
ripple::Seed::operator=
Seed & operator=(Seed const &)=default
ripple::encodeBase58Token
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::array::begin
T begin(T... args)
optional
std::size_t
std::array::end
T end(T... args)
ripple::Seed::cend
const_iterator cend() const noexcept
Definition: Seed.h:88
ripple::parseBase58
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:114
ripple::Seed::end
const_iterator end() const noexcept
Definition: Seed.h:82
ripple::Seed::const_iterator
std::array< uint8_t, 16 >::const_iterator const_iterator
Definition: Seed.h:38
std::array::data
T data(T... args)
ripple::Seed::data
std::uint8_t const * data() const
Definition: Seed.h:58
ripple::Seed::cbegin
const_iterator cbegin() const noexcept
Definition: Seed.h:76