Overview
wacore is the core WhatsApp protocol implementation for whatsapp-rust. It’s designed to be platform-agnostic with no runtime dependencies on Tokio or specific databases, making it portable across different async runtimes and storage backends.
Philosophy
wacore contains all the core logic for:- Binary protocol encoding/decoding
- Cryptographic primitives (AES-GCM, Signal Protocol)
- IQ protocol types and specifications
- State management traits
- Message builders and parsers
whatsapp-rust crate integrates wacore with Tokio for async operations and Diesel for persistence.
Key Exports
Re-exported Crates
Derive Macros
EmptyNode- For protocol nodes with only a tag (no attributes)ProtocolNode- For protocol nodes with string attributesStringEnum- For enums with string representations
Framing
Core Modules
Protocol & Binary
Binary protocol
Type-safe protocol node builders and parsers
xml
XML utilities for protocol nodes
Cryptography
Signal Protocol
Signal Protocol implementation for E2E encryption
noise
Noise Protocol XX for handshake encryption
IQ Protocol
blocklist- Block/unblock contactschatstate- Typing indicators, presencecontacts- Contact synchronizationdirty- Dirty bit checkinggroups- Group management operationskeepalive- Connection keepalivemediaconn- Media server connectionsmex- Message Extension queriespassive- Passive IQ handlingprekeys- Prekey distributionprivacy- Privacy settingsprops- Server propertiesspam_report- Spam reportingtctoken- Temporary client tokensusync- User synchronization
Message Handling
messages
Message encryption and decryption
send
Message sending logic
download
Media download and decryption
upload
Media encryption and upload preparation
State Management
Device- Core device state structureDeviceCommand- State mutation commandstraits- Backend trait definitions (Backend,SessionStore, etc.)
Connection & Pairing
handshake
Noise Protocol handshake
pair
QR code pairing
pair_code
Phone number pairing
net
Network utilities
Specialized Features
appstate
App state synchronization (contacts, settings)
history_sync
Message history synchronization
usync
User device list synchronization
prekeys
Signal Protocol prekey generation
Utilities
client- Client context traitsib- Identity byte utilitiesproto_helpers- Protobuf conversion helpersreporting_token- Reporting token generationrequest- Request building utilitiesstanza- Common stanza builderstypes- Common type definitions (JID, events, messages)version- WhatsApp version constants
Submodule Packages
wacore is split into several workspace crates:wacore-binary
Location:wacore/binary
Binary protocol encoding/decoding using WhatsApp’s custom format.
jid::Jid- WhatsApp JID (Jabber ID) parsingnode::{Node, NodeRef, NodeValue}- Protocol node typesbuilder::NodeBuilder- Fluent node buildermarshal::*- Binary marshaling functionsattrs::AttrParser- Attribute parsing utilitiestoken- Token dictionary
wacore-libsignal
Location:wacore/libsignal
Signal Protocol implementation for end-to-end encryption.
core- Core session cipher logiccrypto- Cryptographic primitives (HKDF, HMAC, AES)protocol- Protocol message typesstore- Store trait definitions
wacore-noise
Location:wacore/noise
Noise Protocol XX implementation for handshake encryption.
NoiseState- Generic Noise XX state machineNoiseHandshake- WhatsApp-specific handshake wrapperHandshakeUtils- Protocol message building/parsingframing- WebSocket frame encodingbuild_edge_routing_preintro- Edge routing helper
wacore-appstate
Location:wacore/appstate
App state synchronization for contacts, settings, and metadata.
process_snapshot- Process full state snapshotsprocess_patch- Apply incremental patchesMutation- State mutation recordsLTHash- LTHash implementation for integrityexpand_app_state_keys- Key derivation
wacore-derive
Location:wacore/derive
Procedural macros for protocol node generation.
Usage in Main Library
The mainwhatsapp-rust crate uses wacore modules throughout:
Design Principles
Platform-Agnostic
No dependencies on:- Tokio or any async runtime
- Specific database implementations
- File system operations
- Runtime: Tokio (current), async-std, smol, etc.
- Storage: SQLite (current), PostgreSQL, in-memory, etc.
- Transport: WebSocket (current), custom protocols
Type Safety
Strong typing throughout:Jidfor WhatsApp identifiersNodefor protocol messages- Validated newtypes (e.g.,
GroupSubjectwith length limits) - Enum variants with
StringEnumfor protocol values
Zero-Copy Where Possible
NodeReffor borrowed node parsingAttrParserReffor attribute iterationmarshal_reffor encoding without cloning