From 73a8708b0f1eff772eb43d1e0f1419625f509235 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn <github@nathan.woodburn.au> Date: Fri, 7 Mar 2025 15:10:17 +1100 Subject: [PATCH] feat: Add login with signature --- hnslinks.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/hnslinks.py b/hnslinks.py index f377a93..7755173 100644 --- a/hnslinks.py +++ b/hnslinks.py @@ -7,7 +7,7 @@ import os # Plugin Data info = { "name": "HNS Links", - "description": "This is a plugin to quickly setup a HNS Links site<br>1. Connect varo instance with api key<br>2. Add domain to varo<br> 3. Add it to hns-links<br>4. Wait a few minutes and add it to HNS Links to ensure the TLSA is correct<br>5. Wait for the DNS update to propogate (up to 7 hrs)", + "description": "This is a plugin to quickly setup a HNS Links site<br>1. Connect varo instance with api key<br>2. Add domain to varo<br> 3. Add it to HNS Links<br>4. Wait a few minutes and readd it to HNS Links to ensure the generated TLSA is added<br>5. Wait for the DNS update to propogate (up to 7 hrs)", "version": "1.0", "author": "Nathan.Woodburn/" } @@ -73,7 +73,24 @@ functions = { "type": "text" } } - + }, + "edit": { + "name":" Edit HNS Links", + "type": "default", + "description": "Login and Edit your HNS Links", + "params": { + "domain": { + "name":"Domain", + "type":"text" + } + }, + "returns": { + "url": + { + "name": "Login URL", + "type": "text" + } + } } } @@ -290,3 +307,28 @@ def hnslinks(params, authentication): return {"status": "YAY!!! All done! Just wait a few minutes for HNS Links to fully initialize the site."} + +def edit(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(authentication,domain,"hns-links") + if "error" in response and response["error"]: + return {"status": f"Error: {response['error']}"} + + if 'result' not in response: + return {"status": "Error signing message"} + signature = response["result"] + return {"url": f"https://links.hns.au/auth?username={domain}&signature={signature}"} \ No newline at end of file