@me2em/crypto
    Preparing search index...

    Function encryptChannelMessage

    • Encrypts a message for the channel at the given sequence number.

      The application is responsible for managing sequence counters (immutable design — React-friendly). Each call generates a fresh random IV, so encrypting the same plaintext with the same seq produces different ciphertexts. However, re-encrypting with a seq already used for this channel will fail on decrypt (replay) while the sequence stays inside the receiver's replay window.

      Parameters

      • channel: Channel

        The channel to encrypt for.

      • seq: number

        Sequence number (must be ≥ 0).

      • plaintext: Uint8Array

        The plaintext to encrypt.

      Returns Promise<ChannelMessage>

      ChannelMessage with epoch, sequence, ciphertext, and IV.

      If the channel is unknown (rotated away) or seq is invalid.

      const msg = await encryptChannelMessage(channel, 0, plaintext);
      // send msg.ciphertext + msg.iv + msg.sequence + msg.epoch