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#include <array>
27#include <optional>
28
29namespace ripple {
30
32class Seed
33{
34private:
36
37public:
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
97Seed
99
111Seed
112generateSeed(std::string const& passPhrase);
113
115template <>
117parseBase58(std::string const& s);
118
125parseGenericSeed(std::string const& str, bool rfc1751 = true);
126
129seedAs1751(Seed const& seed);
130
132inline std::string
133toBase58(Seed const& seed)
134{
135 return encodeBase58Token(TokenType::FamilySeed, seed.data(), seed.size());
136}
137
138} // namespace ripple
139
140#endif
T begin(T... args)
Seeds are used to generate deterministic secret keys.
Definition: Seed.h:33
Seed()=delete
std::array< uint8_t, 16 > buf_
Definition: Seed.h:35
const_iterator cend() const noexcept
Definition: Seed.h:88
std::size_t size() const
Definition: Seed.h:64
const_iterator end() const noexcept
Definition: Seed.h:82
~Seed()
Destroy the seed.
Definition: Seed.cpp:37
const_iterator cbegin() const noexcept
Definition: Seed.h:76
std::array< uint8_t, 16 >::const_iterator const_iterator
Definition: Seed.h:38
Seed(Seed const &)=default
Seed & operator=(Seed const &)=default
const_iterator begin() const noexcept
Definition: Seed.h:70
std::uint8_t const * data() const
Definition: Seed.h:58
An immutable linear range of bytes.
Definition: Slice.h:45
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:85
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:106
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:116
Seed randomSeed()
Create a seed using secure random numbers.
Definition: Seed.cpp:59
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Encode data in Base58Check format using XRPL alphabet.
Definition: tokens.cpp:195
std::string seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition: Seed.cpp:128
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition: Seed.cpp:90
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition: Seed.cpp:69
T size(T... args)