Main ShogunCore class - implements the IShogunCore interface

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

  • Decentralized database (GunDB)
  • Authentication methods (traditional, WebAuthn, MetaMask)
  • Plugin system for extensibility
  • DID (Decentralized Identity) management
  • 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, GunDB connection, and plugin system.

Properties

SDK configuration

eventEmitter: EventEmitter

Event emitter for SDK events

gun: IGunInstance<any>

Gun database instance

gundb: GunDB

GunDB wrapper

plugins: Map<string, ShogunPlugin> = ...

Plugin registry

provider?: Provider

Ethereum provider

RxJS integration

storage: ShogunStorage

Storage implementation

user: null | IGunUserInstance<any, any, any, any>

Gun user instance

API_VERSION: "2.0.0"

Current API version - used for deprecation warnings and migration guidance

Methods

  • Compute derived values from gun data

    Type Parameters

    • T
    • R

    Parameters

    • sources: (string | Observable<any>)[]

      Array of paths or observables to compute from

    • computeFn: (...values: T[]) => R

      Function that computes a new value from the sources

    Returns Observable<R>

    Observable of computed values

  • 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.

  • Create a new user with GunDB

    Parameters

    • username: string

      Username

    • password: string

      Password

    Returns Promise<{ error?: string; success: boolean; userPub?: string }>

    Promise with success status and user public key

    Creates a new user in GunDB with error handling

  • 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

  • Private

    Ensure the current user has a DID associated, creating one if needed

    Parameters

    • Optionaloptions: DIDCreateOptions

      Optional configuration for DID creation including:

      • network: The network to use (default: 'main')
      • controller: The controller of the DID (default: user's public key)
      • services: Array of service definitions to add to the DID document

    Returns Promise<null | string>

    The DID identifier string or null if operation fails

    Checks if the authenticated user already has a DID. If not, creates a new one. If the user already has a DID and options are provided, updates the DID document accordingly.

  • Retrieves data from a Gun node at the specified path

    Parameters

    • path: string

      The path to the Gun node

    Returns Promise<any>

    Promise that resolves with the node data or rejects with an error

  • Get an authentication method plugin by type

    Parameters

    • type: "webauthn" | "password" | "metamask"

      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

  • 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

  • Get the currently configured RPC URL

    Returns null | string

    The current provider URL or null if not set

  • 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 GunDB 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 GunDB and emits logout event. If user is not authenticated, the logout operation is ignored.

  • Match data based on Gun's '.map()' and convert to Observable

    Type Parameters

    • T

    Parameters

    • path: any

      Path to the collection

    • OptionalmatchFn: (data: any) => boolean

      Optional function to filter results

    Returns Observable<T[]>

    Observable array of matched items

  • Observe a Gun node for changes

    Type Parameters

    • T

    Parameters

    • path: string

      Path to observe (can be a string or a Gun chain)

    Returns Observable<T>

    Observable that emits whenever the node changes

  • Observe user data

    Type Parameters

    • T

    Parameters

    • path: string

      Path to observe in user space

    Returns Observable<T>

    Observable that emits whenever the user data changes

  • 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

  • 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

  • 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

  • Get data once and return as Observable

    Type Parameters

    • T

    Parameters

    • path: any

      Path to get data from

    Returns Observable<T>

    Observable that emits the data once

  • Stores data in Gun at the root level

    Parameters

    • data: Record<string, any>

      The data to store

    Returns Promise<any>

    Promise that resolves when data is stored or rejects with an error

  • 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

  • Put data and return an Observable

    Type Parameters

    • T

    Parameters

    • path: any

      Path where to put the data

    • data: T

      Data to put

    Returns Observable<T>

    Observable that completes when the put is acknowledged

  • Set data on a node and return an Observable

    Type Parameters

    • T

    Parameters

    • path: any

      Path to the collection

    • data: T

      Data to set

    Returns Observable<T>

    Observable that completes when the set is acknowledged

  • User put data and return an Observable (for authenticated users)

    Type Parameters

    • T

    Parameters

    • path: string

      Path where to put the data

    • data: T

      Data to put

    Returns Observable<T>

    Observable that completes when the put is acknowledged

  • Set the RPC URL used for Ethereum network connections

    Parameters

    • rpcUrl: string

      The RPC provider URL to use

    Returns boolean

    True if the URL was successfully set

  • 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

  • Retrieves data from the authenticated user's space at the specified path

    Parameters

    • path: string

      The path to the user data

    Returns Promise<any>

    Promise that resolves with the user data or rejects with an error

  • Stores data in the authenticated user's space

    Parameters

    • data: Record<string, any>

      The data to store in user space

    Returns Promise<any>

    Promise that resolves when data is stored or rejects with an error