Overview
TheLocalAuth class provides persistent authentication storage using the local filesystem. It automatically encrypts session data using AES-256-GCM encryption with your bot’s UUID as the encryption key, ensuring sensitive credentials are protected at rest.
Key Features
- Encrypted Storage: All session data is encrypted using AES-256-GCM
- File-based Persistence: Sessions stored as encrypted files in a dedicated directory
- Automatic Hashing: Keys are MD5-hashed for consistent filenames
- In-memory Cache: Reduces disk I/O with intelligent caching
- Zero Configuration: Works out of the box with minimal setup
LocalAuth is the default authentication strategy and is ideal for development, testing, and single-server deployments.
Constructor
new LocalAuth(uuid, directory)
Creates a new LocalAuth instance for managing bot authentication on the filesystem.
A valid UUID (v4) that uniquely identifies this bot instance. This UUID is used as the encryption key and as a subdirectory name.
The base directory where encrypted session files will be stored. Can be relative or absolute. A subdirectory named after the UUID will be created inside this directory.
Example
Throws
Error: If the provided UUID is not a valid UUID v4 format
Properties
uuid
The UUID associated with this authentication instance. This is the same UUID provided to the constructor.
Methods
init()
Initializes the authentication system by loading or creating credentials and setting up the key store.
Behavior
- Directory Creation: Creates the session directory if it doesn’t exist
- Credential Loading: Attempts to load existing credentials from disk
- New Session: If no credentials exist, generates new authentication credentials
- Key Store Setup: Initializes the Signal protocol key store for WhatsApp encryption
Returns
Example
This method is called automatically by the
Bot class during initialization. You rarely need to call it directly.save()
Persists the current authentication credentials to disk.
Behavior
- Validation: Ensures credentials have been loaded via
init() - Serialization: Converts credentials to JSON format
- Encryption: Encrypts the data using AES-256-GCM
- Persistence: Writes the encrypted data to disk
- Cache Update: Updates the in-memory cache
Throws
Error: If credentials haven’t been initialized (“Credentials not loaded.”)
Example
remove()
Deletes all authentication data from disk and clears the cache.
Behavior
- Directory Removal: Recursively deletes the entire session directory
- Cache Clearing: Clears the in-memory cache
- Force Delete: Uses
force: trueto ignore missing files
Example
Storage Details
Directory Structure
File Naming
- Each key (e.g., “creds”, “pre-key-1”, “session-2”) is MD5-hashed
- Files are stored with
.encextension - Example:
creds→5f4dcc3b5aa765d61d8327deb882cf99.enc
Encryption
- Algorithm
- Data Format
- Decryption
- Cipher: AES-256-GCM (Galois/Counter Mode)
- Key: Derived from the bot’s UUID
- Security: Authenticated encryption with associated data (AEAD)
Complete Example
Advantages
- Simplicity
- Security
- Performance
- No external dependencies
- Works out of the box
- Perfect for development
- Easy to backup (just copy directory)
Limitations
- Single Server Only: Cannot share sessions across multiple servers
- No Redundancy: If directory is deleted, session is lost
- Scaling: Each server instance needs its own session directory
- Backups: Manual backup process required
When to Use
- Use LocalAuth
- Use RedisAuth
- Use MongoAuth
✅ Development and testing
✅ Single-server production
✅ Simple deployments
✅ Personal bots
✅ Low-scale applications
✅ Single-server production
✅ Simple deployments
✅ Personal bots
✅ Low-scale applications
See Also
- RedisAuth - Redis-based authentication
- MongoAuth - MongoDB-based authentication
- Bot Class - Main bot class
- Authentication Guide - Authentication strategies overview