TcToken feature provides APIs for issuing and managing trusted contact privacy tokens (TC tokens). These tokens are used for privacy-gated operations like sending messages and fetching profile pictures.
The library also supports cstoken (client-side token / NCT) as a fallback when no TC token exists for a recipient. This matches WhatsApp Web’s MsgCreateFanoutStanza.js behavior.
Token timing (bucket duration and count) is configurable via server-side AB props, with sensible defaults matching WhatsApp Web.
Access
Access TC token operations through the client:Methods
issue_tokens
Issue privacy tokens for specified contacts.jids- Array of JIDs (should be LID JIDs) to issue tokens for
Vec<ReceivedTcToken>- List of received tokens
Issued tokens are automatically stored in the backend and used for subsequent operations like message sending and profile picture fetching. Tokens are also automatically issued after sending a message when the current bucket has expired (see automatic usage).
prune_expired
Remove expired tokens from storage.- Number of tokens deleted
By default, tokens expire after 28 days (4 buckets × 7 days). The server may override this via AB props. Expired tokens are also automatically pruned on connect. Call this method if you need to trigger pruning manually.The received token and the sender-side issuance bucket expire on independent cutoffs — a row is only pruned once both are stale, so recent sender-side rate-limit state survives an expired received token (and vice versa).
get
Get a stored token for a specific JID.jid- User portion of the JID (without domain)
Option<TcTokenEntry>- The stored token entry, if found
get_all_jids
Get all JIDs that have stored tokens.- List of JID user portions with stored tokens
Error handling
Each method returnsResult<T, TcTokenError>:
Iq— the server token request failed (timeout, server error, etc.)Store— token persistence failed
Types
ReceivedTcToken
Token received from the server.TcTokenEntry
Stored token entry.An entry with an empty
token is a byte-less placeholder — it records that a post-send issuance IQ succeeded before any real token was received from the contact. For a fresh placeholder, token_timestamp is set equal to sender_timestamp (there is no received epoch yet); since token is empty, the received-token side of the prune cutoff always treats the row as expired-or-absent regardless of that value, so pruning a placeholder depends only on whether sender_timestamp is still live. See Post-send issuance.TcTokenConfig
Runtime-configurable timing for token expiration, sourced from server AB props.Automatic usage
The library automatically includes privacy tokens in outgoing 1:1 message stanzas using a fallback chain that matches WhatsApp Web:- tctoken — used when
PRIVACY_TOKEN_ON_ALL_1_ON_1_MESSAGESis on and a stored, unexpired token exists for the recipient - cstoken — an independent HMAC-SHA256 fallback using the NCT salt and recipient LID, used when
NCT_TOKEN_SEND_ENABLEDis on and the tctoken above didn’t win (its prop is off, or no valid token is stored) — see AB prop gating for the full priority logic - No token — send without a token if neither is available (the server may return a 463 error)
USyncStatusProtocol/OutSpamTCTokenMixin/StartCall.js:
get_user_info— a per-recipient tctoken is attached to each queried<user>node in the usync IQ, so status/about for a privacy-restricted contact resolves instead of coming back hidden. Gated behindprofile_scraping_privacy_token_in_about_usync.send_spam_report— whenSpamReportRequest::from_jidis set, that contact’s tctoken is attached to the spam report IQ so the report is accepted for a privacy-restricted account. Gated behindenable_spam_report_iq_with_privacy_token. Group reports that only setgroup_jid/participant_jid(nofrom_jid) don’t get a token attached.- Outgoing 1:1 call offers (
voipfeature) — placing a call attaches the callee’s stored, unexpired tctoken as the offer’s leading<privacy>node, and issues a fresh token to the callee in the background after the offer sends. This mirrors WA Web’ssendTcTokeninStartCall.jsand prevents 463 nacks on later offers to a privacy-restricted contact. Unlike the other paths, it isn’t gated by any AB prop — issuance is rate-limited only by the same sender bucket that governs message reissuance (see Post-send issuance). Group-call initiation isn’t implemented yet.
AB prop gating
Token inclusion on message stanzas is gated by two independent server-side AB props, matching WhatsApp Web’sMsgCreateFanoutStanza.js (Re = R(te) ?? D(te, s)):
PRIVACY_TOKEN_ON_ALL_1_ON_1_MESSAGES— gates the tctoken only (R). When off, a stored, valid tctoken is never attached.NCT_TOKEN_SEND_ENABLED— gates the cstoken fallback independently (D). The cstoken is attached whenever this flag is on and the NCT salt/recipient LID are available — even when the tctoken prop above is off, or a valid tctoken exists but its prop is disabled. The cstoken is not nested behind the tctoken prop.
profile_scraping_privacy_token_in_about_usync, enable_spam_report_iq_with_privacy_token) — unrelated to the message-stanza props above, and with no cstoken fallback.
Outgoing call offers (voip feature) attach and issue tokens unconditionally — there is no AB prop gate for this path at all, matching WA Web’s StartCall.js.
Post-send issuance
After sending a 1:1 message, the library checks whether a new token should be issued for the recipient. If the sender-side bucket has rolled over since the last issuance, a background IQ request fires. On IQ success, the sender-side issuance timestamp is recorded unconditionally, matching WhatsApp Web’ssendTcToken in MsgJob.js, which persists tcTokenSenderTimestamp on success regardless of the response body — the real set privacy IQ response carries no token bytes, so the timestamp can’t be derived from an echoed token.
If no entry exists yet for the recipient, this creates a byte-less placeholder that carries only the sender timestamp. The placeholder is superseded by the contact’s first real token (see Incoming token notifications), regardless of the real token’s own timestamp.
Identity change reissuance
When a contact reinstalls WhatsApp and their identity key changes, the library automatically re-issues TC tokens so the contact retains a valid privacy token. This matches WhatsApp Web’ssendTcTokenWhenDeviceIdentityChange behavior.
The reissuance is triggered when an UntrustedIdentity error is encountered during message decryption from the sender’s primary device (device 0) — an identity change on a companion device does not trigger reissuance, matching WA Web. After handling the identity change (clearing the old identity and retrying decryption), the client spawns a background task that:
- Checks if a token was previously issued to the sender (via
sender_timestamp) - Verifies the token hasn’t expired on the sender side
- Re-issues the token using the original issuance timestamp to preserve the bucket window
Token reissuance is skipped for bot JIDs, status broadcast senders, and identity changes reported for non-primary (companion) devices. The operation is deduplicated via session locks to prevent concurrent reissuance for the same sender.
Incoming token notifications
When a contact sends you a privacy token, the library handles it automatically:- Parses the
<notification type="privacy_token">stanza - Resolves the sender to a LID for storage (using
sender_lidattribute or LID-PN cache) - Applies a timestamp monotonicity pre-filter — if the incoming token is older than a stored real token, storage and the presence re-subscribe are both skipped
- Stores the token in the backend, preserving any
sender_timestampalready recorded by the post-send issuance path - Re-subscribes presence for the sender to pick up the updated token
store_received_tc_token. This is what closes the cross-source race between this notification path and history-sync’s tc-token candidates: both call the same store method, so whichever call lands last can never clobber a fresher token, without needing a lock shared across the two paths.
A byte-less placeholder (written by post-send issuance before any real token has been received) is always replaced by the contact’s first real token, even if the placeholder’s own timestamp is newer — the newer-wins rule only blocks a stale write once a real token is on record.
Startup pruning
Expired tokens are automatically pruned when the client connects, matching WhatsApp Web’sPrivacyTokenJob.
Skipped recipients
Tokens are not sent to:- Your own JID
- Bot JIDs
- Status broadcast
- Pre-issuing tokens for a batch of contacts
- Debugging token-related issues
cstoken (NCT fallback)
When no valid TC token exists for a recipient, the library falls back to a cstoken (client-side token). This is computed using an NCT salt that is provisioned by the server via app state sync.How it works
- The server provides an NCT salt through the
nct_salt_syncapp state mutation (or via history sync during initial pairing) - The salt is stored in the
Devicestruct asnct_salt - When sending a message where the tctoken doesn’t win — either
PRIVACY_TOKEN_ON_ALL_1_ON_1_MESSAGESis off, or no valid TC token is stored — andNCT_TOKEN_SEND_ENABLEDis on, the library computesHMAC-SHA256(nct_salt, recipient_lid)and includes it as a<cstoken>stanza child (see AB prop gating for the full priority logic)
Wire format
NCT salt provisioning
The NCT salt is delivered through two channels:- App state sync — The
nct_salt_syncmutation in theRegularHighsyncd collection sets or removes the salt. This is the authoritative source. - History sync — During initial pairing, the salt may be included in the history sync payload. This is a backfill-only source and won’t overwrite a salt already set via app state sync.
The cstoken fallback is fully automatic. You don’t need to manage the NCT salt or compute tokens manually. The library handles salt storage, LID resolution, and token computation transparently during message sending.
Token lifecycle
Expiration
TC token expiration uses a bucket-aligned system. By default, tokens expire after 28 days (4 buckets × 7-day duration). The server can override these defaults via AB props:
Bucket durations are capped at 180 days. The expiration cutoff is bucket-aligned — it always falls on a bucket boundary, matching WhatsApp Web’s
tokenExpirationCutoff logic.
Pruning evaluates the received-token cutoff and the sender-bucket cutoff independently: a row is only removed once its received token is expired-or-absent and its sender bucket is expired-or-absent, so recent sender-side rate-limit state is never dropped just because the received token expired (and vice versa).
Best practices
- Pre-issue tokens for contacts you frequently interact with
- Don’t over-issue — tokens are automatically issued after each message send when the bucket rolls over
- Use LID JIDs when issuing tokens manually
- Let startup pruning handle cleanup — expired tokens are pruned automatically on connect