Amarula.Protocol.Messages.MessageDecryptor (amarula v0.1.0)

View Source

Decrypts the <enc> payloads of an incoming message node, ported from the routing in src/Utils/decode-wa-message.ts (decryptMessageNode).

For each <enc> child it dispatches by type:

  • pkmsg / msg → 1:1 Signal session cipher (SessionCipher)
  • plaintext → passthrough
  • skmsg → group sender-key (not handled here yet; left to caller)

The decrypted bytes are unpadded (random-max-16) and decoded as a Proto.Message, unwrapping deviceSentMessage.

Sessions are loaded/stored via SessionStore keyed by the sender's signal address. This module is pure aside from the session file I/O.

Summary

Functions

Decrypt all decryptable <enc> children of node.

Functions

decrypt_node(node, opts)

@spec decrypt_node(
  map(),
  keyword()
) :: {:ok, [struct()], [integer()], [term()]}

Decrypt all decryptable <enc> children of node.

Returns {:ok, [%Proto.Message{}], used_pre_key_ids} (one message per successfully decrypted enc), or {:ok, [], []} if nothing decryptable. used_pre_key_ids lists our one-time prekey ids consumed by PreKeySignalMessages — the caller must delete them from storage, as libsignal's session_cipher does via removePreKey. opts requires:

  • :store — the cipher store from SessionStore.build/1
  • :conn — the Amarula.Conn scoping session persistence