From 8205ccedd5570db9ae1b225681d1c9c01c11dc2d Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 29 Jan 2025 12:25:51 +1100 Subject: [PATCH] feat: Add init code --- .gitignore | 3 ++ README.md | 10 +++++ hns-address.py | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 hns-address.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78306c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +hns-address/ +.venv/ +*.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c5f6bd --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Some additional plugins for FireWallet + +These plugins aren't included by default as there are already a lot of plugins included + +## Import +Go to Plugins > Custom Plugin Manager +Import this URL: +``` +https://git.woodburn.au/nathanwoodburn/FireWalletPlugins.git +``` diff --git a/hns-address.py b/hns-address.py new file mode 100644 index 0000000..5455f5c --- /dev/null +++ b/hns-address.py @@ -0,0 +1,102 @@ +import json +# import account +import requests +import os +import subprocess + + +# Plugin Data +info = { + "name": "HNS-Address Functions", + "description": "Run HNS-Address functions within FireWallet", + "version": "1.0", + "author": "Nathan.Woodburn/" +} + +# Functions +functions = { + "generate": { + "name": "Generate HNS Addresses", + "type": "default", + "description": "Generate HNS addresses", + "params": { + "count": { + "name": "Count", + "type": "number", + "description": "Number of addresses to generate (default 1000)" + }, + "startIndex": { + "name": "Start Index", + "type": "number", + "description": "Start index for the generated addresses (default 0)" + }, + "xpub": { + "name": "XPUB", + "type": "text", + "description": "Extended public key to use for generating addresses (default account xpub)" + } + }, + "returns": { + "result": + { + "name": "Result", + "type": "list" + } + } + } +} + +def initialize(): + # Check if hns-address is installed + if not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address")): + # Try to install hns-address + try: + print("Cloning hns-address...") + result = subprocess.run(["git", "clone", "https://git.woodburn.au/nathanwoodburn/hns-address.git"], capture_output=True, text=True) + if result.returncode != 0: + return -1 + except: + return -1 + + # Check if npm install was successful + if not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address", "node_modules")): + try: + print("Installing hns-address dependencies...") + result = subprocess.run(["npm", "install"], cwd=os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address"), capture_output=True, text=True) + if result.returncode != 0: + return -1 + except: + return -1 + + return 0 + +def generate(params, authentication): + # Check if hns-address is installed + if (initialize() != 0): + return {"result": ["Failed to initialize hns-address"]} + + count = params["count"] + startIndex = params["startIndex"] + xpub = params["xpub"] + + if (count == None): + count = 1000 + + if (startIndex == None): + startIndex = 0 + + if (xpub == None): + xpub = "xpub6BvF6DnLZRV6my62FuQ8nw5TRebL8qr9Wa7u2tE1aEedHWBt4XAfSaNTmP1SM2nXErGWSzxRAHVwqstPzRrsXtA2vn1a4KzLwAVEgLNmfca" + + result = subprocess.run(["node", "generate-address.js", "--xpub", xpub, "--number", str(count), "--startIndex", str(startIndex)], capture_output=True, text=True, cwd=os.path.join(os.path.dirname(os.path.realpath(__file__)), "hns-address")) + with open(f"{xpub}-addresses.txt", "w") as f: + f.write(result.stdout) + + return {"result": result.stdout.split("\n")[2:-1]} + +if __name__ == "__main__": + print(generate({ + "count": 1000, + "startIndex": 0, + "xpub": "xpub6BvF6DnLZRV6my62FuQ8nw5TRebL8qr9Wa7u2tE1aEedHWBt4XAfSaNTmP1SM2nXErGWSzxRAHVwqstPzRrsXtA2vn1a4KzLwAVEgLNmfca" + }, None)) \ No newline at end of file