rippled
Loading...
Searching...
No Matches
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 <xrpl/basics/Slice.h>
24#include <xrpl/basics/base_uint.h>
25#include <xrpl/protocol/tokens.h>
26
27#include <array>
28#include <optional>
29
30namespace ripple {
31
33class Seed
34{
35private:
37
38public:
40
41 Seed() = delete;
42
43 Seed(Seed const&) = default;
44 Seed&
45 operator=(Seed const&) = default;
46
50 ~Seed();
51
54 explicit Seed(Slice const& slice);
55 explicit Seed(uint128 const& seed);
58 std::uint8_t const*
59 data() const
60 {
61 return buf_.data();
62 }
63
65 size() const
66 {
67 return buf_.size();
68 }
69
71 begin() const noexcept
72 {
73 return buf_.begin();
74 }
75
77 cbegin() const noexcept
78 {
79 return buf_.cbegin();
80 }
81
83 end() const noexcept
84 {
85 return buf_.end();
86 }
87
89 cend() const noexcept
90 {
91 return buf_.cend();
92 }
93};
94
95//------------------------------------------------------------------------------
96
98Seed
100
112Seed
113generateSeed(std::string const& passPhrase);
114
116template <>
118parseBase58(std::string const& s);
119
126parseGenericSeed(std::string const& str, bool rfc1751 = true);
127
130seedAs1751(Seed const& seed);
131
133inline std::string
134toBase58(Seed const& seed)
135{
136 return encodeBase58Token(TokenType::FamilySeed, seed.data(), seed.size());
137}
138
139} // namespace ripple
140
141#endif
T begin(T... args)
Seeds are used to generate deterministic secret keys.
Definition: Seed.h:34
Seed()=delete
std::array< uint8_t, 16 > buf_
Definition: Seed.h:36
const_iterator cend() const noexcept
Definition: Seed.h:89
std::size_t size() const
Definition: Seed.h:65
const_iterator end() const noexcept
Definition: Seed.h:83
~Seed()
Destroy the seed.
Definition: Seed.cpp:44
const_iterator cbegin() const noexcept
Definition: Seed.h:77
std::array< uint8_t, 16 >::const_iterator const_iterator
Definition: Seed.h:39
Seed(Seed const &)=default
Seed & operator=(Seed const &)=default
const_iterator begin() const noexcept
Definition: Seed.h:71
std::uint8_t const * data() const
Definition: Seed.h:59
An immutable linear range of bytes.
Definition: Slice.h:46
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:86
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:26
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:114
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:124
Seed randomSeed()
Create a seed using secure random numbers.
Definition: Seed.cpp:66
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 seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition: Seed.cpp:135
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition: Seed.cpp:97
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition: Seed.cpp:76
T size(T... args)