ExWapp.Signal.SenderKey (ExWapp v0.1.2)

Copy Markdown View Source

Group sender-key support for WhatsApp skmsg payloads.

Handles:

  • processing sender key distribution messages from decrypted WA message payloads
  • decrypting sender-key group messages (enc type="skmsg")

Summary

Functions

Creates (or reuses) the local outbound sender-key state and returns a WA message payload containing senderKeyDistributionMessage (field 2).

Decrypts a group sender-key message (skmsg) for a specific group and sender.

Encrypts plaintext for outbound group send as a sender-key message (skmsg).

Parses and persists any sender key distribution payloads found inside a decrypted WhatsApp message protobuf.

Types

sender_key_message_keys()

@type sender_key_message_keys() :: %{iv: binary(), cipher_key: binary()}

sender_key_state()

@type sender_key_state() :: %{
  id: non_neg_integer(),
  iteration: non_neg_integer(),
  chain_key: binary(),
  signing_key: binary(),
  signing_private: binary() | nil,
  message_keys: %{optional(non_neg_integer()) => sender_key_message_keys()}
}

Functions

create_outbound_distribution_message(store, group_jid, sender_jid)

@spec create_outbound_distribution_message(ExWapp.Store.t(), term(), term()) ::
  {:ok, binary()} | {:error, term()}

Creates (or reuses) the local outbound sender-key state and returns a WA message payload containing senderKeyDistributionMessage (field 2).

decrypt_group_message(store, group_jid, sender_jid, ciphertext)

@spec decrypt_group_message(ExWapp.Store.t(), term(), term(), binary()) ::
  {:ok, binary()} | {:error, term()}

Decrypts a group sender-key message (skmsg) for a specific group and sender.

encrypt_outbound_group_message(store, group_jid, sender_jid, plaintext)

@spec encrypt_outbound_group_message(ExWapp.Store.t(), term(), term(), binary()) ::
  {:ok, binary()} | {:error, term()}

Encrypts plaintext for outbound group send as a sender-key message (skmsg).

process_distributions_from_plaintext(store, group_jid_hint, sender_jid, plaintext)

@spec process_distributions_from_plaintext(
  ExWapp.Store.t() | nil,
  term(),
  term(),
  binary()
) ::
  {:ok, non_neg_integer()} | {:error, term()}

Parses and persists any sender key distribution payloads found inside a decrypted WhatsApp message protobuf.

Returns {:ok, processed_count}.