Skip to content

Commit

Permalink
Implement RequesterAuthorizerWithErc721 authorizers (#1670)
Browse files Browse the repository at this point in the history
* Implement RequesterAuthorizerWithErc721 authorizers

* Fix authorizers empty arrays behavior

Previously requesterEndpointAuthorizers being empty would result in all
requests being authorized, independent of whether the other authorizer
arrays were nonempty

* Add INFO log for all authorizer arrays being empty

---------

Co-authored-by: Emanuel Tesar <[email protected]>
  • Loading branch information
dcroote and Siegrift authored Mar 17, 2023
1 parent e1746a1 commit 1b486bb
Show file tree
Hide file tree
Showing 63 changed files with 1,654 additions and 152 deletions.
7 changes: 7 additions & 0 deletions .changeset/tiny-pumpkins-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@api3/airnode-node': minor
'@api3/airnode-protocol': minor
'@api3/airnode-validator': minor
---

Implement RequesterAuthorizerWithErc721 authorizers
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ config.json

# !!! Temporary until the proper formatting is sorted out !!!
# https://github.com/api3dao/airnode/issues/1660
packages/airnode-protocol/contracts
packages/airnode-protocol/contracts
Binary file added .swp
Binary file not shown.
4 changes: 3 additions & 1 deletion packages/airnode-deployer/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"url": "${CROSS_CHAIN_PROVIDER_URL}"
}
}
]
],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
},
},
],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
4 changes: 3 additions & 1 deletion packages/airnode-node/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"maxConcurrency": 100,
"authorizers": {
"requesterEndpointAuthorizers": [],
"crossChainRequesterAuthorizers": []
"crossChainRequesterAuthorizers": [],
"requesterAuthorizersWithErc721": [],
"crossChainRequesterAuthorizersWithErc721": []
},
"authorizations": {
"requesterEndpointAuthorizations": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const createChainConfig = (overrides: Partial<ChainConfig>): ChainConfig => {
authorizers: {
requesterEndpointAuthorizers: [],
crossChainRequesterAuthorizers: [],
requesterAuthorizersWithErc721: [],
crossChainRequesterAuthorizersWithErc721: [],
},
authorizations: {
requesterEndpointAuthorizations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ describe('mergeAuthorizations', () => {
const apiCall = fixtures.requests.buildApiCall({ id: '0xapiCallId' });
const authorizationByRequestId = { '0xapiCallId': true };
const [logs, res] = authorization.mergeAuthorizations([apiCall], authorizationByRequestId);
expect(logs).toEqual([]);
expect(logs).toEqual([
{
level: 'DEBUG',
message: 'Requester:requesterAddress is authorized to access Endpoint ID:endpointId for Request ID:0xapiCallId',
},
]);
expect(res).toEqual([apiCall]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ function applyAuthorization(
}

if (authorized) {
return { ...acc, requests: [...acc.requests, apiCall] };
const log = logger.pend(
'DEBUG',
`Requester:${apiCall.requesterAddress} is authorized to access Endpoint ID:${apiCall.endpointId} for Request ID:${apiCall.id}`
);
return { ...acc, logs: [...acc.logs, log], requests: [...acc.requests, apiCall] };
}

// If the request is unauthorized, update drop the request
Expand Down
Loading

0 comments on commit 1b486bb

Please sign in to comment.