20#include <xrpl/ledger/CredentialHelpers.h>
21#include <xrpl/ledger/View.h>
22#include <xrpl/protocol/TER.h>
23#include <xrpl/protocol/digest.h>
28namespace credentials {
35 std::uint32_t const exp = (*sleCredential)[~sfExpiration].value_or(
45 bool foundExpired =
false;
47 for (
auto const& h : arr)
51 auto const sleCred = view.
peek(k);
56 <<
"Credentials are expired. Cred: " << sleCred->getText();
76 [&view, &sleCredential, j](
81 JLOG(j.
fatal()) <<
"Internal error: can't retrieve Owner account.";
90 JLOG(j.
fatal()) <<
"Unable to delete Credential from owner.";
100 auto const issuer = sleCredential->getAccountID(sfIssuer);
101 auto const subject = sleCredential->getAccountID(sfSubject);
104 auto err = delSLE(issuer, sfIssuerNode, !
accepted || (subject == issuer));
108 if (subject != issuer)
110 err = delSLE(subject, sfSubjectNode,
accepted);
116 view.
erase(sleCredential);
127 auto const& credentials = tx.
getFieldV256(sfCredentialIDs);
131 <<
"Malformed transaction: Credentials array size is invalid: "
132 << credentials.size();
137 for (
auto const& cred : credentials)
139 auto [it, ins] = duplicates.
insert(cred);
143 <<
"Malformed transaction: duplicates in credentials.";
162 for (
auto const& h : credIDs)
167 JLOG(j.
trace()) <<
"Credential doesn't exist. Cred: " << h;
171 if (sleCred->getAccountID(sfSubject) != src)
174 <<
"Credential doesn't belong to the source account. Cred: "
181 JLOG(j.
trace()) <<
"Credential isn't accepted. Cred: " << h;
200 bool foundExpired =
false;
201 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
203 auto const issuer = h.getAccountID(sfIssuer);
204 auto const type = h.getFieldVL(sfCredentialType);
205 auto const keyletCredential =
207 auto const sleCredential = view.
read(keyletCredential);
240 for (
auto const& h : credIDs)
247 sorted.
emplace((*sleCred)[sfIssuer], (*sleCred)[sfCredentialType]);
250 lifeExtender.
push_back(std::move(sleCred));
263 for (
auto const& cred : credentials)
265 auto [it, ins] =
out.
emplace(cred[sfIssuer], cred[sfCredentialType]);
275 if (credentials.
empty() || (credentials.
size() > maxSize))
277 JLOG(j.
trace()) <<
"Malformed transaction: "
278 "Invalid credentials size: "
279 << credentials.
size();
289 JLOG(j.
trace()) <<
"Malformed transaction: "
290 "Issuer account is invalid: "
298 JLOG(j.
trace()) <<
"Malformed transaction: "
299 "Invalid credentialType size: "
307 JLOG(j.
trace()) <<
"Malformed transaction: "
308 "duplicates in credenentials.";
332 for (
auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
334 auto const issuer = h.getAccountID(sfIssuer);
335 auto const type = h.getFieldVL(sfCredentialType);
336 auto const keyletCredential =
338 if (view.
exists(keyletCredential))
339 credentials.
push_back(keyletCredential.key);
343 for (
auto const& h : credentials)
371 bool const credentialsPresent = tx.
isFieldPresent(sfCredentialIDs);
373 if (credentialsPresent &&
382 return !credentialsPresent
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 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(STTx const &tx, beast::Journal j)
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(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
bool checkExpired(std::shared_ptr< SLE const > const &sleCredential, NetClock::time_point const &closed)
TER authorizedDepositPreauth(ApplyView const &view, STVector256 const &ctx, AccountID const &dst)
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.
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
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)
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.
T time_since_epoch(T... args)