# Kind 14: Direct Message

## Overview

Direct Message events (kind 14) are used for private messaging between users. They use a sophisticated multi-layer encryption approach to protect the privacy and security of conversations. They replace the deprecated kind 4 encrypted direct messages, offering significantly improved privacy.

## Specification

| Property | Value |
|----------|-------|
| **Kind Number** | 14 |
| **Event Range** | Regular |
| **Defined in** | [NIP-17](https://github.com/nostr-protocol/nips/blob/master/17.md) |

## Content Format

The `content` field contains plain text message content. Unlike kind 4 messages, the content is not directly encrypted—instead, the entire event is encrypted using the Gift Wrap protocol (NIP-59) before transmission.

### Schema

```json
"content": "Plain text message content"
```

## Tags

| Tag Name | Description | Format | Required |
|----------|-------------|--------|----------|
| `p` | Recipient public key(s) | `["p", "<pubkey-hex>", "<relay-url>"]` | Yes |
| `e` | Referenced message (for replies) | `["e", "<event-id>", "<relay-url>"]` | No |
| `subject` | Conversation title/topic | `["subject", "Conversation subject"]` | No |
| `q` | Quoted event reference | `["q", "<event-id>", "<relay-url>", "<pubkey-hex>"]` | No |

## Client Behavior

Clients should:
1. Create direct messages as unsigned kind 14 events (called rumors)
2. Never sign or broadcast raw kind 14 events directly
3. Encrypt and wrap the messages using the NIP-59 Gift Wrap protocol:
   - Wrap the unsigned message in a Seal (kind 13)
   - Wrap the Seal in a Gift Wrap (kind 1059)
   - Create individual wrapped messages for each recipient
   - Create a copy for the sender too, for consistent history display

4. When publishing messages:
   - Look for the recipient's preferred DM relays in their kind 10050 event
   - Send the wrapped message to those relays

5. When receiving direct messages:
   - Unwrap the Gift Wrap and Seal layers
   - Verify that the inner message's pubkey matches the Seal's pubkey
   - Display messages from the same group of participants as a conversation thread

## Relay Behavior

Relays should:
1. Only serve kind 1059 Gift Wrap events to their intended recipients
2. Consider requiring authentication (NIP-42) for DM access
3. Not retain or log the encrypted content of messages

## Use Cases

- Private one-on-one conversations
- Small private group chats
- Encrypted file sharing (using kind 15)
- Secure conversations with metadata protection

## Example

```json
// Note: This is how the UNSIGNED event looks before being sealed and wrapped
{
  "id": "4376c65d2f232afbe9b882a35baa4f6fe8667c4e684749af565f981833ed6a65",
  "pubkey": "79dff8f82963424e0bb02708a22e44b4980893e3a4be0fa3cb60a43b946764e3",
  "created_at": 1671217411,
  "kind": 14,
  "tags": [
    ["p", "f7234bd4c1394dda46d09f35bd384dd30cc552ad5541990f98844fb06676e9ca", "wss://relay.example.com"],
    ["subject", "Meeting tomorrow"]
  ],
  "content": "Hey, are we still meeting tomorrow at 2pm?"
}

// This event would never be broadcast directly - it would be wrapped in a Seal and Gift Wrap
```

## Authentication & Privacy

The multi-layered encryption approach:
1. **Rumor Layer**: Unsigned event (deniability)
2. **Seal Layer**: Encrypted with sender's key (authenticity)
3. **Gift Wrap Layer**: Encrypted with a throwaway key (metadata protection)

This protects:
- Message content (through encryption)
- Sender identity (only recipient can know who sent it)
- Message timestamps (randomized to prevent timing analysis)
- Social graph information (hard to determine who is messaging whom)

## Relay Discovery

Users publish a kind 10050 event listing their preferred DM relays:

```json
{
  "kind": 10050,
  "tags": [
    ["relay", "wss://inbox.nostr.wine"],
    ["relay", "wss://relay.example.com"]
  ],
  "content": ""
}
```

Senders should check this list and only send messages to the recipient's chosen relays.

## References

- [NIP-17: Private Direct Messages](https://github.com/nostr-protocol/nips/blob/master/17.md)
- [NIP-59: Gift Wrap](https://github.com/nostr-protocol/nips/blob/master/59.md)
- [NIP-44: Encrypted Payloads](https://github.com/nostr-protocol/nips/blob/master/44.md)

## Related Kinds

- [Kind 4: Encrypted Direct Message](/kinds/4) - Deprecated predecessor
- [Kind 13: Seal](/kinds/13) - Used to wrap and sign the message
- [Kind 15: File Message](/kinds/15) - For sending encrypted files
- [Kind 1059: Gift Wrap](/kinds/1059) - Outer encryption layer
- [Kind 10050: DM Relays](/kinds/10050) - User's preferred DM relays

## Notes

- Unlike kind 4 messages, kind 14 messages must never be signed or broadcast directly
- Kind 14 messages support both one-on-one and small group conversations
- The same encryption approach is used for kind 15 file messages
- Users can opt into disappearing messages functionality
- Participants in a conversation are determined by the combination of the sender pubkey and all p-tagged pubkeys
- The newest message with a subject tag determines the conversation's title