SELFHOLD / FOR DEVELOPERS Guide pages ↓
How Selfhold works
Selfhold is a wallet for Lattice ↗. Your site asks it for things; the person approves them in Selfhold; your site gets the answer. This page explains the parts, so you know what to expect and what to tell people.
Two wallets, one library
selfhold() gives you one wallet object. Behind it is one of two wallets:
| Selfhold's window | Selfhold for Chrome | |
|---|---|---|
| What it is | A page at wallet.selfhold.app that opens over yours, as a payment window does. On iPhone it opens as a tab. | A Chrome extension the person installed. |
| Where it works | Any current browser with passkeys, phones included. | Desktop Chrome. |
| The account | Derived from a passkey. The person's password manager keeps it and syncs it to their other devices. | Kept in the extension, protected by its password and recovery phrase. |
| Used when | Selfhold for Chrome isn't installed, or you pass use: "window". | It's installed, or you pass use: "extension". |
The two keep separate accounts. Someone with both has two addresses, so say on your page which one is connected: wallet.kind tells you.
What happens in a write
- Your page calls
writeRecords()in a click, which opens Selfhold's window. - The window says it's ready.
- Your page sends the write, and the hosts and fee sponsor to use.
- The window shows the person what the write does and costs. They approve with their passkey.
- The window derives the key from the passkey, signs, and sends the transaction to a node.
- The window answers your page with the transaction's ID and nonce, then closes.
sent.wait()reads the account at the node until the write lands.
Selfhold for Chrome is similar, with differences: its own window asks, a site it's connected to isn't asked again to connect, it sends through the node the person chose in it (not your hosts), and it pays fees from coins (no sponsor).
The account
- One account for every site. Selfhold's window gives the same address to every site the person connects. Sites can see each other's records about that address on the chain, as with any public account.
- The key is never stored. The window derives it from the passkey for each request the person approves (WebAuthn's PRF extension), and erases it when the request is done. The passkey belongs to wallet.selfhold.app, so no other site can ask for it.
- A new device signs in with I have a Selfhold passkey, using the synced passkey. A browser or password manager without the PRF extension can't make the key; the window says so.
What your site can and can't do
| Your site can | Your site can't |
|---|---|
| Ask to connect, and learn the account's address once the person agrees. | See or use the key, the passkey or the recovery details. |
| Propose a write: records to change, payments, a fee sponsor and hosts. | Send anything without the person's approval. Every write and every signature asks. |
| Hear progress, and get the sent transaction's ID and nonce. | Get the signed transaction's bytes, to send again later. |
| Ask for a signature on text. | Sign as another site: the signed bytes include your origin, as "lattice-message:" + origin + "\n" + text. |
| Suggest a fee sponsor. | Let the sponsor change the write: the window checks that the sponsor added only its own fee, and refuses otherwise. |
The window shows the person your site's origin on every request: the host in bold, and the scheme when it isn't https. A page on localhost is marked "a site on this computer". It answers only the page that opened it, and only to that page's origin.
The Lattice you need to know
- Chains and
chainPath - Lattice has a main chain, Nexus, and child chains under it. A write names its chain by path, such as
["Nexus", "your-chain"]. Each chain may have its own rules for the records it accepts. - Records
- A chain holds records: keys with string values. A write changes some of them, all at once or not at all.
- Nodes and hosts
- A node holds a chain and takes transactions for it. Selfhold's window sends a write to the hosts you give
selfhold(), or else the ones Nexus lists for the chain. - Fees
- Each transaction pays a fee to the miner who records it. It comes from the account's coins, or from a fee sponsor, paid with work: see Pay fees with work.
- Nonce
- Each account's transactions are numbered. A write has landed once the account's next number has passed it.
- Blocks
- A block every 10 seconds or so records the transactions waiting. That's why a write usually lands within seconds of being sent.
For more on chains, nodes and mining, see lattice.build ↗.
Something wrong or missing here? Report it on GitHub ↗