SignalProtocol.PreKeyBundle (libsignal_protocol v0.3.0)

View Source

Serialization for the pre-key bundle a party publishes so others can start sessions with them asynchronously.

The wire form is exactly what the NIF's process_pre_key_bundle/2 consumes:

identity_pub(32) || signed_pre_key_pub(32) || signature(64) [|| one_time_pre_key_pub(32)]

128 bytes, or 160 with a one-time pre-key. signature is Ed25519 over signed_pre_key_pub under the identity key -- produced by SignalProtocol.generate_signed_pre_key/2.

Key ids and the registration id are not part of this binary: they travel in the PreKeySignalMessage of the first message, where the responder needs them to look up which private keys to use.

Summary

Functions

Parses a bundle from its wire form. Accepts exactly 128 or 160 bytes.

Serializes a bundle to the NIF wire form.

Verifies the bundle's Ed25519 signature over its signed pre-key, under the identity key the bundle itself carries. Returns :ok or the bare atom :invalid_signature, mirroring signal_nif:verify_signature/3.

Types

t()

@type t() :: %SignalProtocol.PreKeyBundle{
  identity_key: binary(),
  one_time_pre_key: binary() | nil,
  signature: binary(),
  signed_pre_key: binary()
}

Functions

decode(bundle)

@spec decode(binary()) :: {:ok, t()} | {:error, :invalid_bundle_size}

Parses a bundle from its wire form. Accepts exactly 128 or 160 bytes.

encode(pre_key_bundle)

@spec encode(t()) :: {:ok, binary()} | {:error, :invalid_key_size}

Serializes a bundle to the NIF wire form.

Returns {:error, :invalid_key_size} if any component is the wrong length, rather than emitting a binary the NIF would reject with :invalid_bundle_size or a signature failure.

verify_signature(pre_key_bundle)

@spec verify_signature(t()) :: :ok | :invalid_signature | {:error, atom()}

Verifies the bundle's Ed25519 signature over its signed pre-key, under the identity key the bundle itself carries. Returns :ok or the bare atom :invalid_signature, mirroring signal_nif:verify_signature/3.

This is the same check process_pre_key_bundle/2 performs, exposed for callers who want to validate a bundle before using it. It proves internal consistency only: trust in identity_key has to come from out-of-band identity verification.