diff --git a/lnbits/extensions/nostr/__init__.py b/lnbits/extensions/nostr/__init__.py
index 775960e3d..9774a2790 100644
--- a/lnbits/extensions/nostr/__init__.py
+++ b/lnbits/extensions/nostr/__init__.py
@@ -11,7 +11,5 @@ nostr_ext: APIRouter = APIRouter(prefix="/nostr", tags=["nostr"])
def nostr_renderer():
return template_renderer(["lnbits/extensions/nostr/templates"])
-
-from .lnurl import * # noqa
from .views import * # noqa
from .views_api import * # noqa
diff --git a/lnbits/extensions/nostr/crud.py b/lnbits/extensions/nostr/crud.py
index 55e99ec67..0b30bc9a7 100644
--- a/lnbits/extensions/nostr/crud.py
+++ b/lnbits/extensions/nostr/crud.py
@@ -1,33 +1,31 @@
from typing import List, Optional, Union
from lnbits.helpers import urlsafe_short_hash
-
+import shortuuid
from . import db
-from .models import nostrKeys, nostrNotes, nostrRelays, nostrConnections
+from .models import nostrKeys, nostrNotes, nostrCreateRelays, nostrRelays, nostrConnections, nostrCreateConnections
###############KEYS##################
async def create_nostrkeys(
data: nostrKeys
) -> nostrKeys:
- nostrkey_id = urlsafe_short_hash()
await db.execute(
"""
INSERT INTO nostr.keys (
- id,
pubkey,
privkey
)
- VALUES (?, ?, ?)
+ VALUES (?, ?)
""",
- (nostrkey_id, data.pubkey, data.privkey),
+ (data.pubkey, data.privkey),
)
return await get_nostrkeys(nostrkey_id)
-async def get_nostrkeys(nostrkey_id: str) -> nostrKeys:
+async def get_nostrkeys(pubkey: str) -> nostrKeys:
row = await db.fetchone(
- "SELECT * FROM nostr.keys WHERE id = ?",
- (lnurldevicepayment_id,),
+ "SELECT * FROM nostr.keys WHERE pubkey = ?",
+ (pubkey,),
)
return nostrKeys(**row) if row else None
@@ -64,9 +62,12 @@ async def get_nostrnotes(nostrnote_id: str) -> nostrNotes:
###############RELAYS##################
async def create_nostrrelays(
- relay: str
-) -> nostrRelays:
- nostrrelay_id = urlsafe_short_hash()
+ data: nostrCreateRelays
+) -> nostrCreateRelays:
+ nostrrelay_id = shortuuid.uuid(name=relay)
+
+ if await get_nostrrelays(nostrrelay_id):
+ return "error"
await db.execute(
"""
INSERT INTO nostr.relays (
@@ -75,7 +76,7 @@ async def create_nostrrelays(
)
VALUES (?, ?)
""",
- (nostrrelay_id, relay),
+ (nostrrelay_id, data.relay),
)
return await get_nostrnotes(nostrrelay_id)
@@ -90,45 +91,25 @@ async def get_nostrrelays(nostrrelay_id: str) -> nostrRelays:
###############CONNECTIONS##################
async def create_nostrconnections(
- data: nostrNotes
-) -> nostrNotes:
- nostrkey_id = urlsafe_short_hash()
+ data: nostrCreateConnections
+) -> nostrCreateConnections:
+ nostrrelay_id = shortuuid.uuid(name=data.relayid + data.pubkey)
await db.execute(
"""
- INSERT INTO nostr.notes (
+ INSERT INTO nostr.connections (
id,
pubkey,
- created_at,
- kind,
- tags,
- content,
- sig
+ relayid
)
- VALUES (?, ?, ?, ?, ?, ?, ?)
+ VALUES (?, ?, ?)
""",
- (data.id, data.pubkey, data.created_at, data.kind, data.tags, data.content, data.sig),
+ (data.id, data.pubkey, data.relayid),
)
- return await get_nostrnotes(data.id)
+ return await get_nostrconnections(data.id)
-async def get_nostrnotes(nostrnote_id: str) -> nostrNotes:
+async def get_nostrconnections(nostrconnections_id: str) -> nostrConnections:
row = await db.fetchone(
- "SELECT * FROM nostr.notes WHERE id = ?",
- (nostrnote_id,),
+ "SELECT * FROM nostr.connections WHERE id = ?",
+ (nostrconnections_id,),
)
- return nostrNotes(**row) if row else None
-
-
-
-async def update_lnurldevicepayment(
- lnurldevicepayment_id: str, **kwargs
-) -> Optional[lnurldevicepayment]:
- q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
- await db.execute(
- f"UPDATE lnurldevice.lnurldevicepayment SET {q} WHERE id = ?",
- (*kwargs.values(), lnurldevicepayment_id),
- )
- row = await db.fetchone(
- "SELECT * FROM lnurldevice.lnurldevicepayment WHERE id = ?",
- (lnurldevicepayment_id,),
- )
- return lnurldevicepayment(**row) if row else None
\ No newline at end of file
+ return nostrConnections(**row) if row else None
\ No newline at end of file
diff --git a/lnbits/extensions/nostr/migrations.py b/lnbits/extensions/nostr/migrations.py
index de32a5787..0c616110e 100644
--- a/lnbits/extensions/nostr/migrations.py
+++ b/lnbits/extensions/nostr/migrations.py
@@ -24,7 +24,7 @@ async def m001_initial(db):
kind INT NOT NULL,
tags TEXT NOT NULL,
content TEXT NOT NULL,
- sig TEXT NOT NULL,
+ sig TEXT NOT NULL
);
"""
)
diff --git a/lnbits/extensions/nostr/models.py b/lnbits/extensions/nostr/models.py
index ba0c87a5e..e21e5d76f 100644
--- a/lnbits/extensions/nostr/models.py
+++ b/lnbits/extensions/nostr/models.py
@@ -3,15 +3,10 @@ from sqlite3 import Row
from typing import Optional
from fastapi import Request
-from lnurl import Lnurl
-from lnurl import encode as lnurl_encode # type: ignore
-from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
-from lnurl.types import LnurlPayMetadata # type: ignore
from pydantic import BaseModel
from pydantic.main import BaseModel
class nostrKeys(BaseModel):
- id: str
pubkey: str
privkey: str
@@ -24,6 +19,13 @@ class nostrNotes(BaseModel):
content: str
sig: str
+class nostrCreateRelays(BaseModel):
+ relay: str
+
+class nostrCreateConnections(BaseModel):
+ pubkey: str
+ relayid: str
+
class nostrRelays(BaseModel):
id: str
relay: str
diff --git a/lnbits/extensions/nostr/templates/lnurldevice/_api_docs.html b/lnbits/extensions/nostr/templates/lnurldevice/_api_docs.html
deleted file mode 100644
index af69b76e3..000000000
--- a/lnbits/extensions/nostr/templates/lnurldevice/_api_docs.html
+++ /dev/null
@@ -1,169 +0,0 @@
-
- Register LNURLDevice devices to receive payments in your LNbits wallet.
- Build your own here
- https://github.com/arcbtc/bitcoinpos
-
- Created by, Ben Arc
- /lnurldevice/api/v1/lnurlpos
- Headers
- {"X-Api-Key": <admin_key>}
-
- Body (application/json)
-
-
- Returns 200 OK (application/json)
-
- [<lnurldevice_object>, ...]
- Curl example
- curl -X POST {{ request.base_url }}api/v1/lnurldevice -d '{"title":
- <string>, "message":<string>, "currency":
- <integer>}' -H "Content-type: application/json" -H "X-Api-Key:
- {{user.wallets[0].adminkey }}"
-
- PUT
- /lnurldevice/api/v1/lnurlpos/<lnurldevice_id>
- Headers
- {"X-Api-Key": <admin_key>}
-
- Body (application/json)
-
-
- Returns 200 OK (application/json)
-
- [<lnurldevice_object>, ...]
- Curl example
- curl -X POST {{ request.base_url
- }}api/v1/lnurlpos/<lnurldevice_id> -d ''{"title":
- <string>, "message":<string>, "currency":
- <integer>} -H "Content-type: application/json" -H "X-Api-Key:
- {{user.wallets[0].adminkey }}"
-
- GET
- /lnurldevice/api/v1/lnurlpos/<lnurldevice_id>
- Headers
- {"X-Api-Key": <invoice_key>}
-
- Body (application/json)
-
-
- Returns 200 OK (application/json)
-
- [<lnurldevice_object>, ...]
- Curl example
- curl -X GET {{ request.base_url
- }}api/v1/lnurlpos/<lnurldevice_id> -H "X-Api-Key: {{
- user.wallets[0].inkey }}"
-
- GET
- /lnurldevice/api/v1/lnurlposs
- Headers
- {"X-Api-Key": <invoice_key>}
-
- Body (application/json)
-
-
- Returns 200 OK (application/json)
-
- [<lnurldevice_object>, ...]
- Curl example
- curl -X GET {{ request.base_url }}api/v1/lnurldevices -H
- "X-Api-Key: {{ user.wallets[0].inkey }}"
-
- DELETE
- /lnurldevice/api/v1/lnurlpos/<lnurldevice_id>
- Headers
- {"X-Api-Key": <admin_key>}
- Returns 204 NO CONTENT
-
-
Curl example
- curl -X DELETE {{ request.base_url
- }}api/v1/lnurlpos/<lnurldevice_id> -H "X-Api-Key: {{
- user.wallets[0].adminkey }}"
-
-