1
0
Fork 0
VaultUI/src/api/transit/transitEncrypt.ts

35 lines
775 B
TypeScript
Raw Normal View History

import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
2021-05-09 11:18:18 +01:00
import { removeDoubleSlash } from "../../utils";
2021-05-07 11:53:26 +01:00
2021-05-08 00:21:58 +01:00
type EncryptionResult = {
ciphertext: string;
};
2021-05-07 11:53:26 +01:00
type EncryptionPayload = {
plaintext: string;
};
2021-05-08 00:21:58 +01:00
export async function transitEncrypt(
baseMount: string,
name: string,
payload: EncryptionPayload,
2021-05-08 00:21:58 +01:00
): Promise<EncryptionResult> {
2021-05-07 11:53:26 +01:00
const request = new Request(appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/encrypt/${name}`)), {
method: "POST",
2021-05-07 11:53:26 +01:00
headers: {
"Content-Type": "application/json",
2021-05-07 11:53:26 +01:00
...getHeaders(),
},
body: JSON.stringify(payload),
2021-05-07 11:53:26 +01:00
});
2021-05-10 11:35:14 +01:00
const resp = await fetch(request);
await checkResponse(resp);
const data = (await resp.json()) as {
data?: EncryptionResult;
};
return data.data;
2021-05-07 11:53:26 +01:00
}