Key derivation and backup
How the post-quantum seed is made, backed up as 24 words, encrypted on disk, and turned into one-time keys.
Everything post-quantum in Lean Key comes from one secret: a 32-byte seed. This page follows it from generation to the one-time keys a vault uses. Source: packages/core/src/seed.ts and packages/core/src/wots.ts.
The seed
- 32 bytes from the platform's cryptographic random generator (
crypto.getRandomValues). - It is generated by the CLI (
leankey keygen) or the extension (Create a new seed). Neither sends it anywhere. - It is a separate secret from any wallet's recovery phrase. It does not derive your Ed25519 key, and your Ed25519 key does not derive it.
The 24 words
The backup is the seed's 32 bytes written as 24 words of the BIP-39 English word list, the way BIP-39 writes 256 bits of entropy: 256 bits of seed plus an 8-bit checksum, in 24 groups of 11 bits.
Only the word encoding is BIP-39. The words are not turned into a key the way a wallet does it (there is no PBKDF2 step and no passphrase); they decode straight back to the 32 bytes. Two consequences:
- Typing these words into an ordinary wallet gives you an unrelated wallet, and exposes your Lean Key backup to that wallet. Do not.
- A mistyped word is caught: restoring requires exactly 24 words from the list with a matching checksum ("those 24 words are not a valid backup (checksum)").
Backup check
The extension does not let you continue until you prove you wrote the words down. After showing them, it asks for three of them at random positions (three distinct positions from 1 to 24, drawn with crypto.getRandomValues). A wrong word sends you back with "One of the words does not match. Check your paper."
The CLI prints the words once, right after leankey keygen, and never again: there is no command that shows them later. leankey keygen --json --show-words puts them in the JSON output instead, for scripts. The extension can show them again under Settings, after you enter the password.
Encryption at rest
The seed is stored encrypted with your password:
| Step | Detail |
|---|---|
| Password | At least 8 characters; normalized to Unicode NFKC before use |
| Key derivation | scrypt, N = 32,768 (2^15), r = 8, p = 1, 32-byte output |
| Salt | 16 random bytes per encryption |
| Cipher | AES-256-GCM through WebCrypto |
| IV | 12 random bytes per encryption |
The stored form is JSON, with binary fields in base64:
{
"v": 1,
"kdf": "scrypt",
"n": 32768,
"r": 8,
"p": 1,
"salt": "…16 bytes, base64…",
"iv": "…12 bytes, base64…",
"ct": "…32 bytes of seed + 16 bytes of GCM tag, base64…"
}
- CLI: this JSON is the seed file (
--out pq.seedby default), written with file mode 600.keygenrefuses to overwrite an existing file. A wrong password is reported as "wrong password". The local-validator test checks that the file contains no word of the backup. - Extension: the same structure is kept in the extension's local storage as part of its keystore. The optional hot Ed25519 account's 32-byte secret is encrypted the same way with the same password. While unlocked, the decrypted values are held in the extension's session storage and removed when it locks. See Extension guide.
From the seed to one-time keys
A vault never stores your seed or a public key, only the 32-byte hash of its current one-time public key. Every key is computed on demand from three things: the seed, the vault's address and the key index k.
sk[k][i] = SHA-256( "TWOKEY/v1/SK" ‖ seed ‖ vault ‖ k_le ‖ i )[0..24] i = 0 … 25
end[k][i] = F^255( sk[k][i] ) 255 steps of the tweakable hash
pk_hash[k] = SHA-256( "TWOKEY/v1/PK" ‖ vault ‖ k_le ‖ end[k][0] ‖ … ‖ end[k][25] )
The tweakable hash F also includes the program id. The exact byte layouts are in WOTS+ parameters.
What follows from this:
- No state to back up besides the words. Given the 24 words, a client can compute the key for any vault and any index. It reads the vault's current
key_indexfrom the chain and derives that key. - One seed, many vaults. The vault address is part of every secret, so the keys of vault A and vault B are unrelated even with the same seed (tested on a local validator: "a second vault of the same owner with the same seed is independent").
- Bound to one deployment. The program id is part of every chain hash, so a signature made for the devnet program is not valid for the localnet program, and the reverse.
- Opening a vault computes
pk_hash[0]for the vault's address and puts it inInitVault. Every withdrawal signs with key k and computespk_hash[k+1]for the intent'snext_pk_hash.
Restoring
| Where | How |
|---|---|
| CLI | leankey keygen --import --out pq.seed reads the 24 words from the terminal (or from LEANKEY_WORDS), asks for a new password and writes a new encrypted seed file. |
| Extension | Set up Lean Key → Restore from 24 words, then choose the owner mode and a password. |
Restoring gives back the ability to sign. It does not give back the journal of signed intents, which lives next to the old seed file or in the old browser profile. Before you rely on a restored seed, read Recovery and safety: the one-device rule exists because a fresh journal does not know what an old device signed.
Hot account (extension only)
In built-in owner mode the extension also holds an Ed25519 account:
- New: 32 random bytes used as the Ed25519 seed.
- Import: a 64-byte Solana secret key in base58 or as a JSON array of numbers (a 32-byte secret is also accepted). For a 64-byte key, the extension checks that the last 32 bytes are the public key of the first 32.
The hot account's secret has no word backup in Lean Key. If you import a key, keep the backup you already have for it. If you let the extension create one, the extension's storage is its only copy.