After working on this on and off for 7 days, I've finally finished implementing NIP-44 encryption in Swift for use on Apple platforms! This will replace the unrecommended NIP-04 encryption. Definitely lost a few hairs and gained a few gray ones. ๐Ÿ˜… Thanks to nostr:npub1qlk0nqupxmlyxravg0aqscxmcc4q4tq898z6x003rykwwh3npj0syvyayc for reviewing my PR to Nostr SDK for Apple Platforms and thanks to nostr:npub16zsllwrkrwt5emz2805vhjewj6nsjrw0ge0latyrn2jv5gxf5k0q5l92l7 from Nos for pair programming with me when I got stuck.

https://github.com/nostr-sdk/nostr-sdk-ios/pull/138

Iโ€™ve submitted a forked copy to the shared nip44 repo. Please review and double-check my work if youโ€™re able to read Swift code. All the test vectors pass, though. nostr:npub10jcnehsxwrjepupvh602pl83up0dh3wv3fqfwv062smygqvpeuwsk03kag nostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z nostr:npub1acg6thl5psv62405rljzkj8spesceyfz2c32udakc2ak0dmvfeyse9p35c

https://github.com/paulmillr/nip44/pull/11

Reply to this note

Please Login to reply.

Discussion

Haha! Nice work Terry!

Can you translate for us non-tech fam, thanks!

Appreciate your work ๐Ÿ™

The claim is that every time you encrypt a message with NIP-04, it decreases the difficulty for an attacker to determine your private key. Iโ€™m not a cryptographer, so I canโ€™t verify the claim. The design and professional cryptography audit of NIP-44 was funded by OpenSats, mitigates that attack vector, and is allegedly a better encryption scheme than NIP-04. It does have known limitations as mentioned in the specification. NIP-04 is unrecommended but it has not yet been replaced in all the other NIPs that use it. The developer community needs to work on moving towards implementing NIP-44 encryption for all encrypted messages, including DMs, while still maintaining backward compatibility with NIP-04 encrypted messages.

https://github.com/nostr-protocol/nips/blob/master/44.md

https://opensats.org/blog/nostr-grants-december-2023#nip-44-cryptography-audit

Thanks! Weโ€™re looking forward being able to use this for encrypted notes, not just DMs, in NOS!

One real world scenario I encountered while testing coracle is that if only nip-44 is implemented this is not backwards compatible with nip-04. Not sure at all about NIPs best practices, and if this is best addressed at all in NIPs, SDKs.

I think nostr:npub1jlrs53pkdfjnts29kveljul2sm0actt6n8dxrrzqcersttvcuv3qdjynqn had thought this through on coracle, and there was some bug he squashed to make these DMs NIPs compatible.

The way I see it working is:

1. Have all the major clients and SDKs support encryption and decryption for both NIP-04 and NIP-44 for some time but have NIP-44 be the default for encryption.

2. Clients can allow users to migrate their signed NIP-04 encrypted events by decrypting them and creating new ones with identical content but encrypted with NIP-44.

3. Once most people stop creating new NIP-04 encrypted events, remove support for encrypting in NIP-04 and support only decrypting NIP-04 moving forward. NIP-44 becomes the only way to encrypt events.

NIP 04 is used all over the place still, including DMs, can you describe what you're seeing in more detail?

Coracle handles backwards compatibility to nip-04 fine, no issues with Coracle.

I mentioned to Terry that some apps may still use nip-04, and not nip-44. Therefore if new apps build only nip-44, without taking into account backwards compatibility this would be a nostr interoperability or #nostrability pain point.

Ah yes, it certainly would

Nice! Let's go! ๐Ÿš€

๐Ÿš€ fuck yeah