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

View Source

Minimal protobuf decode for the two Signal v3 message types (libsignal WhisperTextProtocol). These are tiny — a few bytes/uint32 fields — so we decode them directly rather than dragging them through the WAProto build.

Field tags (from node_modules/libsignal/src/WhisperTextProtocol.js):

WhisperMessage: 1 ephemeralKey bytes 2 counter uint32 3 previousCounter uint32 4 ciphertext bytes

PreKeyWhisperMessage: 1 preKeyId uint32 2 baseKey bytes 3 identityKey bytes 4 message bytes (a full WhisperMessage, version-tupled) 5 registrationId uint32 6 signedPreKeyId uint32

Summary

Functions

Decode a PreKeyWhisperMessage protobuf body (without the version byte).

Decode a WhisperMessage protobuf body (without the version byte/MAC).

Encode a PreKeyWhisperMessage protobuf body (without the version byte). Fields in number order; pre_key_id is optional (omitted when nil).

Encode a WhisperMessage protobuf body (without the version byte/MAC). Fields in number order: ephemeralKey(1), counter(2), previousCounter(3), ciphertext(4) — matching protobufjs output so the MAC over these bytes agrees with the peer.

Types

pre_key_whisper_message()

@type pre_key_whisper_message() :: %{
  pre_key_id: non_neg_integer() | nil,
  base_key: binary() | nil,
  identity_key: binary() | nil,
  message: binary() | nil,
  registration_id: non_neg_integer() | nil,
  signed_pre_key_id: non_neg_integer() | nil
}

whisper_message()

@type whisper_message() :: %{
  ephemeral_key: binary() | nil,
  counter: non_neg_integer(),
  previous_counter: non_neg_integer(),
  ciphertext: binary() | nil
}

Functions

decode_pre_key_whisper_message(bin)

@spec decode_pre_key_whisper_message(binary()) :: pre_key_whisper_message()

Decode a PreKeyWhisperMessage protobuf body (without the version byte).

decode_whisper_message(bin)

@spec decode_whisper_message(binary()) :: whisper_message()

Decode a WhisperMessage protobuf body (without the version byte/MAC).

encode_pre_key_whisper_message(m)

@spec encode_pre_key_whisper_message(map()) :: binary()

Encode a PreKeyWhisperMessage protobuf body (without the version byte). Fields in number order; pre_key_id is optional (omitted when nil).

encode_whisper_message(ephemeral_key, counter, previous_counter, ciphertext)

@spec encode_whisper_message(binary(), non_neg_integer(), non_neg_integer(), binary()) ::
  binary()

Encode a WhisperMessage protobuf body (without the version byte/MAC). Fields in number order: ephemeralKey(1), counter(2), previousCounter(3), ciphertext(4) — matching protobufjs output so the MAC over these bytes agrees with the peer.