mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-04-01 00:18:04 +02:00
commit
4e67e13249
2
.gitignore
vendored
2
.gitignore
vendored
@ -181,3 +181,5 @@ ui/noogle/node_modules
|
||||
ui/noogle/.idea/
|
||||
ui/noogle/package-lock.json
|
||||
search.py
|
||||
identifier.sqlite
|
||||
.idea/dataSources.xml
|
||||
|
19
.idea/dataSources.xml
generated
19
.idea/dataSources.xml
generated
@ -68,5 +68,24 @@
|
||||
</library>
|
||||
</libraries>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="Profiles" uuid="77eda71f-1c66-4b3d-bc34-dfe34fb45fc2">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/db/nostr_profiles.db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<libraries>
|
||||
<library>
|
||||
<url>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</url>
|
||||
</library>
|
||||
</libraries>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="identifier.sqlite" uuid="7b0e6d22-6530-4715-8aa9-b7e1707839e9">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:identifier.sqlite</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
@ -4,7 +4,7 @@ from pathlib import Path
|
||||
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 @@ from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
|
||||
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()} ")
|
||||
|
@ -5,7 +5,7 @@ from threading import Thread
|
||||
|
||||
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 @@ from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
|
||||
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()
|
||||
|
2
main.py
2
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
|
||||
|
@ -5,7 +5,7 @@ import time
|
||||
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 @@ class Bot:
|
||||
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 @@ class Bot:
|
||||
|
||||
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())
|
||||
|
@ -5,7 +5,7 @@ from datetime import timedelta
|
||||
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,7 @@ from nostr_dvm.utils.zap_utils import check_bolt11_ln_bits_is_paid, create_bolt1
|
||||
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,13 +35,13 @@ 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)
|
||||
|
||||
|
||||
@ -472,7 +470,7 @@ class DVM:
|
||||
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(
|
||||
|
@ -40,7 +40,7 @@ class DVMTaskInterface:
|
||||
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
|
||||
|
@ -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 @@ class AdvancedSearch(DVMTaskInterface):
|
||||
|
||||
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"])
|
||||
|
@ -3,7 +3,7 @@ import os
|
||||
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
|
||||
|
@ -3,7 +3,7 @@ import os
|
||||
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 @@ class DiscoverInactiveFollows(DVMTaskInterface):
|
||||
|
||||
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 @@ class DiscoverInactiveFollows(DVMTaskInterface):
|
||||
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)
|
||||
|
@ -3,7 +3,7 @@ import os
|
||||
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 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
||||
|
||||
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 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
||||
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)
|
||||
|
208
nostr_dvm/tasks/search_users.py
Normal file
208
nostr_dvm/tasks/search_users.py
Normal file
@ -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)
|
@ -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)
|
||||
|
||||
|
@ -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.")
|
||||
|
@ -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,
|
||||
|
@ -15,6 +15,7 @@ class DVMConfig:
|
||||
FIX_COST: float = None
|
||||
PER_UNIT_COST: float = None
|
||||
|
||||
|
||||
RELAY_LIST = ["wss://relay.damus.io", "wss://nos.lol", "wss://nostr.wine",
|
||||
"wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||
"wss://relay.f7z.io", "wss://pablof7z.nostr1.com", "wss://relay.nostr.net", "wss://140.f7z.io",
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@ from hashlib import sha256
|
||||
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
|
||||
@ -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)
|
||||
@ -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 = {}
|
||||
@ -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)
|
||||
|
@ -6,14 +6,14 @@ from typing import List
|
||||
|
||||
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'):
|
||||
@ -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")
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
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 @@ from nostr_dvm.utils.zap_utils import zaprequest
|
||||
|
||||
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")
|
||||
|
@ -165,7 +165,7 @@ def XitterDownload(source_url, target_location):
|
||||
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 + "/"
|
||||
|
||||
|
@ -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)
|
||||
|
4
setup.py
4
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 @@ setup(
|
||||
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",
|
||||
|
@ -3,7 +3,7 @@ import time
|
||||
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 @@ from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
@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
|
||||
|
||||
|
@ -5,7 +5,7 @@ from threading import Thread
|
||||
|
||||
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 @@ from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
# 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,32 @@ 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:
|
||||
client.add_relay(relay)
|
||||
client.connect()
|
||||
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:
|
||||
@ -41,9 +66,8 @@ def nostr_client_test_translation(input, kind, lang, sats, satsmax):
|
||||
send_event(event, client=client, dvm_config=config)
|
||||
return event.as_json()
|
||||
|
||||
|
||||
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 +84,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 +95,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 +110,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 +121,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 +149,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 +160,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()
|
||||
@ -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=="
|
||||
|
@ -4,20 +4,20 @@ from pathlib import Path
|
||||
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:
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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 () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user