Encoding and decoding helpers for app-state patches.
This module owns the cryptographic transformation layer: it turns high-level patch descriptions into protobuf payloads for WhatsApp and validates incoming patch payloads back into decoded mutations that the local store can apply.
Summary
Functions
Decodes a list of SyncdMutation records and optionally validates their MACs.
Decodes a complete incoming patch and validates its hash-chain transition.
Encodes a high-level patch description into a SyncdPatch protobuf payload.
Types
@type action_value() :: WAWebProtobufSyncAction.SyncActionValue.t() | nil
@type decoded_mutation() :: %{ operation: non_neg_integer(), action: action_value(), version: integer() | nil, index: [String.t()], index_mac: binary(), value_mac: binary() }
@type hash_state() :: %{version: non_neg_integer(), hash: binary()}
@type patch_info() :: %{ type: String.t(), mutations: [mutation_info()], timestamp: integer() | nil }
@type syncd_mutation() :: WAWebProtobufsServerSync.SyncdMutation.t()
@type syncd_patch() :: WAWebProtobufsServerSync.SyncdPatch.t()
Functions
@spec decode_mutations([syncd_mutation()], map(), boolean()) :: {:ok, [decoded_mutation()]} | {:error, term()}
Decodes a list of SyncdMutation records and optionally validates their MACs.
@spec decode_patch(syncd_patch(), String.t(), hash_state(), map(), map(), boolean()) :: {:ok, [decoded_mutation()], hash_state(), map()} | {:error, term()}
Decodes a complete incoming patch and validates its hash-chain transition.
Besides decoding each mutation, this verifies snapshot and patch MACs and returns the updated hash state plus the refreshed mutation-MAC map.
@spec encode_patch(patch_info(), binary(), binary(), hash_state(), map()) :: {:ok, binary(), hash_state(), map()} | {:error, term()}
Encodes a high-level patch description into a SyncdPatch protobuf payload.
The returned binary is ready to be embedded in the app-state IQ request, and the hash state / mutation MAC map are advanced to reflect the encoded patch.