Class that manages Ethereum wallet functionality including:

  • Wallet creation and derivation
  • Balance checking and transactions
  • Importing/exporting wallets
  • Encrypted storage and backup

Hierarchy

  • EventEmitter
    • WalletManager

Constructors

  • Creates a new WalletManager instance

    Parameters

    • gun: any

      Raw Gun instance

    • storage: ShogunStorage

      Storage interface for local persistence

    • Optionalconfig: Partial<WalletConfig>

      Additional configuration options

    Returns WalletManager

Properties

balanceCache: Map<string, BalanceCache> = ...
config: WalletConfig
gun: any
mainWallet: null | Wallet = null
pendingTransactions: Map<string, TransactionResponse> = ...
storage: ShogunStorage
transactionMonitoringInterval: null | Timeout = null
walletPaths: { [address: string]: WalletPath } = {}

Methods

  • Check status of pending transactions

    Returns Promise<void>

  • Returns void

  • Crea e carica un wallet con un percorso specifico

    Parameters

    • path: string

      Percorso di derivazione

    Returns Promise<any>

    Informazioni sul wallet

  • Decrypt sensitive text encrypted with SEA

    Parameters

    • encryptedText: string

      Encrypted text

    Returns Promise<null | string>

    Decrypted text

  • Private

    Derives a private wallet from a mnemonic and derivation path

    Parameters

    • mnemonic: string

      The BIP-39 mnemonic phrase

    • path: string

      The derivation path

    Returns HDNodeWallet

    A derived HDNodeWallet instance

  • Deriva un wallet da un percorso derivazione

    Parameters

    • path: string

      Percorso di derivazione BIP-44 (es: m/44'/60'/0'/0/0)

    Returns Promise<Wallet>

    Wallet derivato

  • Emits an event with arguments

    Parameters

    • event: EventType
    • Optionaldata: unknown

    Returns boolean

  • Encrypt sensitive text using SEA

    Parameters

    • text: string

      Text to encrypt

    Returns Promise<string>

    Encrypted text

  • Esporta tutti i dati dell'utente in un unico file

    Parameters

    • password: string

      Password obbligatoria per cifrare i dati esportati

    Returns Promise<string>

    Un oggetto JSON contenente tutti i dati dell'utente

  • Export GunDB pair, optionally encrypted with a password

    Parameters

    • Optionalpassword: string

      Optional password to encrypt the exported data

    Returns Promise<string>

    Exported GunDB pair (SENSITIVE DATA!) SECURITY WARNING: This method exports your GunDB credentials which give access to your encrypted data. Never share this data with anyone, store it securely, and only use it for backup purposes.

  • Export the mnemonic phrase, optionally encrypting it with a password

    Parameters

    • Optionalpassword: string

      Optional password to encrypt the exported data

    Returns Promise<string>

    Exported mnemonic phrase (SENSITIVE DATA!) SECURITY WARNING: This method exports your mnemonic phrase which gives FULL ACCESS to all your wallets. Never share this data with anyone, store it securely, and only use it for backup purposes.

  • Export wallet data with enhanced security

    Parameters

    • options: WalletBackupOptions = {}

    Returns Promise<string>

  • Export wallet private keys, optionally encrypted with a password

    Parameters

    • Optionalpassword: string

      Optional password to encrypt the exported data

    Returns Promise<string>

    Exported wallet keys (SENSITIVE DATA!) SECURITY WARNING: This method exports your wallet private keys which give FULL ACCESS to your funds. Never share this data with anyone, store it securely, and only use it for backup purposes.

  • Generate a new BIP-39 standard mnemonic compatible with all wallets

    Returns string

    A new 12-word BIP-39 mnemonic phrase

  • Override of main function with fixes and improvements

    Parameters

    • input: string

    Returns string

  • Get wallet balance with caching to reduce RPC calls

    Parameters

    • wallet: Wallet

    Returns Promise<string>

  • Get the main wallet

    Returns Wallet

  • Parameters

    • wallet: Wallet

    Returns Promise<number>

  • Gets a configured JSON RPC provider instance

    Returns JsonRpcProvider

    An ethers.js JsonRpcProvider instance

  • Get addresses that would be derived from a mnemonic using BIP-44 standard This is useful to verify that wallets are correctly compatible with MetaMask and other wallets

    Parameters

    • mnemonic: string

      The BIP-39 mnemonic phrase

    • count: number = 5

      Number of addresses to derive

    Returns string[]

    An array of Ethereum addresses

  • Private

    Gets a unique identifier for the current user for storage purposes

    Returns string

    A string identifier based on user's public key or "guest"

  • Get user's master mnemonic, first checking GunDB then localStorage

    Returns Promise<null | string>

  • Ottiene il mnemonic dell'utente

    Returns Promise<null | string>

    Mnemonic dell'utente

  • Ottiene il saldo del wallet principale

    Returns Promise<string>

    Saldo formattato come stringa

  • Get wallet transaction history

    Returns Promise<any[]>

  • Ottiene tutti i wallet dell'utente

    Returns Promise<any[]>

    Array di wallet

  • Importa un backup completo

    Parameters

    • backupData: string

      JSON cifrato contenente tutti i dati dell'utente

    • password: string

      Password per decifrare il backup

    • options: { importGunPair?: boolean; importMnemonic?: boolean; importWallets?: boolean } = ...

      Opzioni di importazione (quali dati importare)

    Returns Promise<
        {
            gunPairImported?: boolean;
            mnemonicImported?: boolean;
            success: boolean;
            walletsImported?: number;
        },
    >

    Un oggetto con il risultato dell'importazione

  • Importa un pair di Gun

    Parameters

    • pairData: string

      JSON contenente il pair di Gun o JSON cifrato

    • Optionalpassword: string

      Password opzionale per decifrare i dati se cifrati

    Returns Promise<boolean>

    true se l'importazione è riuscita

  • Importa una frase mnemonica

    Parameters

    • mnemonicData: string

      La mnemonica o il JSON cifrato da importare

    • Optionalpassword: string

      Password opzionale per decifrare la mnemonica se cifrata

    Returns Promise<boolean>

    true se l'importazione è riuscita

  • Import wallet data with validation

    Parameters

    • data: string
    • options: WalletImportOptions = {}

    Returns Promise<number>

  • Importa le chiavi private dei wallet

    Parameters

    • walletsData: string

      JSON contenente i dati dei wallet o JSON cifrato

    • Optionalpassword: string

      Password opzionale per decifrare i dati se cifrati

    Returns Promise<number>

    Il numero di wallet importati con successo

  • Initializes wallet paths from both GunDB and localStorage Call this method explicitly when needed

    Returns Promise<void>

    If there's an error during wallet path initialization

  • Private

    Initialize wallet paths synchronously with basic setup

    Returns void

  • Invalidate balance cache for an address

    Parameters

    • address: string

    Returns void

  • Verifica se l'utente è loggato

    Returns boolean

    true se l'utente è loggato, false altrimenti

  • Private

    Verifica se l'utente è autenticato

    Returns boolean

    true se l'utente è autenticato

  • Private

    Loads wallet paths from GunDB

    Returns Promise<void>

  • Private

    Loads wallet paths from localStorage as backup

    Returns void

  • Removes an event listener

    Parameters

    • event: EventType
    • listener: (data: unknown) => void

    Returns void

  • Registers an event listener

    Parameters

    • event: EventType
    • listener: (data: unknown) => void

    Returns void

  • Registers a one-time event listener

    Parameters

    • event: EventType
    • listener: (data: unknown) => void

    Returns void

  • Removes all listeners for an event or all events

    Parameters

    • Optionalevent: EventType

    Returns void

  • Reset main wallet Useful when we want to force wallet regeneration

    Returns void

  • Salva una transazione pendente

    Parameters

    • tx: any

      Transazione da salvare

    Returns Promise<void>

  • Save user's master mnemonic to both GunDB and localStorage

    Parameters

    • mnemonic: string

    Returns Promise<void>

  • Salva il percorso di derivazione di un wallet

    Parameters

    • address: string

      Indirizzo del wallet

    • path: string

      Percorso di derivazione

    Returns Promise<void>

  • Private

    Saves wallet paths to localStorage for backup

    Returns void

  • Parameters

    • wallet: Wallet
    • toAddress: string
    • value: string
    • options: TransactionOptions = {}

    Returns Promise<string>

  • Update the balance cache TTL

    Parameters

    • ttlMs: number

      Time-to-live in milliseconds

    Returns void

  • Sets the RPC URL used for Ethereum network connections

    Parameters

    • rpcUrl: string

      The RPC provider URL to use

    Returns void

  • Setup transaction monitoring

    Returns void

  • Sign a message with a wallet

    Parameters

    • wallet: Wallet
    • message: string | Uint8Array<ArrayBufferLike>

    Returns Promise<string>

  • Sign a transaction

    Parameters

    • wallet: Wallet
    • toAddress: string
    • value: string
    • Optionalprovider: JsonRpcProvider

    Returns Promise<string>

  • Verify a signature

    Parameters

    • message: string | Uint8Array<ArrayBufferLike>
    • signature: string

    Returns string