Expand description
Pair code authentication for phone number linking.
This module provides an alternative to QR code pairing. Users enter an 8-character code on their phone instead of scanning a QR code.
§Usage
§Random Code (Default)
use whatsapp_rust::pair_code::PairCodeOptions;
let options = PairCodeOptions {
phone_number: "15551234567".to_string(),
..Default::default()
};
let code = client.pair_with_code(options).await?;
println!("Enter this code on your phone: {}", code);§Custom Pairing Code
You can specify your own 8-character code using Crockford Base32 alphabet
(characters: 123456789ABCDEFGHJKLMNPQRSTVWXYZ - excludes 0, I, O, U):
use whatsapp_rust::pair_code::PairCodeOptions;
let options = PairCodeOptions {
phone_number: "15551234567".to_string(),
custom_code: Some("MYCODE12".to_string()), // Must be exactly 8 valid chars
..Default::default()
};
let code = client.pair_with_code(options).await?;
assert_eq!(code, "MYCODE12");§Concurrent with QR Codes
Pair code and QR code run on the same connection, and whichever completes first wins — matching WA Web, which leaves its QR rotation running when the user switches to phone-number linking.
They are not, however, the same clock. A QR code is superseded every 20s and
the surface re-renders it; a pair code is read off a screen and typed into a
phone minutes later, so a QR rotation is not a reason to request a new
pair code. WA Web mints one per user action and regenerates it only on the
server’s refresh_code, on force_manual_refresh, or on its own expiry
timers. Client::pair_with_code enforces that: it refuses to supersede a
code that is still live, and Client::cancel_pair_code is the explicit
way to replace one.
Structs§
- Pair
Code Options - Options for pair code authentication.
Enums§
- Companion
Os - Canonical OS label for the pair-code
companion_platform_display. - Companion
WebClient Type - Web codes follow
WAWebCompanionRegClientUtils.DEVICE_PLATFORM. Android letters need server-side attestation, so they’re reachable only through explicit opt-in. - Pair
Code Error - Errors raised by wacore-side pair-code validation, key derivation, and
protocol-bundle building. The high-level crate wraps this in
whatsapp_rust::pair_code::PairErrorand adds an IQ-failure variant for the transport layer. - Pair
Code Rejection - How the server refused a pair-code request, as a matchable status.
- Pair
Error - Errors raised by the high-level pair-code flow.