1#include <xrpl/ledger/helpers/CredentialHelpers.h>
3#include <xrpl/ledger/View.h>
4#include <xrpl/ledger/helpers/AccountRootHelpers.h>
5#include <xrpl/protocol/TER.h>
6#include <xrpl/protocol/digest.h>
11namespace credentials {
26 bool foundExpired =
false;
28 for (
auto const& h : arr)
32 auto const sleCred = view.
peek(k);
36 JLOG(j.
trace()) <<
"Credentials are expired. Cred: " << sleCred->getText();
52 auto delSLE = [&view, &sleCredential, j](
58 JLOG(j.
fatal()) <<
"Internal error: can't retrieve Owner account.";
68 JLOG(j.
fatal()) <<
"Unable to delete Credential from owner.";
79 auto const issuer = sleCredential->getAccountID(sfIssuer);
80 auto const subject = sleCredential->getAccountID(sfSubject);
81 bool const accepted = (sleCredential->getFlags() & lsfAccepted) != 0u;
83 auto err = delSLE(issuer, sfIssuerNode, !
accepted || (subject == issuer));
87 if (subject != issuer)
89 err = delSLE(subject, sfSubjectNode,
accepted);
95 view.
erase(sleCredential);
106 auto const& credentials = tx.
getFieldV256(sfCredentialIDs);
109 JLOG(j.
trace()) <<
"Malformed transaction: Credentials array size is invalid: "
110 << credentials.size();
115 for (
auto const& cred : credentials)
117 auto [it, ins] = duplicates.
insert(cred);
120 JLOG(j.
trace()) <<
"Malformed transaction: duplicates in credentials.";
135 for (
auto const& h : credIDs)
140 JLOG(j.
trace()) <<
"Credential doesn't exist. Cred: " << h;
144 if (sleCred->getAccountID(sfSubject) != src)
146 JLOG(j.
trace()) <<
"Credential doesn't belong to the source account. Cred: " << h;
150 if ((sleCred->getFlags() & lsfAccepted) == 0u)
152 JLOG(j.
trace()) <<
"Credential isn't accepted. Cred: " << h;
171 bool foundExpired =
false;
172 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
174 auto const issuer = h.getAccountID(sfIssuer);
175 auto const type = h.getFieldVL(sfCredentialType);
177 auto const sleCredential = view.
read(keyletCredential);
191 if ((sleCredential->getFlags() & lsfAccepted) != 0u)
209 for (
auto const& h : credIDs)
215 auto [it, ins] = sorted.
emplace((*sleCred)[sfIssuer], (*sleCred)[sfCredentialType]);
218 lifeExtender.
push_back(std::move(sleCred));
231 for (
auto const& cred : credentials)
233 auto [it, ins] =
out.
emplace(cred[sfIssuer], cred[sfCredentialType]);
243 if (credentials.
empty() || (credentials.
size() > maxSize))
245 JLOG(j.
trace()) <<
"Malformed transaction: "
246 "Invalid credentials size: "
247 << credentials.
size();
252 for (
auto const& credential : credentials)
254 auto const& issuer = credential[sfIssuer];
257 JLOG(j.
trace()) <<
"Malformed transaction: "
258 "Issuer account is invalid: "
263 auto const ct = credential[sfCredentialType];
266 JLOG(j.
trace()) <<
"Malformed transaction: "
267 "Invalid credentialType size: "
275 JLOG(j.
trace()) <<
"Malformed transaction: "
276 "duplicates in credentials.";
296 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
298 auto const issuer = h.getAccountID(sfIssuer);
299 auto const type = h.getFieldVL(sfCredentialType);
301 if (view.
exists(keyletCredential))
302 credentials.
push_back(keyletCredential.key);
306 for (
auto const& h : credentials)
312 if ((sleCredential->getFlags() & lsfAccepted) != 0u)
334 bool const credentialsPresent = tx.
isFieldPresent(sfCredentialIDs);
339 if (sleDst && ((sleDst->getFlags() & lsfDepositAuth) != 0u))
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool isFieldPresent(SField const &field) const
STVector256 const & getFieldV256(SField const &field) const
void push_back(uint256 const &v)
TER validDomain(ReadView const &view, uint256 domainID, AccountID const &subject)
bool checkExpired(std::shared_ptr< SLE const > const &sleCredential, NetClock::time_point const &closed)
bool removeExpired(ApplyView &view, STVector256 const &arr, beast::Journal const j)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
NotTEC checkFields(STTx const &tx, beast::Journal j)
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
TER authorizedDepositPreauth(ReadView const &view, STVector256 const &ctx, AccountID const &dst)
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
std::string to_string(base_uint< Bits, Tag > const &a)
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE const > const &sleDst, beast::Journal j)
TERSubset< CanCvtToTER > TER
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
bool isTesSuccess(TER x) 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)
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
@ accepted
Manifest is valid.
T time_since_epoch(T... args)