diff options
| author | Adam Soltys <[email protected]> | 2026-02-27 14:46:27 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-27 14:46:27 -0800 |
| commit | 8ffcf769052461e03a2c69220392cb37a623f3f4 (patch) | |
| tree | 5b0b16269a729fbe9db44c65b3a0da3d95c11b78 /src/routes/(app)/settings/+layout.svelte | |
| parent | 6ba952f16fc60fc56f0834e5b1d08671885618c5 (diff) | |
| download | coinos-ui-8ffcf769052461e03a2c69220392cb37a623f3f4.tar.gz coinos-ui-8ffcf769052461e03a2c69220392cb37a623f3f4.zip | |
2 step register
Diffstat (limited to 'src/routes/(app)/settings/+layout.svelte')
| -rw-r--r-- | src/routes/(app)/settings/+layout.svelte | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/routes/(app)/settings/+layout.svelte b/src/routes/(app)/settings/+layout.svelte index ce45f915..99bdc4ce 100644 --- a/src/routes/(app)/settings/+layout.svelte +++ b/src/routes/(app)/settings/+layout.svelte @@ -13,6 +13,8 @@ import { sign, send, getPrivateKey } from "$lib/nostr"; import { invalidateAll } from "$app/navigation"; import { bytesToHex } from "@noble/hashes/utils.js"; + import { getCachedPrfKey } from "$lib/passwordCache"; + import { wrapCanonicalKey, saveEncryptedKeys, passwordMethodId } from "$lib/keyWrapping"; import { SimplePool } from "nostr-tools/pool"; import { finalizeEvent } from "nostr-tools/pure"; @@ -201,14 +203,21 @@ } } - // If password is changing, derive new authPubkey + // If password is changing, derive new authPubkey and re-wrap canonical key const pw = body.get("password") as string; const un = (body.get("username") as string) || user.username; + let pendingEncryptedKeys: Record<string, string> | null = null; if (pw && pw === body.get("confirm")) { try { const { deriveAuthKeypair } = await import("$lib/deriveAuthKey"); - const { pubkey: authPubkey } = await deriveAuthKeypair(un, pw); + const { sk, pubkey: authPubkey } = await deriveAuthKeypair(un, pw); body.set("authPubkey", authPubkey); + + const canonicalKey = getCachedPrfKey(); + if (canonicalKey) { + const wrapped = await wrapCanonicalKey(sk.buffer as ArrayBuffer, canonicalKey); + pendingEncryptedKeys = { ...(user.encryptedKeys || {}), [passwordMethodId()]: wrapped }; + } } catch (e) { console.log("Failed to derive authPubkey for password change", e); } @@ -222,6 +231,13 @@ const result = deserialize(await response.text()); if (result.type === "success") { + if (pendingEncryptedKeys) { + try { + await saveEncryptedKeys(pendingEncryptedKeys); + } catch (e) { + console.log("Failed to save re-wrapped encryptedKeys", e); + } + } await invalidateAll(); if (pw) $password = pw; } |
