forked from pieterjm/DeviceTimer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.py
More file actions
38 lines (29 loc) · 936 Bytes
/
helpers.py
File metadata and controls
38 lines (29 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Helper utilities for DeviceTimer extension"""
from lnurl import Lnurl
from loguru import logger
def encode_lnurl(url: str) -> str:
"""
Encode a URL to LNURL bech32 format.
Args:
url: The URL to encode (must be https for production)
Returns:
Bech32 encoded LNURL string (uppercase, starting with LNURL1...)
"""
try:
lnurl_obj = Lnurl(url)
encoded = lnurl_obj.bech32
return encoded.upper()
except Exception as e:
logger.error(f"Failed to encode LNURL: {e}, url: {url}")
raise ValueError(f"Invalid URL for LNURL encoding: {url}") from e
def is_valid_lnurl(value: str) -> bool:
"""
Check if a string is a valid bech32 encoded LNURL.
Args:
value: The string to check
Returns:
True if valid LNURL format, False otherwise
"""
if not value:
return False
return value.upper().startswith("LNURL1")