146 lines
4.4 KiB
Python
146 lines
4.4 KiB
Python
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/"
|
|
}
|
|
|
|
hnsAddressPath = os.path.realpath("customPlugins/hns-address-plugin/hns-address")
|
|
path = os.path.realpath("customPlugins/hns-address-plugin")
|
|
|
|
# Functions
|
|
functions = {
|
|
"generate": {
|
|
"name": "Generate HNS Addresses",
|
|
"type": "default",
|
|
"description": "Generate HNS addresses",
|
|
"params": {
|
|
"count": {
|
|
"name": "Number of Addresses to generate (default 1000)",
|
|
"type": "number"
|
|
},
|
|
"startIndex": {
|
|
"name": "Start Index of Addresses to generate (default 0)",
|
|
"type": "number"
|
|
},
|
|
"xpub": {
|
|
"name": "xPub of the account to generate addresses for (defaults to current account)",
|
|
"type": "text"
|
|
}
|
|
},
|
|
"returns": {
|
|
"result":
|
|
{
|
|
"name": "Result",
|
|
"type": "list"
|
|
}
|
|
}
|
|
},
|
|
"validate": {
|
|
"name": "Validate HNS Addresses",
|
|
"type": "default",
|
|
"description": "Validates if an addresses belongs to an xPub",
|
|
"params": {
|
|
"address": {
|
|
"name": "Address to validate",
|
|
"type": "text"
|
|
},
|
|
"xpub": {
|
|
"name": "xPub of the account to check addresses for (defaults to current account)",
|
|
"type": "text"
|
|
}
|
|
},
|
|
"returns": {
|
|
"result":
|
|
{
|
|
"name": "Result",
|
|
"type": "text"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
def initialize():
|
|
# Check if hns-address is installed
|
|
if not os.path.exists(hnsAddressPath):
|
|
# 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, cwd=path)
|
|
if result.returncode != 0:
|
|
return -1
|
|
except:
|
|
return -1
|
|
|
|
# Check if npm install was successful
|
|
if not os.path.exists(f"{hnsAddressPath}/node_modules"):
|
|
try:
|
|
print("Installing hns-address dependencies...")
|
|
result = subprocess.run(["npm", "install"], cwd=hnsAddressPath, 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 == ""):
|
|
xpub = account.getxPub(authentication)
|
|
if (xpub == None):
|
|
return {"result": "No xpub found"}
|
|
|
|
result = subprocess.run(["node", "generate-address.js", "--xpub", xpub, "--number", str(count), "--startIndex", str(startIndex)], capture_output=True, text=True, cwd=hnsAddressPath)
|
|
with open(f"{xpub}-addresses.txt", "w") as f:
|
|
f.write(result.stdout)
|
|
|
|
return {"result": result.stdout.split("\n")[2:-1]}
|
|
|
|
def validate(params, authentication):
|
|
# Check if hns-address is installed
|
|
if (initialize() != 0):
|
|
return {"result": ["Failed to initialize hns-address"]}
|
|
|
|
xpub = params["xpub"]
|
|
address = params["address"]
|
|
|
|
if (xpub == ""):
|
|
xpub = account.getxPub(authentication)
|
|
if (xpub == None):
|
|
return {"result": "No xpub found"}
|
|
|
|
if (address == None):
|
|
return {"result": "Address is required"}
|
|
|
|
result = subprocess.run(["node", "find-address.js", "--xpub", xpub, "--address", address, "--end", "10000"], capture_output=True, text=True, cwd=hnsAddressPath)
|
|
|
|
return {"result": result.stdout.replace("\n", "<br>")}
|
|
|
|
if __name__ == "__main__":
|
|
print(generate({
|
|
"count": 1000,
|
|
"startIndex": 0,
|
|
"xpub": "xpub6BvF6DnLZRV6my62FuQ8nw5TRebL8qr9Wa7u2tE1aEedHWBt4XAfSaNTmP1SM2nXErGWSzxRAHVwqstPzRrsXtA2vn1a4KzLwAVEgLNmfca"
|
|
}, None)) |