mirror of
https://github.com/kccleoc/seedpgp-web.git
synced 2026-03-07 09:57:50 +08:00
fix(krux): add Base43 decoding for encrypted QR codes
Implements support for Base43-encoded QR codes generated by Krux devices, resolving a bug where they were misidentified as invalid text. - Adds a new `lib/base43.ts` module with a decoder ported from the official Krux Python implementation. - Updates `detectEncryptionMode` to use the Base43 alphabet for more accurate `'krux'` format detection. - Modifies `decryptFromKrux` to be robust, attempting to decode input as Hex first and falling back to Base43. - This allows the Seed Blender to correctly parse and trigger the decryption flow for both Hex and Base43-encoded Krux QR codes.
This commit is contained in:
@@ -310,18 +310,34 @@ export async function encryptToKrux(params: {
|
||||
};
|
||||
}
|
||||
|
||||
import { base43Decode } from './base43';
|
||||
|
||||
// ... (rest of the file until decryptFromKrux)
|
||||
|
||||
/**
|
||||
* Decrypt KEF hex to mnemonic
|
||||
* Decrypt KEF data (Hex or Base43) to mnemonic
|
||||
*/
|
||||
export async function decryptFromKrux(params: {
|
||||
kefHex: string;
|
||||
kefData: string;
|
||||
passphrase: string;
|
||||
}): Promise<{ mnemonic: string; label: string; version: number; iterations: number }> {
|
||||
if (!params.passphrase) {
|
||||
throw new Error("Passphrase is required for Krux decryption");
|
||||
}
|
||||
|
||||
const bytes = hexToBytes(params.kefHex);
|
||||
let bytes: Uint8Array;
|
||||
try {
|
||||
// First, try to decode as hex
|
||||
bytes = hexToBytes(params.kefData);
|
||||
} catch (e) {
|
||||
// If hex fails, try to decode as Base43
|
||||
try {
|
||||
bytes = base43Decode(params.kefData);
|
||||
} catch (e2) {
|
||||
throw new Error("Invalid Krux data: Not a valid Hex or Base43 string.");
|
||||
}
|
||||
}
|
||||
|
||||
const { label, version, iterations, payload } = unwrap(bytes);
|
||||
const cipher = new KruxCipher(params.passphrase, label, iterations);
|
||||
const decrypted = await cipher.decrypt(payload, version);
|
||||
|
||||
Reference in New Issue
Block a user