1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! API key persistence to OPFS.
//!
//! Stored next to `.lh_history.json` in the same per-origin OPFS
//! sandbox. Same security model as `sessionStorage`: anything with JS
//! access to this origin can read the file. The win over
//! `sessionStorage` is that it survives a tab close / browser restart.
//!
//! **At rest:** the file is encrypted with the per-origin device key
//! (see [`super::encryption`]) — OPFS holds ciphertext. This does NOT
//! defend against XSS (the page can read the key); it removes the
//! plaintext secret from OPFS for copy/export/disk-inspection channels.
//! Legacy plaintext files are read transparently and re-encrypted on the
//! next save.
use crateFilesystem;
const KEY_FILE: &str = ".lh_api_key";
/// Read the persisted Gemini API key, if any. Empty/missing → `None`.
pub async
/// Persist the key (encrypted). Best-effort; logs and swallows errors.
pub async
/// Delete the persisted key (the "clear" button).
pub async