NIP-17 json formatting fix, text cleanup and more precise language (#1909)

This commit is contained in:
Vitor Pamplona 2025-05-05 09:36:20 -04:00 committed by GitHub
parent 5b7d338200
commit 86f0da716f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

75
17.md
View file

@ -15,17 +15,17 @@ Kind `14` is a chat message. `p` tags identify one or more receivers of the mess
```jsonc ```jsonc
{ {
"id": "<usual hash>", "id": "<usual hash>",
  "pubkey": "<sender-pubkey>", "pubkey": "<sender-pubkey>",
"created_at": "<current-time>", "created_at": "<current-time>",
  "kind": 14, "kind": 14,
  "tags": [ "tags": [
    ["p", "<receiver-1-pubkey>", "<relay-url>"], ["p", "<receiver-1-pubkey>", "<relay-url>"],
    ["p", "<receiver-2-pubkey>", "<relay-url>"], ["p", "<receiver-2-pubkey>", "<relay-url>"],
    ["e", "<kind-14-id>", "<relay-url>"] // if this is a reply ["e", "<kind-14-id>", "<relay-url>"] // if this is a reply
["subject", "<conversation-title>"], ["subject", "<conversation-title>"],
    // rest of tags... // rest of tags...
  ], ],
  "content": "<message-in-plain-text>", "content": "<message-in-plain-text>",
} }
``` ```
@ -65,21 +65,22 @@ Kind `14`s MUST never be signed. If it is signed, the message might leak to rela
} }
``` ```
Kind 15 is used for sending encrypted file event messages: Kind `15` is used for sending encrypted file event messages:
- `file-type`: Specifies the MIME type of the attached file (e.g., `image/jpeg`, `audio/mpeg`, etc.). - `file-type`: Specifies the MIME type of the attached file (e.g., `image/jpeg`, `audio/mpeg`, etc.) before encryption.
- `encryption-algorithm`: Indicates the encryption algorithm used for encrypting the file. Supported algorithms may include `aes-gcm`, `chacha20-poly1305`,`aes-cbc` etc. - `encryption-algorithm`: Indicates the encryption algorithm used for encrypting the file. Supported algorithms: `aes-gcm`.
- `decryption-key`: The decryption key that will be used by the recipient to decrypt the file. - `decryption-key`: The decryption key that will be used by the recipient to decrypt the file.
- `decryption-nonce`: The decryption nonce that will be used by the recipient to decrypt the file. - `decryption-nonce`: The decryption nonce that will be used by the recipient to decrypt the file.
- `content`: The URL of the file (`<file-url>`). - `content`: The URL of the file (`<file-url>`).
- `x` containing the SHA-256 hexencoded string of the file. - `x` containing the SHA-256 hexencoded string of the encrypted file.
- `size` (optional) size of file in bytes - `ox` containing the SHA-256 hexencoded string of the file before encryption.
- `dim` (optional) size of the file in pixels in the form `<width>x<height>` - `size` (optional) size of the encrypted file in bytes
- `dim` (optional) size in pixels in the form `<width>x<height>`
- `blurhash`(optional) the [blurhash](https://github.com/woltapp/blurhash) to show while the client is loading the file - `blurhash`(optional) the [blurhash](https://github.com/woltapp/blurhash) to show while the client is loading the file
- `thumb` (optional) URL of thumbnail with same aspect ratio (encrypted with the same key, nonce) - `thumb` (optional) URL of thumbnail with same aspect ratio (encrypted with the same key, nonce)
- `fallback` (optional) zero or more fallback file sources in case `url` fails - `fallback` (optional) zero or more fallback file sources in case `url` fails (encrypted with the same key, nonce)
Just like kind 14, kind `15`s MUST never be signed. Just like kind `14`, kind `15`s MUST never be signed.
## Chat Rooms ## Chat Rooms
@ -87,34 +88,34 @@ The set of `pubkey` + `p` tags defines a chat room. If a new `p` tag is added or
Clients SHOULD render messages of the same room in a continuous thread. Clients SHOULD render messages of the same room in a continuous thread.
An optional `subject` tag defines the current name/topic of the conversation. Any member can change the topic by simply submitting a new `subject` to an existing `pubkey` + `p`-tags room. There is no need to send `subject` in every message. The newest `subject` in the thread is the subject of the conversation. An optional `subject` tag defines the current name/topic of the conversation. Any member can change the topic by simply submitting a new `subject` to an existing `pubkey` + `p` tags room. There is no need to send `subject` in every message. The newest `subject` in the chat room is the subject of the conversation.
## Encrypting ## Encrypting
Following [NIP-59](59.md), the **unsigned** `kind:14` & `kind:15` chat messages must be sealed (`kind:13`) and then gift-wrapped (`kind:1059`) to each receiver and the sender individually. Following [NIP-59](59.md), the **unsigned** `kind:14` & `kind:15` chat messages must be sealed (`kind:13`) and then gift-wrapped (`kind:1059`) to each receiver and the sender individually.
```jsonc ```js
{ {
"id": "<usual hash>", "id": "<usual hash>",
  "pubkey": randomPublicKey, "pubkey": randomPublicKey,
  "created_at": randomTimeUpTo2DaysInThePast(), "created_at": randomTimeUpTo2DaysInThePast(),
"kind": 1059, // gift wrap "kind": 1059, // gift wrap
  "tags": [ "tags": [
    ["p", receiverPublicKey, "<relay-url>"] // receiver ["p", receiverPublicKey, "<relay-url>"] // receiver
  ], ],
  "content": nip44Encrypt( "content": nip44Encrypt(
    { {
"id": "<usual hash>", "id": "<usual hash>",
      "pubkey": senderPublicKey, "pubkey": senderPublicKey,
      "created_at": randomTimeUpTo2DaysInThePast(), "created_at": randomTimeUpTo2DaysInThePast(),
      "kind": 13, // seal "kind": 13, // seal
      "tags": [], // no tags "tags": [], // no tags
      "content": nip44Encrypt(unsignedKind14, senderPrivateKey, receiverPublicKey), "content": nip44Encrypt(unsignedKind14, senderPrivateKey, receiverPublicKey),
      "sig": "<signed by senderPrivateKey>" "sig": "<signed by senderPrivateKey>"
    }, },
    randomPrivateKey, receiverPublicKey randomPrivateKey, receiverPublicKey
  ), ),
  "sig": "<signed by randomPrivateKey>" "sig": "<signed by randomPrivateKey>"
} }
``` ```
@ -124,7 +125,7 @@ Clients MUST verify if pubkey of the `kind:13` is the same pubkey on the `kind:1
Clients SHOULD randomize `created_at` in up to two days in the past in both the seal and the gift wrap to make sure grouping by `created_at` doesn't reveal any metadata. Clients SHOULD randomize `created_at` in up to two days in the past in both the seal and the gift wrap to make sure grouping by `created_at` doesn't reveal any metadata.
The gift wrap's `p`-tag can be the receiver's main pubkey or an alias key created to receive DMs without exposing the receiver's identity. The gift wrap's `p` tag can be the receiver's main pubkey or an alias key created to receive DMs without exposing the receiver's identity.
Clients CAN offer disappearing messages by setting an `expiration` tag in the gift wrap of each receiver or by not generating a gift wrap to the sender's public key Clients CAN offer disappearing messages by setting an `expiration` tag in the gift wrap of each receiver or by not generating a gift wrap to the sender's public key