키 관리 로직을 Keyring으로 통합하여 하드코딩된 MEK 및 HSK 버전을 제거하고 Svelte Store를 Rune으로 대체

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
staticandClaude Opus 5.5 committed 2026-10-12 00:10:37 +09:00
1 parent aee87fd9b6
commit 2ce73aa331
50 files changed
+633 -641

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { keyring } from "#lib/client/keys/keyring.svelte.js";
import type { MasterKey } from "#lib/client/keys/types.js";
vi.mock("#lib/client/storage/indexedDB/index.js", () => ({
getClientKey: vi.fn(async () => null),
getMasterKeys: vi.fn(async () => []),
getHmacSecrets: vi.fn(async () => []),
storeClientKey: vi.fn(async () => {}),
storeMasterKeys: vi.fn(async () => {}),
storeHmacSecrets: vi.fn(async () => {}),
}));
const key = {} as CryptoKey;
const masterKey = (version: number, state: MasterKey["state"]): MasterKey => ({
version,
state,
key,
});
beforeEach(async () => {
await keyring.setMasterKeys([]);
await keyring.setHmacSecrets([]);
});
describe("Keyring", () => {
it("uses the latest active master key for new data", async () => {
await keyring.setMasterKeys([
masterKey(1, "retired"),
masterKey(3, "active"),
masterKey(2, "active"),
]);
expect(keyring.hasMasterKeys).toBe(true);
expect(keyring.activeMasterKey.version).toBe(3);
});
it("finds master keys by version", async () => {
await keyring.setMasterKeys([masterKey(1, "retired"), masterKey(2, "active")]);
expect(keyring.getMasterKey(1).state).toBe("retired");
expect(() => keyring.getMasterKey(3)).toThrow("not found");
});
it("throws if there is no active key", async () => {
await keyring.setMasterKeys([masterKey(1, "retired")]);
expect(() => keyring.activeMasterKey).toThrow("Active master key not found");
expect(() => keyring.activeHmacSecret).toThrow("Active HMAC secret not found");
});
it("requires client keys", () => {
expect(() => keyring.requireClientKeys()).toThrow("Client keys not found");
});
});