Amarula.Protocol.Socket.Login (amarula v0.1.0)
View SourceThe 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
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.
@spec digest_iq() :: Amarula.Protocol.Binary.Node.t()
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.)
@spec unified_session_node() :: Amarula.Protocol.Binary.Node.t()
The unified-session <ib><unified_session id=> node (id per Baileys).