feat: Add initial WALLET DNS record support
All checks were successful
Build Docker / Build Image (push) Successful in 2m46s

This commit is contained in:
2025-08-25 11:55:15 +10:00
parent 545a0b9475
commit f090b7b71a
3 changed files with 40 additions and 5 deletions

View File

@@ -68,7 +68,7 @@ def hsdVersion(format=True):
return info['version'] return info['version']
def check_account(cookie: str): def check_account(cookie: str | None):
if cookie is None: if cookie is None:
return False return False
@@ -403,13 +403,20 @@ def check_hip2(domain: str):
return 'Invalid domain' return 'Invalid domain'
address = domainLookup.hip2(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 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): 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 return address
def send(account, address, amount): def send(account, address, amount):
account_name = check_account(account) account_name = check_account(account)

View File

@@ -6,6 +6,9 @@ import subprocess
import binascii import binascii
import datetime import datetime
import dns.asyncresolver import dns.asyncresolver
import dns.message
import dns.query
import dns.rdatatype
import httpx import httpx
from requests_doh import DNSOverHTTPSSession, add_dns_provider from requests_doh import DNSOverHTTPSSession, add_dns_provider
import requests import requests
@@ -120,6 +123,32 @@ def hip2(domain: str):
print(f"Hip2: Lookup failed with error: {e}",flush=True) print(f"Hip2: Lookup failed with error: {e}",flush=True)
return "Hip2: Lookup failed." 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"): def resolve_with_doh(query_name, doh_url="https://hnsdoh.com/dns-query"):
with httpx.Client() as client: with httpx.Client() as client:

View File

@@ -66,7 +66,6 @@ def index():
# Check if the user is logged in # Check if the user is logged in
if request.cookies.get("account") is None: if request.cookies.get("account") is None:
return redirect("/login") return redirect("/login")
account = account_module.check_account(request.cookies.get("account")) account = account_module.check_account(request.cookies.get("account"))
if not account: if not account:
return redirect("/logout") return redirect("/logout")