-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Add NIP-04 and NIP-44 encryption #83 #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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