DataBaseHolster

Manages Holster user authentication and various utility helpers for session, alias/username, SEA cryptography, event handling, and reactive streams. This is a native Holster implementation that doesn't require Gun compatibility layer.

Constructors

  • Constructs a new DataBaseHolster instance connected to a Holster instance.

    Parameters

    • holster: any

      The main Holster instance.

    • Optionalcore: any
    • Optionalsea: any

      Optional cryptography (Holster SEA) instance; will be auto-discovered if not provided.

    Returns DataBaseHolster

    If holster or holster.user() is not provided.

Properties

_isDestroyed: boolean = false

Whether the database instance has been destroyed

_rxjs?: RxJSHolster

RxJS-based Holster observable/stream helper

authPollInterval: any = null

Polling interval for auth state changes

core?: any

ShogunCore instance for emitting events

crypto: crypto

Crypto utilities used internally

eventEmitter: EventEmitter

EventEmitter for app-specific event management

holster: any

Holster instance

lastUserState: any = null

Last known user state

onAuthCallbacks: AuthCallback[] = []

Registered callbacks for auth state changes

sea: any

Holster SEA cryptography context

user: any = null

Cached user instance or null if not logged in

usernamesNode: any

Holster node dedicated to mapping usernames to pubkeys

Accessors

  • get gun(): any

    Get the Holster instance (for backward compatibility with gun property). Returns a proxy that provides Gun-like API on top of Holster.

    Returns any

Methods

  • Aggressively clean up authentication state and session.

    Returns void

  • Assemble a standard AuthResult object after a successful login.

    Parameters

    • username: string
    • userPub: string

    Returns AuthResult

  • Internal

    Helper to create a graph structure compatible with Holster.

    Parameters

    • soul: string
    • data: any
    • sig: null | string
    • pub: null | string
    • timestamp: null | number

    Returns any

  • Create a proxy that makes Holster look like Gun for compatibility.

    Returns any

  • Internal

    Helper to create a user with pair and register alias.

    Parameters

    • normalizedUsername: string
    • pair: ISEAPair
    • userPub: string
    • soul: string
    • resolve: (result: AuthResult) => void

    Returns Promise<void>

  • Tears down the DataBaseHolster instance and performs cleanup.

    Returns void

  • Emit a custom event.

    Parameters

    • event: string | symbol
    • Optionaldata: any

    Returns boolean

  • Ensures that an alias/username is available in Holster for registration.

    Parameters

    • alias: string
    • timeout: number = 5000

    Returns Promise<void>

  • Returns the currently authenticated user's public key and Holster user instance.

    Returns null | { pub: string; user?: any }

  • Get current user's public key.

    Returns null | string

  • Initialize the database instance.

    Returns void

  • Checks if a given alias/username is available on Holster. Uses the same approach as isAliasTaken but returns the inverse.

    Parameters

    • alias: string
    • timeout: number = 5000

    Returns Promise<boolean>

  • Checks if a given alias/username is taken on Holster.

    Parameters

    • alias: string

    Returns Promise<boolean>

  • Check if a user is currently logged in (there is a valid session).

    Returns boolean

    true if logged in; otherwise false.

  • Sign in (authenticate) as an existing user by username/password or SEA pair.

    Parameters

    • username: string
    • password: string
    • Optionalpair: null | ISEAPair

    Returns Promise<AuthResult>

  • Authenticate using a SEA pair directly. If username doesn't exist, creates a new user with the provided pair.

    Parameters

    • username: string
    • pair: ISEAPair

    Returns Promise<AuthResult>

  • Legacy API: Sign in using a username and SEA pair.

    Parameters

    • username: string
    • pair: ISEAPair

    Returns Promise<AuthResult>

  • Log out the current user, clear local state and remove session from storage.

    Returns void

  • Internal

    Internal: notify all onAuth callbacks with current user.

    Parameters

    • pub: string

      User's public key (pub).

    Returns void

  • Remove an event handler.

    Parameters

    • event: string | symbol
    • listener: EventListener

    Returns void

  • Register an event handler.

    Parameters

    • event: string | symbol
    • listener: EventListener

    Returns void

  • Listen for authentication/sign-in events (login, logout, etc).

    Parameters

    • callback: AuthCallback

      Function to call with new user instance.

    Returns () => void

    Function to remove the registered callback.

  • Register an event handler for a single event occurrence.

    Parameters

    • event: string | symbol
    • listener: EventListener

    Returns void

  • Register a new alias (username) → public key mapping on Holster.

    Parameters

    • alias: string
    • userPub: string
    • timeout: number = 5000

    Returns Promise<void>

  • Internal

    Reset holster.user() authentication state and clear cached user.

    Returns void

  • Attempt to restore a previously saved session from sessionStorage.

    Returns { error?: string; success: boolean; userPub?: string }

    Object indicating success, error, and userPub if restored.

  • Save credentials for the current session to sessionStorage, if available.

    Parameters

    • userInfo: { alias: string; pair: ISEAPair; userPub: string }

    Returns void

  • Register and authenticate a new user account.

    Parameters

    • username: string
    • password: string
    • Optionalpair: null | ISEAPair

    Returns Promise<SignUpResult>

  • Internal

    Internal: subscribe to Holster auth state changes and notify listeners. Since Holster doesn't have native auth events, we poll for changes.

    Returns void

  • Validate that a provided password meets minimum length requirements.

    Parameters

    • password: string

    Returns { error?: string; valid: boolean }

  • Validate a signup request's username, password, and/or cryptographic pair.

    Parameters

    • username: string
    • password: string
    • Optionalpair: null | ISEAPair

    Returns { error?: string; valid: boolean }