From 64ee3a26e41c8b0e799e2c0792af52a5f4327c4e Mon Sep 17 00:00:00 2001
From: Nathan Woodburn <github@nathan.woodburn.au>
Date: Fri, 7 Mar 2025 14:19:22 +1100
Subject: [PATCH] feat: Add start of hns-link

---
 hnslinks.py | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/hnslinks.py b/hnslinks.py
index 405d63a..c88f774 100644
--- a/hnslinks.py
+++ b/hnslinks.py
@@ -55,6 +55,25 @@ functions = {
             }
         }
     
+    },
+    "hnslinks":{
+        "name": "Add domain to HNS Links with wallet address",
+        "type": "default",
+        "description": "Add a domain to HNS Links",
+        "params": {
+            "domain": {
+                "name":"Domain",
+                "type":"text"
+            }
+        },
+        "returns": {
+            "status": 
+            {
+                "name": "Status of the function",
+                "type": "text"
+            }
+        }
+    
     }
 }
 
@@ -152,4 +171,27 @@ def addDomain(params, authentication):
     dns.append({'type': 'DS', 'keyTag': int(ds[0]), 'algorithm': int(ds[1]), 'digestType': int(ds[2]), 'digest': ds[3]})
     dns = json.dumps(dns)
     response = account.setDNS(authentication,domain,dns)
-    return {"status": "Success"}
\ No newline at end of file
+    return {"status": "Success"}
+
+def hnslinks(params, authentication):
+    # Verify domain is owned by user
+    domain = params["domain"]
+    wallet = authentication.split(":")[0]
+    owned = account.getDomains(wallet)
+    # Only keep owned domains ["name"]
+    ownedNames = [domain["name"] for domain in owned]
+    if domain not in ownedNames:
+        return {"status": "Domain not owned by user"}
+    
+    # Get wallet address
+    address = account.getAddress(wallet)
+    if address == "":
+        return {"status": "Error getting wallet address"}
+    
+    # Sign message hns-links
+    response = account.signMessage(wallet,domain,"hns-links")
+    if "error" in response:
+        return {"status": "Error signing message"}
+    return {"status": response}
+    
+