rippled
Loading...
Searching...
No Matches
credentials.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 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#ifndef RIPPLE_TEST_JTX_CREDENTIALS_H_INCLUDED
21#define RIPPLE_TEST_JTX_CREDENTIALS_H_INCLUDED
22
23#include <test/jtx/Account.h>
24#include <test/jtx/Env.h>
25#include <test/jtx/owners.h>
26
27namespace ripple {
28namespace test {
29namespace jtx {
30
31namespace credentials {
32
33inline Keylet
35 test::jtx::Account const& subject,
36 test::jtx::Account const& issuer,
37 std::string_view credType)
38{
39 return keylet::credential(
40 subject.id(), issuer.id(), Slice(credType.data(), credType.size()));
41}
42
43// Sets the optional URI.
44class uri
45{
46private:
48
49public:
50 explicit uri(std::string_view u) : uri_(strHex(u))
51 {
52 }
53
54 void
56 {
57 jtx.jv[sfURI.jsonName] = uri_;
58 }
59};
60
61// Set credentialsIDs array
62class ids
63{
64private:
66
67public:
68 explicit ids(std::vector<std::string> const& creds) : credentials_(creds)
69 {
70 }
71
72 void
74 {
75 auto& arr(jtx.jv[sfCredentialIDs.jsonName] = Json::arrayValue);
76 for (auto const& hash : credentials_)
77 arr.append(hash);
78 }
79};
80
82create(
83 jtx::Account const& subject,
84 jtx::Account const& issuer,
85 std::string_view credType);
86
88accept(
89 jtx::Account const& subject,
90 jtx::Account const& issuer,
91 std::string_view credType);
92
95 jtx::Account const& acc,
96 jtx::Account const& subject,
97 jtx::Account const& issuer,
98 std::string_view credType);
99
102 jtx::Env& env,
103 jtx::Account const& subject,
104 jtx::Account const& issuer,
105 std::string_view credType);
106
108ledgerEntry(jtx::Env& env, std::string const& credIdx);
109
110} // namespace credentials
111} // namespace jtx
112} // namespace test
113} // namespace ripple
114
115#endif
Represents a JSON value.
Definition: json_value.h:149
An immutable linear range of bytes.
Definition: Slice.h:46
Immutable cryptographic account descriptor.
Definition: Account.h:39
AccountID id() const
Returns the Account ID.
Definition: Account.h:107
A transaction testing environment.
Definition: Env.h:121
std::vector< std::string > const credentials_
Definition: credentials.h:65
ids(std::vector< std::string > const &creds)
Definition: credentials.h:68
void operator()(jtx::Env &, jtx::JTx &jtx) const
Definition: credentials.h:73
void operator()(jtx::Env &, jtx::JTx &jtx) const
Definition: credentials.h:55
T data(T... args)
@ arrayValue
array value (ordered list)
Definition: json_value.h:44
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition: Indexes.cpp:553
Json::Value create(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:32
Json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:48
Keylet keylet(test::jtx::Account const &subject, test::jtx::Account const &issuer, std::string_view credType)
Definition: credentials.h:34
Json::Value deleteCred(jtx::Account const &acc, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:62
Json::Value ledgerEntry(jtx::Env &env, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:78
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
T size(T... args)
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
Execution context for applying a JSON transaction.
Definition: JTx.h:45
Json::Value jv
Definition: JTx.h:46