robosats/mobile/services/Tor/index.ts
2024-10-19 15:33:55 +02:00

58 lines
1.5 KiB
TypeScript

import TorModule from '../../native/TorModule';
class TorClient {
public get: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
baseUrl,
path,
headers,
) => {
return await new Promise<object>((resolve, reject) => {
try {
TorModule.sendRequest('GET', `${baseUrl}${path}`, JSON.stringify(headers), '{}').then(
(response) => {
resolve(JSON.parse(response));
},
);
} catch (error) {
reject(error);
}
});
};
public delete: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
baseUrl,
path,
headers,
) => {
return await new Promise<object>((resolve, reject) => {
try {
TorModule.sendRequest('DELETE', `${baseUrl}${path}`, JSON.stringify(headers), '{}').then(
(response) => {
resolve(JSON.parse(response));
},
);
} catch (error) {
reject(error);
}
});
};
public post: (baseUrl: string, path: string, body: object, headers: object) => Promise<object> =
async (baseUrl, path, body, headers) => {
return await new Promise<object>((resolve, reject) => {
try {
const json = JSON.stringify(body);
TorModule.sendRequest('POST', `${baseUrl}${path}`, JSON.stringify(headers), json).then(
(response) => {
resolve(JSON.parse(response));
},
);
} catch (error) {
reject(error);
}
});
};
}
export default TorClient;