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