Amarula.Protocol.Socket.Login (amarula v0.1.0)

View Source

The Noise XX handshake + login-bootstrap stanza builders, extracted from Connection. Pure: these compute frames/nodes from inputs and return values — they do NOT touch the websocket, timers, or emit events. CM stays the process: it sends the frames/nodes, transitions state, and emits updates.

Handshake flow (CM drives it across :ws_event frames):

client_hello(creds, config)   {:ok, hello_frame, handshake_state}   # CM sends hello_frame
server_hello(handshake, frame)  {:ok, finish_frame, final_noise}    # CM sends finish_frame
complete(final_noise)         transport_noise_state                 # CM enters transport

Summary

Functions

Build the ClientHello frame + initial handshake state from creds/config. Returns {:ok, encoded_frame, handshake_state} (with sent_intro set) or {:error, reason}.

Transition the post-ClientFinish noise state into the transport phase.

The digest-key-bundle IQ (<iq get xmlns=encrypt><digest/>).

Process a ServerHello frame against handshake_state: decode, validate, and produce the ClientFinish frame. Returns {:ok, finish_frame, final_noise_state} or {:error, reason}. (CM sends finish_frame, then calls complete/1.)

The unified-session <ib><unified_session id=> node (id per Baileys).

Functions

client_hello(auth_creds, config)

@spec client_hello(map(), map()) :: {:ok, binary(), map()} | {:error, term()}

Build the ClientHello frame + initial handshake state from creds/config. Returns {:ok, encoded_frame, handshake_state} (with sent_intro set) or {:error, reason}.

complete(final_noise_state)

@spec complete(map()) :: map()

Transition the post-ClientFinish noise state into the transport phase.

digest_iq()

@spec digest_iq() :: Amarula.Protocol.Binary.Node.t()

The digest-key-bundle IQ (<iq get xmlns=encrypt><digest/>).

server_hello(handshake_state, frame_data)

@spec server_hello(map(), binary()) :: {:ok, binary(), map()} | {:error, term()}

Process a ServerHello frame against handshake_state: decode, validate, and produce the ClientFinish frame. Returns {:ok, finish_frame, final_noise_state} or {:error, reason}. (CM sends finish_frame, then calls complete/1.)

unified_session_node()

@spec unified_session_node() :: Amarula.Protocol.Binary.Node.t()

The unified-session <ib><unified_session id=> node (id per Baileys).