Amarula.Protocol.Signal.SessionRecord (amarula v0.1.0)
View SourceSignal session storage, ported from node_modules/libsignal/src/session_record.js.
A SessionRecord holds one or more session entries keyed by the base key. Each entry is a plain map:
%{
registration_id: integer | nil,
current_ratchet: %{
root_key: binary,
ephemeral_key_pair: %{public: binary, private: binary},
last_remote_ephemeral_key: binary,
previous_counter: integer
},
index_info: %{
created: integer, used: integer,
remote_identity_key: binary,
base_key: binary, base_key_type: 1|2, # OURS | THEIRS
closed: integer # -1 = open
},
chains: %{ base64_pubkey => chain },
pending_pre_key: map | nil
}The record is a map: %{sessions: %{base64_basekey => entry}}. We persist via
:erlang.term_to_binary, so unlike the JS impl no base64-of-buffers is needed
for storage — but chains/sessions are still keyed by base64 strings to match
libsignal's lookup-by-pubkey semantics exactly.
Summary
Functions
Close a session (mark it with a closed timestamp). Idempotent.
A fresh session entry shell (libsignal createEntry — chains start empty).
First open (closed == -1) session, or nil.
Look up a session by base key. Raises if it resolves to one of our own base keys.
All sessions, most-recently-used first (by index_info.used).
An empty record.
Drop oldest closed sessions while over CLOSED_SESSIONS_MAX.
Store/replace a session, keyed by its index_info.base_key.
Types
Functions
Close a session (mark it with a closed timestamp). Idempotent.
@spec create_entry() :: map()
A fresh session entry shell (libsignal createEntry — chains start empty).
First open (closed == -1) session, or nil.
Look up a session by base key. Raises if it resolves to one of our own base keys.
All sessions, most-recently-used first (by index_info.used).
@spec new() :: t()
An empty record.
Drop oldest closed sessions while over CLOSED_SESSIONS_MAX.
Store/replace a session, keyed by its index_info.base_key.