Wallet Manager API
The BrowserWalletManager is a singleton class that handles all wallet operations with browser-based encryption.
Location: packages/ui/src/lib/browserWallet.ts
BrowserWalletManager
Getting the Instance
import { getWalletManager } from '../lib/browserWallet'
const manager = getWalletManager()The manager is a singleton — all components share the same instance.
Methods
unlock(password)
async unlock(password: string): Promise<Wallet[]>Decrypts the wallet vault and loads all wallets into memory. Stores the password for later operations.
lock()
lock(): voidClears all in-memory keypairs and the stored password. The encrypted vault in localStorage remains intact.
getPassword()
getPassword(): string | nullReturns the vault password if currently unlocked, or null if locked.
generateWallet(name, type, password)
async generateWallet(name: string, type: WalletType, password: string): Promise<Wallet>Generates a new random Solana keypair, adds it to the vault, and re-encrypts.
generateWallets(count, namePrefix, type, password)
async generateWallets(count: number, namePrefix: string, type: WalletType, password: string): Promise<Wallet[]>Generates multiple wallets at once. Names are suffixed with index: {prefix}1, {prefix}2, etc.
removeWallets(walletIds, password)
async removeWallets(walletIds: string[], password: string): Promise<void>Removes wallets by ID from the vault and re-encrypts. Throws if no matching wallets found.
getKeypairs(walletIds, password)
async getKeypairs(walletIds: string[], password: string): Promise<Keypair[]>Returns decrypted Keypair objects for the specified wallet IDs.
getAllKeypairs()
getAllKeypairs(): Map<string, Keypair>Returns all currently loaded keypairs (only available while unlocked).
Wallet Type
interface Wallet {
id: string // wallet_{first8CharsOfPublicKey}
name: string // User-assigned name
type: WalletType // 'treasury' | 'sniper' | 'burner'
address: string // Base58 public key
}
type WalletType = 'treasury' | 'sniper' | 'burner'Cross-Tab Sync
After any mutation (generate, remove, rename), the manager broadcasts a state change event:
broadcastWalletStateChange()
// Dispatches a custom event that all useSecureWallet hook instances listen toAll tabs/components automatically sync via syncStateFromManager().
Important Notes
- Wallet IDs are deterministic:
wallet_{publicKey.slice(0, 8)} - The vault uses Argon2 for key derivation and AES-GCM for encryption
- The
keypairsMap in memory is the only place unencrypted keys exist - Always check
isLockedbefore attempting operations that need keypairs