Constructors

  • Parameters

    • gun: IGunInstance<any>
    • appScope: string = "shogun"

    Returns GunInstance

Properties

_rxjs?: GunRxJS
crypto: crypto
eventEmitter: EventEmitter
gun: IGunInstance<any>
node: IGunChain<any, IGunInstance<any>, IGunInstance<any>, string>
onAuthCallbacks: AuthCallback[] = []
rateLimitStorage: Map<string, RateLimitEntry> = ...
sea: SEA
user: null | IGunUserInstance<any, any, any, any> = null
Errors: GunErrors = GunErrors

Methods

  • Adds a new peer to the network

    Parameters

    • peer: string

      URL of the peer to add

    Returns void

  • Authenticates user after creation

    Parameters

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

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

  • Builds the full path for frozen data

    Parameters

    • hash: string
    • Optionaloptions: { namespace?: string; path?: string }

    Returns string

  • Builds login result object

    Parameters

    • username: string
    • userPub: string

    Returns AuthResult

  • 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

  • Checks rate limiting for login attempts

    Parameters

    • username: string
    • operation: "login" | "signup"

    Returns { allowed: boolean; error?: string }

  • Checks if user exists by attempting authentication

    Parameters

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

    Returns Promise<UserExistenceResult>

  • Parameters

    • username: string

    Returns Promise<any>

  • Debug method: Clears all Gun-related data from local and session storage This is useful for debugging and testing purposes

    Returns void

    This will completely reset the user's local Gun data

  • Clear session

    Returns void

  • Creates a frozen space entry for immutable data

    Parameters

    • data: any

      Data to freeze

    • Optionaloptions: {
          description?: string;
          metadata?: Record<string, any>;
          namespace?: string;
          path?: string;
      }

      Optional configuration

    Returns Promise<{ data: any; fullPath: string; hash: string }>

    Promise resolving to the frozen data hash

  • Creates lookup strategies array

    Parameters

    • normalizedUsername: string
    • frozenKey: string
    • alternateKey: string

    Returns () => Promise<null | UsernameLookupResult>[]

  • Creates a new user in Gun

    Parameters

    • username: string
    • password: string

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

  • Creates a new user in Gun with pair-based authentication (for Web3/plugins)

    Parameters

    • username: string
    • pair: ISEAPair

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

  • Decrypts session data from storage

    Parameters

    • encryptedData: string

    Returns Promise<any>

  • Derive cryptographic keys from password and optional extras Supports multiple key derivation algorithms: P-256, secp256k1 (Bitcoin), secp256k1 (Ethereum)

    Parameters

    • password: string | number

      Password or seed for key derivation

    • Optionalextra: string | string[]

      Additional entropy (string or array of strings)

    • Optionaloptions: DeriveOptions

      Derivation options to specify which key types to generate

    Returns Promise<
        {
            p256?: { epriv: string; epub: string; priv: string; pub: string };
            secp256k1Bitcoin?: { address: string; priv: string; pub: string };
            secp256k1Ethereum?: { address: string; priv: string; pub: string };
        },
    >

    Promise resolving to derived keys object

  • Derive all supported key types

    Parameters

    • password: string | number

      Password for key derivation

    • Optionalextra: string | string[]

      Additional entropy

    Returns Promise<
        {
            p256: { epriv: string; epub: string; priv: string; pub: string };
            secp256k1Bitcoin: { address: string; priv: string; pub: string };
            secp256k1Ethereum: { address: string; priv: string; pub: string };
        },
    >

    Promise resolving to all key types

  • Derive Bitcoin secp256k1 keys with P2PKH address

    Parameters

    • password: string | number

      Password for key derivation

    • Optionalextra: string | string[]

      Additional entropy

    Returns Promise<{ address: string; priv: string; pub: string }>

    Promise resolving to Bitcoin keys and address

  • Derive Ethereum secp256k1 keys with Keccak256 address

    Parameters

    • password: string | number

      Password for key derivation

    • Optionalextra: string | string[]

      Additional entropy

    Returns Promise<{ address: string; priv: string; pub: string }>

    Promise resolving to Ethereum keys and address

  • Derive P-256 keys (default Gun.SEA behavior)

    Parameters

    • password: string | number

      Password for key derivation

    • Optionalextra: string | string[]

      Additional entropy

    Returns Promise<{ epriv: string; epub: string; priv: string; pub: string }>

    Promise resolving to P-256 keys

  • Emits an event

    Parameters

    • event: string | symbol

      Event name

    • Optionaldata: any

      Event data

    Returns boolean

  • Private

    Emits a Gun data event

    Parameters

    • eventType: "gun:put" | "gun:get" | "gun:set" | "gun:remove"
    • path: string
    • Optionaldata: any
    • success: boolean = true
    • Optionalerror: string

    Returns void

  • Private

    Emits a Gun peer event

    Parameters

    • action: "add" | "remove" | "connect" | "disconnect"
    • peer: string

    Returns void

  • Encrypts session data before storage

    Parameters

    • data: any

    Returns Promise<string>

  • Recovers password hint using security question answers

    Parameters

    • username: string

      Username

    • securityAnswers: string[]

      Array of answers to security questions

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

    Promise resolving with the password hint

  • Generates hash for frozen data

    Parameters

    • frozenData: any

    Returns Promise<null | string>

  • Gets a node at the specified path

    Parameters

    • path: string

      Path to the node

    Returns any

    Gun node

  • Gets the list of all configured peers (connected and disconnected)

    Returns string[]

    Array of peer URLs

  • Get app scope

    Returns string

  • Gets the list of currently connected peers

    Returns string[]

    Array of peer URLs

  • Gets the current user

    Returns null | UserInfo

    Current user object or null

  • Gets data at the specified path (one-time read)

    Parameters

    • path: string

      Path to get the data from

    Returns Promise<any>

    Promise resolving to the data

  • Retrieves data from frozen space

    Parameters

    • hash: string

      Hash of the frozen data

    • namespace: string = "default"

      Optional namespace

    • Optionalpath: string

      Optional custom path

    Returns Promise<any>

    Promise resolving to the frozen data

  • Gets the Gun instance

    Returns IGunInstance<any>

    Gun instance

  • Get password hint

    Returns null | string

  • Gets detailed information about all peers

    Returns { [peer: string]: { connected: boolean; status: string } }

    Object with peer information

  • Gets the current user instance

    Returns GunUser

    User instance

  • Gets user data from the specified path

    Parameters

    • path: string

      Path to get the data from (supports nested paths like "test/data/marco")

    Returns Promise<any>

    Promise that resolves with the data

  • Get username for the current user

    Returns null | string

  • Get user public key

    Returns null | string

  • Initialize the GunInstance asynchronously This method should be called after construction to perform async operations

    Parameters

    • appScope: string = "shogun"

    Returns Promise<void>

  • Check if user is authenticated

    Returns boolean

  • Checks if a user is currently logged in

    Returns boolean

    True if logged in

  • Leave user session

    Returns void

  • Load session from storage

    Returns any

  • Parameters

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

    Returns Promise<AuthResult>

  • Returns void

  • Strategy 3: Alternate key lookup

    Parameters

    • normalizedUsername: string
    • alternateKey: string

    Returns Promise<null | UsernameLookupResult>

  • Strategy 4: Comprehensive scan fallback

    Parameters

    • normalizedUsername: string
    • frozenKey: string
    • alternateKey: string

    Returns Promise<null | UsernameLookupResult>

  • Strategy 2: Direct frozen mapping lookup

    Parameters

    • normalizedUsername: string
    • frozenKey: string

    Returns Promise<null | UsernameLookupResult>

  • Strategy 1: Frozen space scan for immutable data

    Parameters

    • normalizedUsername: string

    Returns Promise<null | UsernameLookupResult>

  • Helper method to navigate to a nested path by splitting and chaining .get() calls

    Parameters

    • node: any

      Starting Gun node

    • path: string

      Path string (e.g., "test/data/marco")

    Returns any

    Gun node at the specified path

  • Normalizes username for consistent lookup

    Parameters

    • username: string

    Returns { alternateKey: string; frozenKey: string; normalizedUsername: string }

  • Parameters

    • pub: string

    Returns void

  • Removes an event listener

    Parameters

    • event: string | symbol

      Event name

    • listener: EventListener

      Event listener function

    Returns void

  • Adds an event listener

    Parameters

    • event: string | symbol

      Event name

    • listener: EventListener

      Event listener function

    Returns void

  • Registers an authentication callback

    Parameters

    • callback: AuthCallback

      Function to call on auth events

    Returns () => void

    Function to unsubscribe the callback

  • Adds a one-time event listener

    Parameters

    • event: string | symbol

      Event name

    • listener: EventListener

      Event listener function

    Returns void

  • Performs authentication with Gun

    Parameters

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

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

  • Prepares data for freezing with metadata

    Parameters

    • data: any
    • Optionaloptions: { description?: string; metadata?: Record<string, any> }

    Returns any

  • Processes lookup result to get complete user data

    Parameters

    • result: UsernameLookupResult
    • normalizedUsername: string

    Returns Promise<any>

  • Puts data at the specified path

    Parameters

    • path: string

      Path to store data

    • data: any

      Data to store

    Returns Promise<GunOperationResult>

    Promise resolving to operation result

  • Saves user data at the specified path

    Parameters

    • path: string

      Path to save the data (supports nested paths like "test/data/marco")

    • data: any

      Data to save

    Returns Promise<void>

    Promise that resolves when the data is saved

  • Recall user session

    Returns void

  • Reconnects to a specific peer

    Parameters

    • peer: string

      URL of the peer to reconnect

    Returns void

  • Removes data at the specified path

    Parameters

    • path: string

      Path to remove

    Returns Promise<GunOperationResult>

    Promise resolving to operation result

  • Removes a peer from the network

    Parameters

    • peer: string

      URL of the peer to remove

    Returns void

  • Clears all peers and optionally adds new ones

    Parameters

    • OptionalnewPeers: string[]

      Optional array of new peers to add

    Returns void

  • Reset rate limit

    Returns void

  • Resets rate limiting for successful authentication

    Parameters

    • username: string
    • operation: "login" | "signup"

    Returns void

  • Attempts to restore user session from local storage

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

    Promise resolving to session restoration result

  • Parameters

    • username: string
    • userPub: string
    • authResult: any

    Returns Promise<SignUpResult>

  • Accesses the RxJS module for reactive programming

    Returns GunRxJS

    GunRxJS instance

  • Sanitizes username to prevent path construction issues

    Parameters

    • username: string

      Raw username

    Returns string

    Sanitized username

  • Parameters

    • userInfo: { pair: null | ISEAPair; username: string; userPub: string }

    Returns void

  • Save session to storage

    Parameters

    • session: any

    Returns void

  • Sets data at the specified path

    Parameters

    • path: string

      Path to store data

    • data: any

      Data to store

    Returns Promise<GunOperationResult>

    Promise resolving to operation result

  • Set password hint

    Parameters

    • hint: string

    Returns void

  • Sets up security questions and password hint

    Parameters

    • username: string

      Username

    • password: string

      Current password

    • hint: string

      Password hint

    • securityQuestions: string[]

      Array of security questions

    • securityAnswers: string[]

      Array of answers to security questions

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

    Promise resolving with the operation result

  • Set user data

    Parameters

    • data: any

    Returns void

  • Set username for the current user

    Parameters

    • username: string

    Returns void

  • Signs up a new user using direct Gun authentication

    Parameters

    • username: string

      Username

    • password: string

      Password

    • Optionalpair: null | ISEAPair

      Optional SEA pair for Web3 login

    Returns Promise<SignUpResult>

    Promise resolving to signup result

  • Stores frozen data in Gun

    Parameters

    • frozenData: any
    • fullPath: string
    • hash: string

    Returns Promise<{ data: any; fullPath: string; hash: string }>

  • Returns void

  • Debug method: Tests Gun connectivity and returns status information This is useful for debugging connection issues

    Returns Promise<any>

  • Updates the user's alias (username) in Gun and saves the updated credentials

    Parameters

    • newAlias: string

      New alias/username to set

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

    Promise resolving to update result

  • Validates password strength according to security requirements

    Parameters

    • password: string

    Returns { error?: string; valid: boolean }

  • Validates signup credentials with enhanced security

    Parameters

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

    Returns { error?: string; valid: boolean }

  • Verifies if data matches a frozen space entry

    Parameters

    • data: any

      Data to verify

    • hash: string

      Expected hash

    • namespace: string = "default"

      Optional namespace

    • Optionalpath: string

      Optional custom path

    Returns Promise<{ error?: string; frozenData?: any; verified: boolean }>

    Promise resolving to verification result