Skip to content

nostr: add Double Ratchet sessions and invites (NIP-117/118) - #1441

Closed
mmalmi wants to merge 6 commits into
nostrdevkit:masterfrom
mmalmi:codex/nip117-118-double-ratchet
Closed

nostr: add Double Ratchet sessions and invites (NIP-117/118)#1441
mmalmi wants to merge 6 commits into
nostrdevkit:masterfrom
mmalmi:codex/nip117-118-double-ratchet

Conversation

@mmalmi

@mmalmi mmalmi commented Aug 10, 2026

Copy link
Copy Markdown

If your main Nostr private key is compromised, all past NIP-17 messages you received and future ones sent to you are exposed. Double Ratchet fixes this for established conversations by using separate session keys that change after every message, so the main key alone cannot decrypt the session’s past or future messages.

This PR adds NIP-117 and NIP-118:

  • Session encrypts unsigned Nostr events as signed kind-1060 events, rotates keys per message, serializes its ratchet state, and handles delayed or out-of-order delivery.
  • Invite creates matching sessions through private links/QR codes or signed public invites and kind-1059 responses. Each response proves possession of its advertised session key.

Developers can use these APIs for one-to-one chat or encrypted transport of messages, replies, reactions, and file metadata through existing relay clients.

Invite is optional. If both sides exchange the ephemeral public keys and shared secret through another authenticated channel, they can construct matching Session values directly.

Persist the updated session after every successful send or receive. Serialized sessions and private invite URLs contain secret material; public invites can be answered by anyone.

The features are disabled by default, support no_std + alloc, and include interoperability, out-of-order delivery, persistence, tampering, identity-forgery, and failure-atomicity tests.

Checklist

  • I followed the contribution guidelines
  • I updated the relevant CHANGELOG.md
  • I understand and can explain all code in this PR

Dev added 2 commits August 10, 2026 14:14
Implement persistable Double Ratchet sessions and invite bootstrapping without session-manager storage or routing policy.

Follow the deployed reference protocol where the draft pseudocode was internally inconsistent.

Refs nostr-protocol/nips#1813
Explain that private invite URLs retain sensitive shared capability material while public invite events expose it, and distinguish acceptor-side invites from owned invites.
@mmalmi mmalmi changed the title nostr: add NIP-117 and NIP-118 support nostr: add Double Ratchet sessions and invites (NIP-117/118) Aug 10, 2026
Dev added 3 commits August 10, 2026 15:23
Add concise Rustdoc workflows for session routing, durable send state, invite acceptance, and first-message behavior. Remove the experimental label while retaining the proposal link.
Explain the protection provided when a main Nostr key is compromised and document direct session initialization through an authenticated key-exchange channel.
Separate session and crypto logic, invite and wire handling, tests, and interoperability fixtures without changing the public API or behavior.
@mmalmi
mmalmi marked this pull request as ready for review August 10, 2026 17:40
Bind invitee identities to their advertised session keys with a mandatory Schnorr proof, and reject proofless responses.\n\nBound encrypted inputs before allocation, strictly parse unsigned rumors, validate ratchet headers and raw NIP-44 versions, compare authentication tags in fixed time, and document identity and persistence requirements.\n\nAdd adversarial, atomicity, no_std, and TypeScript interoperability coverage.
@TheAwiteb

Copy link
Copy Markdown
Member

I think this NIP should have a crate for its own, like NIP-EE (Marmot) and Concord. Also we closed an issue before about Double Ratchet, it's not planned #791, this type of protocols is hard to maintain.

@TheAwiteb TheAwiteb closed this Aug 10, 2026
@TheAwiteb

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants