Amarula.Protocol.Signal.SessionStore (amarula v0.1.0)

View Source

Storage glue for the 1:1 Signal session cipher.

Two responsibilities:

  1. Build the store map that SessionBuilder/SessionCipher need — our identity keypair and prekey lookups — sourced from the auth creds map.
  2. Persist SessionRecords via Amarula.Storage (the :session namespace, keyed by signal address). Survives restart so ratchet state isn't lost.

Persistence is scoped to the connection: the conn (Amarula.Conn) supplies the storage scope and name passed to every Amarula.Storage call.

Keys here are raw 32-byte X25519 (no 0x05 prefix); the cipher/DH handle wire prefixing where needed.

Summary

Functions

Build the cipher store from auth creds.

Load a SessionRecord for addr on conn, or nil if none saved.

Persist a SessionRecord for addr on conn.

Functions

build(creds)

@spec build(map()) :: map()

Build the cipher store from auth creds.

creds must have signed_identity_key (%{public, private}), signed_pre_key (%{key_pair: %{public, private}, key_id, ...}). One-time prekeys come from creds.pre_keys (integer id => %{public, private}, populated by Signal.PreKeys at upload time); when the id is unknown — e.g. already consumed — load_pre_key returns nil and the responder X3DH falls back to the 4-DH path (no a4), which libsignal supports.

load_session(conn, addr)

@spec load_session(Amarula.Conn.t(), String.t()) :: map() | nil

Load a SessionRecord for addr on conn, or nil if none saved.

store_session(conn, addr, record)

@spec store_session(Amarula.Conn.t(), String.t(), map()) :: :ok | {:error, term()}

Persist a SessionRecord for addr on conn.