fix(krux): restore missing encryption exports

Restores the `encryptToKrux` and `bytesToHex` functions that were accidentally removed during previous refactoring.

Their absence caused a build failure due to missing imports in other parts of the application. This commit re-adds the functions to ensure the application builds correctly.
This commit is contained in:
LC mac
2026-02-04 15:05:11 +08:00
parent 7d48d2ade2
commit 49d73a7ae4

View File

@@ -152,3 +152,19 @@ export async function decryptFromKrux(params: { kefData: string; passphrase: str
const mnemonic = new TextDecoder().decode(decrypted);
return { mnemonic, label, version, iterations };
}
export function bytesToHex(bytes: Uint8Array): string {
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('').toUpperCase();
}
export async function encryptToKrux(params: { mnemonic: string; passphrase: string; label?: string; iterations?: number; version?: number; }): Promise<{ kefHex: string; label: string; version: number; iterations: number }> {
const { mnemonic, passphrase, label = "Seed Backup", iterations = 200000, version = 21 } = params;
if (!passphrase) throw new Error("Passphrase is required for Krux encryption");
const mnemonicBytes = new TextEncoder().encode(mnemonic);
// For encryption, we encode the string label to get the salt bytes
const cipher = new KruxCipher(passphrase, new TextEncoder().encode(label), iterations);
const payload = await cipher.encrypt(mnemonicBytes, version);
const kef = wrap(label, version, iterations, payload);
return { kefHex: bytesToHex(kef), label, version, iterations };
}