Skip to content
Lean Key
Concepts

Concepts

Two keys, intents, one-time keys and their rotation, the journal rule, and how a withdrawal is sent safely.

Two keys

A Lean Key vault has two authorities, and every instruction that moves anything needs both in the same transaction.

Ed25519 owner keyPost-quantum seed
What it isAn ordinary Solana keypair32 random bytes, backed up as 24 words
Where it livesYour wallet (Phantom, Solflare, Backpack, a Ledger), a keypair file for the CLI, or the extension's optional hot accountThe extension or an encrypted CLI seed file
What it signsThe Solana transaction, like any other signerOne WOTS+ signature per withdrawal, over the intent
Checked byThe runtime marks account 0 as a signer; the program requires that and compares it with the owner stored in the vaultThe program rebuilds the intent and verifies the hash signature against the vault's stored key hash
Can it be changedNo. No instruction changes a vault's ownerRotates on every withdrawal; the seed itself never changes

The two keys are independent: the 24 words are not derived from your wallet's recovery phrase, and your wallet's key is not derived from them. Having one tells nothing about the other.

The vault's Solana address is a program-derived address computed from the owner and a vault number: ["vault", owner, vault_id]. One owner can have many vaults (vault #0, #1, …), and one seed can serve all of them, because every one-time key is bound to the vault's address.

Intents

The WOTS+ signature never covers a Solana transaction. It covers a 193-byte intent:

"TWOKEY/v1/INTENT" ‖ program_id ‖ vault ‖ key_index ‖ action ‖ asset ‖ amount ‖ destination ‖ next_pk_hash
  • program_id and vault bind the signature to one deployment and one vault.
  • key_index binds it to one one-time key.
  • action is 1 to 4: withdraw SOL, withdraw token, close a token account, close the vault.
  • asset is 32 zero bytes for SOL, otherwise the mint.
  • amount is lamports or token base units, and 0 for the two closing actions.
  • destination is the account that receives: a wallet for SOL and rent, a token account for tokens.
  • next_pk_hash is the hash of the one-time key the vault will hold after this withdrawal.

The program does not read an intent from the instruction. It rebuilds the intent from what the instruction is about to do (its own program id, the vault account it was given, the vault's current key index, the destination account it was given, the amount and next key hash from the instruction data, the mint) and verifies the signature against those bytes. A signature therefore authorizes exactly one transfer. Change the amount, the destination, the asset or the vault and the program computes a different intent, and the signature fails with BadSignature (6005). The Lean theorems intent_binds_transfer and intent_binds_token_transfer state this for the model of the program.

There is no blockhash in the intent. Only the Ed25519 signature covers the blockhash, so the same intent can be put into a new transaction with a fresh blockhash and sent again. That is what makes a retry safe. Byte-exact layout: Intent format.

One-time keys and rotation

A WOTS+ key may sign one message, ever. A signature reveals, on each of 26 hash chains, the value at a position chosen by the message. Anyone can hash forward from there, nobody can hash backward. Two signatures of different messages with the same key reveal the lower of the two positions on every chain, and anyone could then sign any message whose positions are all at or above those. One signature alone gives nothing usable: the Lean theorem wots_no_domination shows that for any two intents with different digits, the second has a strictly lower digit than the first on some chain, so it cannot be reached by hashing forward.

So the vault holds a sequence of keys. The vault account stores only key_index and pk_hash, the SHA-256 hash of the current one-time public key. The key for index k of a vault is derived from your seed, the vault's address and k. Each intent names the hash of key k+1. After a successful withdrawal the program sets:

key_index := key_index + 1
pk_hash   := intent.next_pk_hash

The theorem withdraw_rotates_key states this for every instruction that carries a hash signature, and that the owner never changes. Once the key has rotated, every earlier signature is for an old key index and an old key hash, so it cannot be replayed.

CloseTokenAccount and CloseVault rotate the key as well. They are withdrawals in every sense that matters here.

The journal rule

The program cannot know how many intents a key has signed off chain. The clients make sure it is one:

  • Before signing, the client reads key_index from the chain.
  • It looks in its journal of signed intents for that vault and key index.
  • If there is no entry, it may sign a new intent, and it writes the intent and the signature to the journal before the signature leaves the signer.
  • If there is an entry, it signs only those same intent bytes again. Signing is deterministic, so the signature is identical and nothing new is revealed. Any other intent is refused with: "Key #k of this vault already signed a different intent. Only that intent can be sent (Retry); signing another one with the same one-time key would weaken it."

An intent that was signed but has not landed yet is a pending intent. The CLI shows it with leankey status --pq and leankey pending, and re-sends it with leankey pending --send. The extension shows "Pending intent for key #k" on the vault screen with a Retry button.

The journal lives with the signer: a JSON file next to the CLI's seed file (pq.seed.journal.json), or the extension's local storage. Two copies of the seed on two devices have two journals that do not know about each other. Hence the rule in Recovery and safety: one active signer per seed.

How a withdrawal is sent

The CLI and the extension share one send order (prepareSend in packages/core):

  1. Preflight with a placeholder. Build the instruction with an all-zero 624-byte signature and simulate it. Every check the program makes before the WOTS+ verification must pass, so the simulation must stop at exactly BadSignature (6005). Anything else (wrong owner, not a vault, zero amount, unsupported token program) is reported and no one-time key is used.
  2. Local checks. Things the program checks after the signature are checked against the chain: SOL above the rent-exempt minimum, token balance, frozen token accounts, a transfer-hook mint, an empty destination that would be left below its own rent minimum.
  3. Sign under the journal rule. Derive key k+1's hash, build the intent, sign with key k, write the journal entry.
  4. Simulate with the real signature. If it fails, nothing is sent and the intent stays pending in the journal, to be retried once the cause is fixed.
  5. Send with a fresh blockhash. If the transaction expires before it lands, nothing moved and only the same intent can be sent again.

Owner modes

The extension supports two arrangements for the Ed25519 half:

  • External owner (recommended). Your existing wallet is the owner and signs every transaction; the extension holds only the post-quantum seed and answers twokey:signIntent requests from the site. Two independent apps, or two devices with a hardware wallet.
  • Built-in owner. The extension also holds a hot Ed25519 account and signs both halves itself. The WOTS+ requirement still holds, so a broken Ed25519 key alone is not enough, but anything that compromises the extension's storage and password gets both keys.

The CLI corresponds to the built-in case when you give it a keypair file. See Extension guide.

Deposits, closing and tombstones

Deposits need no instruction and no signature from you: send SOL to the vault address, or tokens to the vault's associated token account (the CLI's deposit --mint creates it when needed). The vault keeps its rent-exempt minimum at all times; the withdrawable SOL is the balance above it.

CloseVault sends everything above the rent-exempt minimum to the destination and sets the closed flag. Its intent says asset 0 and amount 0, meaning "everything", so a few lamports sent to the vault after you signed cannot make the close fail. The account is not deleted: it stays as a tombstone owned by the program, so the address can never be opened again by someone holding only the owner key. The program does not refuse later instructions on a closed vault; tokens left in it can still be withdrawn with both signatures. The clients treat a closed vault as closed: the CLI refuses to deposit into one and refuses to close it again, and the extension hides the Withdraw SOL and Close buttons for it while still offering token withdrawals.

Connect a wallet

Your wallet signs as the owner (Key A). Lean Key adds the post-quantum key (Key B).

Wallets

Any wallet that supports the Solana Wallet Standard appears under Installed. Lean Key never asks for your seed phrase on this site.