35 lines
870 B
Python
35 lines
870 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from yuxi.channels.adapters.nostr.crypto import normalize_pubkey
|
||
|
|
|
||
|
|
|
||
|
|
def normalize_target(raw: str) -> str:
|
||
|
|
if not raw:
|
||
|
|
return ""
|
||
|
|
cleaned = raw.strip().lower()
|
||
|
|
if cleaned.startswith("nostr:"):
|
||
|
|
cleaned = cleaned[6:]
|
||
|
|
normalized = normalize_pubkey(cleaned)
|
||
|
|
if normalized:
|
||
|
|
return normalized
|
||
|
|
return ""
|
||
|
|
|
||
|
|
|
||
|
|
def looks_like_id(raw: str) -> bool:
|
||
|
|
if not raw:
|
||
|
|
return False
|
||
|
|
cleaned = raw.strip().lower()
|
||
|
|
if cleaned.startswith("nostr:"):
|
||
|
|
cleaned = cleaned[6:]
|
||
|
|
if cleaned.startswith("npub1") and len(cleaned) == 63:
|
||
|
|
return True
|
||
|
|
if cleaned.startswith("nprofile1"):
|
||
|
|
return True
|
||
|
|
if len(cleaned) == 64 and all(c in "0123456789abcdef" for c in cleaned):
|
||
|
|
return True
|
||
|
|
return False
|
||
|
|
|
||
|
|
|
||
|
|
def hint() -> str:
|
||
|
|
return "<npub|hex pubkey|nprofile>"
|