Skip to content
Lean Key
Reference

Intent format

The 193 bytes a WOTS+ signature covers, field by field, with the values each instruction puts in them.

An intent is what one WOTS+ signature authorizes. It is 193 bytes. The same layout is defined in three places, which agree byte for byte: the Lean specification (Intent.encode in program/Twokey/Spec/Intent.lean), the program's work buffer (buildWork in program/Twokey/Program.lean) and the TypeScript encoder (encodeIntent in packages/core/src/intent.ts).

Layout

All integers are unsigned little-endian. Addresses are the 32 raw bytes of a Solana public key.

OffsetSizeFieldEncodingValue
016tagASCIITWOKEY/v1/INTENT (54574f4b45592f76312f494e54454e54)
1632program_idaddressThe Lean Key program's own id, as the runtime passes it to the program
4832vaultaddressThe vault account given to the instruction (account 1)
808key_indexu64 LEThe vault's key_index before the instruction, read from its data
881actionu81 WithdrawSol, 2 WithdrawToken, 3 CloseTokenAccount, 4 CloseVault
8932assetaddress32 zero bytes for SOL; otherwise the mint
1218amountu64 LELamports or token base units; 0 for the closing actions
12932destinationaddressThe receiving account given to the instruction
16132next_pk_hash32 bytesThe hash of the next one-time public key, from the instruction data
193

The value 0 for action is not used in intents; it is the InitVault discriminator, which carries no hash signature.

Values per instruction

The program never reads an intent from the transaction. It writes these bytes itself, from the accounts and data of the instruction it is executing, and verifies the WOTS+ signature against them. So each field is exactly what the instruction will do:

FieldWithdrawSolWithdrawTokenCloseTokenAccountCloseVault
action1234
assetzerothe mint account (account 4)the mint stored in the vault's token account (bytes 0 to 31 of its data)zero
amountamount from the dataamount from the data00
destinationaccount 2 (the owner itself is allowed)account 3, the destination token accountaccount 3 (the owner itself is allowed)account 2 (the owner itself is allowed)
next_pk_hashdata bytes 9 to 40data bytes 10 to 41data bytes 1 to 32data bytes 1 to 32

Consequences:

  • For a token withdrawal the destination in the intent is the token account, not the recipient's wallet. The clients put the recipient's associated token account there unless you name another token account.
  • A close-vault intent says "everything above rent" (asset 0, amount 0), so its validity does not depend on the vault's exact balance at the moment it lands.
  • A close-token-account intent names the mint but no amount; the token program refuses to close an account that still holds tokens.

What is not in the intent

Not includedWhy that is safe
Recent blockhashOnly the Ed25519 signature covers it. The same intent can be re-sent in a new transaction after the old one expired.
The ownerThe vault is in the intent, and the program requires that account 0 signed and equals the owner stored in the vault.
Fee payer, compute budget, priority feeNot the vault's business; they are set by whoever builds the transaction.
decimals (WithdrawToken)Passed to TransferChecked, which refuses a value that does not match the mint.
The token programThe program accepts only the SPL Token and Token-2022 program ids, and checks that the vault's token account, the destination token account and the mint all belong to the one given.

Annotated example

The first intent in program/release/vectors.json (withdraw_sol), computed by the Lean specification. It uses the localnet program id, a made-up vault (bytes 00 to 1f), a made-up destination (bytes a0 to bf), key #0 and 1.5 SOL:

offset  bytes
  0     54574f4b45592f76312f494e54454e54                                   "TWOKEY/v1/INTENT"
 16     06e70fe07f60caf2e06651c42cbb59615ef7a028e3d0753abe5fb98ecd5dbddf   program id (TwoKWxqD6kL6ow9bAEZ3Kir9hUFKbocX4LZR4j5R3W6)
 48     000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f   vault
 80     0000000000000000                                                   key_index = 0
 88     01                                                                 action = WithdrawSol
 89     0000000000000000000000000000000000000000000000000000000000000000   asset = SOL
121     002f685900000000                                                   amount = 1,500,000,000 lamports
129     a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf   destination
161     7d7067d1e6f48bea569d914232534299ed5fac1ff231a1271b9ea50e27100c71   next_pk_hash = pk_hash of key #1

Its 26 digits are 117, 139, 108, 193, 134, 225, 195, 12, 156, 99, 84, 138, 40, 180, 214, 74, 242, 250, 107, 81, 18, 252, 233, 131, 10, 138. The message checksum is 2,698 = 10 × 256 + 138, which gives the last two digits, and the verifier walks 255 × (10 + 2) = 3,060 chain steps.

Encoding and decoding in TypeScript

import { PublicKey } from "@solana/web3.js";
import { Action, encodeIntent, decodeIntent, describeIntent, INTENT_LEN } from "@twokey/core";

const bytes = encodeIntent({
  programId: new PublicKey("TwoKhewkScEnH75rbs9nC5ScrsFQT93DrHsSSZvpVHn"),
  vault,                       // PublicKey of the vault
  keyIndex: 3n,                // the vault's key_index on chain now
  action: Action.WithdrawSol,
  asset: null,                 // null = 32 zero bytes (SOL)
  amount: 1_500_000_000n,
  destination,                 // PublicKey
  nextPkHash,                  // 32 bytes: pkHash(seed, vault, keyIndex + 1)
});
bytes.length === INTENT_LEN;   // 193

const intent = decodeIntent(bytes); // checks length, tag and action
describeIntent(intent);              // "Send 1.5 SOL to 7xKX…9fPq (key #3 → #4)"

decodeIntent refuses anything that is not 193 bytes, does not start with the tag, or has an action outside 1 to 4. In practice you do not build intents by hand: buildIntent and signWithdrawal in packages/core/src/vault.ts derive next_pk_hash, pick the token accounts and enforce the journal rule.

Reading intents back from the chain

A withdrawal transaction contains the instruction data but not the intent. decodeInstruction in packages/core/src/decode.ts rebuilds it from the instruction's accounts and data, given the key index before the instruction. That index is in the program's log: every successful instruction logs five numbers with sol_log_64, which the runtime prints as

Program log: 0x1, 0x3, 0x3b9aca00, 0x0, 0x0

meaning action 1, key index 3, amount 1,000,000,000. For CloseTokenAccount the mint is not in the instruction; the decoder takes it from the transaction's token balances.

The message the signature covers

WOTS+ does not sign the 193 bytes directly. It signs the first 24 bytes of SHA-256("TWOKEY/v1/MSG" ‖ intent), as 24 digits, plus a 2-digit checksum. See WOTS+ parameters.

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.