dostr_nip44 0.1.0
dostr_nip44: ^0.1.0 copied to clipboard
Pure Dart NIP-44 encryption for Nostr, with the deprecated NIP-04 encryption next to it.
0.1.0 #
- Initial release, moved out of the
ndkpackage. Nip04only exposesencryptanddecrypt, and takes the same keys asNip44.Nip04.encrypt,Nip04.decrypt,Nip44.encryptMessageandNip44.decryptMessagetake the text or the payload first, then the keys as named parameters, so that a private key cannot take the place of a public key:senderPrivateKeyandrecipientPublicKeyto encrypt,recipientPrivateKeyandsenderPublicKeyto decrypt.Nip44.encryptMessageandNip44.decryptMessagereturn aStringinstead of aFuture<String>: they always did the work on the calling isolate.Nip04.decryptthrows aFormatExceptioninstead of returning an empty string for a payload without?iv=, and on any other malformed payload.Nip44.conversationKey,Nip44.encryptandNip44.decryptreplacecomputeSharedSecret,deriveConversationKeyand thecustomConversationKeyandcustomNonceparameters ofencryptMessageanddecryptMessage.conversationKeytakesprivateKeyandpublicKeyas named parameters.Nip44throwsNip44InvalidMacExceptionwhen the MAC does not match, aFormatExceptionfor an invalid key or payload, and anArgumentErrorfor a plaintext that is empty or longer than 4294967295 bytes, instead of a bareException.Nip44andNip04can no longer be instantiated, extended or implemented: they only hold static members.- No key ends up in an error message: neither an invalid private key nor an invalid public key, which could be a private key passed in its place.
Nip44.decryptMessagerejects a payload whose padding is not the one NIP-44 requires.Nip44.decryptandNip44.decryptMessagereject a payload that is not standard base64 with padding, as NIP-44 requires, instead of decoding the URL-safe alphabet or a%3Dpadding.Nip44encrypts and decrypts messages longer than 65535 bytes, up to 4294967295, with the 6-byte length prefix that NIP-44 added in nostr-protocol/nips#1907.Nip44.conversationKeyis 4 to 8 times faster: the secp256k1 key agreement runs ondostr_secp256k1instead of the pointycastle curve.Nip44.encryptandNip44.decryptare 2 to 4 times faster, with HMAC-SHA256 frompackage:crypto.