Skip to content

Commit

Permalink
fix: npub to hex
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 committed Jul 19, 2024
1 parent fd49870 commit 3a4889f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def normalize_identifier(identifier: str):
return identifier


def validate_pub_key(pubkey: str):
def validate_pub_key(pubkey: str) -> str:
if pubkey.startswith("npub"):
_, data = bech32_decode(pubkey)
if data:
Expand Down
10 changes: 9 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lnbits.db import FilterModel, FromRowModel
from pydantic import BaseModel

from .helpers import format_amount, is_ws_url, normalize_identifier
from .helpers import format_amount, is_ws_url, normalize_identifier, validate_pub_key


class CustomCost(BaseModel):
Expand All @@ -23,13 +23,21 @@ class UpdateAddressData(BaseModel):
pubkey: Optional[str] = None
relays: Optional[List[str]] = None

def validate_data(self):
self.validate_relays_urls()
self.validate_pubkey()

def validate_relays_urls(self):
if not self.relays:
return
for r in self.relays:
if not is_ws_url(r):
raise ValueError(f"Relay '{r}' is not valid!")

def validate_pubkey(self):
if self.pubkey and self.pubkey != "":
self.pubkey = validate_pub_key(self.pubkey)


class CreateAddressData(BaseModel):
domain_id: str
Expand Down
2 changes: 1 addition & 1 deletion views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async def api_update_user_address(
if not user_id:
raise HTTPException(HTTPStatus.FORBIDDEN)

data.validate_relays_urls()
data.validate_data()

address = await get_address(domain_id, address_id)
assert address, "Address not found"
Expand Down

0 comments on commit 3a4889f

Please sign in to comment.