사소한 리팩토링 2

This commit is contained in:
static
2026-01-11 15:54:05 +09:00
parent 83369f83e3
commit 80368c3a29
3 changed files with 46 additions and 112 deletions

View File

@@ -5,16 +5,6 @@ export const digestMessage = async (message: BufferSource) => {
return await crypto.subtle.digest("SHA-256", message);
};
export const createStreamingHmac = async (hmacSecret: CryptoKey) => {
const keyBytes = new Uint8Array(await crypto.subtle.exportKey("raw", hmacSecret));
const h = hmac.create(sha256, keyBytes);
return {
update: (data: Uint8Array) => h.update(data),
digest: () => h.digest(),
};
};
export const generateHmacSecret = async () => {
return {
hmacSecret: await crypto.subtle.generateKey(
@@ -28,6 +18,10 @@ export const generateHmacSecret = async () => {
};
};
export const signMessageHmac = async (message: BufferSource, hmacSecret: CryptoKey) => {
return await crypto.subtle.sign("HMAC", hmacSecret, message);
export const createHmacStream = async (hmacSecret: CryptoKey) => {
const h = hmac.create(sha256, new Uint8Array(await crypto.subtle.exportKey("raw", hmacSecret)));
return {
update: (data: Uint8Array) => h.update(data),
digest: () => h.digest(),
};
};