User API

The User API stores data under user accounts. Every update is signed by the account that made it and verified before it's written, so only the owner of an account can change its data.

import Holster from "@mblaney/holster/src/holster.js"

const holster = Holster()
const user = holster.user()

Accounts

An account is created with a username and password using create(), then logged in with auth(). Each account has a public key, which is what Holster uses to identify it and where its data is stored. Usernames are only used to log in, and aren't guaranteed to be unique, since two accounts can be created with the same username at the same time.

user.create("alice", "a strong password", err => {
  if (err) return console.error(err)

  user.auth("alice", "a strong password", async err => {
    if (err) return console.error(err)

    await user.get("profile").put({name: "Alice"})
  })
})

Account functions take a callback rather than returning a promise. Once logged in, reading and writing data uses the same chain as the Holster API, so it can be awaited.

Logged in user

After auth() succeeds, user.is holds the account's details, and it's null when nobody is logged in.

Property

Description

username

The username the account logged in with.

pub

Public key, used to verify the account's signatures.

priv

Private key, used to sign updates.

epub

Public key for encryption.

epriv

Private key for encryption.

user.is is also a "pair object", so it can be passed to the SEA API functions to sign, verify and encrypt data as the logged in user:

const enc = await holster.SEA.encrypt("for my eyes only", user.is)

An extension of the Holster API

holster.user() returns the Holster API with a get() function that works with user accounts, and the account functions added. Chains continue with next(), put(), on() and off() exactly as they do on the Holster API. user.wire and user.SEA are available too.