mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
프론트엔드에서의 암호 키 관련된 변수 이름 리팩토링
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import { TitleDiv, BottomDiv } from "$lib/components/divs";
|
||||
import { TextInput } from "$lib/components/inputs";
|
||||
import { refreshToken } from "$lib/hooks/callAPI";
|
||||
import { keyPairsStore } from "$lib/stores";
|
||||
import { clientKeyStore } from "$lib/stores";
|
||||
import { requestLogin, requestTokenUpgrade } from "./service";
|
||||
|
||||
let { data } = $props();
|
||||
@@ -19,14 +19,11 @@
|
||||
try {
|
||||
if (!(await requestLogin(email, password))) throw new Error("Failed to login");
|
||||
|
||||
if (
|
||||
$keyPairsStore &&
|
||||
!(await requestTokenUpgrade($keyPairsStore.encKeyPair, $keyPairsStore.sigKeyPair))
|
||||
)
|
||||
if ($clientKeyStore && !(await requestTokenUpgrade($clientKeyStore)))
|
||||
throw new Error("Failed to upgrade token");
|
||||
|
||||
await goto(
|
||||
$keyPairsStore
|
||||
$clientKeyStore
|
||||
? data.redirectPath
|
||||
: "/key/generate?redirect=" + encodeURIComponent(data.redirectPath),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { exportRSAKeyToBase64 } from "$lib/modules/crypto";
|
||||
import { requestTokenUpgrade as requestTokenUpgradeInternal } from "$lib/services/auth";
|
||||
import { requestClientRegistration } from "$lib/services/key";
|
||||
import type { ClientKeys } from "$lib/stores";
|
||||
|
||||
export const requestLogin = async (email: string, password: string) => {
|
||||
const res = await fetch("/api/auth/login", {
|
||||
@@ -13,33 +14,24 @@ export const requestLogin = async (email: string, password: string) => {
|
||||
return res.ok;
|
||||
};
|
||||
|
||||
export const requestTokenUpgrade = async (encKeyPair: CryptoKeyPair, sigKeyPair: CryptoKeyPair) => {
|
||||
const encPubKeyBase64 = await exportRSAKeyToBase64(encKeyPair.publicKey, "public");
|
||||
const sigPubKeyBase64 = await exportRSAKeyToBase64(sigKeyPair.publicKey, "public");
|
||||
if (
|
||||
await requestTokenUpgradeInternal(
|
||||
encPubKeyBase64,
|
||||
encKeyPair.privateKey,
|
||||
sigPubKeyBase64,
|
||||
sigKeyPair.privateKey,
|
||||
)
|
||||
) {
|
||||
export const requestTokenUpgrade = async ({
|
||||
encryptKey,
|
||||
decryptKey,
|
||||
signKey,
|
||||
verifyKey,
|
||||
}: ClientKeys) => {
|
||||
const encryptKeyBase64 = await exportRSAKeyToBase64(encryptKey, "public");
|
||||
const verifyKeyBase64 = await exportRSAKeyToBase64(verifyKey, "public");
|
||||
if (await requestTokenUpgradeInternal(encryptKeyBase64, decryptKey, verifyKeyBase64, signKey)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
await requestClientRegistration(
|
||||
encPubKeyBase64,
|
||||
encKeyPair.privateKey,
|
||||
sigPubKeyBase64,
|
||||
sigKeyPair.privateKey,
|
||||
)
|
||||
) {
|
||||
if (await requestClientRegistration(encryptKeyBase64, decryptKey, verifyKeyBase64, signKey)) {
|
||||
return await requestTokenUpgradeInternal(
|
||||
encPubKeyBase64,
|
||||
encKeyPair.privateKey,
|
||||
sigPubKeyBase64,
|
||||
sigKeyPair.privateKey,
|
||||
encryptKeyBase64,
|
||||
decryptKey,
|
||||
verifyKeyBase64,
|
||||
signKey,
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user