Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Endpoint #16

Merged
merged 13 commits into from
May 8, 2023
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from typing import List

from fastapi import APIRouter
from starlette.staticfiles import StaticFiles

Expand Down
19 changes: 19 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from bech32 import bech32_decode, convertbits


def normalize_public_key(pubkey: str) -> str:
if pubkey.startswith("npub1"):
_, decoded_data = bech32_decode(pubkey)
if not decoded_data:
raise ValueError("Public Key is not valid npub")

decoded_data_bits = convertbits(decoded_data, 5, 8, False)
if not decoded_data_bits:
raise ValueError("Public Key is not valid npub")
return bytes(decoded_data_bits).hex()

# check if valid hex
if len(pubkey) != 64:
raise ValueError("Public Key is not valid hex")
int(pubkey, 16)
return pubkey
10 changes: 10 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ class Filters(BaseModel):
__root__: List[Filter]


class TestMessage(BaseModel):
sender_private_key: Optional[str]
reciever_public_key: str
message: str

class TestMessageResponse(BaseModel):
private_key: str
public_key: str
event_json: str

# class nostrKeys(BaseModel):
# pubkey: str
# privkey: str
Expand Down
1 change: 1 addition & 0 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fastapi import WebSocket, WebSocketDisconnect
from loguru import logger

from lnbits.helpers import urlsafe_short_hash

from .models import Event, Filter, Filters, Relay, RelayList
Expand Down
4 changes: 2 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import ssl
import json
import ssl
import threading

from .crud import get_relays
Expand All @@ -11,8 +11,8 @@
from .services import (
nostr,
received_subscription_eosenotices,
received_subscription_notices,
received_subscription_events,
received_subscription_notices,
)


Expand Down
Loading