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: ShogunEventEmitter
plugins: Map<string, ShogunPlugin> = ...
provider?: Provider
storage: ShogunStorage
wallets: undefined | Wallets
API_VERSION: "^1.6.6"

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

  • Changes the username for the currently authenticated user

    Parameters

    • newUsername: string

      New username to set

    Returns Promise<
        {
            error?: string;
            newUsername?: string;
            oldUsername?: string;
            success: boolean;
        },
    >

    Promise resolving to the operation result

  • Check plugin compatibility with current ShogunCore version

    Returns {
        compatible: { name: string; version: string }[];
        incompatible: { name: string; reason: string; version: string }[];
        unknown: { name: string; version: string }[];
    }

    Object with compatibility information

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

    Type Parameters

    • K extends keyof ShogunEventMap

    Parameters

    • eventName: K

      The name of the event to emit.

    • Optionaldata: ShogunEventMap[K] extends void ? never : ShogunEventMap[K]

      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
        | undefined
        | ShogunPlugin
        | {
            login: (username: string, password: string) => Promise<AuthResult>;
            signUp: (
                username: string,
                password: string,
                confirm?: string,
            ) => Promise<SignUpResult>;
        }

    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

  • Gets the current user information

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

    Current user object or null

  • Returns boolean

  • Retrieve a registered plugin by name

    Type Parameters

    Parameters

    • name: string

      Name of the plugin

    Returns undefined | T

    The requested plugin or undefined if not found

  • Get the total number of registered plugins

    Returns number

    Number of registered plugins

  • Get information about all registered plugins

    Returns {
        category?: PluginCategory;
        description?: string;
        name: string;
        version: string;
    }[]

    Array of plugin information objects

  • Check if all plugins are properly initialized

    Returns Record<string, { error?: string; initialized: boolean }>

    Object with initialization status for each plugin

  • Get comprehensive debug information about the plugin system

    Returns {
        compatibility: {
            compatible: { name: string; version: string }[];
            incompatible: { name: string; reason: string; version: string }[];
            unknown: { name: string; version: string }[];
        };
        initializationStatus: Record<
            string,
            { error?: string; initialized: boolean },
        >;
        plugins: {
            category?: PluginCategory;
            description?: string;
            error?: string;
            initialized: boolean;
            name: string;
            version: string;
        }[];
        shogunCoreVersion: string;
        totalPlugins: number;
        validation: {
            failedPlugins: string[];
            initializedPlugins: number;
            totalPlugins: number;
            warnings: string[];
        };
    }

    Complete plugin system debug information

  • 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

  • Initialize the Shogun SDK asynchronously This method handles initialization tasks that require async operations

    Returns Promise<void>

  • 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

    • Optionalpair: null | ISEAPair

    Returns Promise<AuthResult>

    Promise with authentication result

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

  • Login with GunDB pair directly

    Parameters

    • pair: ISEAPair

      GunDB SEA pair for authentication

    Returns Promise<AuthResult>

    Promise with authentication result

    Authenticates user using a GunDB pair directly. 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

    Type Parameters

    • K extends keyof ShogunEventMap

    Parameters

    • eventName: K

      The name of the event to stop listening for

    • listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void

      The callback function to remove

    Returns this

    Returns this instance for method chaining

  • Add an event listener

    Type Parameters

    • K extends keyof ShogunEventMap

    Parameters

    • eventName: K

      The name of the event to listen for

    • listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => 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

    Type Parameters

    • K extends keyof ShogunEventMap

    Parameters

    • eventName: K

      The name of the event to listen for

    • listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void

      The callback function to execute when the event is emitted

    Returns this

    Returns this instance for method chaining

  • Registers a plugin with the Shogun SDK

    Parameters

    Returns void

    Error if a plugin with the same name is already registered

  • Internal method to register a plugin

    Parameters

    Returns void

  • Attempt to reinitialize failed plugins

    Returns { failed: { error: string; name: string }[]; success: string[] }

    Object with reinitialization results

  • 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

  • Saves the current user credentials to storage

    Parameters

    • credentials: any

    Returns Promise<void>

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

    Parameters

    Returns void

  • Private

    Setup event forwarding from GunInstance to main event emitter

    Returns void

  • Register a new user with provided credentials

    Parameters

    • username: string

      Username

    • password: string = ""

      Password

    • email: string = ""
    • Optionalpair: null | ISEAPair

      Pair of keys

    Returns Promise<SignUpResult>

    Registration result

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

  • Unregisters a plugin from the Shogun SDK

    Parameters

    • pluginName: string

      Name of the plugin to unregister

    Returns void

  • Internal method to unregister a plugin

    Parameters

    • name: string

      Name of the plugin to unregister

    Returns boolean

  • Validate plugin system integrity

    Returns {
        failedPlugins: string[];
        initializedPlugins: number;
        totalPlugins: number;
        warnings: string[];
    }

    Object with validation results