feat: Add NIP-04 and NIP-44 encryption #83#84
Conversation
|
@dsbaars thanks for this great PR for adding NIP-04 and NIP-44! In general these are my first comments when checking the code: For consistency, in line with the other examples:
The NIP-04 and NIP-44 classes require the hex formatted key values, but there are no specific checks or expections returned when you enter a bech32 formatted key for example. |
| * Decrypt a message using NIP-04 (AES-CBC). | ||
| */ | ||
| public static function decrypt(string $ciphertext, string $privateKey, string $publicKey): string | ||
| { |
There was a problem hiding this comment.
If $privateKey and/or $publicKey are bech32 formatted:
- convert to hex formatted key
- throw Exception
| * Encrypt a message using NIP-04 (AES-CBC). | ||
| */ | ||
| public static function encrypt(string $text, string $privateKey, string $publicKey): string | ||
| { |
There was a problem hiding this comment.
If $privateKey and/or $publicKey are bech32 formatted:
- convert to hex formatted key
- throw Exception
src/Examples/encrypted-messages.php
Outdated
| use swentel\nostr\Sign\Sign; | ||
| use swentel\nostr\Key\Key; | ||
|
|
||
| // Initialize key generator |
There was a problem hiding this comment.
You could surround the runtime code with a try-catch.
src/Examples/nip44-gift-wrapping.php
Outdated
| use swentel\nostr\Sign\Sign; | ||
| use swentel\nostr\Key\Key; | ||
|
|
||
| // Initialize key generator |
There was a problem hiding this comment.
You could surround the runtime code with a try-catch.
src/Examples/encrypted-messages.php
Outdated
| $event->setCreatedAt(time()); | ||
| $signer->signEvent($event, $alicePrivKey); | ||
|
|
||
| echo "Original message: $message\n"; |
There was a problem hiding this comment.
You could replace all \n newlines with a PHP_EOL
src/Examples/nip44-gift-wrapping.php
Outdated
| $charliePubKey = $keyGenerator->getPublicKey($charliePrivKey); | ||
| $charlieNpub = $keyGenerator->convertPublicKeyToBech32($charliePubKey); | ||
|
|
||
| echo "Generated keys:\n"; |
There was a problem hiding this comment.
You could replace all \n newlines with a PHP_EOL
Added NIP-04 and NIP-44 encryption (version 2) based on nostr-tools, also added examples and tests, based on the vectors provided at https://github.com/paulmillr/nip44/blob/main/nip44.vectors.json.
It does show some depreciated notices because of not yet updated dependencies.
Implements #83