rippled
Loading...
Searching...
No Matches
DoManifest.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 <xrpld/app/main/Application.h>
21#include <xrpld/rpc/Context.h>
22
23#include <xrpl/basics/base64.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/protocol/ErrorCodes.h>
26#include <xrpl/protocol/jss.h>
27
28namespace ripple {
31{
32 auto& params = context.params;
33
34 if (!params.isMember(jss::public_key))
35 return RPC::missing_field_error(jss::public_key);
36
37 auto const requested = params[jss::public_key].asString();
38
39 Json::Value ret;
40 ret[jss::requested] = requested;
41
42 auto const pk = parseBase58<PublicKey>(TokenType::NodePublic, requested);
43 if (!pk)
44 {
46 return ret;
47 }
48
49 // first attempt to use params as ephemeral key,
50 // if this lookup succeeds master key will be returned,
51 // else an unseated optional is returned
52 auto const mk = context.app.validatorManifests().getMasterKey(*pk);
53
54 auto const ek = context.app.validatorManifests().getSigningKey(mk);
55
56 // if ephemeral key not found, we don't have specified manifest
57 if (!ek)
58 return ret;
59
60 if (auto const manifest = context.app.validatorManifests().getManifest(mk))
61 ret[jss::manifest] = base64_encode(*manifest);
62 Json::Value details;
63
64 details[jss::master_key] = toBase58(TokenType::NodePublic, mk);
65 details[jss::ephemeral_key] = toBase58(TokenType::NodePublic, *ek);
66
67 if (auto const seq = context.app.validatorManifests().getSequence(mk))
68 details[jss::seq] = *seq;
69
70 if (auto const domain = context.app.validatorManifests().getDomain(mk))
71 details[jss::domain] = *domain;
72
73 ret[jss::details] = details;
74 return ret;
75}
76} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
virtual ManifestCache & validatorManifests()=0
std::optional< std::uint32_t > getSequence(PublicKey const &pk) const
Returns master key's current manifest sequence.
Definition Manifest.cpp:335
std::optional< std::string > getManifest(PublicKey const &pk) const
Returns mainfest corresponding to a given public key.
Definition Manifest.cpp:359
std::optional< PublicKey > getSigningKey(PublicKey const &pk) const
Returns master key's current signing key.
Definition Manifest.cpp:311
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
Definition Manifest.cpp:323
std::optional< std::string > getDomain(PublicKey const &pk) const
Returns domain claimed by a given public key.
Definition Manifest.cpp:347
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition ErrorCodes.h:233
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:283
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.
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:84
Json::Value doManifest(RPC::JsonContext &context)
std::string base64_encode(std::uint8_t const *data, std::size_t len)
@ manifest
Manifest.
Application & app
Definition Context.h:41