dominusnode-haystack 1.2.0__py3-none-any.whl → 1.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dominusnode-haystack might be problematic. Click here for more details.
- dominusnode_haystack/tools.py +48 -1
- {dominusnode_haystack-1.2.0.dist-info → dominusnode_haystack-1.2.1.dist-info}/METADATA +1 -1
- dominusnode_haystack-1.2.1.dist-info/RECORD +7 -0
- dominusnode_haystack-1.2.0.dist-info/RECORD +0 -7
- {dominusnode_haystack-1.2.0.dist-info → dominusnode_haystack-1.2.1.dist-info}/WHEEL +0 -0
- {dominusnode_haystack-1.2.0.dist-info → dominusnode_haystack-1.2.1.dist-info}/licenses/LICENSE +0 -0
- {dominusnode_haystack-1.2.0.dist-info → dominusnode_haystack-1.2.1.dist-info}/top_level.txt +0 -0
dominusnode_haystack/tools.py
CHANGED
|
@@ -42,6 +42,7 @@ Requires: httpx (``pip install httpx``), haystack-ai (``pip install haystack-ai`
|
|
|
42
42
|
|
|
43
43
|
from __future__ import annotations
|
|
44
44
|
|
|
45
|
+
import hashlib
|
|
45
46
|
import ipaddress
|
|
46
47
|
import json
|
|
47
48
|
import math
|
|
@@ -381,6 +382,46 @@ def _sanitize_error(message: str) -> str:
|
|
|
381
382
|
return _CREDENTIAL_RE.sub("***", message)
|
|
382
383
|
|
|
383
384
|
|
|
385
|
+
def _count_leading_zero_bits(data: bytes) -> int:
|
|
386
|
+
"""Count leading zero bits in a byte array."""
|
|
387
|
+
count = 0
|
|
388
|
+
for byte in data:
|
|
389
|
+
if byte == 0:
|
|
390
|
+
count += 8
|
|
391
|
+
else:
|
|
392
|
+
mask = 0x80
|
|
393
|
+
while mask and not (byte & mask):
|
|
394
|
+
count += 1
|
|
395
|
+
mask >>= 1
|
|
396
|
+
break
|
|
397
|
+
return count
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def _solve_pow(base_url: str) -> Optional[dict]:
|
|
401
|
+
"""Solve a Proof-of-Work challenge for CAPTCHA-free registration."""
|
|
402
|
+
try:
|
|
403
|
+
pow_url = f"{base_url.rstrip('/')}/api/auth/pow/challenge"
|
|
404
|
+
with httpx.Client(timeout=30.0, follow_redirects=False) as client:
|
|
405
|
+
resp = client.post(pow_url, headers={"Content-Type": "application/json"})
|
|
406
|
+
if resp.status_code >= 400:
|
|
407
|
+
return None
|
|
408
|
+
challenge = resp.json()
|
|
409
|
+
prefix = challenge.get("prefix", "")
|
|
410
|
+
difficulty = challenge.get("difficulty", 20)
|
|
411
|
+
challenge_id = challenge.get("challengeId", "")
|
|
412
|
+
if not prefix or not challenge_id:
|
|
413
|
+
return None
|
|
414
|
+
nonce = 0
|
|
415
|
+
while nonce < 100_000_000:
|
|
416
|
+
h = hashlib.sha256((prefix + str(nonce)).encode()).digest()
|
|
417
|
+
if _count_leading_zero_bits(h) >= difficulty:
|
|
418
|
+
return {"challengeId": challenge_id, "nonce": str(nonce)}
|
|
419
|
+
nonce += 1
|
|
420
|
+
return None
|
|
421
|
+
except Exception:
|
|
422
|
+
return None
|
|
423
|
+
|
|
424
|
+
|
|
384
425
|
# ---------------------------------------------------------------------------
|
|
385
426
|
# Prototype pollution prevention
|
|
386
427
|
# ---------------------------------------------------------------------------
|
|
@@ -1858,11 +1899,17 @@ class DominusNodeToolkit:
|
|
|
1858
1899
|
return {"error": err}
|
|
1859
1900
|
|
|
1860
1901
|
try:
|
|
1902
|
+
body: dict = {"email": email, "password": password}
|
|
1903
|
+
pow_result = _solve_pow(self.base_url)
|
|
1904
|
+
if pow_result:
|
|
1905
|
+
body["pow"] = pow_result
|
|
1861
1906
|
result = self._api_request_public(
|
|
1862
1907
|
"POST",
|
|
1863
1908
|
"/api/auth/register",
|
|
1864
|
-
|
|
1909
|
+
body,
|
|
1865
1910
|
)
|
|
1911
|
+
if pow_result and isinstance(result, dict):
|
|
1912
|
+
result["_pow_verified"] = True
|
|
1866
1913
|
return result
|
|
1867
1914
|
except Exception as e:
|
|
1868
1915
|
return {"error": _sanitize_error(str(e))}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
dominusnode_haystack/__init__.py,sha256=T_yPVVK5_muWIMrtagjrstVox8ycVJad5bg9U5QvwnI,163
|
|
2
|
+
dominusnode_haystack/tools.py,sha256=ga1x6wXFBj0U77H5shT4usK5IK5vHEJLzjD7pUQy9sA,124990
|
|
3
|
+
dominusnode_haystack-1.2.1.dist-info/licenses/LICENSE,sha256=NBkjfgN0tpbJjWf7uqsPCOMgq7uuSEW4uaGDCpB8HbI,1069
|
|
4
|
+
dominusnode_haystack-1.2.1.dist-info/METADATA,sha256=DqQLd-0ISlpmYdN_IolcLp2Kf4C7Udm8JPr0SEiBIQs,968
|
|
5
|
+
dominusnode_haystack-1.2.1.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
6
|
+
dominusnode_haystack-1.2.1.dist-info/top_level.txt,sha256=fQyiWIOvfOKV6wVVcQDoakEiJfQ3XumGBoHBrovFD0U,21
|
|
7
|
+
dominusnode_haystack-1.2.1.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
dominusnode_haystack/__init__.py,sha256=T_yPVVK5_muWIMrtagjrstVox8ycVJad5bg9U5QvwnI,163
|
|
2
|
-
dominusnode_haystack/tools.py,sha256=9-9mcgUFXzdY86Nj7J5iBqOb-RV8Hb6KIGKRuZtBFec,123338
|
|
3
|
-
dominusnode_haystack-1.2.0.dist-info/licenses/LICENSE,sha256=NBkjfgN0tpbJjWf7uqsPCOMgq7uuSEW4uaGDCpB8HbI,1069
|
|
4
|
-
dominusnode_haystack-1.2.0.dist-info/METADATA,sha256=lZRuo_moycs4WeKcDBvl6eEymWqcPZWsLjia6q6LGd4,968
|
|
5
|
-
dominusnode_haystack-1.2.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
6
|
-
dominusnode_haystack-1.2.0.dist-info/top_level.txt,sha256=fQyiWIOvfOKV6wVVcQDoakEiJfQ3XumGBoHBrovFD0U,21
|
|
7
|
-
dominusnode_haystack-1.2.0.dist-info/RECORD,,
|
|
File without changes
|
{dominusnode_haystack-1.2.0.dist-info → dominusnode_haystack-1.2.1.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|