20#include <xrpl/basics/Slice.h> 
   21#include <xrpl/basics/base_uint.h> 
   22#include <xrpl/basics/contract.h> 
   23#include <xrpl/basics/strHex.h> 
   24#include <xrpl/protocol/KeyType.h> 
   25#include <xrpl/protocol/PublicKey.h> 
   26#include <xrpl/protocol/UintTypes.h> 
   27#include <xrpl/protocol/detail/secp256k1.h> 
   28#include <xrpl/protocol/digest.h> 
   29#include <xrpl/protocol/tokens.h> 
   31#include <boost/multiprecision/fwd.hpp> 
   32#include <boost/multiprecision/number.hpp> 
   71    if (buf.
size() < 3 || buf[0] != 0x02)
 
   73    auto const len = buf[1];
 
   75    if (len > buf.
size() || len < 1 || len > 33)
 
   78    if ((buf[0] & 0x80) != 0)
 
   86        if ((buf[1] & 0x80) == 0)
 
 
  108    for (
int i = 0; i < slice.
size(); ++i)
 
  110        constexpr char hex[] = 
"0123456789ABCDEF";
 
  111        s += hex[((slice[i] & 0xf0) >> 4)];
 
  112        s += hex[((slice[i] & 0x0f) >> 0)];
 
 
  133        boost::multiprecision::number<boost::multiprecision::cpp_int_backend<
 
  136            boost::multiprecision::signed_magnitude,
 
  137            boost::multiprecision::unchecked,
 
  140    static uint264 
const G(
 
  141        "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
 
  145    if ((sig.
size() < 8) || (sig.
size() > 72))
 
  147    if ((sig[0] != 0x30) || (sig[1] != (sig.
size() - 2)))
 
  152    if (!r || !s || !p.
empty())
 
  165    auto const Sp = G - S;
 
 
  174    if (sig.
size() != 64)
 
  178        0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 
  179        0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xDE, 0xF9, 0xDE, 0xA2, 0xF7,
 
  180        0x9C, 0xD6, 0x58, 0x12, 0x63, 0x1A, 0x5C, 0xF5, 0xD3, 0xED,
 
  184    auto const le = sig.
data() + 32;
 
 
  197            "PublicKey::PublicKey - Input slice cannot be an undersized " 
  201        LogicError(
"PublicKey::PublicKey invalid type");
 
 
  226    if (slice.
size() == 33)
 
  228        if (slice[0] == 0xED)
 
  231        if (slice[0] == 0x02 || slice[0] == 0x03)
 
 
  243    bool mustBeFullyCanonical) 
noexcept 
  246        LogicError(
"sign: secp256k1 required for digest signing");
 
  250    if (mustBeFullyCanonical &&
 
  254    secp256k1_pubkey pubkey_imp;
 
  255    if (secp256k1_ec_pubkey_parse(
 
  258            reinterpret_cast<unsigned char const*
>(publicKey.data()),
 
  259            publicKey.size()) != 1)
 
  262    secp256k1_ecdsa_signature sig_imp;
 
  263    if (secp256k1_ecdsa_signature_parse_der(
 
  266            reinterpret_cast<unsigned char const*
>(sig.data()),
 
  271        secp256k1_ecdsa_signature sig_norm;
 
  272        if (secp256k1_ecdsa_signature_normalize(
 
  275        return secp256k1_ecdsa_verify(
 
  278                   reinterpret_cast<unsigned char const*
>(
digest.data()),
 
  281    return secp256k1_ecdsa_verify(
 
  284               reinterpret_cast<unsigned char const*
>(
digest.data()),
 
 
  293    bool mustBeFullyCanonical) 
noexcept 
  300                publicKey, 
sha512Half(m), sig, mustBeFullyCanonical);
 
  311            return ed25519_sign_open(
 
  312                       m.data(), m.size(), publicKey.data() + 1, sig.data()) ==
 
 
std::uint8_t const * data() const noexcept
 
std::size_t size() const noexcept
 
static constexpr std::size_t size_
 
Slice slice() const noexcept
 
PublicKey & operator=(PublicKey const &other)
 
An immutable linear range of bytes.
 
bool empty() const noexcept
Return true if the byte range is empty.
 
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
 
std::size_t size() const noexcept
Returns the number of bytes in the storage.
 
static std::size_t constexpr bytes
 
T lexicographical_compare(T... args)
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
secp256k1_context const * secp256k1Context()
 
std::optional< ECDSACanonicality > ecdsaCanonicality(Slice const &sig)
Determines the canonicality of a signature.
 
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.
 
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
 
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a signature on a message.
 
static std::string sliceToHex(Slice const &slice)
 
base_uint< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
 
static std::optional< Slice > sigPart(Slice &buf)
 
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
 
std::string decodeBase58Token(std::string const &s, TokenType type)
 
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
 
std::string strHex(FwdIt begin, FwdIt end)
 
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
 
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
 
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
 
static bool ed25519Canonical(Slice const &sig)
 
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
 
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
 
T reverse_copy(T... args)
 
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
 
std::array< std::uint8_t, 20 > result_type