commit 68a98f8ec74e88992772fe1252e8006258b08fe1
Author: lash <dev@holbrook.no>
Date: Thu, 23 Oct 2025 02:33:21 +0100
Initial commit
Diffstat:
5 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,4 @@
+uwsgi.ini
+build
+*.egg-info
+__pycache__
diff --git a/requirements.txt b/requirements.txt
@@ -0,0 +1,15 @@
+asn1crypto==1.5.1
+base58==2.1.1
+bip32==4.0
+cffi==2.0.0
+coincurve==20.0.0
+pycparser==2.23
+uWSGI==2.0.31
+asn1crypto==1.5.1
+base58==2.1.1
+bip32==4.0
+cffi==2.0.0
+coincurve==20.0.0
+lmdb==1.7.5
+pycparser==2.23
+uWSGI==2.0.31
diff --git a/srvaddrgen/__init__.py b/srvaddrgen/__init__.py
@@ -0,0 +1 @@
+from .const import DbKey
diff --git a/srvaddrgen/app/app.py b/srvaddrgen/app/app.py
@@ -0,0 +1,56 @@
+import os
+import json
+import hashlib
+import logging
+from bip32 import BIP32
+import base58
+import lmdb
+
+from srvaddrgen import DbKey
+
+logging.basicConfig(level=logging.DEBUG)
+logg = logging.getLogger()
+
+
+def application(environ, start_response):
+ status_code = 200
+ status_reason = 'OK'
+ status_content = b''
+
+ db_path = os.environ.get('SRVADDRGEN_DB_PATH', 'srvaddrgen_data')
+ env = lmdb.open(db_path, readonly=False)
+ xpub = os.environ.get("SRVADDRGEN_BTC_XPUB", None)
+ idx = -1
+ addr = None
+ k = DbKey.BTC_XPUB.value
+ xpub_bin = xpub.encode('utf-8')
+ if xpub != None:
+ tx = env.begin(write=True)
+ v = tx.get(k)
+ if v == None:
+ logg.info('BTC XPUB not set')
+ v = b'\x00' * 8
+ v += xpub_bin
+ tx.put(k, v, dupdata=False)
+ tx.commit()
+
+ tx = env.begin()
+ v = tx.get(k)
+ idx = int.from_bytes(v[:8])
+ if v[8:] != xpub_bin:
+ status_code = 500
+ status_reason = 'Key changed.'
+ status_content = b'Master key has changed on server. Contact server administrator.'
+
+ xpub = v[8:].decode('utf-8')
+ o = BIP32.from_xpub(xpub)
+ pubk_bytes = o.get_pubkey_from_path('m/0/' + str(idx))
+ addr = b'\x00' + hashlib.new('ripemd160', hashlib.new('sha256', pubk_bytes).digest()).digest()
+ pfx = hashlib.new('sha256', hashlib.new('sha256', addr).digest()).digest()[:4]
+ status_content = base58.b58encode(addr + pfx)
+
+ status = str(status_code) + ' ' + status_reason
+ headers = [('Content-Type', 'text/plain')]
+ start_response(status, headers)
+ #return json.dumps(o).encode('utf-8')
+ return status_content
diff --git a/srvaddrgen/const.py b/srvaddrgen/const.py
@@ -0,0 +1,6 @@
+import enum
+
+class DbKey(enum.Enum):
+ ADDR = b'\x00'
+ BTC_XPUB = b'\x01'
+ BTC_LIGHTNING = b'\x02'