From 48e8acbe32e556b3766a40d808967459e3d0da6b Mon Sep 17 00:00:00 2001 From: LC mac Date: Wed, 4 Feb 2026 13:10:12 +0800 Subject: [PATCH] fix(blender): improve QR content detection Fixes a bug where plain text mnemonics and Krux QR codes were being misidentified as encrypted SeedPGP frames. - The `detectEncryptionMode` function has been rewritten to be stricter and now correctly identifies 'text' as a type. - It no longer defaults to 'pgp', which was causing plain text to be treated as an encrypted format. - The `EncryptionMode` type in `types.ts` has been updated to include 'text'. - This resolves issues where the UI would incorrectly ask for a password for plain text mnemonics and use the wrong decryption logic for Krux QRs. --- src/lib/seedpgp.ts | 34 ++++++++++++++-------------------- src/lib/types.ts | 2 +- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/lib/seedpgp.ts b/src/lib/seedpgp.ts index ef65784..d2034ce 100644 --- a/src/lib/seedpgp.ts +++ b/src/lib/seedpgp.ts @@ -308,29 +308,23 @@ export async function decryptFromSeed(params: DecryptionParams): Promise= 5) { - const lenId = bytes[0]; - if (lenId > 0 && lenId <= 252 && 1 + lenId + 4 <= bytes.length) { - return 'krux'; - } - } - } catch { - // Not valid KEF, fall through - } + + // 2. Check for Krux KEF format (hex, optional KEF: prefix) + const cleanedHex = trimmed.replace(/\s/g, '').replace(/^KEF:/i, ''); + if (/^[0-9a-fA-F]+$/.test(cleanedHex) && cleanedHex.length > 10) { // check for hex and minimum length + return 'krux'; + } + + // 3. If it contains spaces, it's almost certainly a plain text mnemonic + if (trimmed.includes(' ')) { + return 'text'; } - // Default to PGP for backward compatibility - return 'pgp'; + // 4. Default to text for anything else. The component validation will handle it. + return 'text'; } diff --git a/src/lib/types.ts b/src/lib/types.ts index d725c90..dd5ad60 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -20,7 +20,7 @@ export type KruxEncryptionParams = { version?: number; }; -export type EncryptionMode = 'pgp' | 'krux'; +export type EncryptionMode = 'pgp' | 'krux' | 'text'; export type EncryptionParams = { plaintext: SeedPgpPlaintext | string;