fix bug in bot with nip44 encryption

This commit is contained in:
Believethehype
2024-12-05 08:33:55 +01:00
parent b5c2fdd1e7
commit 93ab545581
4 changed files with 186 additions and 33 deletions

View File

@@ -7,55 +7,62 @@
import asyncio
from nostr_sdk import EventId, Keys, Client, NostrSigner
from datetime import timedelta
from nostr_sdk import Keys, Client, NostrSigner, Filter
from nostr_dvm.utils.definitions import EventDefinitions
from nostr_dvm.utils.dvmconfig import DVMConfig
from nostr_dvm.utils.nip89_utils import fetch_nip89_parameters_for_deletion
# Method to delete the NIP89, don't worry, you don't have to touch this, take a look in the main function.
async def delete_nip_89(event_id, private_key, relay_list, pow=True):
event_id = EventId.parse(event_id).to_hex()
async def delete_nip_89(private_key, relay_list, pow=True):
keys = Keys.parse(private_key)
dvm_config = DVMConfig()
dvm_config.RELAY_LIST = relay_list
client = Client(NostrSigner.keys(keys))
for relay in dvm_config.RELAY_LIST:
await client.add_relay(relay)
await client.connect()
filter = Filter().kind(EventDefinitions.KIND_ANNOUNCEMENT).author(keys.public_key())
events = await client.fetch_events([filter], timedelta(seconds=5))
await fetch_nip89_parameters_for_deletion(keys, event_id, client, dvm_config, pow)
if len(events.to_vec()) == 0:
print("Couldn't find note on relays. Seems they are gone.")
return
for event in events.to_vec():
print(event)
await fetch_nip89_parameters_for_deletion(keys, event.id().to_hex(), client, dvm_config, pow)
if __name__ == '__main__':
# What do you need to delete an event?
# First, you need the event id of the announcement. You can copy the json of the announcement from various clients,
# like Amethyst or you should also see it at noogle.lol/nip89. Copy the json to a text editor and in the first line
# you should see an entry "id":"someid". Copy the id and enter it in the event_id field below:
evend_id = "6f91dce309e....."
# The second thing you need is the private key of the DVM the announcement was made for.
# NostrDVM stores all your keys in the .env file. Open the .env file and search for
# The first thing you need is the private key of the DVM the announcement was made for.
# NostrDVM stores all your keys in the .env file. Open the .env file and search for
# DVM_PRIVATE_KEY_{IDENTIFIER_OF_YOUR_DVM}. Enter it below in the field private_key:
private_key = "6221e3181....."
private_key = "83274234123..."
# You can either use Proof of Work to send the delete event or not. Some relays require you to use POW in order to write.
# Sending a POW event might take up to a couple of minutes, so if you decide to use it, have some patience in the progress.
# If you know the relays you published your announcements to do not require POW, you can also set it to False which speeds up the progress.
pow = True
# And finally set the relay list you want to send the deletion request to. Ideally, you use the same relays that you use
pow = False
# And finally set the relay list you want to send the deletion request to. Ideally, you use the same relays that you use
# in your DVM's config. Maybe announcements also got propagated to other relays, so you might need to play around a bit until it's gone everywhere.
RELAY_LIST = ["wss://relay.primal.net",
"wss://relay.damus.io",
"wss://relay.nostrplebs.com",
"wss://promenade.fiatjaf.com",
"wss://nostr.mom",
"wss://nostr.oxtr.dev",
"wss://relay.nostr.band"
]
# That's it. Once you entered the info, run the script and if your private key matches the ID and the event can be found it should be deleted.
# That's it. Once you entered the info, run the script and if your private key matches the ID and the event can be found it should be deleted.
# Otherwise you'll get a warning
asyncio.run(delete_nip_89(evend_id, private_key, RELAY_LIST, pow))
asyncio.run(delete_nip_89(private_key, RELAY_LIST, pow))