The wallet
Status: on Arctic, as the
arcticbinary. The wallet runs only the no-op program, and its sync doesn't recognise programs yet. Its library's source isn't published yet.
arctic wallet is a Styx wallet on the command line. It keeps its seed and state in one file, finds its payments through a node's lookup RPCs, and pays through Styx. Its logic is the arctic-wallet crate, which another wallet will be able to use as a library once its source is published.
Commands
| Command | What it does |
|---|---|
arctic wallet init --wallet <file> | Creates a wallet file with a new 32-byte seed, and prints address 0. --seed-hex gives a seed of 32 to 252 bytes instead. --bucket-bits sets its addresses' bucket width, 0 by default (First contacts and buckets). |
arctic wallet address --wallet <file> | Prints the next unused address, or with --index the address at that index. |
arctic wallet sync --wallet <file> | Finds the wallet's new channels and notes, and which of its notes are spent. |
arctic wallet balance --wallet <file> | Prints the spendable balance and every note. |
arctic wallet send --wallet <file> --to <address> --amount <zatoshis> | Pays an address with a channel receiver. --backup makes the payment carry a backup. |
arctic wallet restore --wallet <file> --seed-hex <seed> | Recreates a wallet file from its seed: its newest backup, then a sync. --bucket-bits sets the width it looks for first contacts with. |
Each command prints JSON, apart from address, which prints the address. There's no receive command: a wallet receives by syncing.
--rpc, or the ARCTIC_RPC environment variable, gives the node's JSON-RPC URL. By default it's a node on the same machine, on port 18332.
A node's RPC listener requires the node's cookie unless its config sets rpc.enable_cookie_auth = false, and it closes the connection on a call without it. --rpc-cookie, or ARCTIC_RPC_COOKIE, gives the wallet the cookie file: .cookie in the node's rpc.cookie_dir, by default the zakura folder of the cache directory of the user the node runs as. The cookie goes as HTTP Basic credentials, so send it only to a node on the same machine, or over HTTPS.
The wallet file holds the seed, in hex, and the wallet's state: its channels, counters and notes. Keep it private. The seed spends the funds, and the channel secrets find every payment, though without the seed they can't spend them.
A first session
arctic wallet init --wallet alice.json
arctic wallet sync --wallet alice.json
arctic wallet balance --wallet alice.json
arctic wallet send --wallet alice.json --to <address> --amount 100000
init prints address 0. Give it to whoever pays you, Arctic's faucet included: the faucet pays from transparent funds, with a first contact that opens a channel to the address. Once the payment is in a block, sync finds it, and balance shows it. send prints the transaction ID, the fee, and whether the payment carried a backup.
What a sync does
A sync looks things up in rounds. Each round asks for:
- first contacts in the buckets of the addresses up to 10 past the last one used. A bucket holds other recipients' first contacts too, so the wallet tests each one: it decapsulates, checks the tag against the channel that gives, and opens the memo as the channel's first payment. Each one that's the wallet's opens a receive channel.
- memos under the next 10 payment tags of every receive channel, and of the self channel, which holds the wallet's change.
It repeats while a round finds something, since a payment moves its channel's window and a first contact opens a channel. Each memo must open under its payment's key and carry a note whose commitment is its action's. Anything else is counted as rejected. Then the sync asks which of the wallet's notes the chain has spent, by their nullifiers.
Every sync reads the last 100 blocks below the previous sync's height again, forgetting what it found there first. That's the deepest reorg a node accepts, so a reorg can't leave stale notes or channels behind.
The sync prints:
| Field | Meaning |
|---|---|
notes_found | Notes the wallet didn't have, change included |
channels_opened | Channels other wallets opened to this one that it didn't know |
rejected | Entries under the wallet's tags that didn't open: someone else's, or tampered with |
others_in_buckets | First contacts in the wallet's buckets for other recipients: the cover a bucket gives |
newly_spent | Notes the chain now shows spent |
synced_height | The height the wallet is synced to |
balance | The spendable balance |
Sending
send pays only an address with a channel receiver. It:
- uses the channel it opened to the address before, at the channel's next index, or opens one with a first contact;
- spends the largest spendable notes first, as few as cover the amount and the fee;
- always adds change on its self channel, so every payment has at least two actions;
- runs the no-op program, which every plain payment runs, so a payment doesn't show which wallet made it;
- expires 40 blocks after the next block.
The notes it spends stay pending until the chain shows them spent. If the payment expires instead, a sync releases them. A pending note doesn't count in the balance.
A payment that opens a channel always carries a backup that already holds the new channel, so the newest backup on the chain holds every channel the wallet has opened. Other payments carry one only with --backup. For a payment that spends one or two notes:
| Payment | Fee (zatoshis) |
|---|---|
| On an open channel | 10,000 |
On an open channel, with --backup | 20,000 |
| Opening a channel, with its backup | 25,000 |
Spending more notes adds actions, and with them proof bytes and fee (Fees and weight).
Backups
A wallet restored from its seed can find again, by tag:
- the channels others opened to it, through its addresses' buckets;
- the payments on them;
- its change, on its self channel.
It can't find the channels it opened itself: their secrets came from fresh randomness. A backup holds those, with the next index on each, and the wallet's address and change counters, so no index is used twice.
Backup n is filed under the self channel's backup tag n, and sealed under its backup key n (Channels). Its plaintext is, with integers little-endian:
| Field | Bytes |
|---|---|
| Version (1) | 1 |
| The next address index | 4 |
| The next change index | 8 |
| The number of channels | 2 |
| Each channel: the recipient's address, the channel's secret, its next index | 43 + 32 + 8 |
It's padded with zeros to the smallest size class that holds it, 1 to 4 KiB, so its size shows only roughly how many channels the wallet has opened. A bigger backup costs more:
| Backup | Channels it holds | Fee of a payment that opens a channel |
|---|---|---|
| 1 KiB | up to 12 | 25,000 |
| 2 KiB | up to 24 | 35,000 |
| 3 KiB | up to 36 | 40,000 |
| 4 KiB | up to 49 | 50,000 |
A wallet that has opened 49 channels can't open another: the backup wouldn't fit.
Restoring
restore looks up backups under the self channel's backup tags, 10 at a time, until a window finds none. It takes the newest backup's channels and counters, then syncs. A wallet that never opened a channel needs no backup, and loses nothing without one.
The restored wallet resumes each of its channels at the index its newest backup recorded. Payments on an open channel carry no backup unless sent with --backup.
--bucket-bits on restore is the width the wallet looks for first contacts with, and gives new addresses. A bucket of width k holds every bucket of a greater width that starts with its bits, so the default, 0, finds first contacts to addresses of any width.
As a library
A sync asks for what it needs through one interface, MemoRetrieval: entries by tag, first contacts by bucket, and whether nullifiers are spent. Today a node's plain lookup implements it. Private information retrieval would implement the same interface, over the same fixed-size records (The lookup RPCs).