2023-02-23 12:38:09 +01:00
|
|
|
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
2023-01-23 15:32:01 +01:00
|
|
|
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
|
|
|
|
2023-02-23 12:38:09 +01:00
|
|
|
const fetchWithTimeout = getFetchWithTimeout();
|
|
|
|
|
2023-01-23 15:32:01 +01:00
|
|
|
export async function securityProviderCheck(
|
|
|
|
requestData,
|
|
|
|
methodName,
|
|
|
|
chainId,
|
|
|
|
currentLocale,
|
|
|
|
) {
|
|
|
|
let dataToValidate;
|
|
|
|
|
|
|
|
if (methodName === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
|
|
|
|
dataToValidate = {
|
|
|
|
host_name: requestData.msgParams.origin,
|
|
|
|
rpc_method_name: methodName,
|
|
|
|
chain_id: chainId,
|
|
|
|
data: requestData.msgParams.data,
|
|
|
|
currentLocale,
|
|
|
|
};
|
|
|
|
} else if (
|
|
|
|
methodName === MESSAGE_TYPE.ETH_SIGN ||
|
|
|
|
methodName === MESSAGE_TYPE.PERSONAL_SIGN
|
|
|
|
) {
|
|
|
|
dataToValidate = {
|
|
|
|
host_name: requestData.msgParams.origin,
|
|
|
|
rpc_method_name: methodName,
|
|
|
|
chain_id: chainId,
|
|
|
|
data: {
|
|
|
|
signer_address: requestData.msgParams.from,
|
|
|
|
msg_to_sign: requestData.msgParams.data,
|
|
|
|
},
|
|
|
|
currentLocale,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
dataToValidate = {
|
|
|
|
host_name: requestData.origin,
|
|
|
|
rpc_method_name: methodName,
|
|
|
|
chain_id: chainId,
|
|
|
|
data: {
|
2023-03-23 18:01:51 +01:00
|
|
|
from_address: requestData?.txParams?.from,
|
|
|
|
to_address: requestData?.txParams?.to,
|
|
|
|
gas: requestData?.txParams?.gas,
|
|
|
|
gasPrice: requestData?.txParams?.gasPrice,
|
|
|
|
value: requestData?.txParams?.value,
|
|
|
|
data: requestData?.txParams?.data,
|
2023-01-23 15:32:01 +01:00
|
|
|
},
|
|
|
|
currentLocale,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-23 12:38:09 +01:00
|
|
|
const response = await fetchWithTimeout(
|
2023-03-30 22:03:35 +02:00
|
|
|
'https://proxy.metafi.codefi.network/opensea/security/v1/validate',
|
2023-01-23 15:32:01 +01:00
|
|
|
{
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify(dataToValidate),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
return await response.json();
|
|
|
|
}
|