nostr-double-ratchet
    Preparing search index...

    Class Session

    Double ratchet secure communication session over Nostr

    Very similar to Signal's "Double Ratchet with header encryption" https://signal.org/docs/specifications/doubleratchet/

    Index

    Methods

    • Stop listening to incoming messages

      Returns void

    • Sends a text message through the encrypted session. Sent in a Nostr event with the kind CHAT_MESSAGE_KIND.

      Parameters

      • text: string

        The plaintext message to send

      Returns { event: VerifiedEvent; innerEvent: Rumor }

      A verified Nostr event containing the encrypted message. You need to publish this event to the Nostr network.

      Error if we are not the initiator and trying to send the first message

    • Send a partial Nostr event through the encrypted session. In addition to chat messages, it could be files, webrtc negotiation or many other types of messages.

      Parameters

      • event: Partial<UnsignedEvent>

        Partial Nostr event to send. Must be unsigned. Id and will be generated if not provided.

      Returns { event: VerifiedEvent; innerEvent: Rumor }

      A verified Nostr event containing the encrypted message. You need to publish this event to the Nostr network.

      Error if we are not the initiator and trying to send the first message

    • Initializes a new secure communication session

      Parameters

      • nostrSubscribe: NostrSubscribe

        Function to subscribe to Nostr events. Make sure it deduplicates events (doesn't return the same event twice), otherwise you'll see decryption errors!

      • theirEphemeralNostrPublicKey: string

        The ephemeral public key of the other party for the initial handshake

      • ourEphemeralNostrPrivateKey: Uint8Array

        Our ephemeral private key for the initial handshake

      • isInitiator: boolean

        Whether we are initiating the conversation (true) or responding (false)

      • sharedSecret: Uint8Array

        Initial shared secret for securing the first message chain

      • Optionalname: string

        Optional name for the session (for debugging)

      Returns Session

      A new Session instance