Need help with whatsapp-web-reveng?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

5.3K Stars 717 Forks MIT License 179 Commits 136 Opened issues


Reverse engineering WhatsApp Web.

Services available


Need anything else?

Contributors list

WhatsApp Web reverse engineered


This project intends to provide a complete description and re-implementation of the WhatsApp Web API, which will eventually lead to a custom client. WhatsApp Web internally works using WebSockets; this project does as well.

Trying it out

With Nix

There's no need to install or manage python and node versions, the file

defines an environment with all the dependencies included to run this project.

There's an

file in root folder that is called automatically when
ing (changing directory) to project, if program
is installed along with
you should get an output like this:
>cd ~/dev/whatsapp
Installing node modules
npm WARN prepare removing existing node_modules/ before installation

> [email protected] install /home/rainy/dev/whatsapp/node_modules/fsevents > node-gyp rebuild

make: Entering directory '/home/rainy/dev/whatsapp/node_modules/fsevents/build' SOLINK_MODULE(target) Release/ COPY Release/.node make: Leaving directory '/home/rainy/dev/whatsapp/node_modules/fsevents/build'

> [email protected] postinstall /home/rainy/dev/whatsapp/node_modules/nodemon > node bin/postinstall || exit 0

added 310 packages in 3.763s Done.

$$\ $$\ $$\ $$
$$ | $\ $$ |$$ | $$ | $$ |$$$\ $$ |$$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$
$$ $$ $$$$ |$$ $$\ __$$\$$ | $$ ____| ___$$\ $$ $$\ $$ __$$
$$$$ $$$$ |$$ | $$ | $$$$$$$ | $$ | $$$$$$\ $$$$$$$ |$$ / $$ |$$ / $$ | $$$ / $$$ |$$ | $$ |$$ __$$ | $$ |$$\ _
$$\ $$ $$ |$$ | $$ |$$ | $$ | $$ / $$ |$$ | $$ |$$$$$$$ | $$$$ |$$$$$$$ |$$$$$$$ |$$$$$$$ |$$$$$$$ | \/ _|_| _| ______| _/ ____/ ___|$$ __/ $$ __/ $$ | $$ | $$ | $$ | _| _| Node v13.13.0 Python 2.7.17

Try running server with: npm start


If you don't use

or just want to manually get into the build environment do:

in the project root

Bare metal

Before you can run the application, make sure that you have the following software installed:

  • Node.js (at least version 8, as the
    syntax is used)
  • Python 2.7 with the following
    packages installed:
    • websocket-client
      for acting as WebSocket server and client.
    • curve25519-donna
      for the encryption stuff.
    • pyqrcode
      for QR code generation.
    • protobuf
      for reading and writing the binary conversation format.
  • Note: On Windows
    requires Microsoft Visual C++ 9.0 and you need to copy
    C:\Users\YOUR USERNAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\include

Before starting the application for the first time, run

npm install -f
to install all Node and
pip install -r requirements.txt
for all Python dependencies.

Lastly, to finally launch it, just run

npm start
on Linux based OS's and
npm run win
on Windows. Using fancy
magic, all three local components will be started after each other and when you edit a file, the changed module will automatically restart to apply the changes.



A recent addition is a version of the decryption routine translated to in-browser JavaScript. Run

node index_jsdemo.js
(just needed because browsers don't allow changing HTTP headers for WebSockets), then open
as a normal file in any browser. The console output should show decrypted binary messages after scanning the QR code.

adiwajshing created Baileys, a Node library that implements the WhatsApp Web API.

ndunks made a TypeScript reimplementation at WaJs.


With whatsappweb-rs, wiomoc created a WhatsApp Web client in Rust.


Rhymen created go-whatsapp, a Go package that implements the WhatsApp Web API.


vzaramel created whatsappweb-clj, a Clojure library the implements the WhatsApp Web API.

Application architecture

The project is organized in the following way. Note the used ports and make sure that they are not in use elsewhere before starting the application. whatsapp-web-reveng Application architecture

Login and encryption details

WhatsApp Web encrypts the data using several different algorithms. These include AES 256 CBC, Curve25519 as Diffie-Hellman key agreement scheme, HKDF for generating the extended shared secret and HMAC with SHA256.

Starting the WhatsApp Web session happens by just connecting to one of its websocket servers at

means that the websocket connection is secure;
means that any number between 1 and 8 can follow the
). Also make sure that, when establishing the connection, the HTTP header
is set, otherwise the connection will be rejected.


When you send messages to a WhatsApp Web websocket, they need to be in a specific format. It is quite simple and looks like

, e.g.
. Note that apparently the message tag can be anything. This application mostly uses the current timestamp as tag, just to be a bit unique. WhatsApp itself often uses message tags like
or something like that. Obviously the message tag may not contain a comma. Additionally, JSON objects are possible as well as payload.

Logging in

To log in at an open websocket, follow these steps:

  1. Generate your own
    , which needs to be 16 base64-encoded bytes (i.e. 25 characters). This application just uses 16 random bytes, i.e.
    in Python.
  2. Decide for a tag for your message, which is more or less arbitrary (see above). This application uses the current timestamp (in seconds) for that. Remember this tag for later.
  3. The message you send to the websocket looks like this:
    messageTag,["admin","init",[0,3,2390],["Long browser description","ShortBrowserDesc"],"clientId",true]
    • Obviously, you need to replace
      by the values you chose before
    • The
      part specifies the current WhatsApp Web version. The last value changes frequently. It should be quite backwards-compatible though.
    • "Long browser description"
      is an arbitrary string that will be shown in the WhatsApp app in the list of registered WhatsApp Web clients after you scan the QR code.
    • "ShortBrowserDesc"
      has not been observed anywhere yet but is arbitrary as well.
  4. After a few moments, your websocket will receive a message in the specified format with the message tag you chose in step 2. The JSON object of this message has the following attributes:
    • status
      : should be 200
    • ref
      : in the application, this is treated as the server ID; important for the QR generation, see below
    • ttl
      : is 20000, maybe the time after the QR code becomes invalid
    • update
      : a boolean flag
    • curr
      : the current WhatsApp Web version, e.g.
    • time
      : the timestamp the server responded at, as floating-point milliseconds, e.g.

QR code generation

  1. Generate your own private key with Curve25519, e.g.
  2. Get the public key from your private key, e.g.
  3. Obtain the string later encoded by the QR code by concatenating the following values with a comma:
    • the server ID, i.e. the
      attribute from step 4
    • the base64-encoded version of your public key, i.e.
    • your client ID
  4. Turn this string into an image (e.g. using
    ) and scan it using the WhatsApp app.

Requesting new ref for QR code generation (not implemented)

  1. You can request up to 5 new server refs when previous one expires (
  2. Do it by sending
  3. The server responds with JSON with the following attributes:
    • status
      : should be 200 (other ones: 304 - reuse previous ref, 429 - new ref denied)
    • ref
      : new ref
    • ttl
      : expiration time
  4. Update your QR code with the new ref.

After scanning the QR code

  1. Immediately after you scan the QR code, the websocket receives several important JSON messages that build up the encryption details. These use the specified message format and have a JSON array as payload. Their message tag has no special meaning. The first entry of the JSON array has one of the following values:
    • Conn
      : array contains JSON object as second element with connection information containing the following attributes and many more:
      • battery
        : the current battery percentage of your phone
      • browserToken
        : used to logout without active WebSocket connection (not implemented yet)
      • clientToken
        : used to resuming closed sessions aka "Remember me" (not implemented yet)
      • phone
        : an object with detailed information about your phone, e.g.
      • platform
        : your phone OS, e.g.
      • pushname
        : the name of yours you provided WhatsApp
      • secret
        (remember this!)
      • serverToken
        : used to resuming closed sessions aka "Remember me" (not implemented yet)
      • wid
        : your phone number in the chat identification format (see below)
    • Stream
      : array has four elements in total, so the entire payload is like
    • Props
      : array contains JSON object as second element with several properties like
      (960) and others

Key generation

  1. You are now ready for generating the final encryption keys. Start by decoding the
    as base64 and storing it as
    . This decoded secret will be 144 bytes long.
  2. Take the first 32 bytes of the decoded secret and use it as a public key. Together with your private key, generate a shared key out of it and call it
    . The application does it using
    privateKey.get_shared_key(curve25519.Public(secret[:32]), lambda a:a)
  3. Extend
    to 80 bytes using HKDF. Call this value
  4. This step is optional, it validates the data provided by the server. The method is called HMAC validation. Do it by first calculating
    HmacSha256(sharedSecretExpanded[32:64], secret[:32] + secret[64:])
    . Compare this value to
    . If they are not equal, abort the login.
  5. You now have the encrypted keys: store
    sharedSecretExpanded[64:] + secret[64:]
  6. The encrypted keys now need to be decrypted using AES with
    as key, i.e. store
    AESDecrypt(sharedSecretExpanded[:32], keysEncrypted)
  7. The
    variable is 64 bytes long and contains two keys, each 32 bytes long. The
    is used for decrypting binary messages sent to you by the WhatsApp Web server or encrypting binary messages you send to the server. The
    is needed to validate the messages sent to you:
    • encKey
    • macKey

Restoring closed sessions (not implemented)

  1. After sending
    command, check whether you have
  2. If so, send
  3. The server should respond with
    {"status": 200}
    . Other statuses:
    • 401: Unpaired from the phone
    • 403: Access denied, check
      field in the JSON: if it equals or greater than 2, you have violated TOS
    • 405: Already logged in
    • 409: Logged in from another location

Resolving challenge (not implemented)

  1. When using old or expired
    , you will be challenged to confirm that you still have valid encryption keys.
  2. The challenge looks like this
  3. Decode
    string from Base64, sign it with your macKey, encode it back with Base64 and send
  4. The server should respond with
    {"status": 200}
    , but it means nothing.
  5. After solving challenge your connection should be restored.

Logging out

  1. When you have an active WebSocket connection, just send
  2. When you don't have such connection (for example your session has been taken over from another location), sign your
    with your
    and encode it with Base64. Let's say it is your
  3. Send a POST request to
  4. Remember to always clear your sessions, so sessions list in your phone will not grow big.

Validating and decrypting messages

Now that you have the two keys, validating and decrypting messages the server sent to you is quite easy. Note that this is only needed for binary messages, all JSON you receive stays plain. The binary messages always have 32 bytes at the beginning that specify the HMAC checksum. Both JSON and binary messages have a message tag at their very start that can be discarded, i.e. only the portion after the first comma character is significant.

  1. Validate the message by hashing the actual message content with the
    is the entire binary message):
    HmacSha256(macKey, messageContent[32:])
    . If this value is not equal to
    , the message sent to you by the server is invalid and should be discarded.
  2. Decrypt the message content using AES and the
    AESDecrypt(encKey, messageContent[32:])

The data you get in the final step has a binary format which is described in the following. Even though it's binary, you can still see several strings in it, especially the content of messages you sent is quite obvious there.

Binary message format

Binary decoding

The Python script

implements the
class. It is able to create a JSON structure out of binary data in which the data is still organized in a rather messy way. The section about Node Handling below will discuss how the nodes are reorganized afterwards.

initially just needs some data and then processes it byte by byte, i.e. as a stream. It has a couple of constants and a lot of methods which all build on each other.


  • Tags with their respective integer values
    • LISTEMPTY_: 0
    • STREAM8_: 2
    • DICTIONARY0_: 236
    • DICTIONARY1_: 237
    • DICTIONARY2_: 238
    • DICTIONARY3_: 239
    • LIST8_: 248
    • LIST16_: 249
    • JIDPAIR_: 250
    • HEX8_: 251
    • BINARY8_: 252
    • BINARY20_: 253
    • BINARY32_: 254
    • NIBBLE8_: 255
  • Tokens are a long list of 151 strings in which the indices matter:
    • [None,None,None,"200","400","404","500","501","502","action","add",

Number reformatting

  • Unpacking nibbles: Returns the ASCII representation for numbers between 0 and 9. Returns
    for 10,
    for 11 and
    for 15.
  • Unpacking hex values: Returns the ASCII representation for numbers between 0 and 9 or letters between A and F (i.e. uppercase) for numbers between 10 and 15.
  • Unpacking bytes: Expects a tag as an additional parameter, namely NIBBLE8_ or HEX8_. Unpacks a nibble or hex value accordingly.

Number formats

  • Byte: A plain ol' byte.
  • Integer with N bytes: Reads N bytes and builds a number out of them. Can be little or big endian; if not specified otherwise, big endian is used. Note that no negative values are possible.
  • Int16: An integer with two bytes, read using Integer with N bytes.
  • Int20: Consumes three bytes and constructs an integer using the last four bits of the first byte and the entire second and third byte. Is therefore always big endian.
  • Int32: An integer with four bytes, read using Integer with N bytes.
  • Int64: An integer with eight bytes, read using Integer with N bytes.
  • Packed8: Expects a tag as an additional parameter, namely NIBBLE8_ or HEX8_. Returns a string.
    • First reads a byte
      and does the following
      many times: Reads a byte
      and for each nibble, adds the result of its unpacked version to the return value (using unpacking bytes with the given tag). Most significant nibble first.
    • If the most significant bit of
      was set, removes the last character of the return value.

Helper methods

  • Read bytes: Reads and returns the specified number of bytes.
  • Check for list tag: Expects a tag as parameter and returns true if the tag is
    (i.e. 0, 248 or 249).
  • Read list size: Expects a list tag as parameter. Returns 0 for
    , returns a read byte for
    or a read Int16 for
  • Read a string from characters: Expects the string length as parameter, reads this many bytes and returns them as a string.
  • Get a token: Expects an index to the array of Tokens, and returns the respective string.
  • Get a double token: Expects two integers
    and gets the token at index


Reading a string needs a tag as parameter. Depending on this tag, different data is read.

  • If the tag is between 3 and 235, the token (i.e. a string) of this tag is got. If the token is
    is returned instead, otherwise the token is returned as is.
  • If the tag is between DICTIONARY0_ and DICTIONARY3, a _double token is returned, with
    as first and a read byte as second parameter.
  • LISTEMPTY_: Nothing is returned (e.g.
  • BINARY8: A byte is read which is then used to _read a string from characters with this length.
  • BINARY20: An _Int20 is read which is then used to read a string from characters with this length.
  • BINARY32: An _Int32 is read which is then used to read a string from characters with this length.
    • First, a byte is read which is then used to read a string
      with this tag.
    • Second, another byte is read which is then used to read a string
      with this tag.
    • Finally,
      are joined together with an
      sign and the result is returned.
  • NIBBLE8_ or HEX8: A _Packed8 with this tag is returned.

Attribute lists

Reading an attribute list needs the number of attributes to read as parameter. An attribute list is always a JSON object. For each attribute read, the following steps are executed for getting key-value pairs (exactly in this order!): - Key: A byte is read which is then used to read a string with this tag. - Value: A byte is read which is then used to read a string with this tag.


A node always consists of a JSON array with exactly three entries: description, attributes and content. The following steps are needed to read a node:

  1. A list size
    is read by using a read byte as the tag. The list size 0 is invalid.
  2. The description tag is read as a byte. The value 2 is invalid for this tag. The description string
    is then obtained by reading a string with this tag.
  3. The attributes object
    is read by reading an attributes object with length
    (a-2 + a%2) >> 1
  4. If
    was odd, this node does not have any content, i.e.
    [descr, attrs, None]
    is returned.
  5. For getting the node's content, first a byte, i.e. a tag is read. Depending on this tag, different types of content emerge:
    • If the tag is a list tag, a list is read using this tag (see below for lists).
    • BINARY8: A byte is read which is then used as length for _reading bytes.
    • BINARY20: An _Int20 is read which is then used as length for reading bytes.
    • BINARY32: An _Int32 is read which is then used as length for reading bytes.
    • If the tag is something else, a string is read using this tag.
  6. Eventually,
    [descr, attrs, content]
    is returned.


Reading a list requires a list tag (i.e. LISTEMPTY, _LIST8_ or LIST16). The length of the list is then obtained by _reading a list size using this tag. For each list entry, a node is read.

Node Handling

After a binary message has been transformed into JSON, it is still rather hard to read. That's why, internally, WhatsApp Web completely retransforms this structure into something that can be easily processed and eventually translated into user interface content. This section will deal with this and awaits completion.

Binary conversation format

When a node has been read, the contents of messages that have been actually sent by the user (i.e. text, image, audio, video etc.) are still not directly visible or accessible via the JSON. Instead, they are kept in a protobuf message. See here for the definitions. The "wrapper" message type is


WhatsApp Web API

WhatsApp Web itself has an interesting API as well. You can even try it out directly in your browser. Just log in at the normal, then open the browser development console. Now enter something like the following (see below for details on the chat identification):

Using the amazing Chrome developer console, you can see that

contains a lot of other very interesting functions. Many of them return JavaScript promises. When you click on the Network tab and then on WS (maybe you need to reload the site first), you can look at all the communication between WhatsApp Web and its servers.

Chat identification / JID

The WhatsApp Web API uses the following formats to identify chats with individual users and groups of multiple users.

  • Chats:
    [country code][number]
    , e.g.
    [email protected]
    when you are from Germany and your phone number is
    0123 456789
  • Groups:
    [phone number of group creator]-[timestamp of group creation]
    , e.g.
    [email protected]
    for the group that
    [email protected]
    created on November 5 2017.
  • Broadcast Channels
    [timestamp of broadcast channel creation]@broadcast
    , e.g.
    [email protected]
    for an broadcast channel created on November 5 2017.

WebSocket messages

There are two types of WebSocket messages that are exchanged between server and client. On the one hand, plain JSON that is rather unambiguous (especially for the API calls above), on the other hand encrypted binary messages.

Unfortunately, these binary ones cannot be looked at using the Chrome developer tools. Additionally, the Python backend, that of course also receives these messages, needs to decrypt them, as they contain encrypted data. The section about encryption details discusses how it can be decrypted.

Dealing with E2E media


  1. Generate your own
    , which needs to be 32 bytes.
  2. Expand it to 112 bytes using HKDF with type-specific application info (see below). Call this value
  3. Split
    • iv
    • cipherKey
    • macKey
    • refKey
      (not used)
  4. Encrypt the file with AES-CBC using
    , pad it and call it
  5. Sign
    iv + enc
    using HMAC SHA-256 and store the first 10 bytes of the hash as
  6. Hash the file with SHA-256 and store it as
    , hash the
    enc + mac
    with SHA-256 and store it as
  7. Encode the
    with base64 and store it as
  8. This step is required only for streamable media, e.g. video and audio. As CBC mode allows to decrypt a data from random offset (block-size aligned), it is possible to play and seek the media without the need to fully download it. That said, we need to generate a
    . Do it by signing every
    [n*64K, (n+1)*64K+16]
    chunk with
    , truncating the result to the first 10 bytes. Then combine everything in one piece.


  1. Retrieve the upload-url by sending
    messageTag,["action", "encr_upload", filetype, fileEncSha256B64]
    • filetype
      can be one of
  2. Create a multipart-form with the following fields:
    • fieldname:
    • fieldname:
      , filename:

  3. Do a POST request to the url with query string
    and the correct
    and the multipart-form, WhatsApp will respond with the download url for the file.
  4. All relevant information to send the file are now generated, just build the proto and send it.


  1. Obtain
    and decode it from Base64 if necessary.
  2. Expand it to 112 bytes using HKDF with type-specific application info (see below). Call this value
  3. Split
    • iv
    • cipherKey
    • macKey
    • refKey
      (not used)
  4. Download media data from the
    and split it into:
    • file
    • mac
  5. Validate media data with HMAC by signing
    iv + file
    using SHA-256. Take in mind that
    is truncated to 10 bytes, so you should compare only the first 10 bytes.
  6. Decrypt
    with AES-CBC using
    , and unpad it. Note that this means that your session's keys (i.e.
    from the Key generation section) are not necessary to decrypt a media file.

Application info for HKDF

Depending on the media type, the literal strings in the right column are the values for the

parameter from the

| Media Type | Application Info | | ---------- | ------------------------ | | IMAGE |

WhatsApp Image Keys
| | VIDEO |
WhatsApp Video Keys
| | AUDIO |
WhatsApp Audio Keys
WhatsApp Document Keys

Extending the web app's capabilities

Adding own commands

The message forwarding procedures are rather complex, as there are several layers of websockes involved in the process. For adding your own commands, follow these steps.

  1. First, decide on what the final destination of your command shall be. To be consistent with the other, please prefix it with
    if it's meant to be received by the Python backend or use
    if the command is directed to the NodeJS API.
  2. Now, look at

    . In line 214, you can see an instantiation of the

    JavaScript class. It needs the following information:
    • websocket
      : is probably always the same
    • request.type
      : should generally be
      , as this allows a response to be passed back to the command's sender
    • request.callArgs
      : an object which has to contain a
      attribute specifying the name of your command and as many additional key-value-pairs as you want. All of these will be passed to the receiver.
    • request.successCondition
      : on receiving a response for a call, this shall be a function returning
      when the response is valid/expected. Use the next attribute for specifying code to be executed when the response is valid.
    • request.successActor
      : when the success condition evaluated to
      , this success actor function is called

    When the

    object has been constructed, call
    for running indefinitely or
    for failing when no response has been received after a specific timeout. The
    function returns a Promise.
  3. Next, edit

    . It contains a couple of blocks beginning with

    . You can copy one of these blocks and edit the parameters. The
    function needs the following attributes:
    • condition
      : when a message is received and this condition evaluates to
      on it, the message will be processed by the following
    • keepWhenHit
      : it is possible for a message handler to be detached immediately after it receives its first fitting message. Control this here. The returned promise's
      block finally handles a received message. It gets a
      you can call
      on to send a JSON response to the caller. If the NodeJS API is not the message's final destination, you need to instantiate a new
      here which will contact to the Python backend and, after it receives its response, will return it to the original caller.
  4. Thus, when you want a message for the backend, now edit

    . In the if-else-compound starting in line 88, add your own branch for the command name you chose. Then, edit
    and add a function similar to

    in line 223. Just using something like in
    may not be enough, as your command may require an asynchronous request to the WhatsApp Web servers. In this case, make sure to add an entry to
    with the message tag you chose and send an appropriate message to
    . The servers will respond to your request with a response containing the same tag, thus this is resolved in line 134. Make sure to eventually call
    with the JSON object containing your response data to resolve the callback.


Please note, this version is not stable enough to be deployabled in production.

Build docker image

docker build . -t whatsapp-web-reveng

Run your image and redirect front & back ports

docker run -p 2019:2019 -p 2018:2018 whatsapp-web-reveng

Front end (client) at : http://localhost:2018/

For server use

The addresses of the websockets used are "localhost" by default. If you want to deploy this docker on your own server and share it, modify the backend websocket address on the front end.

let backendInfo = {
    url: "ws://{{your-server-addr}}:2020",
    timeout: 10000
Front end (client) at : : http://{{your-server-addr}}:2018/



  • [ ] More and more errors start to occur in the binary message decoding. Update this documentation to resemble the changes, then implement them.
  • [ ] Allow sending messages as well. Of course JSON is easy, but writing the binary message format needs to start being examined.

Web frontend

  • [ ] Allow reusing the session after successful login. Probably normal cookies are best for this. See #9 for details.
  • [ ] An UI that is not that technical, but rather starts to emulate the actual WhatsApp Web UI.

General development

  • [ ] Allow usage on Windows, i.e. entirely fix #16.


  • [ ] The Node Handling section. Could become very long.
  • [ ] Outsource the different documentation parts into their own files, maybe into the


This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.

Cryptography Notice

This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See for more information.

The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.