@iexec/iexec-oracle-factory-wrapper
Version:
A wrapper for creating API based oracles for ethereum on the top of iExec
22 lines • 1.28 kB
JavaScript
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ethers } from 'ethers';
import { sortObjKeys } from './format.js';
import { strictParamSetSchema, strictCallParamsSchema } from './validators.js';
const bytes32Regex = /^(0x)([0-9a-f]{2}){32}$/;
const isOracleId = (oracleId) => typeof oracleId === 'string' && bytes32Regex.test(oracleId);
const formatMap = (obj) => {
const sortedObj = sortObjKeys(obj);
return Object.entries(sortedObj);
};
const computeOracleId = async (paramSet) => {
const { JSONPath, body, dataType, dataset, headers, method, url } = await strictParamSetSchema().validate(paramSet);
const formatedHeaders = formatMap(headers);
return ethers.solidityPackedKeccak256(['string', 'string', 'string', 'address', 'string[][]', 'string', 'string'], [JSONPath, body, dataType, dataset, formatedHeaders, method, url]);
};
const computeCallId = async (callParams) => {
const { body, headers, method, url } = await strictCallParamsSchema().validate(callParams);
const formatedHeaders = formatMap(headers);
return ethers.solidityPackedKeccak256(['string', 'string[][]', 'string', 'string'], [body, formatedHeaders, method, url]);
};
export { isOracleId, computeOracleId, computeCallId };
//# sourceMappingURL=hash.js.map