From 19c554d7bf3ab35b11b52259cef2b72fcfb8145a Mon Sep 17 00:00:00 2001 From: Believethehype Date: Sat, 17 Feb 2024 20:40:56 +0100 Subject: [PATCH 1/3] update to nostrsdk0.11.1 (for testing) --- examples/ollama_dvm/test_client.py | 8 +++---- examples/tts_dvm/test_client.py | 10 ++++---- main.py | 2 +- nostr_dvm/bot.py | 8 +++---- nostr_dvm/dvm.py | 13 +++++----- nostr_dvm/interfaces/dvmtaskinterface.py | 2 +- nostr_dvm/tasks/advanced_search.py | 6 ++--- nostr_dvm/tasks/advanced_search_wine.py | 2 +- nostr_dvm/tasks/discovery_inactive_follows.py | 10 ++++---- nostr_dvm/tasks/discovery_nonfollowers.py | 10 ++++---- nostr_dvm/utils/admin_utils.py | 2 +- nostr_dvm/utils/database_utils.py | 2 +- nostr_dvm/utils/definitions.py | 4 +++- nostr_dvm/utils/dvmconfig.py | 3 ++- nostr_dvm/utils/external_dvm_utils.py | 6 ++--- nostr_dvm/utils/nip89_utils.py | 4 ++-- nostr_dvm/utils/nostr_utils.py | 6 ++--- nostr_dvm/utils/nwc_tools.py | 10 ++++---- nostr_dvm/utils/zap_utils.py | 2 +- setup.py | 4 ++-- tests/gui/nicegui/nostrAI_search_client.py | 6 ++--- tests/test_dvm_client.py | 24 +++++++++---------- tests/test_events.py | 6 ++--- ui/noogle/src/components/Nip89view.vue | 2 +- ui/noogle/src/store.js | 2 +- 25 files changed, 78 insertions(+), 76 deletions(-) diff --git a/examples/ollama_dvm/test_client.py b/examples/ollama_dvm/test_client.py index b16aa356..331745dc 100644 --- a/examples/ollama_dvm/test_client.py +++ b/examples/ollama_dvm/test_client.py @@ -4,7 +4,7 @@ from threading import Thread import dotenv -from nostr_sdk import Keys, Client, ClientSigner, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt +from nostr_sdk import Keys, Client, NostrSigner, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key @@ -12,7 +12,7 @@ def nostr_client_test_llm(prompt): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) iTag = Tag.parse(["i", prompt, "text"]) relaysTag = Tag.parse(['relays', "wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", @@ -24,7 +24,7 @@ def nostr_client_test_llm(prompt): relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", "wss://nostr-pub.wellorder.net"] - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) for relay in relay_list: @@ -35,7 +35,7 @@ def nostr_client_test_llm(prompt): return event.as_json() def nostr_client(): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) sk = keys.secret_key() pk = keys.public_key() print(f"Nostr Test Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ") diff --git a/examples/tts_dvm/test_client.py b/examples/tts_dvm/test_client.py index bd211f34..a12a3a53 100644 --- a/examples/tts_dvm/test_client.py +++ b/examples/tts_dvm/test_client.py @@ -5,7 +5,7 @@ import dotenv from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \ - ClientSigner + NostrSigner from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key @@ -13,7 +13,7 @@ def nostr_client_test_tts(prompt): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) iTag = Tag.parse(["i", prompt, "text"]) paramTag1 = Tag.parse(["param", "language", "en"]) @@ -30,7 +30,7 @@ def nostr_client_test_tts(prompt): "wss://nostr-pub.wellorder.net"] - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) for relay in relay_list: client.add_relay(relay) @@ -40,11 +40,11 @@ def nostr_client_test_tts(prompt): return event.as_json() def nostr_client(): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) sk = keys.secret_key() pk = keys.public_key() print(f"Nostr Test Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ") - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) dvmconfig = DVMConfig() diff --git a/main.py b/main.py index 36d220f1..0dd5efba 100644 --- a/main.py +++ b/main.py @@ -25,7 +25,7 @@ def playground(): # Note this is very basic for now and still under development bot_config = DVMConfig() bot_config.PRIVATE_KEY = check_and_set_private_key("bot") - npub = Keys.from_sk_str(bot_config.PRIVATE_KEY).public_key().to_bech32() + npub = Keys.parse(bot_config.PRIVATE_KEY).public_key().to_bech32() invoice_key, admin_key, wallet_id, user_id, lnaddress = check_and_set_ln_bits_keys("bot", npub) bot_config.LNBITS_INVOICE_KEY = invoice_key bot_config.LNBITS_ADMIN_KEY = admin_key # The dvm might pay failed jobs back diff --git a/nostr_dvm/bot.py b/nostr_dvm/bot.py index cde4ece6..6e3022fe 100644 --- a/nostr_dvm/bot.py +++ b/nostr_dvm/bot.py @@ -5,7 +5,7 @@ from datetime import timedelta from nostr_sdk import (Keys, Client, Timestamp, Filter, nip04_decrypt, HandleNotification, EventBuilder, PublicKey, - Options, Tag, Event, nip04_encrypt, ClientSigner, EventId, Nip19Event) + Options, Tag, Event, nip04_encrypt, NostrSigner, EventId, Nip19Event) from nostr_dvm.utils.admin_utils import admin_make_database_updates from nostr_dvm.utils.database_utils import get_or_add_user, update_user_balance, create_sql_table, update_sql_table @@ -30,12 +30,12 @@ def __init__(self, dvm_config, admin_config=None): nip89config.NAME = self.NAME self.dvm_config.NIP89 = nip89config self.admin_config = admin_config - self.keys = Keys.from_sk_str(dvm_config.PRIVATE_KEY) + self.keys = Keys.parse(dvm_config.PRIVATE_KEY) wait_for_send = True skip_disconnected_relays = True opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)) .skip_disconnected_relays(skip_disconnected_relays)) - signer = ClientSigner.keys(self.keys) + signer = NostrSigner.keys(self.keys) self.client = Client.with_opts(signer, opts) pk = self.keys.public_key() @@ -211,7 +211,7 @@ def handle_nip90_feedback(nostr_event): if is_encrypted: if ptag == self.keys.public_key().to_hex(): - tags_str = nip04_decrypt(Keys.from_sk_str(dvm_config.PRIVATE_KEY).secret_key(), + tags_str = nip04_decrypt(Keys.parse(dvm_config.PRIVATE_KEY).secret_key(), nostr_event.author(), nostr_event.content()) params = json.loads(tags_str) params.append(Tag.parse(["p", ptag]).as_vec()) diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index 2563e794..fec61cc0 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -5,7 +5,7 @@ from sys import platform from nostr_sdk import PublicKey, Keys, Client, Tag, Event, EventBuilder, Filter, HandleNotification, Timestamp, \ - init_logger, LogLevel, Options, nip04_encrypt, ClientSigner + init_logger, LogLevel, Options, nip04_encrypt, NostrSigner import time @@ -21,9 +21,6 @@ parse_amount_from_bolt11_invoice, zaprequest, pay_bolt11_ln_bits, create_bolt11_lud16 from nostr_dvm.utils.cashu_utils import redeem_cashu -use_logger = False -if use_logger: - init_logger(LogLevel.DEBUG) class DVM: @@ -37,15 +34,17 @@ class DVM: def __init__(self, dvm_config, admin_config=None): self.dvm_config = dvm_config self.admin_config = admin_config - self.keys = Keys.from_sk_str(dvm_config.PRIVATE_KEY) + self.keys = Keys.parse(dvm_config.PRIVATE_KEY) wait_for_send = True skip_disconnected_relays = True opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)) .skip_disconnected_relays(skip_disconnected_relays)) - signer = ClientSigner.keys(self.keys) + signer = NostrSigner.keys(self.keys) self.client = Client.with_opts(signer,opts) + if dvm_config.SHOWLOG: + init_logger(LogLevel.DEBUG) self.job_list = [] self.jobs_on_hold_list = [] @@ -472,7 +471,7 @@ def send_job_status_reaction(original_event, status, is_paid=True, amount=0, cli else: content = reaction - keys = Keys.from_sk_str(dvm_config.PRIVATE_KEY) + keys = Keys.parse(dvm_config.PRIVATE_KEY) reaction_event = EventBuilder(EventDefinitions.KIND_FEEDBACK, str(content), reply_tags).to_event(keys) send_event(reaction_event, client=self.client, dvm_config=self.dvm_config) print("[" + self.dvm_config.NIP89.NAME + "]" + ": Sent Kind " + str( diff --git a/nostr_dvm/interfaces/dvmtaskinterface.py b/nostr_dvm/interfaces/dvmtaskinterface.py index c3b2e070..6b45b4d5 100644 --- a/nostr_dvm/interfaces/dvmtaskinterface.py +++ b/nostr_dvm/interfaces/dvmtaskinterface.py @@ -40,7 +40,7 @@ def init(self, name, dvm_config, admin_config=None, nip89config=None, task=None) self.NAME = name self.PRIVATE_KEY = dvm_config.PRIVATE_KEY if dvm_config.PUBLIC_KEY == "" or dvm_config.PUBLIC_KEY is None: - dvm_config.PUBLIC_KEY = Keys.from_sk_str(dvm_config.PRIVATE_KEY).public_key().to_hex() + dvm_config.PUBLIC_KEY = Keys.parse(dvm_config.PRIVATE_KEY).public_key().to_hex() self.PUBLIC_KEY = dvm_config.PUBLIC_KEY if dvm_config.FIX_COST is not None: self.FIX_COST = dvm_config.FIX_COST diff --git a/nostr_dvm/tasks/advanced_search.py b/nostr_dvm/tasks/advanced_search.py index eadc4fe4..a3c92a8d 100644 --- a/nostr_dvm/tasks/advanced_search.py +++ b/nostr_dvm/tasks/advanced_search.py @@ -1,7 +1,7 @@ import json import os from datetime import timedelta -from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, ClientSigner +from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv from nostr_dvm.utils.admin_utils import AdminConfig @@ -90,8 +90,8 @@ def process(self, request_form): opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))) sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) - keys = Keys.from_sk_str(sk.to_hex()) - signer = ClientSigner.keys(keys) + keys = Keys.parse(sk.to_hex()) + signer = NostrSigner.keys(keys) cli = Client.with_opts(signer, opts) cli.add_relay(options["relay"]) diff --git a/nostr_dvm/tasks/advanced_search_wine.py b/nostr_dvm/tasks/advanced_search_wine.py index 00ab5c76..746c18e3 100644 --- a/nostr_dvm/tasks/advanced_search_wine.py +++ b/nostr_dvm/tasks/advanced_search_wine.py @@ -3,7 +3,7 @@ from datetime import timedelta import requests -from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, ClientSigner, Event +from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Event from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv from nostr_dvm.utils.admin_utils import AdminConfig diff --git a/nostr_dvm/tasks/discovery_inactive_follows.py b/nostr_dvm/tasks/discovery_inactive_follows.py index 66bc81bd..83849b86 100644 --- a/nostr_dvm/tasks/discovery_inactive_follows.py +++ b/nostr_dvm/tasks/discovery_inactive_follows.py @@ -3,7 +3,7 @@ from datetime import timedelta from threading import Thread -from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, ClientSigner +from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv from nostr_dvm.utils.admin_utils import AdminConfig @@ -68,8 +68,8 @@ def process(self, request_form): opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))) sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) - keys = Keys.from_sk_str(sk.to_hex()) - signer = ClientSigner.keys(keys) + keys = Keys.parse(sk.to_hex()) + signer = NostrSigner.keys(keys) cli = Client.with_opts(signer, opts) for relay in self.dvm_config.RELAY_LIST: cli.add_relay(relay) @@ -107,10 +107,10 @@ def process(self, request_form): def scanList(users, instance, i, st, notactivesince): from nostr_sdk import Filter - keys = Keys.from_sk_str(self.dvm_config.PRIVATE_KEY) + keys = Keys.parse(self.dvm_config.PRIVATE_KEY) opts = Options().wait_for_send(True).send_timeout( timedelta(seconds=5)).skip_disconnected_relays(True) - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) cli = Client.with_opts(signer, opts) for relay in self.dvm_config.RELAY_LIST: cli.add_relay(relay) diff --git a/nostr_dvm/tasks/discovery_nonfollowers.py b/nostr_dvm/tasks/discovery_nonfollowers.py index b43694ae..7f0cc862 100644 --- a/nostr_dvm/tasks/discovery_nonfollowers.py +++ b/nostr_dvm/tasks/discovery_nonfollowers.py @@ -3,7 +3,7 @@ from datetime import timedelta from threading import Thread -from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, ClientSigner +from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv from nostr_dvm.utils.admin_utils import AdminConfig @@ -63,8 +63,8 @@ def process(self, request_form): opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))) sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) - keys = Keys.from_sk_str(sk.to_hex()) - signer = ClientSigner.keys(keys) + keys = Keys.parse(sk.to_hex()) + signer = NostrSigner.keys(keys) cli = Client.with_opts(signer, opts) #cli.add_relay("wss://relay.nostr.band") for relay in self.dvm_config.RELAY_LIST: @@ -100,10 +100,10 @@ def process(self, request_form): def scanList(users, instance, i, st): from nostr_sdk import Filter - keys = Keys.from_sk_str(self.dvm_config.PRIVATE_KEY) + keys = Keys.parse(self.dvm_config.PRIVATE_KEY) opts = Options().wait_for_send(True).send_timeout( timedelta(seconds=5)).skip_disconnected_relays(True) - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) cli = Client.with_opts(signer, opts) for relay in self.dvm_config.RELAY_LIST: cli.add_relay(relay) diff --git a/nostr_dvm/utils/admin_utils.py b/nostr_dvm/utils/admin_utils.py index 3b32a16f..5274234a 100644 --- a/nostr_dvm/utils/admin_utils.py +++ b/nostr_dvm/utils/admin_utils.py @@ -81,7 +81,7 @@ def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMC if adminconfig.DELETE_NIP89: event_id = adminconfig.EVENTID - keys = Keys.from_sk_str( + keys = Keys.parse( adminconfig.PRIVKEY) # Private key from sender of Event (e.g. the key of an nip89 announcement you want to delete) fetch_nip89_paramters_for_deletion(keys, event_id, client, dvmconfig) diff --git a/nostr_dvm/utils/database_utils.py b/nostr_dvm/utils/database_utils.py index 16e9250a..163d2e90 100644 --- a/nostr_dvm/utils/database_utils.py +++ b/nostr_dvm/utils/database_utils.py @@ -174,7 +174,7 @@ def update_user_balance(db, npub, additional_sats, client, config): " Zap amount: " + str(additional_sats) + " Sats. New balance: " + str(new_balance) +" Sats") if config is not None: - keys = Keys.from_sk_str(config.PRIVATE_KEY) + keys = Keys.parse(config.PRIVATE_KEY) #time.sleep(1.0) message = ("Added " + str(additional_sats) + " Sats to balance. New balance is " + str(new_balance) + " Sats.") diff --git a/nostr_dvm/utils/definitions.py b/nostr_dvm/utils/definitions.py index 3397307c..7e3d90f5 100644 --- a/nostr_dvm/utils/definitions.py +++ b/nostr_dvm/utils/definitions.py @@ -23,15 +23,17 @@ class EventDefinitions: KIND_NIP90_CONVERT_VIDEO = 5200 KIND_NIP90_RESULT_CONVERT_VIDEO = KIND_NIP90_CONVERT_VIDEO + 1000 KIND_NIP90_GENERATE_VIDEO = 5202 + KIND_NIP90_RESULT_GENERATE_VIDEO = KIND_NIP90_GENERATE_VIDEO + 1000 KIND_NIP90_TEXT_TO_SPEECH = 5250 KIND_NIP90_RESULT_TEXT_TO_SPEECH = KIND_NIP90_TEXT_TO_SPEECH + 1000 - KIND_NIP90_RESULT_GENERATE_VIDEO = KIND_NIP90_GENERATE_VIDEO + 1000 KIND_NIP90_CONTENT_DISCOVERY = 5300 KIND_NIP90_RESULT_CONTENT_DISCOVERY = KIND_NIP90_CONTENT_DISCOVERY + 1000 KIND_NIP90_PEOPLE_DISCOVERY = 5301 KIND_NIP90_RESULT_PEOPLE_DISCOVERY = KIND_NIP90_PEOPLE_DISCOVERY + 1000 KIND_NIP90_CONTENT_SEARCH = 5302 KIND_NIP90_RESULTS_CONTENT_SEARCH = KIND_NIP90_CONTENT_SEARCH + 1000 + KIND_NIP90_USER_SEARCH = 5303 + KIND_NIP90_RESULTS_USER_SEARCH = KIND_NIP90_USER_SEARCH + 1000 KIND_NIP90_GENERIC = 5999 KIND_NIP90_RESULT_GENERIC = KIND_NIP90_GENERIC + 1000 ANY_RESULT = [KIND_NIP90_RESULT_EXTRACT_TEXT, diff --git a/nostr_dvm/utils/dvmconfig.py b/nostr_dvm/utils/dvmconfig.py index 06a2c323..4cab4db1 100644 --- a/nostr_dvm/utils/dvmconfig.py +++ b/nostr_dvm/utils/dvmconfig.py @@ -14,6 +14,7 @@ class DVMConfig: PUBLIC_KEY: str = "" FIX_COST: float = None PER_UNIT_COST: float = None + SHOWLOG: bool = False # Shows Nostr logs from Rust-Library, default off, turn on in config if needed. RELAY_LIST = ["wss://relay.damus.io", "wss://nos.lol", "wss://nostr.wine", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg", @@ -40,7 +41,7 @@ def build_default_config(identifier): dvm_config = DVMConfig() dvm_config.PRIVATE_KEY = check_and_set_private_key(identifier) dvm_config.IDENTIFIER = identifier - npub = Keys.from_sk_str(dvm_config.PRIVATE_KEY).public_key().to_bech32() + npub = Keys.parse(dvm_config.PRIVATE_KEY).public_key().to_bech32() invoice_key, admin_key, wallet_id, user_id, lnaddress = check_and_set_ln_bits_keys(identifier, npub) dvm_config.LNBITS_INVOICE_KEY = invoice_key dvm_config.LNBITS_ADMIN_KEY = admin_key # The dvm might pay failed jobs back diff --git a/nostr_dvm/utils/external_dvm_utils.py b/nostr_dvm/utils/external_dvm_utils.py index d123e5c6..d9e227e4 100644 --- a/nostr_dvm/utils/external_dvm_utils.py +++ b/nostr_dvm/utils/external_dvm_utils.py @@ -1,7 +1,7 @@ import json from datetime import timedelta -from nostr_sdk import PublicKey, Options, Keys, Client, ClientSigner +from nostr_sdk import PublicKey, Options, Keys, Client, NostrSigner from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface from nostr_dvm.utils.dvmconfig import DVMConfig @@ -19,8 +19,8 @@ def build_external_dvm(pubkey, task, kind, fix_cost, per_unit_cost, config, opts = (Options().wait_for_send(True).send_timeout(timedelta(seconds=config.RELAY_TIMEOUT)) .skip_disconnected_relays(True)) - keys = Keys.from_sk_str(config.PRIVATE_KEY) - signer = ClientSigner.keys(keys) + keys = Keys.parse(config.PRIVATE_KEY) + signer = NostrSigner.keys(keys) client = Client.with_opts(signer, opts) diff --git a/nostr_dvm/utils/nip89_utils.py b/nostr_dvm/utils/nip89_utils.py index 37d5f98e..0f47f683 100644 --- a/nostr_dvm/utils/nip89_utils.py +++ b/nostr_dvm/utils/nip89_utils.py @@ -27,7 +27,7 @@ def nip89_create_d_tag(name, pubkey, image): def nip89_announce_tasks(dvm_config, client): k_tag = Tag.parse(["k", str(dvm_config.NIP89.KIND)]) d_tag = Tag.parse(["d", dvm_config.NIP89.DTAG]) - keys = Keys.from_sk_str(dvm_config.NIP89.PK) + keys = Keys.parse(dvm_config.NIP89.PK) content = dvm_config.NIP89.CONTENT event = EventBuilder(EventDefinitions.KIND_ANNOUNCEMENT, content, [k_tag, d_tag]).to_event(keys) send_event(event, client=client, dvm_config=dvm_config) @@ -98,7 +98,7 @@ def nip89_fetch_events_pubkey(client, pubkey, kind): def check_and_set_d_tag(identifier, name, pk, imageurl): if not os.getenv("NIP89_DTAG_" + identifier.upper()): - new_dtag = nip89_create_d_tag(name, Keys.from_sk_str(pk).public_key().to_hex(), + new_dtag = nip89_create_d_tag(name, Keys.parse(pk).public_key().to_hex(), imageurl) nip89_add_dtag_to_env_file("NIP89_DTAG_" + identifier.upper(), new_dtag) print("Some new dtag:" + new_dtag) diff --git a/nostr_dvm/utils/nostr_utils.py b/nostr_dvm/utils/nostr_utils.py index 0d1a2b4a..2862f0b6 100644 --- a/nostr_dvm/utils/nostr_utils.py +++ b/nostr_dvm/utils/nostr_utils.py @@ -116,7 +116,7 @@ def check_and_decrypt_tags(event, dvm_config): return None elif p == dvm_config.PUBLIC_KEY: - tags_str = nip04_decrypt(Keys.from_sk_str(dvm_config.PRIVATE_KEY).secret_key(), + tags_str = nip04_decrypt(Keys.parse(dvm_config.PRIVATE_KEY).secret_key(), event.author(), event.content()) params = json.loads(tags_str) params.append(Tag.parse(["p", p]).as_vec()) @@ -148,7 +148,7 @@ def check_and_decrypt_own_tags(event, dvm_config): return None elif event.author().to_hex() == dvm_config.PUBLIC_KEY: - tags_str = nip04_decrypt(Keys.from_sk_str(dvm_config.PRIVATE_KEY).secret_key(), + tags_str = nip04_decrypt(Keys.parse(dvm_config.PRIVATE_KEY).secret_key(), PublicKey.from_hex(p), event.content()) params = json.loads(tags_str) params.append(Tag.parse(["p", p]).as_vec()) @@ -164,7 +164,7 @@ def check_and_decrypt_own_tags(event, dvm_config): def update_profile(dvm_config, client, lud16=""): - keys = Keys.from_sk_str(dvm_config.PRIVATE_KEY) + keys = Keys.parse(dvm_config.PRIVATE_KEY) nip89content = json.loads(dvm_config.NIP89.CONTENT) if nip89content.get("name"): name = nip89content.get("name") diff --git a/nostr_dvm/utils/nwc_tools.py b/nostr_dvm/utils/nwc_tools.py index 9938d62e..ef332801 100644 --- a/nostr_dvm/utils/nwc_tools.py +++ b/nostr_dvm/utils/nwc_tools.py @@ -2,7 +2,7 @@ import os import requests -from nostr_sdk import Keys, PublicKey, Client, nip04_encrypt, EventBuilder, Tag, ClientSigner +from nostr_sdk import Keys, PublicKey, Client, nip04_encrypt, EventBuilder, Tag, NostrSigner from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.nostr_utils import check_and_set_private_key @@ -11,7 +11,7 @@ def nwc_zap(connectionstr, bolt11, keys): target_pubkey, relay, secret = parse_connection_str(connectionstr) - SecretSK = Keys.from_sk_str(secret) + SecretSK = Keys.parse(secret) content = { "method": "pay_invoice", @@ -20,7 +20,7 @@ def nwc_zap(connectionstr, bolt11, keys): } } - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) client.add_relay(relay) client.connect() @@ -47,7 +47,7 @@ def parse_connection_str(connectionstring): def make_nwc_account(identifier, nwcdomain): - pubkey = Keys.from_sk_str(os.getenv("DVM_PRIVATE_KEY_" + identifier.upper())).public_key().to_hex() + pubkey = Keys.parse(os.getenv("DVM_PRIVATE_KEY_" + identifier.upper())).public_key().to_hex() data = { 'name': identifier, 'host': os.getenv("LNBITS_HOST"), @@ -77,7 +77,7 @@ def nwc_test(nwc_server): # connectionstring = "nostr+walletconnect:..." if connectionstring != "": # we use the keys from a test user - keys = Keys.from_sk_str(check_and_set_private_key("test")) + keys = Keys.parse(check_and_set_private_key("test")) # we zap npub1nxa4tywfz9nqp7z9zp7nr7d4nchhclsf58lcqt5y782rmf2hefjquaa6q8's profile 21 sats and say Cool stuff pubkey = PublicKey.from_bech32("npub1nxa4tywfz9nqp7z9zp7nr7d4nchhclsf58lcqt5y782rmf2hefjquaa6q8") diff --git a/nostr_dvm/utils/zap_utils.py b/nostr_dvm/utils/zap_utils.py index c3695521..4408d458 100644 --- a/nostr_dvm/utils/zap_utils.py +++ b/nostr_dvm/utils/zap_utils.py @@ -269,7 +269,7 @@ def zaprequest(lud16: str, amount: int, content, zapped_event, zapped_user, keys zap_request = EventBuilder(9733, content, [p_tag, e_tag]).to_event(keys).as_json() - keys = Keys.from_sk_str(encryption_key) + keys = Keys.parse(encryption_key) encrypted_content = enrypt_private_zap_message(zap_request, keys.secret_key(), zapped_event.author()) anon_tag = Tag.parse(['anon', encrypted_content]) tags.append(anon_tag) diff --git a/setup.py b/setup.py index fd775ae6..826b028e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.2.2' +VERSION = '0.2.3' DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines' LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. ' 'This is an early stage release. Interfaces might change/brick') @@ -15,7 +15,7 @@ long_description=LONG_DESCRIPTION, packages=find_packages(include=['nostr_dvm', 'nostr_dvm.*']), - install_requires=["nostr-sdk==0.8.0", + install_requires=["nostr-sdk==0.9.1", "bech32", "pycryptodome==3.20.0", "python-dotenv==1.0.0", diff --git a/tests/gui/nicegui/nostrAI_search_client.py b/tests/gui/nicegui/nostrAI_search_client.py index 9d12805e..4ab3b299 100644 --- a/tests/gui/nicegui/nostrAI_search_client.py +++ b/tests/gui/nicegui/nostrAI_search_client.py @@ -3,7 +3,7 @@ from datetime import timedelta from nicegui import run, ui from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, \ - Options, Timestamp, ClientSigner, EventId, Nip19Event, PublicKey + Options, Timestamp, NostrSigner, EventId, Nip19Event, PublicKey from nostr_dvm.utils import dvmconfig from nostr_dvm.utils.dvmconfig import DVMConfig @@ -13,11 +13,11 @@ @ui.page('/', dark=True) def init(): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=2)) .skip_disconnected_relays(True)) - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client.with_opts(signer, opts) relay_list = dvmconfig.DVMConfig.RELAY_LIST diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index 7f13627f..e4e11899 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -5,7 +5,7 @@ import dotenv from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \ - nip04_encrypt, ClientSigner + nip04_encrypt, NostrSigner from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key @@ -14,7 +14,7 @@ # TODO HINT: Best use this path with a previously whitelisted privkey, as zapping events is not implemented in the lib/code def nostr_client_test_translation(input, kind, lang, sats, satsmax): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) if kind == "text": iTag = Tag.parse(["i", input, "text"]) elif kind == "event": @@ -31,7 +31,7 @@ def nostr_client_test_translation(input, kind, lang, sats, satsmax): relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", "wss://nostr-pub.wellorder.net"] - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) for relay in relay_list: @@ -43,7 +43,7 @@ def nostr_client_test_translation(input, kind, lang, sats, satsmax): def nostr_client_test_image(prompt): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) iTag = Tag.parse(["i", prompt, "text"]) outTag = Tag.parse(["output", "image/png;format=url"]) @@ -60,7 +60,7 @@ def nostr_client_test_image(prompt): relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", "wss://nostr-pub.wellorder.net"] - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) for relay in relay_list: client.add_relay(relay) @@ -71,7 +71,7 @@ def nostr_client_test_image(prompt): def nostr_client_test_tts(prompt): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) iTag = Tag.parse(["i", prompt, "text"]) paramTag1 = Tag.parse(["param", "language", "en"]) @@ -86,7 +86,7 @@ def nostr_client_test_tts(prompt): relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", "wss://nostr-pub.wellorder.net"] - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) for relay in relay_list: client.add_relay(relay) @@ -97,8 +97,8 @@ def nostr_client_test_tts(prompt): def nostr_client_test_image_private(prompt, cashutoken): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) - receiver_keys = Keys.from_sk_str(check_and_set_private_key("replicate_sdxl")) + keys = Keys.parse(check_and_set_private_key("test_client")) + receiver_keys = Keys.parse(check_and_set_private_key("replicate_sdxl")) # TODO more advanced logic, more parsing, params etc, just very basic test functions for now @@ -125,7 +125,7 @@ def nostr_client_test_image_private(prompt, cashutoken): nip90request = EventBuilder(EventDefinitions.KIND_NIP90_GENERATE_IMAGE, encrypted_params, [pTag, encrypted_tag]).to_event(keys) - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) for relay in relay_list: client.add_relay(relay) @@ -136,11 +136,11 @@ def nostr_client_test_image_private(prompt, cashutoken): def nostr_client(): - keys = Keys.from_sk_str(check_and_set_private_key("test_client")) + keys = Keys.parse(check_and_set_private_key("test_client")) sk = keys.secret_key() pk = keys.public_key() print(f"Nostr Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ") - signer = ClientSigner.keys(keys) + signer = NostrSigner.keys(keys) client = Client(signer) dvmconfig = DVMConfig() diff --git a/tests/test_events.py b/tests/test_events.py index 8489f630..fd0a4e44 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -4,20 +4,20 @@ import dotenv import nostr_sdk from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \ - nip04_encrypt, EventId, Options, PublicKey, Event, ClientSigner, Nip19Event + nip04_encrypt, EventId, Options, PublicKey, Event, NostrSigner, Nip19Event from nostr_dvm.utils import definitions, dvmconfig from nostr_dvm.utils.nostr_utils import check_and_set_private_key relay_list = dvmconfig.DVMConfig.RELAY_LIST -keys = Keys.from_sk_str(check_and_set_private_key("test_client")) +keys = Keys.parse(check_and_set_private_key("test_client")) wait_for_send = False skip_disconnected_relays = True opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=5)) .skip_disconnected_relays(skip_disconnected_relays)) -signer = ClientSigner.keys(keys) +signer = NostrSigner.keys(keys) client = Client.with_opts(signer, opts) for relay in relay_list: diff --git a/ui/noogle/src/components/Nip89view.vue b/ui/noogle/src/components/Nip89view.vue index ba8f5973..ec6755de 100644 --- a/ui/noogle/src/components/Nip89view.vue +++ b/ui/noogle/src/components/Nip89view.vue @@ -26,7 +26,7 @@ import '../app.css' import store from "@/store.js"; -import {Alphabet, ClientBuilder, ClientSigner, Filter, Keys, NostrDatabase, Tag} from "@rust-nostr/nostr-sdk"; +import {Alphabet, ClientBuilder, NostrSigner, Filter, Keys, NostrDatabase, Tag} from "@rust-nostr/nostr-sdk"; import miniToastr from "mini-toastr"; import VueNotifications from "vue-notifications"; diff --git a/ui/noogle/src/store.js b/ui/noogle/src/store.js index dbad4e05..87ecb56f 100644 --- a/ui/noogle/src/store.js +++ b/ui/noogle/src/store.js @@ -1,5 +1,5 @@ import {createStore} from "vuex"; -import {Client, ClientSigner, PublicKey} from "@rust-nostr/nostr-sdk"; +import {Client, NostrSigner, PublicKey} from "@rust-nostr/nostr-sdk"; const store = createStore({ state () { From d5fef1a115591a803ab7898c4c1c64d7348b69c0 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Sun, 18 Feb 2024 00:25:50 +0100 Subject: [PATCH 2/3] test --- .gitignore | 2 + .idea/dataSources.xml | 19 ++ nostr_dvm/dvm.py | 3 +- nostr_dvm/tasks/search_users.py | 208 +++++++++++++++++++++ nostr_dvm/utils/dvmconfig.py | 2 +- nostr_dvm/utils/scrapper/media_scrapper.py | 2 +- tests/test_dvm_client.py | 28 ++- 7 files changed, 258 insertions(+), 6 deletions(-) create mode 100644 nostr_dvm/tasks/search_users.py diff --git a/.gitignore b/.gitignore index 2e6c75b7..250ad7b4 100644 --- a/.gitignore +++ b/.gitignore @@ -181,3 +181,5 @@ ui/noogle/node_modules ui/noogle/.idea/ ui/noogle/package-lock.json search.py +identifier.sqlite +.idea/dataSources.xml diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index d8ecaba7..2c2e4038 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -68,5 +68,24 @@ + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/db/nostr_profiles.db + $ProjectFileDir$ + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.43.0/org/xerial/sqlite-jdbc/3.43.0.0/sqlite-jdbc-3.43.0.0.jar + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:identifier.sqlite + $ProjectFileDir$ + \ No newline at end of file diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index fec61cc0..94c972e7 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -23,6 +23,7 @@ + class DVM: dvm_config: DVMConfig admin_config: AdminConfig @@ -43,8 +44,6 @@ def __init__(self, dvm_config, admin_config=None): signer = NostrSigner.keys(self.keys) self.client = Client.with_opts(signer,opts) - if dvm_config.SHOWLOG: - init_logger(LogLevel.DEBUG) self.job_list = [] self.jobs_on_hold_list = [] diff --git a/nostr_dvm/tasks/search_users.py b/nostr_dvm/tasks/search_users.py new file mode 100644 index 00000000..3f97c496 --- /dev/null +++ b/nostr_dvm/tasks/search_users.py @@ -0,0 +1,208 @@ +import json +import os +from datetime import timedelta +from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \ + ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel + +from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv +from nostr_dvm.utils.admin_utils import AdminConfig +from nostr_dvm.utils.definitions import EventDefinitions +from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config +from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag +from nostr_dvm.utils.output_utils import post_process_list_to_events, post_process_list_to_users + +""" +This File contains a Module to search for notes +Accepted Inputs: a search query +Outputs: A list of events +Params: None +""" + + +class SearchUser(DVMTaskInterface): + KIND: int = EventDefinitions.KIND_NIP90_USER_SEARCH + TASK: str = "search-user" + FIX_COST: float = 0 + dvm_config: DVMConfig + dependencies = [("nostr-dvm", "nostr-dvm")] + + def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, + admin_config: AdminConfig = None, options=None): + dvm_config.SCRIPT = os.path.abspath(__file__) + + use_logger = False + if use_logger: + init_logger(LogLevel.DEBUG) + + super().__init__(name, dvm_config, nip89config, admin_config, options) + + opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))) + sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + keys = Keys.parse(sk.to_hex()) + signer = NostrSigner.keys(keys) + database = NostrDatabase.sqlite("db/nostr_profiles.db") + cli = ClientBuilder().signer(signer).database(database).opts(opts).build() + + cli.add_relay("wss://relay.damus.io") + #cli.add_relay("wss://atl.purplerelay.com") + cli.connect() + + filter1 = Filter().kind(0) + + # filter = Filter().author(keys.public_key()) + print("Syncing Profile Database.. this might take a while..") + dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN) + cli.reconcile(filter1, dbopts) + print("Done Syncing Profile Database.") + + def is_input_supported(self, tags, client=None, dvm_config=None): + for tag in tags: + if tag.as_vec()[0] == 'i': + input_value = tag.as_vec()[1] + input_type = tag.as_vec()[2] + if input_type != "text": + return False + return True + + def create_request_from_nostr_event(self, event, client=None, dvm_config=None): + self.dvm_config = dvm_config + print(self.dvm_config.PRIVATE_KEY) + + request_form = {"jobID": event.id().to_hex()} + + # default values + search = "" + max_results = 100 + relay = "wss://relay.nostr.band" + if self.options["relay"]: + relay = self.options["relay"] + + for tag in event.tags(): + if tag.as_vec()[0] == 'i': + input_type = tag.as_vec()[2] + if input_type == "text": + search = tag.as_vec()[1] + elif tag.as_vec()[0] == 'param': + param = tag.as_vec()[1] + if param == "max_results": # check for param type + max_results = int(tag.as_vec()[2]) + + options = { + "search": search, + "max_results": max_results, + "relay": relay + } + request_form['options'] = json.dumps(options) + return request_form + + def process(self, request_form): + from nostr_sdk import Filter + options = DVMTaskInterface.set_options(request_form) + + opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))) + sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + keys = Keys.parse(sk.to_hex()) + signer = NostrSigner.keys(keys) + + database = NostrDatabase.sqlite("db/nostr_profiles.db") + cli = ClientBuilder().database(database).signer(signer).opts(opts).build() + + cli.add_relay("wss://relay.damus.io") + #cli.add_relay("wss://atl.purplerelay.com") + cli.connect() + + # Negentropy reconciliation + + + + # Query events from database + + filter1 = Filter().kind(0) + events = cli.database().query([filter1]) + #for event in events: + # print(event.as_json()) + + #events = cli.get_events_of([notes_filter], timedelta(seconds=5)) + + result_list = [] + print("Events: " + str(len(events))) + index = 0 + if len(events) > 0: + + for event in events: + if index < options["max_results"]: + try: + if options["search"].lower() in event.content().lower(): + p_tag = Tag.parse(["p", event.author().to_hex()]) + print(event.as_json()) + result_list.append(p_tag.as_vec()) + index += 1 + except Exception as exp: + print(str(exp) + " " + event.author().to_hex()) + else: + break + + return json.dumps(result_list) + + def post_process(self, result, event): + """Overwrite the interface function to return a social client readable format, if requested""" + for tag in event.tags(): + if tag.as_vec()[0] == 'output': + format = tag.as_vec()[1] + if format == "text/plain": # check for output type + result = post_process_list_to_users(result) + + # if not text/plain, don't post-process + return result + + +# We build an example here that we can call by either calling this file directly from the main directory, +# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the +# playground or elsewhere +def build_example(name, identifier, admin_config): + dvm_config = build_default_config(identifier) + dvm_config.USE_OWN_VENV = False + dvm_config.SHOWLOG = True + # Add NIP89 + nip89info = { + "name": name, + "image": "https://image.nostr.build/a99ab925084029d9468fef8330ff3d9be2cf67da473b024f2a6d48b5cd77197f.jpg", + "about": "I search users.", + "encryptionSupported": True, + "cashuAccepted": True, + "nip90Params": { + "users": { + "required": False, + "values": [], + "description": "Search for content from specific users" + }, + "since": { + "required": False, + "values": [], + "description": "A unix timestamp in the past from where the search should start" + }, + "until": { + "required": False, + "values": [], + "description": "A unix timestamp that tells until the search should include results" + }, + "max_results": { + "required": False, + "values": [], + "description": "The number of maximum results to return (default currently 20)" + } + } + } + + nip89config = NIP89Config() + nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["image"]) + nip89config.CONTENT = json.dumps(nip89info) + + options = {"relay": "wss://relay.damus.io"} + + return SearchUser(name=name, dvm_config=dvm_config, nip89config=nip89config, + admin_config=admin_config, options=options) + + +if __name__ == '__main__': + process_venv(SearchUser) diff --git a/nostr_dvm/utils/dvmconfig.py b/nostr_dvm/utils/dvmconfig.py index 4cab4db1..a80765be 100644 --- a/nostr_dvm/utils/dvmconfig.py +++ b/nostr_dvm/utils/dvmconfig.py @@ -14,7 +14,7 @@ class DVMConfig: PUBLIC_KEY: str = "" FIX_COST: float = None PER_UNIT_COST: float = None - SHOWLOG: bool = False # Shows Nostr logs from Rust-Library, default off, turn on in config if needed. + RELAY_LIST = ["wss://relay.damus.io", "wss://nos.lol", "wss://nostr.wine", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg", diff --git a/nostr_dvm/utils/scrapper/media_scrapper.py b/nostr_dvm/utils/scrapper/media_scrapper.py index 16ba2e1f..9b7cb03e 100644 --- a/nostr_dvm/utils/scrapper/media_scrapper.py +++ b/nostr_dvm/utils/scrapper/media_scrapper.py @@ -165,7 +165,7 @@ def get_tweet_details(tweet_url, guest_token, bearer_token): return details def get_tweet_status_id(tweet_url): - sid_patern = r"https://x\.com/[^/]+/status/(\d+)" + sid_patern = r'https://(?:x\.com|twitter\.com)/[^/]+/status/(\d+)' if tweet_url[len(tweet_url) - 1] != "/": tweet_url = tweet_url + "/" diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index e4e11899..c1e8e4e4 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -40,8 +40,32 @@ def nostr_client_test_translation(input, kind, lang, sats, satsmax): config = DVMConfig send_event(event, client=client, dvm_config=config) return event.as_json() +def nostr_client_test_search_profile(input): + keys = Keys.parse(check_and_set_private_key("test_client")) + + iTag = Tag.parse(["i", input, "text"]) + + relaysTag = Tag.parse(['relays', "wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", + "wss://nostr-pub.wellorder.net"]) + alttag = Tag.parse(["alt", "This is a NIP90 DVM AI task to translate a given Input"]) + event = EventBuilder(EventDefinitions.KIND_NIP90_USER_SEARCH, str("Search for user"), + [iTag, relaysTag, alttag]).to_event(keys) + + relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", + "wss://nostr-pub.wellorder.net"] + + signer = NostrSigner.keys(keys) + client = Client(signer) + + for relay in relay_list: + client.add_relay(relay) + client.connect() + config = DVMConfig + send_event(event, client=client, dvm_config=config) + return event.as_json() + def nostr_client_test_image(prompt): keys = Keys.parse(check_and_set_private_key("test_client")) @@ -158,8 +182,8 @@ def nostr_client(): # nostr_client_test_translation("This is the result of the DVM in spanish", "text", "es", 20, 20) # nostr_client_test_translation("note1p8cx2dz5ss5gnk7c59zjydcncx6a754c0hsyakjvnw8xwlm5hymsnc23rs", "event", "es", 20,20) # nostr_client_test_translation("44a0a8b395ade39d46b9d20038b3f0c8a11168e67c442e3ece95e4a1703e2beb", "event", "zh", 20, 20) - nostr_client_test_image("a beautiful purple ostrich watching the sunset") - + #nostr_client_test_image("a beautiful purple ostrich watching the sunset") + nostr_client_test_search_profile("dontbelievew") # nostr_client_test_tts("Hello, this is a test. Mic check one, two.") # cashutoken = "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6InZxc1VRSVorb0sxOSIsImFtb3VudCI6MSwiQyI6IjAyNWU3ODZhOGFkMmExYTg0N2YxMzNiNGRhM2VhMGIyYWRhZGFkOTRiYzA4M2E2NWJjYjFlOTgwYTE1NGIyMDA2NCIsInNlY3JldCI6InQ1WnphMTZKMGY4UElQZ2FKTEg4V3pPck5rUjhESWhGa291LzVzZFd4S0U9In0seyJpZCI6InZxc1VRSVorb0sxOSIsImFtb3VudCI6NCwiQyI6IjAyOTQxNmZmMTY2MzU5ZWY5ZDc3MDc2MGNjZmY0YzliNTMzMzVmZTA2ZGI5YjBiZDg2Njg5Y2ZiZTIzMjVhYWUwYiIsInNlY3JldCI6IlRPNHB5WE43WlZqaFRQbnBkQ1BldWhncm44UHdUdE5WRUNYWk9MTzZtQXM9In0seyJpZCI6InZxc1VRSVorb0sxOSIsImFtb3VudCI6MTYsIkMiOiIwMmRiZTA3ZjgwYmMzNzE0N2YyMDJkNTZiMGI3ZTIzZTdiNWNkYTBhNmI3Yjg3NDExZWYyOGRiZDg2NjAzNzBlMWIiLCJzZWNyZXQiOiJHYUNIdHhzeG9HM3J2WWNCc0N3V0YxbU1NVXczK0dDN1RKRnVwOHg1cURzPSJ9XSwibWludCI6Imh0dHBzOi8vbG5iaXRzLmJpdGNvaW5maXhlc3RoaXMub3JnL2Nhc2h1L2FwaS92MS9ScDlXZGdKZjlxck51a3M1eVQ2SG5rIn1dfQ==" From 981452a1d0affd91a7b8812f43e4e7d24f09a619 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Sun, 18 Feb 2024 00:35:52 +0100 Subject: [PATCH 3/3] fixes --- nostr_dvm/utils/nip89_utils.py | 6 +++--- nostr_dvm/utils/nostr_utils.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nostr_dvm/utils/nip89_utils.py b/nostr_dvm/utils/nip89_utils.py index 0f47f683..724f5f83 100644 --- a/nostr_dvm/utils/nip89_utils.py +++ b/nostr_dvm/utils/nip89_utils.py @@ -4,7 +4,7 @@ from pathlib import Path import dotenv -from nostr_sdk import Tag, Keys, EventBuilder, Filter, Alphabet, PublicKey, Client, EventId +from nostr_sdk import Tag, Keys, EventBuilder, Filter, Alphabet, PublicKey, Client, EventId, SingleLetterTag from nostr_dvm.utils.definitions import EventDefinitions from nostr_dvm.utils.nostr_utils import send_event @@ -69,7 +69,7 @@ def nip89_fetch_all_dvms(client): for i in range(5000, 5999): ktags.append(str(i)) - filter = Filter().kind(EventDefinitions.KIND_ANNOUNCEMENT).custom_tag(Alphabet.K, ktags) + filter = Filter().kind(EventDefinitions.KIND_ANNOUNCEMENT).custom_tag(SingleLetterTag.lowercase(Alphabet.K), ktags) events = client.get_events_of([filter], timedelta(seconds=5)) for event in events: print(event.as_json()) @@ -80,7 +80,7 @@ def nip89_fetch_events_pubkey(client, pubkey, kind): # for i in range(5000, 5999): # ktags.append(str(i)) nip89filter = (Filter().kind(EventDefinitions.KIND_ANNOUNCEMENT).author(PublicKey.from_hex(pubkey)). - custom_tag(Alphabet.K, ktags)) + custom_tag(SingleLetterTag.lowercase(Alphabet.K), ktags)) events = client.get_events_of([nip89filter], timedelta(seconds=2)) dvms = {} diff --git a/nostr_dvm/utils/nostr_utils.py b/nostr_dvm/utils/nostr_utils.py index 2862f0b6..767106b6 100644 --- a/nostr_dvm/utils/nostr_utils.py +++ b/nostr_dvm/utils/nostr_utils.py @@ -6,14 +6,14 @@ import dotenv from nostr_sdk import Filter, Client, Alphabet, EventId, Event, PublicKey, Tag, Keys, nip04_decrypt, Metadata, Options, \ - Nip19Event + Nip19Event, SingleLetterTag def get_event_by_id(event_id: str, client: Client, config=None) -> Event | None: split = event_id.split(":") if len(split) == 3: pk = PublicKey.from_hex(split[1]) - id_filter = Filter().author(pk).custom_tag(Alphabet.D, [split[2]]) + id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]]) events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) else: if str(event_id).startswith('note'):