rippled
Loading...
Searching...
No Matches
RCLCxPeerPos.cpp
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#include <xrpld/app/consensus/RCLCxPeerPos.h>
21
22#include <xrpl/protocol/Serializer.h>
23#include <xrpl/protocol/jss.h>
24
25namespace ripple {
26
27// Used to construct received proposals
29 PublicKey const& publicKey,
30 Slice const& signature,
31 uint256 const& suppression,
33 : publicKey_(publicKey)
34 , suppression_(suppression)
35 , proposal_(std::move(proposal))
36{
37 // The maximum allowed size of a signature is 72 bytes; we verify
38 // this elsewhere, but we want to be extra careful here:
39 XRPL_ASSERT(
40 signature.size() != 0 && signature.size() <= signature_.capacity(),
41 "ripple::RCLCxPeerPos::RCLCxPeerPos : valid signature size");
42
43 if (signature.size() != 0 && signature.size() <= signature_.capacity())
45}
46
47bool
49{
50 return verifyDigest(
52}
53
56{
57 auto ret = proposal().getJson();
58
59 if (publicKey().size())
60 ret[jss::peer_id] = toBase58(TokenType::NodePublic, publicKey());
61
62 return ret;
63}
64
67 uint256 const& proposeHash,
68 uint256 const& previousLedger,
69 std::uint32_t proposeSeq,
70 NetClock::time_point closeTime,
71 Slice const& publicKey,
72 Slice const& signature)
73{
74 Serializer s(512);
75 s.addBitString(proposeHash);
76 s.addBitString(previousLedger);
77 s.add32(proposeSeq);
78 s.add32(closeTime.time_since_epoch().count());
79 s.addVL(publicKey);
80 s.addVL(signature);
81
82 return s.getSHA512Half();
83}
84
85} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
uint256 const & signingHash() const
The digest for this proposal, used for signing purposes.
Json::Value getJson() const
Get JSON representation for debugging.
A public key.
Definition PublicKey.h:62
Proposal const & proposal() const
boost::container::static_vector< std::uint8_t, 72 > signature_
RCLCxPeerPos(PublicKey const &publicKey, Slice const &signature, uint256 const &suppress, Proposal &&proposal)
Constructor.
bool checkSign() const
Verify the signing hash of the proposal.
Json::Value getJson() const
JSON representation of proposal.
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Slice signature() const
Signature of the proposal (not necessarily verified)
uint256 getSHA512Half() const
int addBitString(base_uint< Bits, Tag > const &v)
Definition Serializer.h:131
int addVL(Blob const &vector)
An immutable linear range of bytes.
Definition Slice.h:46
const_iterator begin() const noexcept
Definition Slice.h:149
const_iterator end() const noexcept
Definition Slice.h:161
std::size_t size() const noexcept
Returns the number of bytes in the storage.
Definition Slice.h:81
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
uint256 proposalUniqueId(uint256 const &proposeHash, uint256 const &previousLedger, std::uint32_t proposeSeq, NetClock::time_point closeTime, Slice const &publicKey, Slice const &signature)
Calculate a unique identifier for a signed proposal.
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.
@ proposal
proposal for signing
STL namespace.
T time_since_epoch(T... args)