import { EnclaveMethods, EnclaveMethodParams, EnclaveResponse } from 'shared/enclave/types'; import { PROTOCOL_NAME } from 'shared/enclave/utils'; export function makeRequest(type: EnclaveMethods, params: EnclaveMethodParams): Promise { return fetch(`${PROTOCOL_NAME}://${type}`, { method: 'POST', body: JSON.stringify(params) }) .then(res => res.json()) .then((res: EnclaveResponse) => { const { error, data } = res; if (data) { return data; } throw new Error(error!.message || 'Unknown response from server'); }); }