20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/ledger/View.h>
23#include <xrpl/protocol/TER.h>
24#include <xrpl/protocol/digest.h>
29namespace credentials {
36 std::uint32_t const exp = (*sleCredential)[~sfExpiration].value_or(
46 bool foundExpired =
false;
48 for (
auto const& h : arr)
52 auto const sleCred = view.
peek(k);
57 <<
"Credentials are expired. Cred: " << sleCred->getText();
77 [&view, &sleCredential, j](
82 JLOG(j.
fatal()) <<
"Internal error: can't retrieve Owner account.";
91 JLOG(j.
fatal()) <<
"Unable to delete Credential from owner.";
101 auto const issuer = sleCredential->getAccountID(sfIssuer);
102 auto const subject = sleCredential->getAccountID(sfSubject);
105 auto err = delSLE(issuer, sfIssuerNode, !
accepted || (subject == issuer));
109 if (subject != issuer)
111 err = delSLE(subject, sfSubjectNode,
accepted);
117 view.
erase(sleCredential);
132 <<
"Malformed transaction: Credentials array size is invalid: "
133 << credentials.size();
138 for (
auto const& cred : credentials)
140 auto [it, ins] = duplicates.
insert(cred);
144 <<
"Malformed transaction: duplicates in credentials.";
159 for (
auto const& h : credIDs)
164 JLOG(ctx.
j.
trace()) <<
"Credential doesn't exist. Cred: " << h;
168 if (sleCred->getAccountID(sfSubject) != src)
171 <<
"Credential doesn't belong to the source account. Cred: "
178 JLOG(ctx.
j.
trace()) <<
"Credential isn't accepted. Cred: " << h;
197 bool foundExpired =
false;
198 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
200 auto const issuer = h.getAccountID(sfIssuer);
201 auto const type = h.getFieldVL(sfCredentialType);
202 auto const keyletCredential =
204 auto const sleCredential = view.
read(keyletCredential);
237 for (
auto const& h : credIDs)
244 sorted.
emplace((*sleCred)[sfIssuer], (*sleCred)[sfCredentialType]);
247 lifeExtender.
push_back(std::move(sleCred));
260 for (
auto const& cred : credentials)
262 auto [it, ins] =
out.emplace(cred[sfIssuer], cred[sfCredentialType]);
272 if (credentials.
empty() || (credentials.
size() > maxSize))
274 JLOG(j.
trace()) <<
"Malformed transaction: "
275 "Invalid credentials size: "
276 << credentials.
size();
286 JLOG(j.
trace()) <<
"Malformed transaction: "
287 "Issuer account is invalid: "
295 JLOG(j.
trace()) <<
"Malformed transaction: "
296 "Invalid credentialType size: "
304 JLOG(j.
trace()) <<
"Malformed transaction: "
305 "duplicates in credenentials.";
329 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
331 auto const issuer = h.getAccountID(sfIssuer);
332 auto const type = h.getFieldVL(sfCredentialType);
333 auto const keyletCredential =
335 if (view.
exists(keyletCredential))
336 credentials.
push_back(keyletCredential.key);
342 for (
auto const& h : credentials)
370 if (credentialsPresent &&
380 return !credentialsPresent
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
State information when applying a tx.
beast::Journal const journal
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 std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
bool isFieldPresent(SField const &field) const
STVector256 const & getFieldV256(SField const &field) const
void push_back(uint256 const &v)
NotTEC checkFields(PreflightContext const &ctx)
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
bool removeExpired(ApplyView &view, STVector256 const &arr, beast::Journal const j)
TER validDomain(ReadView const &view, uint256 domainID, AccountID const &subject)
TER valid(PreclaimContext const &ctx, AccountID const &src)
TER authorizedDepositPreauth(ApplyView const &view, STVector256 const &credIDs, AccountID const &dst)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
bool checkExpired(std::shared_ptr< SLE const > const &sleCredential, NetClock::time_point const &closed)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
@ accepted
Manifest is valid.
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
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)
TER verifyDepositPreauth(ApplyContext &ctx, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst)
bool isTesSuccess(TER x) noexcept
std::string to_string(base_uint< Bits, Tag > const &a)
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
@ credential
Credentials signature.
TERSubset< CanCvtToTER > TER
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.
T time_since_epoch(T... args)