# Nostr NIPs (Implementation Possibilities) - Complete Reference

**Verzió:** 1.0  
**Mélység:** Implementation Details  
**Cél:** Production-ready NIP reference

---

## Core NIPs (Mandatory/Required)

### NIP-01 - Basic Protocol

**Status:** ✅ MANDATORY

**Core requirements:**
- JSON format for events
- WebSocket transport (wss://)
- Client messages: EVENT, REQ, CLOSE
- Relay messages: EVENT, OK, EOSE, NOTICE

**Event structure:**
```json
{
  "id": "32-byte-hex",
  "pubkey": "32-byte-hex",
  "created_at": 1234567890,
  "kind": 1,
  "tags": [["e", "event-id"], ["p", "pubkey"]],
  "content": "Hello Nostr!",
  "sig": "64-byte-schnorr-signature"
}
```

**Implementation notes:**
- Event ID = SHA256(serialized event without signature)
- Signature = BIP-340 Schnorr
- All fields required

---

### NIP-02 - Follow List

**Kind:** 3 (Replaceable)

**Purpose:** Store user's follows (contact list)

**Format:**
```json
{
  "kind": 3,
  "tags": [
    ["p", "followed-pubkey", "relay-url", "petname"],
    ["p", "another-pubkey", "", ""]
  ],
  "content": "",
  "created_at": 1234567890
}
```

**Implementation:**
- Replaceable: Only latest kept per user
- p-tag: ["p", pubkey, relay_hint, local_name]

---

### NIP-19 - Bech32 Encoding

**Formats:**
- `npub1...` - Public key
- `nsec1...` - Private key (NEVER share)
- `note1...` - Event ID
- `nprofile1...` - Profile with relay hints
- `nevent1...` - Event with metadata

**TLV Structure for nprofile/nevent:**
```
Type 0 (Special): Author pubkey
Type 1 (Relay):   Relay URL
Type 2 (Kind):    Event kind (u16)
Type 3 (Identifier): d-tag for addressable
```

---

## Identity NIPs

### NIP-05 - DNS Mapping

**Purpose:** Human-readable identifiers (user@domain.com)

**Discovery:**
```
GET https://domain.com/.well-known/nostr.json?name=user

Response:
{
  "names": {
    "user": "hex-pubkey"
  },
  "relays": {
    "hex-pubkey": ["wss://relay1", "wss://relay2"]
  }
}
```

**Verification:**
1. Extract domain from identifier
2. Fetch /.well-known/nostr.json
3. Verify pubkey matches

---

### NIP-06 - Key Derivation from Seed

**Derivation Path:** `m/1237'/0'/{account}'/0/{index}`

- 1237 = SLIP-44 coin type for Nostr
- Supports BIP-39 mnemonic phrases
- Same seed = multiple Nostr identities

---

### NIP-46 - Remote Signing (nsecBunker)

**Connection URI:**
```
bunker://signer-pubkey?relay=wss://relay&secret=auth-secret
```

**Methods:**
- connect(pubkey, secret)
- get_public_key()
- sign_event(event)
- nip04_encrypt(pubkey, plaintext)
- nip04_decrypt(pubkey, ciphertext)
- nip44_encrypt/decrypt

**Use case:** Mobile signer, browser extension, hardware wallet

---

## Messaging NIPs

### NIP-04 - Encrypted DMs (DEPRECATED)

⚠️ **Use NIP-17 instead**

**Encryption:** ECDH + AES-256-CBC

---

### NIP-17 - Private DMs (Modern)

**Features:**
- Sealed sender (gift wrap - NIP-59)
- Better spam resistance
- Forward secrecy

**Kind 14 - Inner message:**
```json
{
  "kind": 14,
  "pubkey": "sender",
  "tags": **"p", "recipient"**,
  "content": "plaintext message",
  "created_at": 1234567890
}
```

**Wrapped in:** Kind 1059 (Gift Wrap)

---

### NIP-44 - Encrypted Payloads (Modern)

**Algorithm:** ChaCha20-Poly1305

**Versions:**
- v1 (deprecated): XChaCha20-Poly1305, 24-byte nonce
- v2 (current): ChaCha20-Poly1305, 32-byte nonce

**Key Derivation:** HKDF-SHA256(shared_secret, "nip44-v2")

**Format:**
```
version (1 byte) || nonce (32 bytes) || ciphertext || mac (16 bytes)
```

---

### NIP-59 - Gift Wrap (Sealed Sender)

**Purpose:** Anonymous messaging

**Flow:**
1. Generate ephemeral keypair
2. Encrypt real message (NIP-44) to recipient
3. Create wrapper event (kind 1059)
4. Sign with ephemeral key
5. Recipient unwraps and sees real sender

**Anonymity:** Relays can't correlate sender with recipient

---

## Content NIPs

### NIP-10 - Reply Threading

**Tag formats:**
```
["e", "event-id", "relay-url", "reply"]      - Direct reply
["e", "event-id", "relay-url", "root"]       - Thread root
["e", "event-id", "relay-url", "mention"]    - Mention without reply
["p", "pubkey", "relay-url"]                 - Mention user
```

**Thread building:**
1. Find root (oldest ancestor)
2. Build tree structure
3. Display as conversation

---

### NIP-18 - Reposts

**Kind 6 - Generic repost:**
```json
{
  "kind": 6,
  "content": "serialized-original-event",
  "tags": [["e", "event-id"], ["p", "author-pubkey"]]
}
```

**Kind 16 - Generic repost (any kind):**
- Same as 6 but for non-text notes

---

### NIP-23 - Long-form Content

**Kind 30023 - Article:**
```json
{
  "kind": 30023,
  "tags": [
    ["d", "article-slug"],
    ["title", "Article Title"],
    ["published_at", "1234567890"],
    ["image", "https://..."]
  ],
  "content": "# Markdown content"
}
```

**Kind 30024 - Draft:**
- Same structure but unpublished

---

## Financial NIPs

### NIP-57 - Lightning Zaps

**Kind 9734 - Zap Request:**
```json
{
  "kind": 9734,
  "content": "",
  "tags": [
    ["relays", "wss://relay1", "wss://relay2"],
    ["amount", "10000"],
    ["lnurl", "lnurl..."],
    ["p", "recipient-pubkey"],
    ["e", "event-id", "", "root"]
  ]
}
```

**Kind 9735 - Zap Receipt:**
```json
{
  "kind": 9735,
  "content": "description-json",
  "tags": [
    ["bolt11", "lnbc..."],
    ["description", "zap-request-json"],
    ["preimage", "payment-hash"],
    ["p", "recipient"],
    ["e", "zapped-event"]
  ]
}
```

---

### NIP-47 - Nostr Wallet Connect

**Purpose:** Remote wallet control

**Connection:**
```
nostr+walletconnect://pubkey?relay=wss://relay&secret=shared-secret
```

**Methods:**
- get_info
- get_balance
- pay_invoice
- make_invoice
- lookup_invoice
- list_transactions

---

## Infrastructure NIPs

### NIP-42 - Relay Authentication

**Challenge-Response:**
1. Relay sends: ["AUTH", "challenge-string"]
2. Client creates kind 22242:
   ```json
   {
     "kind": 22242,
     "tags": [
       ["relay", "wss://relay-url"],
       ["challenge", "challenge-string"]
     ],
     "content": ""
   }
   ```
3. Client sends: ["AUTH", signed-event]

---

### NIP-65 - Relay List Metadata

**Kind 10002 - User's relay preferences:**
```json
{
  "kind": 10002,
  "tags": [
    ["r", "wss://relay1.com"],
    ["r", "wss://relay2.com", "write"],
    ["r", "wss://relay3.com", "read"]
  ]
}
```

**Outbox model:**
- Write relays: Where user publishes
- Read relays: Where user reads
- Both: Default

---

### NIP-66 - Relay Discovery

**Kind 10013 - Relay information:**
- Operator pubkey
- Fees
- Supported NIPs
- Limitations

**Kind 10014 - Relay reviews:**
- User ratings of relays

---

## Moderation NIPs

### NIP-56 - Reporting

**Kind 1984 - Report:**
```json
{
  "kind": 1984,
  "content": "reason",
  "tags": [
    ["p", "reported-pubkey"],
    ["e", "reported-event"],
    ["report", "nudity|malware|profanity|illegal|spam|impersonation"]
  ]
}
```

---

### NIP-51 - Lists

**Kinds:**
- 10000 - Mute list
- 10001 - Pin list
- 10002 - Relay list (NIP-65)
- 10003 - Bookmark list
- 10004 - Community list
- 10005 - Public chats
- 10006 - Block relays
- 10007 - Search relays
- 10015 - Interests
- 10030 - Emoji sets

---

## Advanced NIPs

### NIP-34 - Git Integration

**Kinds:**
- 3121 - Issue
- 3122 - Reply to issue
- 3123 - Patch
- 3124 - Proposal (PR)

**Workflow:**
- Repository events (kind 30617)
- Git-over-Nostr protocol

---

### NIP-52 - Calendar Events

**Kinds:**
- 31920 - Calendar
- 31921 - RSVP
- 31922 - Date-based event
- 31923 - Time-based event
- 31924 - Check-in

---

### NIP-72 - Moderated Communities

**Kind 34550 - Community definition:**
```json
{
  "kind": 34550,
  "tags": [
    ["d", "community-name"],
    ["description", "Community description"],
    ["image", "url"],
    ["p", "moderator-pubkey", "", "moderator"],
    ["p", "admin-pubkey", "", "admin"]
  ]
}
```

---

## Implementation Priority

### Tier 1 (Core - Required)
- [x] NIP-01 - Basic protocol
- [x] NIP-02 - Follow list
- [x] NIP-19 - Bech32 encoding
- [x] NIP-10 - Reply threading
- [x] NIP-18 - Reposts

### Tier 2 (Messaging)
- [ ] NIP-04 - Legacy DMs (support reading only)
- [x] NIP-17 - Private DMs (implement)
- [x] NIP-44 - Modern encryption
- [x] NIP-59 - Gift wrap

### Tier 3 (Identity)
- [ ] NIP-05 - DNS (optional but nice)
- [x] NIP-06 - Key derivation
- [x] NIP-46 - Remote signing
- [x] NIP-49 - Encrypted key storage

### Tier 4 (Content)
- [ ] NIP-23 - Long-form
- [ ] NIP-30 - Custom emoji
- [x] NIP-57 - Zaps
- [ ] NIP-51 - Lists

### Tier 5 (Infrastructure)
- [x] NIP-42 - Auth
- [x] NIP-65 - Relay list
- [ ] NIP-66 - Relay discovery
- [ ] NIP-47 - Wallet connect

---

## Deprecated NIPs

| NIP | Reason | Replacement |
|-----|--------|-------------|
| NIP-04 | Weak encryption, metadata leaks | NIP-17 + NIP-59 |
| NIP-15 | Marketplace (unused) | - |
| NIP-35 | Torrents (unused) | - |

---

*Document Version: 1.0*  
*Total NIPs documented: 40+*
