Main ShogunCore class - implements the IShogunCore interface

This is the primary entry point for the Shogun SDK, providing access to:

  • Decentralized database (GunInstance)
  • Authentication methods (traditional, WebAuthn, MetaMask)
  • Plugin system for extensibility
  • RxJS integration for reactive programming

2.0.0

Implements

Constructors

  • Initialize the Shogun SDK

    Parameters

    Returns ShogunCore

    Creates a new instance of ShogunCore with the provided configuration. Initializes all required components including storage, event emitter, GunInstance connection, and plugin system.

Properties

_gun: IGunInstance<any>
_user: null | IGunUserInstance<any, any, any, any> = null
currentAuthMethod?: AuthMethod
eventEmitter: EventEmitter
plugins: Map<string, ShogunPlugin> = ...
provider?: Provider
storage: ShogunStorage
API_VERSION: "v1.2.9c"

Accessors

  • get gun(): IGunInstance<any>

    Access to the Gun instance

    Returns IGunInstance<any>

    The Gun instance

  • get user(): null | IGunUserInstance<any, any, any, any>

    Access to the current user

    Returns null | IGunUserInstance<any, any, any, any>

    The current Gun user instance

Methods

  • Configure logging behavior for the Shogun SDK

    Parameters

    • config: LoggingConfig

      Logging configuration object containing:

      • level: The minimum log level to display (error, warn, info, debug, trace)
      • logToConsole: Whether to output logs to the console (default: true)
      • customLogger: Optional custom logger implementation
      • logTimestamps: Whether to include timestamps in logs (default: true)

    Returns void

    Updates the logging configuration for the SDK. Changes take effect immediately for all subsequent log operations.

  • Emits an event through the core's event emitter. Plugins should use this method to emit events instead of accessing the private eventEmitter directly.

    Parameters

    • eventName: string | symbol

      The name of the event to emit.

    • Optionaldata: any

      The data to pass with the event.

    Returns boolean

    Indicates if the event had listeners.

  • Get an authentication method plugin by type

    Parameters

    • type: AuthMethod

      The type of authentication method

    Returns unknown

    The authentication plugin or undefined if not available This is a more modern approach to accessing authentication methods

  • Get the current authentication method

    Returns undefined | AuthMethod

    The current authentication method or undefined if not set

  • Retrieve a registered plugin by name

    Type Parameters

    • T

      Type of the plugin or its public interface

    Parameters

    • name: string

      Name of the plugin

    Returns undefined | T

    The requested plugin or undefined if not found

  • Retrieve recent errors logged by the system

    Parameters

    • count: number = 10

      Number of errors to retrieve (default: 10)

    Returns ShogunError[]

    List of most recent errors

  • Check if a plugin is registered

    Parameters

    • name: string

      Name of the plugin to check

    Returns boolean

    true if the plugin is registered, false otherwise

  • Check if user is logged in

    Returns boolean

    True if user is logged in, false otherwise

    Verifies authentication status by checking GunInstance login state and presence of authentication credentials in storage

  • Authenticate user with username and password

    Parameters

    • username: string

      Username

    • password: string

      User password

    Returns Promise<AuthResult>

    Promise with authentication result

    Attempts to log in user with provided credentials. Emits login event on success.

  • Perform user logout

    Returns void

    Logs out the current user from GunInstance and emits logout event. If user is not authenticated, the logout operation is ignored.

  • Remove an event listener

    Parameters

    • eventName: string | symbol

      The name of the event to stop listening for

    • listener: (data: unknown) => void

      The callback function to remove

    Returns this

    Returns this instance for method chaining

  • Add an event listener

    Parameters

    • eventName: string | symbol

      The name of the event to listen for

    • listener: (data: unknown) => void

      The callback function to execute when the event is emitted

    Returns this

    Returns this instance for method chaining

  • Add a one-time event listener

    Parameters

    • eventName: string | symbol

      The name of the event to listen for

    • listener: (data: unknown) => void

      The callback function to execute when the event is emitted

    Returns this

    Returns this instance for method chaining

  • Register a new plugin with the SDK

    Parameters

    Returns void

    Error if a plugin with the same name is already registered

  • Private

    Register built-in plugins based on configuration

    Parameters

    Returns void

  • Remove all listeners for a specific event or all events

    Parameters

    • OptionaleventName: string | symbol

      Optional. The name of the event to remove listeners for. If not provided, all listeners for all events are removed.

    Returns this

    Returns this instance for method chaining

  • Set the current authentication method This is used by plugins to indicate which authentication method was used

    Parameters

    Returns void

  • Register a new user with provided credentials

    Parameters

    • username: string

      Username

    • password: string

      Password

    • OptionalpasswordConfirmation: string

      Password confirmation

    Returns Promise<SignUpResult>

    Registration result

    Creates a new user account with the provided credentials. Validates password requirements and emits signup event on success.

  • Unregister a plugin from the SDK

    Parameters

    • pluginName: string

      Name of the plugin to unregister

    Returns void