rippled
Loading...
Searching...
No Matches
CredentialHelpers.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_APP_MISC_CREDENTIALHELPERS_H_INCLUDED
21#define RIPPLE_APP_MISC_CREDENTIALHELPERS_H_INCLUDED
22
23#include <xrpl/basics/Log.h>
24#include <xrpl/basics/base_uint.h>
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/ledger/ApplyView.h>
27#include <xrpl/ledger/ReadView.h>
28#include <xrpl/protocol/AccountID.h>
29#include <xrpl/protocol/STArray.h>
30#include <xrpl/protocol/STTx.h>
31#include <xrpl/protocol/TER.h>
32
33namespace ripple {
34namespace credentials {
35
36// These function will be used by the code that use DepositPreauth / Credentials
37// (and any future preauthorization modes) as part of authorization (all the
38// transfer funds transactions)
39
40// Check if credential sfExpiration field has passed ledger's parentCloseTime
41bool
43 std::shared_ptr<SLE const> const& sleCredential,
44 NetClock::time_point const& closed);
45
46// Return true if any expired credential was found in arr (and deleted)
47bool
48removeExpired(ApplyView& view, STVector256 const& arr, beast::Journal const j);
49
50// Actually remove a credentials object from the ledger
51TER
53 ApplyView& view,
54 std::shared_ptr<SLE> const& sleCredential,
56
57// Amendment and parameters checks for sfCredentialIDs field
59checkFields(STTx const& tx, beast::Journal j);
60
61// Accessing the ledger to check if provided credentials are valid. Do not use
62// in doApply (only in preclaim) since it does not remove expired credentials.
63// If you call it in prelaim, you also must call verifyDepositPreauth in doApply
64TER
65valid(
66 STTx const& tx,
67 ReadView const& view,
68 AccountID const& src,
70
71// Check if subject has any credential maching the given domain. If you call it
72// in preclaim and it returns tecEXPIRED, you should call verifyValidDomain in
73// doApply. This will ensure that expired credentials are deleted.
74TER
75validDomain(ReadView const& view, uint256 domainID, AccountID const& subject);
76
77// This function is only called when we about to return tecNO_PERMISSION
78// because all the checks for the DepositPreauth authorization failed.
79TER
81 ApplyView const& view,
82 STVector256 const& ctx,
83 AccountID const& dst);
84
85// Sort credentials array, return empty set if there are duplicates
87makeSorted(STArray const& credentials);
88
89// Check credentials array passed to DepositPreauth/PermissionedDomainSet
90// transactions
92checkArray(STArray const& credentials, unsigned maxSize, beast::Journal j);
93
94} // namespace credentials
95
96// Check expired credentials and for credentials maching DomainID of the ledger
97// object
98TER
100 ApplyView& view,
101 AccountID const& account,
102 uint256 domainID,
104
105// Check expired credentials and for existing DepositPreauth ledger object
106TER
108 STTx const& tx,
109 ApplyView& view,
110 AccountID const& src,
111 AccountID const& dst,
112 std::shared_ptr<SLE> const& sleDst,
114
115} // namespace ripple
116
117#endif
A generic endpoint for log messages.
Definition Journal.h:60
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:143
A view into a ledger.
Definition ReadView.h:51
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)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)