python-nostr icon indicating copy to clipboard operation
python-nostr copied to clipboard

import EncryptedDirectMessage fails using python3.10, nostr 0.0.2

Open realJogicodes opened this issue 2 years ago • 5 comments

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)

realJogicodes avatar May 12 '23 12:05 realJogicodes

I dug a little and turns out that when you pip install nostr, the nostr.event.py is currently lacking EncryptedDirectMessage.

realJogicodes avatar May 12 '23 13:05 realJogicodes

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.

ricardowaldow avatar May 17 '23 01:05 ricardowaldow

I am using CalleBTC fork now. That has DMs working.

realJogicodes avatar May 18 '23 13:05 realJogicodes

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.

ricardowaldow avatar May 19 '23 01:05 ricardowaldow

I am using CalleBTC fork now. That has DMs working.

💁‍♂️ https://github.com/callebtc/python-nostr

escapedcat avatar Jul 12 '23 07:07 escapedcat