Verify dAPI sources
Datafeed values are stored on-chain within the Api3ServerV1.sol
contract and are updated on the basis of beaconIds
.
A beaconId
for each dAPI is derived from the hash of the provider's Airnode address and templateId
.
A templateId
is a hash of one of the Airnode's endpointId
and encoded parameters.
The dAPI team is running Airseekers which are primarily responsible for updating the beaconId
based on the specification of the dAPI. Providers also update the beaconId
at a higher deviation threshold/heartbeat as a fallback.
To verify that the Airnode address of a beaconId
belongs to the provider listed in the market, refer to the Verify Airnode Addresses section.
Verifying beaconId
The templateId
is calculated by taking the hash of the encodedParameters
and endpointId
.
Following is an ethers.js
v5 script to derive the templateId
(you need @airnode-abi
installed):
import { encode } from '@api3/airnode-abi';
import { ethers } from 'ethers';
const encodedParameters = encode(decodedParameters);
const templateId = ethers.utils.solidityKeccak256(
['bytes32', 'bytes'],
[endpointId, encodedParameters]
);
2
3
4
5
6
7
8
Once derived the beaconId
is the hash of the Airnode address and templateId
:
import { ethers } from 'ethers';
const beaconId = ethers.utils.solidityKeccak256(
['address', 'bytes32'],
[AirnodeAddress, templateId]
);
2
3
4
5
6
Verifying beaconSetId
Beacon sets are a collection of beaconIds
that provide the aggregated median value of the underlying beaconIds
. The beaconSetId
is a hash of all the underlying beaconIds
and points to the datafeed containing the median value. Following is an ethers.js v5 script to derive the beaconSetId
.
import { ethers } from 'ethers';
const beacons = [beaconId1, beaconId2, beaconId3];
const sortedBeacons = beacons.sort();
const beaconSetId = ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(['bytes32[]'], [sortedBeacons])
);
2
3
4
5
6
7
8