diff --git a/account.py b/account.py index 76892af..1bad89a 100644 --- a/account.py +++ b/account.py @@ -68,7 +68,7 @@ def hsdVersion(format=True): return info['version'] -def check_account(cookie: str): +def check_account(cookie: str | None): if cookie is None: return False @@ -403,13 +403,20 @@ def check_hip2(domain: str): return 'Invalid domain' address = domainLookup.hip2(domain) - if address.startswith("Hip2: "): + if not address.startswith("Hip2: "): + if not check_address(address, False, True): + return 'Hip2: Lookup succeeded but address is invalid' return address - + # Try using WALLET TXT record + address = domainLookup.wallet_txt(domain) + if not address.startswith("hs1"): + return "No HIP2 or WALLET record found for this domain" if not check_address(address, False, True): - return 'Hip2: Lookup succeeded but address is invalid' + return 'WALLET DNS record found but address is invalid' return address + + def send(account, address, amount): account_name = check_account(account) diff --git a/domainLookup.py b/domainLookup.py index 8ac30a7..749c34d 100644 --- a/domainLookup.py +++ b/domainLookup.py @@ -6,6 +6,9 @@ import subprocess import binascii import datetime import dns.asyncresolver +import dns.message +import dns.query +import dns.rdatatype import httpx from requests_doh import DNSOverHTTPSSession, add_dns_provider import requests @@ -120,6 +123,32 @@ def hip2(domain: str): print(f"Hip2: Lookup failed with error: {e}",flush=True) return "Hip2: Lookup failed." +def wallet_txt(domain: str, doh_url="https://hnsdoh.com/dns-query"): + with httpx.Client() as client: + q = dns.message.make_query(domain, dns.rdatatype.from_text("TYPE262")) + r = dns.query.https(q, doh_url, session=client) + + if not r.answer: + return "No wallet address found for this domain" + + wallet_record = "No WALLET record found" + for ans in r.answer: + raw = ans[0].to_wire() + try: + data = raw[1:].decode("utf-8", errors="ignore") + except UnicodeDecodeError: + return f"Unknown WALLET record format: {raw.hex()}" + + if data.startswith("HNS:"): + wallet_record = data[4:] + break + elif data.startswith("HNS "): + wallet_record = data[4:] + break + elif data.startswith('"HNS" '): + wallet_record = data[6:].strip('"') + break + return wallet_record def resolve_with_doh(query_name, doh_url="https://hnsdoh.com/dns-query"): with httpx.Client() as client: diff --git a/main.py b/main.py index 01f5241..3758de4 100644 --- a/main.py +++ b/main.py @@ -66,7 +66,6 @@ def index(): # Check if the user is logged in if request.cookies.get("account") is None: return redirect("/login") - account = account_module.check_account(request.cookies.get("account")) if not account: return redirect("/logout")