mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-15 22:38:47 +00:00
공개 키 등록시 인증 절차 추가
This commit is contained in:
@@ -13,14 +13,39 @@ export const createBlobFromKeyPairBase64 = (pubKeyBase64: string, privKeyBase64:
|
||||
return new Blob([`${pubKeyPem}\n${privKeyPem}\n`], { type: "text/plain" });
|
||||
};
|
||||
|
||||
export const requestPubKeyRegistration = async (pubKeyBase64: string) => {
|
||||
const res = await callAPI("/api/key/register", {
|
||||
const decryptChallenge = async (challenge: string, privateKey: CryptoKey) => {
|
||||
const challengeBuffer = Uint8Array.from(atob(challenge), (c) => c.charCodeAt(0));
|
||||
const answer = await window.crypto.subtle.decrypt(
|
||||
{
|
||||
name: "RSA-OAEP",
|
||||
} satisfies RsaOaepParams,
|
||||
privateKey,
|
||||
challengeBuffer,
|
||||
);
|
||||
return btoa(String.fromCharCode(...new Uint8Array(answer)));
|
||||
};
|
||||
|
||||
export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey: CryptoKey) => {
|
||||
let res = await callAPI("/api/key/register", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ pubKey: pubKeyBase64 }),
|
||||
});
|
||||
if (!res.ok) return false;
|
||||
|
||||
const data = await res.json();
|
||||
const challenge = data.challenge as string;
|
||||
const answer = await decryptChallenge(challenge, privateKey);
|
||||
|
||||
res = await callAPI("/api/key/verify", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ answer }),
|
||||
});
|
||||
return res.ok;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user