aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/keyWrapping.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-04-08 22:33:43 -0700
committerAdam Soltys <[email protected]>2026-04-08 22:57:55 -0700
commit757a59c5c9c4b56120446cae1ac495773b9905c8 (patch)
tree58ae7c3e3f11fb32164dae59b6e952e54dc6ac93 /src/lib/keyWrapping.ts
parentc7136dbefa4da50297513955cf51084afa23d98c (diff)
downloadcoinos-ui-staging.tar.gz
coinos-ui-staging.zip
breez style passkey derivationstaging
Diffstat (limited to 'src/lib/keyWrapping.ts')
-rw-r--r--src/lib/keyWrapping.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib/keyWrapping.ts b/src/lib/keyWrapping.ts
index 31cb1e5c..cd68947f 100644
--- a/src/lib/keyWrapping.ts
+++ b/src/lib/keyWrapping.ts
@@ -28,9 +28,20 @@ export async function resolveCanonicalKey(
oldPrfKey: ArrayBuffer,
): Promise<{ canonicalKey: ArrayBuffer; encryptedKeys: Record<string, string> }> {
if (encryptedKeys && encryptedKeys[methodId]) {
- const canonicalKey = await unwrapCanonicalKey(wrappingKey, encryptedKeys[methodId]);
- rememberPrfKey(canonicalKey, defaultRememberForMs);
- return { canonicalKey, encryptedKeys };
+ try {
+ // Try new wrapping key first (e.g. PRF-derived)
+ const canonicalKey = await unwrapCanonicalKey(wrappingKey, encryptedKeys[methodId]);
+ rememberPrfKey(canonicalKey, defaultRememberForMs);
+ return { canonicalKey, encryptedKeys };
+ } catch {
+ // Fallback: try old key (e.g. SHA-256(credentialId)) and re-wrap with new key
+ const canonicalKey = await unwrapCanonicalKey(oldPrfKey, encryptedKeys[methodId]);
+ const wrapped = await wrapCanonicalKey(wrappingKey, canonicalKey);
+ const updated = { ...encryptedKeys, [methodId]: wrapped };
+ await saveEncryptedKeys(updated);
+ rememberPrfKey(canonicalKey, defaultRememberForMs);
+ return { canonicalKey, encryptedKeys: updated };
+ }
}
// Migration: old PRF key becomes canonical key