/api/client/[id]/key Endpoint 삭제 및 프론트엔드와의 Zod 스키마 공유 구현

This commit is contained in:
static
2025-01-02 04:44:02 +09:00
parent 45df24b416
commit b07d67b958
27 changed files with 241 additions and 169 deletions

View File

@@ -1,6 +1,7 @@
import { callAPI } from "$lib/hooks";
import { callSignedPostApi } from "$lib/hooks";
import { storeClientKey } from "$lib/indexedDB";
import { encodeToBase64, signRequest, signMasterKeyWrapped } from "$lib/modules/crypto";
import { encodeToBase64, signMasterKeyWrapped } from "$lib/modules/crypto";
import type { InitialMasterKeyRegisterRequest } from "$lib/server/schemas";
import type { ClientKeys } from "$lib/stores";
export { requestTokenUpgrade } from "$lib/services/auth";
@@ -45,18 +46,13 @@ export const requestInitialMasterKeyRegistration = async (
masterKeyWrapped: ArrayBuffer,
signKey: CryptoKey,
) => {
const res = await callAPI("/api/mek/register/initial", {
method: "POST",
headers: {
"Content-Type": "application/json",
const res = await callSignedPostApi<InitialMasterKeyRegisterRequest>(
"/api/mek/register/initial",
{
mek: encodeToBase64(masterKeyWrapped),
mekSig: await signMasterKeyWrapped(1, masterKeyWrapped, signKey),
},
body: await signRequest(
{
mek: encodeToBase64(masterKeyWrapped),
mekSig: await signMasterKeyWrapped(1, masterKeyWrapped, signKey),
},
signKey,
),
});
signKey,
);
return res.ok || res.status === 409;
};