Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RequesterAuthorizerWithErc721 authorizers #1670

Merged
merged 15 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be nice debug level info which requester authorized the given call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We previously had no logging when a request was authorized, so even this is an upgrade 😅. I looked into adding the originating authorizer to the log, but that is not trivial to do based on how authorization fetching currently occurs. I think it's doable, but outside the scope of this PR. Happy to open a separate issue though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I feel you. We can open an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
]);
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