import EncryptedDirectMessage fails using python3.10, nostr 0.0.2
Hi
I cannot import EncryptedDirectMessage. Here's the environment:
$ pip freeze
cffi==1.15.1
cryptography==40.0.2
nostr==0.0.2
pycparser==2.21
secp256k1==0.14.0
websocket-client==1.5.1
The python code:
from nostr.event import EncryptedDirectMessage
The error:
ImportError: cannot import name 'EncryptedDirectMessage' from 'nostr.event' (/home/jogi/nostr-message/env/lib/python3.10/site-packages/nostr/event.py)
I dug a little and turns out that when you pip install nostr, the nostr.event.py is currently lacking EncryptedDirectMessage.
Same is happening to me. It is outdated in pypi, the EncryptedDirectMessage was added at Feb 4 and the latest version on pypi is from Jan 26.
I am using CalleBTC fork now. That has DMs working.
I installed and i can send the DMs but an error always occurs when i try to decrypt the message content.
Traceback (most recent call last):
File "/home/user/folder/nostr-py-test/test.py", line 46, in <module>
print(private_key.decrypt_message(event_msg.event.content, public_key.hex()))
File "/home/user/folder/nostr-py-test/venv/lib/python3.10/site-packages/nostr/key.py", line 102, in decrypt_message
unpadded_data = unpadder.update(decrypted_message) + unpadder.finalize()
File "/home/user/folder/nostr-py-test/venv/lib/python3.10/site-packages/cryptography/hazmat/primitives/padding.py", line 159, in finalize
result = _byte_unpadding_check(
File "/home/user/folder/nostr-py-test/venv/lib/python3.10/site-packages/cryptography/hazmat/primitives/padding.py", line 101, in _byte_unpadding_check
raise ValueError("Invalid padding bytes.")
ValueError: Invalid padding bytes.
Edit: I was using the wrong pubkey to decrypt. Now its working.
I am using CalleBTC fork now. That has DMs working.
💁♂️ https://github.com/callebtc/python-nostr