Amarula.Connection.Pairing (amarula v0.2.4)

View Source

Pure pairing builders for Amarula.Connection — the node-building and creds-transform parts of the QR/multi-device handshake.

The orchestrating handlers (handle_pair_device, handle_pair_success, emit_next_qr) stay on Connection: they send frames, run timers, persist creds, and emit events. What lives here is pure and testable directly — the two reply IQ nodes, the QR-ref extraction, and the post-pairing creds merge.

Summary

Functions

The <iq type=result> ack for a received pair-device IQ.

The <iq><pair-device-sign> reply counter-signing the device identity.

Extract the QR ref payloads from a pair-device IQ node, in order. Returns [] when the <pair-device> wrapper or its <ref> children are absent.

Merge the paired-device fields into creds. me.name defaults to "~" (Baileys) when there's no business name — presence-available requires a non-nil me.name.

Functions

pair_device_ack_node(msg_id)

@spec pair_device_ack_node(String.t()) :: Amarula.Protocol.Binary.Node.t()

The <iq type=result> ack for a received pair-device IQ.

pair_device_sign_reply(msg_id, key_index, account_enc)

@spec pair_device_sign_reply(String.t(), integer(), binary()) ::
  Amarula.Protocol.Binary.Node.t()

The <iq><pair-device-sign> reply counter-signing the device identity.

qr_refs(node)

@spec qr_refs(Amarula.Protocol.Binary.Node.t()) :: [binary()]

Extract the QR ref payloads from a pair-device IQ node, in order. Returns [] when the <pair-device> wrapper or its <ref> children are absent.

update_credentials_after_pairing(creds, account, jid, lid, biz_name, platform, signal_identity)

@spec update_credentials_after_pairing(
  map(),
  term(),
  String.t(),
  String.t(),
  term(),
  term(),
  term()
) :: map()

Merge the paired-device fields into creds. me.name defaults to "~" (Baileys) when there's no business name — presence-available requires a non-nil me.name.