Amarula.Protocol.Auth.DeviceIdentity (amarula v0.1.0)

View Source

The pairing device-identity crypto: verify the primary's signed device identity, counter-sign it with our key, and derive the companion's signal identity. Pure (takes auth creds + the received identity, returns values) — extracted from Connection so the connection process keeps only socket/state concerns.

Ported from Baileys' pair-success handling (src/Socket/socket.ts).

Summary

Functions

Encode an ADVSignedDeviceIdentity for the wire. Drops the account signature key unless include_signature_key? (or it's already empty).

The companion signal identity %{identifier, identifierKey} for lid.

Verify the received identity_hmac (an ADVSignedDeviceIdentityHMAC) against our auth_creds, then return the account with our device signature added. {:ok, signed_account} or {:error, reason}.

Functions

encode(account, include_signature_key?)

@spec encode(
  struct(),
  boolean()
) :: binary()

Encode an ADVSignedDeviceIdentity for the wire. Drops the account signature key unless include_signature_key? (or it's already empty).

signal_identity(lid, account_signature_key)

@spec signal_identity(String.t(), binary()) :: map()

The companion signal identity %{identifier, identifierKey} for lid.

verify_and_sign(identity_hmac, auth_creds)

@spec verify_and_sign(
  struct(),
  map()
) :: {:ok, struct()} | {:error, term()}

Verify the received identity_hmac (an ADVSignedDeviceIdentityHMAC) against our auth_creds, then return the account with our device signature added. {:ok, signed_account} or {:error, reason}.