BaileysEx.Util.LTHash (baileys_ex v0.1.0-alpha.8)

Copy Markdown View Source

Linked Truncated Hash for app state integrity verification.

LTHash is a summation-based hash that maintains data integrity across a series of mutations. Values can be added or removed and the resulting hash equals what you'd get from applying the same mutations sequentially.

The 128-byte hash state is treated as 64 unsigned 16-bit little-endian integers. Each value MAC is expanded to 128 bytes via SHA-256 with 4 counter prefixes, then added to or subtracted from the state with wrapping arithmetic.

Ports LTHashAntiTampering from Baileys' whatsapp-rust-bridge (lt-hash.ts).

Summary

Functions

Create a fresh 128-byte zero hash state.

Apply subtract-then-add operations to the hash state.

Functions

new()

@spec new() :: <<_::1024>>

Create a fresh 128-byte zero hash state.

Ports newLTHashState().hash — the initial hash is all zeros.

subtract_then_add(hash, sub_buffs, add_buffs)

@spec subtract_then_add(binary(), [binary()], [binary()]) :: binary()

Apply subtract-then-add operations to the hash state.

First subtracts all sub_buffs from the hash, then adds all add_buffs. Each buffer is a 32-byte value MAC that gets expanded to 128 bytes before the arithmetic operation.

Ports LT_HASH_ANTI_TAMPERING.subtractThenAdd(hash, subBuffs, addBuffs).

Parameters

  • hash — 128-byte current hash state
  • sub_buffs — list of 32-byte value MACs to subtract
  • add_buffs — list of 32-byte value MACs to add

Returns

Updated 128-byte hash state.