API reference › @evolu/common › local‑first/Protocol › encodeAndEncryptDbChange

function encodeAndEncryptDbChange(
  deps: RandomBytesDep,
): (
  message: CrdtMessage,
  key: Uint8Array<ArrayBufferLike> &
    Brand<"Entropy"> &
    Brand<"Length32"> &
    Brand<"EncryptionKey">,
) => EncryptedDbChange;

Defined in: packages/common/src/local-first/Protocol.ts:2338

Encodes and encrypts a DbChange using the provided owner's encryption key. Returns an encrypted binary representation as EncryptedDbChange.

The plaintext starts with the format version of the change, which is independent of protocolVersion, and the timestamp, which proves that the change belongs to the timestamp it is sent with. decryptAndDecodeDbChange rejects a newer format version and accepts older ones.