Add Kind 15 for Encrypted File message#1537
Conversation
|
@vitorpamplona @staab Do you have any suggestions for this proposal? This allows us to send encrypted files in DMs |
|
Since this is inside a seal and giftwrap, it is already encrypted. But that is OK if the content is at some URL encrypted under any other encryption algorithm. What doesn't make sense to me is base64 data in the content, since that double encryption doesn't seem necessary. Maybe just to have a different algorithm? Also the 'p' tags can't be looked up since they are inside the encrypted giftwrapped seal. So I'm not sure what they are for. |
They are there to define which NIP-17 group of users this image belongs to. It's similar to how kind 14 gets is group definitions. |
For private chats, file content encryption is essential. Otherwise, with only URL encryption, the file could still be visible to the file server, and if the URL is leaked or indexed, it could also be accessed by others. If I remember correctly, Signal uses the AES-GCM algorithm to encrypt file content? I think @erskingardner might also be interested, especially considering NIP-104, where file encryption could be added as well?
Ah yes, that’s right. Base64 placed in the content is encrypted through giftwrap, so there’s no need for additional double encryption. |
|
@water783 I am back to this. Kind 15 should be GiftWrapped in the same way as Kind 14, right? (It's not clear in the text). Can we add the following optional fields?
Those fields really help to set up the UI before the image loads. |
Yes, Kind 15 should be sealed & gift wrapped in the same way as Kind 14. Thanks for pointing that out.
I think they’re a great addition! Just updated the text, pls check it again. |
|
Last thing, it looks like 0xChat is converting hex to bytes for the key but just taking the UTF-8 of the hex string for the nonce. Is that how it is supposed to be? Or should we just hexToBytes the nonce as well? |
Ah my mistake, using hexToBytes is more reasonable, will fix it. |
|
Added support for Amethyst: vitorpamplona/amethyst@94c74a1 @water783 I am encoding the nonce from Hex. There is a fallback on Amethyst for older images from 0xchat. |
Awesome, thank you! I will also update the app to use nonce from Hex as soon as possible. |
|
Amethyst v0.94.0 now supports this add-on. |
|
I'm super late to the party here, but I'm working on adding files (images, videos, audio, etc.) to White Noise now and wanted to double check a few things. This seems to only really make sense for DMs, is that right? Right now, I'm planning on using the same kind: 445 events (which are group message events in the 104 spec). These are NIP-44 encrypted with a key that all group members have access to. The decrypted content of these events will simply be kind: 9 chat events will blossom URLs included. These blossom blobs will be the actual file/image/video being shared and those will be encrypted using the same key as is used for the NIP-44 encryption of the event itself. I've not decided on the encryption scheme but it probably makes the most sense to use the same scheme that is used in the group. Thoughts? |
Kind 15 reuses kind 14's DM tag structure to mark receivers and group chats, room title etc. So, yes I think it would only work within the NIP-17 scopes. But here are a few interesting things about this approach:
|
|
@vitorpamplona how are you using NIP-94 tags in Amethyst? It doesn't look like those are meant for social clients. I can see using some of the tags to help clients know how to render these images but since we're not sharing images as individual messages (I mean, I guess we could but that wasn't the plan) we don't have an event to put all those tags into for the image or file itself. Also - the design of this PR also has the same flaws with HTTP right? You're encrypting the full file and anyone wanting to download the file will need to download the full thing before being able to decrypt. I guess the one benefit here is that you can provide |
|
There are many ways, you can use NIP-92
That's what I said of 4. I don't think there is any way of using range requests with encrypted data at all. It has been an HTTP problem for quite some time. There are some techniques that pre-chunk and encrypt each chunk separately, but that means HTTP clients cannot decide the size of the chunk on demand and thus kind of defeats the purpose of range requests.
This should always be added, regardless of encrypting or not the file. |
File Message Kind
{ "id": "<usual hash>", "pubkey": "<sender-pubkey>", "created_at": "<current-time>", "kind": 15, "tags": [ ["p", "<receiver-1-pubkey>", "<relay-url>"], ["p", "<receiver-2-pubkey>", "<relay-url>"], ["e", "<kind-14-id>", "<relay-url>", "reply"], // if this is a reply ["subject", "<conversation-title>"], ["file-type", "<file-mime-type>"], ["encryption-algorithm", "<encryption-algorithm>"], ["decryption-key", "<decryption-key>"], ["decryption-nonce", "<decryption-nonce>"] // rest of tags... ], "content": "<file-url>" }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.).encryption-algorithm: Indicates the encryption algorithm used for encrypting the file. Supported algorithms may includeaes-gcm,chacha20-poly1305,aes-cbcetc.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.content: The URL of the file (<file-url>).