Authentication State
useMultiFileAuthState
Stores the full authentication state in a multi-file folder structure. More efficient than single-file storage.
function useMultiFileAuthState (
folder : string
) : Promise <{
state : AuthenticationState
saveCreds : () => Promise < void >
}>
Path to the folder where authentication files will be stored
The authentication state object containing credentials and keys Authentication credentials including identity keys and registration ID
Signal protocol key store for managing pre-keys, sessions, and app state
Function to save the current credentials to disk
This implementation is intended for development and bot use cases. For production applications, implement a custom auth state using a proper SQL or NoSQL database.
Example:
const { state , saveCreds } = await useMultiFileAuthState ( './auth_info' )
const sock = makeWASocket ({
auth: state
})
// Save credentials whenever they update
sock . ev . on ( 'creds.update' , saveCreds )
Signal Store Utilities
makeCacheableSignalKeyStore
Adds in-memory caching capability to a SignalKeyStore for improved performance.
function makeCacheableSignalKeyStore (
store : SignalKeyStore ,
logger ?: ILogger ,
cache ?: CacheStore
) : SignalKeyStore
The base signal key store to add caching to
Optional logger for trace events
Optional custom cache store (defaults to NodeCache with 5-minute TTL)
A cached version of the signal key store with the same interface
Features:
Automatic cache management with configurable TTL (default: 5 minutes)
Mutex-based protection for cache operations
Falls back to underlying store for cache misses
Supports all standard SignalKeyStore operations
Example:
const { state } = await useMultiFileAuthState ( './auth_info' )
const cachedStore = makeCacheableSignalKeyStore (
state . keys ,
logger
)
// Use cachedStore for faster key lookups
const preKeys = await cachedStore . get ( 'pre-key' , [ '1' , '2' , '3' ])
addTransactionCapability
Adds database-like transaction capability to the SignalKeyStore using AsyncLocalStorage.
function addTransactionCapability (
state : SignalKeyStore ,
logger : ILogger ,
options : TransactionCapabilityOptions
) : SignalKeyStoreWithTransaction
The key store to add transaction capability to
Logger for transaction events
options
TransactionCapabilityOptions
required
Transaction configuration options Maximum number of retry attempts for commit operations
Delay in milliseconds between retry attempts
return
SignalKeyStoreWithTransaction
Enhanced key store with transaction support Execute operations within a transaction context transaction < T >( work : () => Promise < T > , key : string ): Promise < T >
Check if currently executing within a transaction isInTransaction (): boolean
Features:
Automatic transaction context management with AsyncLocalStorage
Nested transaction support (reuses parent context)
Commit retry logic with configurable attempts
Concurrent operation queuing per signal data type
Automatic rollback on errors
Example:
const txStore = addTransactionCapability (
state . keys ,
logger ,
{ maxCommitRetries: 3 , delayBetweenTriesMs: 200 }
)
await txStore . transaction ( async () => {
// All operations within this block are batched
await txStore . set ({ 'pre-key' : newPreKeys })
await txStore . set ({ 'session' : sessions })
// Committed atomically at the end
}, 'update-keys' )
Credential Management
initAuthCreds
Initializes a new set of authentication credentials.
function initAuthCreds () : AuthenticationCreds
Newly generated authentication credentials Noise protocol key pair for connection encryption
Ephemeral key pair for QR code pairing
Signed identity key for Signal protocol
Initial signed pre-key with signature
Unique registration identifier
Advanced secret key (base64 encoded)
Next pre-key ID to generate (starts at 1)
First pre-key ID not yet uploaded to server
Whether the credentials have been registered (starts false)
Example:
// Initialize new credentials
const creds = initAuthCreds ()
// Use with custom auth state implementation
const authState : AuthenticationState = {
creds ,
keys: myCustomKeyStore
}
Signal Utilities Signal protocol helpers for E2E encryption
Socket Configuration Configure and initialize WhatsApp socket connections