useMultiFileAuthState
Stores the full authentication state in a single folder using separate files for each credential type. More efficient than single-file storage for production use.Parameters
Path to the folder where authentication files will be stored. The folder will be created if it doesn’t exist.
Returns
The authentication state object containing credentials and key storage methods.
Authentication credentials including noise keys, identity keys, and registration data.
Function to save the current credentials to disk.
Usage example
While efficient for bots and small applications, this is not recommended for production-level use. Consider implementing a custom auth state using a SQL or NoSQL database for better scalability.
makeCacheableSignalKeyStore
Adds in-memory caching capability to a SignalKeyStore to improve performance by reducing database queries.Parameters
The base signal key store to add caching to.
Optional logger instance for tracing cache events.
Optional custom cache store. If not provided, a default NodeCache instance with 5-minute TTL will be used.
Returns
ASignalKeyStore instance with caching capability that:
- Checks cache before querying the underlying store
- Automatically updates cache on writes
- Reduces database load for frequently accessed keys
Usage example
initAuthCreds
Initializes a new set of authentication credentials for a fresh WhatsApp connection.Returns
A new authentication credentials object containing:
Noise protocol key pair for encrypted communication.
Ephemeral key pair used during QR code pairing.
Signed identity key for the Signal protocol.
Signed pre-key for Signal protocol key exchange.
Random registration ID (0-16383).
Base64-encoded advanced encryption secret key.
Counter for the next pre-key ID (starts at 1).
ID of the first pre-key that hasn’t been uploaded.
Whether the credentials have been registered (starts as false).
Usage example
addTransactionCapability
Adds database-like transaction capability to a SignalKeyStore for atomic operations and improved consistency.Parameters
The base signal key store to add transaction support to.
Logger instance for transaction events.
Returns
ASignalKeyStoreWithTransaction that extends SignalKeyStore with:
transaction(work, key)- Execute work within a transactionisInTransaction()- Check if currently in a transaction context
Usage example
BufferJSON
Utility object for JSON serialization and deserialization of Buffer objects.Properties
JSON.stringify replacer function that converts Buffer objects to base64-encoded objects.
JSON.parse reviver function that converts base64-encoded objects back to Buffers.
Usage example
The BufferJSON utility is particularly useful when persisting authentication state to JSON files, as it handles the serialization of cryptographic keys and other binary data.
generateRegistrationId
Generates a random registration ID for WhatsApp authentication.Returns
A random number between 0 and 16383 (14-bit value) used as the registration ID.Usage example
Related types
AuthenticationState- Complete authentication state structureAuthenticationCreds- Credential data structureSignalKeyStore- Interface for storing Signal protocol keysSignalKeyStoreWithTransaction- Extended interface with transaction supportSignalDataTypeMap- Mapping of signal data types to their value types