Skip to main content

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>
}>
folder
string
required
Path to the folder where authentication files will be stored
state
AuthenticationState
The authentication state object containing credentials and keys
saveCreds
() => Promise<void>
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
store
SignalKeyStore
required
The base signal key store to add caching to
logger
ILogger
Optional logger for trace events
cache
CacheStore
Optional custom cache store (defaults to NodeCache with 5-minute TTL)
return
SignalKeyStore
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
state
SignalKeyStore
required
The key store to add transaction capability to
logger
ILogger
required
Logger for transaction events
options
TransactionCapabilityOptions
required
Transaction configuration options
return
SignalKeyStoreWithTransaction
Enhanced key store with transaction support
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
return
AuthenticationCreds
Newly generated authentication credentials
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

Build docs developers (and LLMs) love