Skip to content

Commit

Permalink
Merge pull request #16 from lnbits/add_test_button
Browse files Browse the repository at this point in the history
Test Endpoint
  • Loading branch information
callebtc authored May 8, 2023
2 parents 9f44852 + f27b4fa commit 9107834
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 32 deletions.
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

0 comments on commit 9107834

Please sign in to comment.