xrpld
Loading...
Searching...
No Matches
STValidation.cpp
1#include <xrpl/protocol/STValidation.h>
2
3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/chrono.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/protocol/HashPrefix.h>
9#include <xrpl/protocol/KeyType.h>
10#include <xrpl/protocol/PublicKey.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/SOTemplate.h>
13#include <xrpl/protocol/STBase.h>
14#include <xrpl/protocol/STObject.h>
15#include <xrpl/protocol/Serializer.h>
16
17#include <cstddef>
18#include <utility>
19
20namespace xrpl {
21
22STBase*
24{
25 return emplace(n, buf, *this);
26}
27
28STBase*
30{
31 return emplace(n, buf, std::move(*this));
32}
33
34SOTemplate const&
36{
37 // We can't have this be a magic static at namespace scope because
38 // it relies on the SField's below being initialized, and we can't
39 // guarantee the initialization order.
40 // clang-format off
41 static SOTemplate const kFormat{
42 {sfFlags, SoeRequired},
43 {sfLedgerHash, SoeRequired},
44 {sfLedgerSequence, SoeRequired},
45 {sfCloseTime, SoeOptional},
46 {sfLoadFee, SoeOptional},
47 {sfAmendments, SoeOptional},
48 {sfBaseFee, SoeOptional},
49 {sfReserveBase, SoeOptional},
50 {sfReserveIncrement, SoeOptional},
51 {sfSigningTime, SoeRequired},
52 {sfSigningPubKey, SoeRequired},
53 {sfSignature, SoeRequired},
54 {sfConsensusHash, SoeOptional},
55 {sfCookie, SoeDefault},
56 {sfValidatedHash, SoeOptional},
57 {sfServerVersion, SoeOptional},
58 // featureXRPFees
59 {sfBaseFeeDrops, SoeOptional},
60 {sfReserveBaseDrops, SoeOptional},
61 {sfReserveIncrementDrops, SoeOptional},
62 };
63 // clang-format on
64
65 return kFormat;
66};
67
73
76{
77 return getFieldH256(sfLedgerHash);
78}
79
82{
83 return getFieldH256(sfConsensusHash);
84}
85
91
94{
95 return seenTime_;
96}
97
98bool
99STValidation::isValid() const noexcept
100{
101 if (!valid_)
102 {
103 XRPL_ASSERT(
105 "xrpl::STValidation::isValid : valid key type");
106
110 makeSlice(getFieldVL(sfSignature)),
111 (getFlags() & kVfFullyCanonicalSig) != 0u);
112 }
113
114 return valid_.value();
115}
116
117bool
118STValidation::isFull() const noexcept
119{
120 return (getFlags() & kVfFullValidation) != 0;
121}
122
123Blob
125{
126 return getFieldVL(sfSignature);
127}
128
129Blob
131{
132 Serializer s;
133 add(s);
134 return s.peekData();
135}
136
137} // namespace xrpl
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
std::chrono::duration< rep, period > duration
Definition chrono.h:45
Defines the fields and their attributes within a STObject.
Definition SOTemplate.h:96
A type which can be exported to a well known binary format.
Definition STBase.h:117
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:215
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:639
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:591
void add(Serializer &s) const override
Definition STObject.cpp:120
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:621
uint256 getSigningHash(HashPrefix prefix) const
Definition STObject.cpp:374
std::uint32_t getFlags() const
Definition STObject.cpp:507
NetClock::time_point getSignTime() const
static SOTemplate const & validationFormat()
STBase * move(std::size_t n, void *buf) override
Blob getSignature() const
NetClock::time_point getSeenTime() const noexcept
std::optional< bool > valid_
uint256 getConsensusHash() const
STBase * copy(std::size_t n, void *buf) const override
bool isValid() const noexcept
bool isFull() const noexcept
uint256 getLedgerHash() const
PublicKey const & getSignerPublic() const noexcept
uint256 getSigningHash() const
Blob getSerialized() const
NetClock::time_point seenTime_
Blob const & peekData() const
Definition Serializer.h:176
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a secp256k1 signature on the digest of a message.
@ SoeDefault
Definition SOTemplate.h:20
@ SoeOptional
Definition SOTemplate.h:19
@ SoeRequired
Definition SOTemplate.h:18
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
constexpr std::uint32_t kVfFullValidation
constexpr std::uint32_t kVfFullyCanonicalSig
@ Validation
validation for signing
Definition HashPrefix.h:57
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:10
BaseUInt< 256 > uint256
Definition base_uint.h:562
std::enable_if_t< std::is_same_v< T, char >||std::is_same_v< T, unsigned char >, Slice > makeSlice(std::array< T, N > const &a)
Definition Slice.h:215