Skip to content

Commit

Permalink
Merge pull request #22 from believethehype/nostrsdk011
Browse files Browse the repository at this point in the history
Nostrsdk011
  • Loading branch information
believethehype authored Feb 17, 2024
2 parents cd077db + 981452a commit 4e67e13
Show file tree
Hide file tree
Showing 29 changed files with 338 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,5 @@ ui/noogle/node_modules
ui/noogle/.idea/
ui/noogle/package-lock.json
search.py
identifier.sqlite
.idea/dataSources.xml
19 changes: 19 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/ollama_dvm/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
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
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",
Expand All @@ -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:
Expand All @@ -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()} ")
Expand Down
10 changes: 5 additions & 5 deletions examples/tts_dvm/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

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
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"])
Expand All @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions nostr_dvm/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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())
Expand Down
12 changes: 5 additions & 7 deletions nostr_dvm/dvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,9 +21,7 @@
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:
Expand All @@ -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)


Expand Down Expand Up @@ -472,7 +470,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(
Expand Down
2 changes: 1 addition & 1 deletion nostr_dvm/interfaces/dvmtaskinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions nostr_dvm/tasks/advanced_search.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion nostr_dvm/tasks/advanced_search_wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions nostr_dvm/tasks/discovery_inactive_follows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions nostr_dvm/tasks/discovery_nonfollowers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 4e67e13

Please sign in to comment.