ExWapp.Pairing.ADV (ExWapp v0.1.2)

Copy Markdown View Source

Helpers for parsing and validating WhatsApp ADV (Account Device Verification) payloads.

Pair-success device-identity arrives as an ADVSignedDeviceIdentityHMAC container in both Baileys and whatsmeow. The inner payload is an ADVSignedDeviceIdentity.

Outbound message device-identity nodes and pair-success ACK payloads use the direct ADVSignedDeviceIdentity bytes instead.

The methods below verify the pair-success HMAC using the stored ADV secret, validate the server account signature, and prepare the client device signature that must be echoed back to WhatsApp once pairing completes.

Summary

Functions

Encodes an ADVSignedDeviceIdentity payload.

Parses and validates a signed ADV device identity blob.

Types

parsed_identity()

@type parsed_identity() :: %{
  container: struct() | nil,
  signed: struct(),
  details: struct() | map(),
  hosted?: boolean(),
  device_signature: binary(),
  self_signed: binary(),
  details_binary: binary()
}

Result returned by parse_signed_device_identity/3.

Functions

encode_signed_device_identity(signed, opts \\ [])

@spec encode_signed_device_identity(struct(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Encodes an ADVSignedDeviceIdentity payload.

By default it includes accountSignatureKey (required for outgoing messages). Pass include_signature_key: false for pair-device-sign payloads.

parse_signed_device_identity(adv_bytes, adv_secret, identity)

@spec parse_signed_device_identity(binary() | nil, binary(), identity_input()) ::
  {:ok, parsed_identity() | nil} | {:error, term()}

Parses and validates a signed ADV device identity blob.

The returned map exposes both the decoded structs and the serialized payload that must be echoed back to the server (under :self_signed).