/
AuthorizationUtilsV0.sol
87 lines (84 loc) · 3.35 KB
/
AuthorizationUtilsV0.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./interfaces/IAuthorizationUtilsV0.sol";
import "../authorizers/interfaces/IAuthorizerV0.sol";
/// @title Contract that implements authorization checks
contract AuthorizationUtilsV0 is IAuthorizationUtilsV0 {
/// @notice Uses the authorizer contracts of an Airnode to decide if a
/// request is authorized. Once an Airnode receives a request, it calls
/// this method to determine if it should respond. Similarly, third parties
/// can use this method to determine if a particular request would be
/// authorized.
/// @dev This method is meant to be called off-chain, statically by the
/// Airnode to decide if it should respond to a request. The requester can
/// also call it, yet this function returning true should not be taken as a
/// guarantee of the subsequent request being fulfilled.
/// It is enough for only one of the authorizer contracts to return true
/// for the request to be authorized.
/// @param authorizers Authorizer contract addresses
/// @param airnode Airnode address
/// @param requestId Request ID
/// @param endpointId Endpoint ID
/// @param sponsor Sponsor address
/// @param requester Requester address
/// @return status Authorization status of the request
function checkAuthorizationStatus(
address[] calldata authorizers,
address airnode,
bytes32 requestId,
bytes32 endpointId,
address sponsor,
address requester
) public view override returns (bool status) {
for (uint256 ind = 0; ind < authorizers.length; ind++) {
IAuthorizerV0 authorizer = IAuthorizerV0(authorizers[ind]);
if (
authorizer.isAuthorizedV0(
requestId,
airnode,
endpointId,
sponsor,
requester
)
) {
return true;
}
}
return false;
}
/// @notice A convenience function to make multiple authorization status
/// checks with a single call
/// @param authorizers Authorizer contract addresses
/// @param airnode Airnode address
/// @param requestIds Request IDs
/// @param endpointIds Endpoint IDs
/// @param sponsors Sponsor addresses
/// @param requesters Requester addresses
/// @return statuses Authorization statuses of the request
function checkAuthorizationStatuses(
address[] calldata authorizers,
address airnode,
bytes32[] calldata requestIds,
bytes32[] calldata endpointIds,
address[] calldata sponsors,
address[] calldata requesters
) external view override returns (bool[] memory statuses) {
require(
requestIds.length == endpointIds.length &&
requestIds.length == sponsors.length &&
requestIds.length == requesters.length,
"Unequal parameter lengths"
);
statuses = new bool[](requestIds.length);
for (uint256 ind = 0; ind < requestIds.length; ind++) {
statuses[ind] = checkAuthorizationStatus(
authorizers,
airnode,
requestIds[ind],
endpointIds[ind],
sponsors[ind],
requesters[ind]
);
}
}
}