Docs/Concepts
Private balances
The keys one wallet signature gives you, and the notes they own.
Your private balance is the set of unspent notes that your keys can spend. No account on chain holds a total. The app, the SDK and the CLI find your notes by scanning and add them up on your device.
#One signature, every key
Unlocking signs one fixed message with your wallet:
Liora unlock v1
Sign to derive your private keys. This signature stays on this device.The two lines are joined by a single line feed and nothing follows the second. Wallets sign Ed25519 deterministically, so the same wallet produces the same signature and the same keys on any device.
The signature is hashed into a master secret, and every key comes from the master by HKDF-SHA256 under its own label:
master = HKDF-SHA256(signature, salt = wallet address bytes, info = "Liora/master/v1", 32 bytes)
scalar(label) = 1 + (HKDF-SHA256(master, info = label, 64 bytes) as a big-endian integer) mod (q - 1)q is the order of the Baby Jubjub subgroup and G its generator (circomlib's Base8).
| Key | Label | Secret | Public |
|---|---|---|---|
| Spend key | Liora/spend/v1 | s | S = sG |
| View key | Liora/view/v1 | v | V = vG |
Balance owner k | Liora/balance/v1/ then k as 8 big-endian bytes | b | B = bG |
Balance nullifier secret k | Liora/nk/balance/ then the same k | 31 bytes | |
Balance viewing key k | Liora/vk/balance/ then the same k | 32 bytes, X25519 | |
| Change nullifier secret | Liora/nk/change/v1, salted with the owner address the change sits at | 31 bytes | |
| Change viewing key | Liora/vk/change/v1, with the same salt | 32 bytes, X25519 |
S and V together are your meta-address. The balance keys own what you deposit and the change your payments return.
#Notes and their owners
Each note belongs to a program address made from one public key:
import { balanceKey, ownerAddress } from "@liora/contract";
const balance = balanceKey(keys, 0);
const owner = await ownerAddress(balance.point, programId);For the public fixture wallet recipient, balance key 0 is 67cfd68d734a79b5bc4f3bc9d19df256f9e2a914bab22dd4e25dfaf157ade998. Under the program 8i6Rs6mak6AoQH1Cd6asXpJoGMVqWP81iEux5kdnHbA4 its owner address is 3UTJjKiYe78qQsBrDVAtLm75Xx6aHWUJRhFoCKHt59Yh.
| Note | Owner key | Who can spend it |
|---|---|---|
| A deposit | Balance key B | Whoever knows b |
| Change from a payment | The first owner key of that payment | The same holder as before |
| A received payment | Stealth address P | The recipient, who alone can compute p |
A payment's outputs can go to two owners only: the stealth address being paid, and the first of the keys whose notes are being spent, which receives the change. The program checks every output against that rule before it signs.
Change stays at the owner address of the first note spent, and its note keys are derived from your master secret. When you spend a payment you received, the change sits at that payment's stealth address, and the sender, who could read the original note, cannot read the change.
For each transfer your device picks up to three notes of one owner when they cover the amount and both fees. It combines notes of several owners only when no single owner's notes are enough.
#Deposit and withdraw
A deposit moves public SOL from your wallet into a note at owner(B). The wallet, the amount and the balance key are visible on chain, and what the balance is used for afterwards is private.
A withdrawal spends notes and sends SOL to a public wallet. The proof binds the destination wallet and the amount, so the relayer that carries the transaction cannot change either. The destination and the amount are visible on chain.
SOL is asset 1. Amounts are whole lamports, written as decimal strings wherever they cross the API.