rippled
Loading...
Searching...
No Matches
Seed.h
1#ifndef XRPL_PROTOCOL_SEED_H_INCLUDED
2#define XRPL_PROTOCOL_SEED_H_INCLUDED
3
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/protocol/tokens.h>
7
8#include <array>
9#include <optional>
10
11namespace ripple {
12
14class Seed
15{
16private:
18
19public:
21
22 Seed() = delete;
23
24 Seed(Seed const&) = default;
25 Seed&
26 operator=(Seed const&) = default;
27
31 ~Seed();
32
35 explicit Seed(Slice const& slice);
36 explicit Seed(uint128 const& seed);
39 std::uint8_t const*
40 data() const
41 {
42 return buf_.data();
43 }
44
46 size() const
47 {
48 return buf_.size();
49 }
50
52 begin() const noexcept
53 {
54 return buf_.begin();
55 }
56
58 cbegin() const noexcept
59 {
60 return buf_.cbegin();
61 }
62
64 end() const noexcept
65 {
66 return buf_.end();
67 }
68
70 cend() const noexcept
71 {
72 return buf_.cend();
73 }
74};
75
76//------------------------------------------------------------------------------
77
79Seed
81
93Seed
94generateSeed(std::string const& passPhrase);
95
97template <>
99parseBase58(std::string const& s);
100
107parseGenericSeed(std::string const& str, bool rfc1751 = true);
108
111seedAs1751(Seed const& seed);
112
114inline std::string
115toBase58(Seed const& seed)
116{
117 return encodeBase58Token(TokenType::FamilySeed, seed.data(), seed.size());
118}
119
120} // namespace ripple
121
122#endif
T begin(T... args)
Seeds are used to generate deterministic secret keys.
Definition Seed.h:15
Seed()=delete
std::array< uint8_t, 16 > buf_
Definition Seed.h:17
const_iterator cend() const noexcept
Definition Seed.h:70
std::size_t size() const
Definition Seed.h:46
const_iterator end() const noexcept
Definition Seed.h:64
~Seed()
Destroy the seed.
Definition Seed.cpp:25
const_iterator cbegin() const noexcept
Definition Seed.h:58
std::array< uint8_t, 16 >::const_iterator const_iterator
Definition Seed.h:20
Seed(Seed const &)=default
Seed & operator=(Seed const &)=default
const_iterator begin() const noexcept
Definition Seed.h:52
std::uint8_t const * data() const
Definition Seed.h:40
An immutable linear range of bytes.
Definition Slice.h:27
Integers of any length that is a multiple of 32-bits.
Definition base_uint.h:67
T data(T... args)
T end(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Seed randomSeed()
Create a seed using secure random numbers.
Definition Seed.cpp:47
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 seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition Seed.cpp:116
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition Seed.cpp:78
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:57
T size(T... args)