rippled
ValidatorInfo.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2019 Dev Null Productions
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 <ripple/app/main/Application.h>
21 #include <ripple/app/misc/ValidatorKeys.h>
22 #include <ripple/basics/base64.h>
23 #include <ripple/json/json_value.h>
24 #include <ripple/protocol/ErrorCodes.h>
25 #include <ripple/protocol/jss.h>
26 #include <ripple/rpc/Context.h>
27 
28 namespace ripple {
31 {
32  // return error if not configured as validator
33  if (context.app.getValidationPublicKey().empty())
34  return RPC::not_validator_error();
35 
36  Json::Value ret;
37 
38  auto const pk = context.app.getValidationPublicKey();
39 
40  // assume pk is ephemeral key, get master key
41  auto const mk = context.app.validatorManifests().getMasterKey(pk);
42  ret[jss::master_key] = toBase58(TokenType::NodePublic, mk);
43 
44  // pk is maskter key, eg no ephemeral key, eg no manifest, just return
45  if (mk == pk)
46  return ret;
47 
48  // lookup ephemeral key
49  auto const ek = context.app.validatorManifests().getSigningKey(mk);
50  ret[jss::ephemeral_key] = toBase58(TokenType::NodePublic, ek);
51 
52  if (auto const manifest = context.app.validatorManifests().getManifest(mk))
53  ret[jss::manifest] = base64_encode(*manifest);
54 
55  if (auto const seq = context.app.validatorManifests().getSequence(mk))
56  ret[jss::seq] = *seq;
57 
58  if (auto const domain = context.app.validatorManifests().getDomain(mk))
59  ret[jss::domain] = *domain;
60 
61  return ret;
62 }
63 } // namespace ripple
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::ManifestCache::getMasterKey
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
Definition: app/misc/impl/Manifest.cpp:303
ripple::HashPrefix::manifest
@ manifest
Manifest.
ripple::base64_encode
std::string base64_encode(std::uint8_t const *data, std::size_t len)
Definition: base64.cpp:236
ripple::PublicKey::empty
bool empty() const noexcept
Definition: PublicKey.h:117
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
ripple::doValidatorInfo
Json::Value doValidatorInfo(RPC::JsonContext &)
Definition: ValidatorInfo.cpp:30
ripple::RPC::Context::app
Application & app
Definition: Context.h:42
ripple::ManifestCache::getSigningKey
PublicKey getSigningKey(PublicKey const &pk) const
Returns master key's current signing key.
Definition: app/misc/impl/Manifest.cpp:291
ripple::RPC::not_validator_error
Json::Value not_validator_error()
Definition: ErrorCodes.h:340
ripple::Application::getValidationPublicKey
virtual PublicKey const & getValidationPublicKey() const =0
ripple::ManifestCache::getSequence
std::optional< std::uint32_t > getSequence(PublicKey const &pk) const
Returns master key's current manifest sequence.
Definition: app/misc/impl/Manifest.cpp:315
ripple::ManifestCache::getManifest
std::optional< std::string > getManifest(PublicKey const &pk) const
Returns mainfest corresponding to a given public key.
Definition: app/misc/impl/Manifest.cpp:339
ripple::ManifestCache::getDomain
std::optional< std::string > getDomain(PublicKey const &pk) const
Returns domain claimed by a given public key.
Definition: app/misc/impl/Manifest.cpp:327
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Application::validatorManifests
virtual ManifestCache & validatorManifests()=0
ripple::TokenType::NodePublic
@ NodePublic
Json::Value
Represents a JSON value.
Definition: json_value.h:145