Skip to main content

Module account

Module account 

Source
Expand description

The signed-in account: reading what someone signs in with, keeping what is secret where it belongs, signing, and encrypting what the account keeps to itself.

Signing in takes one of three things:

  • an nsec, the account’s secret key: full access, signed here;
  • an npub, its public key: read-only;
  • a bunker:// address (NIP-46): full access, signed by a remote signer that keeps the key.

A remote signer knows this client by a key of the client’s own. There is one for each signer, made the first time that signer is signed in with and the same ever after, signing out included: a signer that only answers clients it was told about (nak bunker -k) is told this key once. When a signer turns a sign-in down, the key’s public half is what is shown, to be authorized there. Revoking it is done at the signer.

What is secret goes to the system keyring (Secret Service: gnome-keyring, KWallet) and nowhere else: an account’s nsec or its bunker address, and the client keys. None is ever written to the config, the event store or a log. The config only names the account by its npub.

Signing with an nsec fetches it from the keyring, signs, and lets go of it: the applet runs for as long as the session does, and holds no secret key between one signature and the next. A remote signer is connected to when the first signature is asked for, and stays connected until the account signs out: connecting anew for every signature would have the signer greet this client each time.

What an account keeps to itself, such as its private bookmarks, it encrypts to its own key (NIP-44), and only it can read back. That takes the secret key as signing does, and goes the same two ways: here, with the key from the keyring, or at the remote signer.

flowchart LR
    subgraph keyring["The system keyring, service cosmic-applet-avestruz"]
        secret["Under the account's npub: its nsec, or its bunker address"]
        client["Under bunker-client and a signer's key: this client's key for that signer"]
    end
    subgraph config["The config"]
        npub["The account's npub, and nothing secret"]
    end
    signer["Signer"] -->|"an nsec: fetched for one signature, and let go of"| secret
    signer -->|"a bunker: fetched once, and the connection kept"| secret
    signer --> client
    restore["At startup"] --> npub
    restore -->|"is anything kept for it?"| secret

The three ways in, step by step, and what a signature goes through, are in crate::guide::flows.

Structs§

Account
The account in use.
ApproveInBrowser 🔒
Opens the page a remote signer asks to be approved on. Some signers answer a request with an address where the person says yes.
Session 🔒
A connection to an account’s remote signer.
Signer
What signs for the account. Cheap to clone; clones share the connection to a remote signer, when there is one.

Enums§

Credential
What someone signed in with.
CredentialError
Why the text in the sign-in field can’t be signed in with.
SignError
Why an event was not signed, or something not encrypted or decrypted.
SignInError
Why nobody was signed in.
StoredSigner 🔒
What the keyring holds for an account: how it signs.

Constants§

BUNKER_SCHEME 🔒
How bunker addresses start.
CLIENT_KEY_PREFIX 🔒
What the keyring user name of a client key starts with; the signer’s public key, in hex, follows.
KEYRING_SERVICE 🔒
The keyring service an account’s secret is filed under; the entry’s user name is the account’s npub.
REMOTE_TIMEOUT 🔒
How long a remote signer gets to answer one request. Someone may have to pick up a phone and approve it.

Functions§

blocking 🔒
Run a keyring call off the async executor: the Secret Service is reached over D-Bus with a blocking client, and may wait on an unlock prompt.
client_keys 🔒
The key this client is known by to the signer remote_signer: the one in the keyring, or, the first time, a new one that is put there.
client_keys_entry 🔒
Where the keyring keeps the key this client is known by to the signer remote_signer.
delete_signer 🔒
Take what public_key signs with out of the keyring, if it is there.
has_signer 🔒
Whether the keyring holds what public_key signs with.
is_bunker_address 🔒
Whether input is meant as a bunker address.
is_nip04 🔒
Whether payload was encrypted the old way (NIP-04) rather than the new (NIP-44): it ends in ?iv= and the 24 characters of an initialisation vector, which nothing encrypted the new way does. Lists written by older clients are.
keyring_entry 🔒
load_signer 🔒
What public_key signs with, read from the keyring for the purpose.
nsec 🔒
keys’ secret half as an nsec: the form the keyring keeps.
parse_credential
Read what was typed or pasted into the sign-in field.
remote_signer 🔒
The signer a bunker address names.
restore
The account the config names by npub, as it stands at startup: able to sign if the keyring holds what it signs with. A keyring that can’t be asked leaves the account read-only rather than signed out.
store_signer 🔒
Put what public_key signs with in the keyring, filed under its npub.