feat: Add initial WALLET DNS record support
All checks were successful
Build Docker / Build Image (push) Successful in 2m46s
All checks were successful
Build Docker / Build Image (push) Successful in 2m46s
This commit is contained in:
15
account.py
15
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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user