feat: implement master key derivation and persistence via IndexedDB

This commit is contained in:
Your Name
2026-04-12 01:24:28 +05:30
parent 9b9f1110ca
commit 7736fa5919
6 changed files with 267 additions and 221 deletions
+17
View File
@@ -0,0 +1,17 @@
import { openDB } from "idb";
// we use this to store master key in browser - secure and good UX
const db = openDB("piku-keys", 1, {
upgrade(db) {
db.createObjectStore("master-key");
},
});
export const saveMasterKey = async (key: CryptoKey) =>
(await db).put("master-key", key, "masterKey");
export const loadMasterKey = async (): Promise<CryptoKey | null> =>
(await db).get("master-key", "masterKey") ?? null;
export const clearMasterKey = async () =>
(await db).delete("master-key", "masterKey");