Crypto Lib
    Preparing search index...

    Class DoubleRatchet

    Double Ratchet providing forward secrecy and break-in recovery.

    Combines:

    • A root chain that advances on each DH ratchet step
    • Sending/receiving symmetric chains for per-message keys
    • DH ratchet steps when receiving a new public key
    Index
    • Initialize a Double Ratchet as the initiator (Alice).

      Parameters

      • sharedSecret: string

        Initial shared secret from PQXDH (hex, 32 bytes).

      • remoteRatchetPublic: string

        Bob's initial ratchet public key (hex).

      Returns DoubleRatchet

    • Initialize a Double Ratchet as the responder (Bob).

      Parameters

      • sharedSecret: string

        Initial shared secret from PQXDH (hex, 32 bytes).

      • ourRatchetKeyPair: { privateKey: string; publicKey: string }

        Bob's initial ratchet key pair {privateKey, publicKey} (hex).

      Returns DoubleRatchet

    • Encrypt a plaintext message.

      Advances the sending symmetric chain and encrypts with XChaCha20-Poly1305 using the derived message key.

      Parameters

      • plaintext: string | Uint8Array<ArrayBufferLike>

      Returns EncryptedMessage

    • Decrypt an incoming message.

      If the message header contains a new ratchet public key, performs a DH ratchet step first to derive the receiving chain key.

      Parameters

      Returns Uint8Array