pax-api 2.5.0__tar.gz → 2.5.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pax-api
3
- Version: 2.5.0
3
+ Version: 2.5.1
4
4
  Summary: Official Python SDK for the PredictAsiaX Trader Track API — Web3-native prediction markets
5
5
  Author-email: PredictAsiaX <support@predictasiax.com>
6
6
  License: MIT
@@ -9,7 +9,7 @@ Project-URL: Documentation, https://docs.predictasiax.com
9
9
  Project-URL: Repository, https://github.com/predictasiax/pax-python-sdk
10
10
  Project-URL: Issues, https://github.com/predictasiax/pax-python-sdk/issues
11
11
  Project-URL: Changelog, https://docs.predictasiax.com/changelog
12
- Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac
12
+ Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac,polymarket-compatible
13
13
  Classifier: Development Status :: 4 - Beta
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Intended Audience :: Financial and Insurance Industry
@@ -40,9 +40,9 @@ Dynamic: license-file
40
40
 
41
41
  # pax-api — Official Python SDK for PredictAsiaX
42
42
 
43
- Web3-native prediction market REST + WebSocket API client. HMAC-SHA256 signed-request auth for high-security trading bots.
43
+ Web3-native prediction market REST + WebSocket API client. Polymarket-compatible HMAC signing pattern.
44
44
 
45
- **Version 2.5.0** · MIT license · Python 3.8+
45
+ **Version 2.2.1** · MIT license · Python 3.8+
46
46
 
47
47
  - **Docs**: https://docs.predictasiax.com
48
48
  - **Verify**: https://docs.predictasiax.com/verify — public Merkle verifier over the operational ledger
@@ -85,7 +85,7 @@ Same production host either way (`api.predictasiax.com/v1`). Sandbox tier is enf
85
85
 
86
86
  ## Production trading (HMAC-signed)
87
87
 
88
- Machine-to-machine bots use HMAC-SHA256 signing (4 PAX_* headers per request):
88
+ Machine-to-machine bots use HMAC signing (Polymarket-compatible 5-header pattern):
89
89
 
90
90
  ```python
91
91
  from pax_api import PaxClient
@@ -1,8 +1,8 @@
1
1
  # pax-api — Official Python SDK for PredictAsiaX
2
2
 
3
- Web3-native prediction market REST + WebSocket API client. HMAC-SHA256 signed-request auth for high-security trading bots.
3
+ Web3-native prediction market REST + WebSocket API client. Polymarket-compatible HMAC signing pattern.
4
4
 
5
- **Version 2.5.0** · MIT license · Python 3.8+
5
+ **Version 2.2.1** · MIT license · Python 3.8+
6
6
 
7
7
  - **Docs**: https://docs.predictasiax.com
8
8
  - **Verify**: https://docs.predictasiax.com/verify — public Merkle verifier over the operational ledger
@@ -45,7 +45,7 @@ Same production host either way (`api.predictasiax.com/v1`). Sandbox tier is enf
45
45
 
46
46
  ## Production trading (HMAC-signed)
47
47
 
48
- Machine-to-machine bots use HMAC-SHA256 signing (4 PAX_* headers per request):
48
+ Machine-to-machine bots use HMAC signing (Polymarket-compatible 5-header pattern):
49
49
 
50
50
  ```python
51
51
  from pax_api import PaxClient
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pax-api"
7
- version = "2.5.0"
7
+ version = "2.5.1"
8
8
  description = "Official Python SDK for the PredictAsiaX Trader Track API — Web3-native prediction markets"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -12,7 +12,7 @@ license = { text = "MIT" }
12
12
  authors = [
13
13
  { name = "PredictAsiaX", email = "support@predictasiax.com" },
14
14
  ]
15
- keywords = ["predictasiax", "pax", "prediction-market", "trading-api", "web3", "hmac"]
15
+ keywords = ["predictasiax", "pax", "prediction-market", "trading-api", "web3", "hmac", "polymarket-compatible"]
16
16
  classifiers = [
17
17
  "Development Status :: 4 - Beta",
18
18
  "Intended Audience :: Developers",
@@ -26,7 +26,7 @@ caps), not a separate host. Same prefix, same URL — promote to production by
26
26
  upgrading the key's tier.
27
27
  """
28
28
 
29
- __version__ = "2.4.0"
29
+ __version__ = "2.5.1"
30
30
 
31
31
  from pax_api.client import PaxClient # noqa: E402
32
32
  from pax_api.ws_client import PaxWSClient # noqa: E402
@@ -1,14 +1,14 @@
1
- """HMAC signing helpers — PAX canonical 5-header signed-request protocol.
1
+ """HMAC signing helpers — Polymarket-compatible 5-header pattern.
2
2
 
3
3
  Signature construction:
4
4
  message = timestamp_ms + method_upper + path + body
5
5
  signature = base64(HMAC-SHA256(secret, message))
6
6
 
7
- Headers sent (canonical PAX_* form):
8
- PAX_ACCESS_KEY: <key_id>
9
- PAX_TIMESTAMP: <ms epoch>
10
- PAX_PASSPHRASE: <passphrase>
11
- PAX_SIGNATURE: <base64 sig>
7
+ Headers sent:
8
+ POLY_ACCESS_KEY: <key_id>
9
+ POLY_TIMESTAMP: <ms epoch>
10
+ POLY_PASSPHRASE: <passphrase>
11
+ POLY_SIGNATURE: <base64 sig>
12
12
 
13
13
  Server rejects with 401 INVALID_SIGNATURE if timestamp is more than
14
14
  ±30 seconds from server clock. Sync your machine via NTP.
@@ -32,7 +32,7 @@ def sign_request(
32
32
  passphrase: str,
33
33
  timestamp_ms: Optional[int] = None,
34
34
  ) -> Dict[str, str]:
35
- """Build the 4 PAX_* headers for an HMAC-signed request.
35
+ """Build the 5 POLY_* headers for an HMAC-signed request.
36
36
 
37
37
  Args:
38
38
  method: HTTP method (GET/POST/DELETE/etc.). Case-normalized to upper.
@@ -46,7 +46,7 @@ def sign_request(
46
46
  timestamp_ms: Override timestamp for testing. Defaults to now.
47
47
 
48
48
  Returns:
49
- Dict of 4 headers to merge into the request.
49
+ Dict of 5 headers to merge into the request.
50
50
  """
51
51
  ts = str(timestamp_ms if timestamp_ms is not None else int(time.time() * 1000))
52
52
  method_u = method.upper()
@@ -54,10 +54,10 @@ def sign_request(
54
54
  digest = hmac.new(secret.encode("utf-8"), message.encode("utf-8"), hashlib.sha256).digest()
55
55
  signature = base64.b64encode(digest).decode("ascii")
56
56
  return {
57
- "PAX_ACCESS_KEY": key_id,
58
- "PAX_TIMESTAMP": ts,
59
- "PAX_PASSPHRASE": passphrase,
60
- "PAX_SIGNATURE": signature,
57
+ "POLY_ACCESS_KEY": key_id,
58
+ "POLY_TIMESTAMP": ts,
59
+ "POLY_PASSPHRASE": passphrase,
60
+ "POLY_SIGNATURE": signature,
61
61
  }
62
62
 
63
63
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Auth modes (auto-detected):
4
4
  1. HMAC — pass ``api_key`` + ``secret`` + ``passphrase``. Every request
5
- signed with 4 PAX_* headers. Use for high-security trading bots.
5
+ signed with 5 POLY_* headers. Use for high-security trading bots.
6
6
  2. API Key — pass only ``api_key``. Sent via X-Api-Key header. Simple
7
7
  for read-only or low-risk M2M flows.
8
8
  3. Bearer — pass ``bearer_token``. Session-based. Browser/mobile only.
@@ -27,7 +27,7 @@ from pax_api.auth import sign_request
27
27
  from pax_api.errors import PaxError, build_error
28
28
  from pax_api.retry import run_with_retry
29
29
 
30
- __version__ = "2.4.0" # keep in sync with __init__.py + pyproject.toml
30
+ __version__ = "2.5.1" # keep in sync with __init__.py + pyproject.toml
31
31
 
32
32
 
33
33
  # v2: sandbox is a tier on the key, not a separate host. All env aliases
@@ -430,15 +430,22 @@ class PaxClient:
430
430
  def verify_merkle_proof(leaf: str, root: str, proof: List[str]) -> bool:
431
431
  """Verify a Merkle inclusion proof locally — no PAX call needed.
432
432
 
433
- Mirrors OpenZeppelin sorted-pair sha256 (identical to server-side
434
- batcher + on-chain Solidity ``MerkleProof.verify``).
433
+ Sorted-pair SHA-256 over the RAW 32-byte digests (identical to the
434
+ server-side batcher). Each hex leaf/sibling is decoded to its raw
435
+ bytes, the pair is sorted by byte value, the raw bytes are concatenated
436
+ and hashed with SHA-256 — hashing the hex STRINGS instead gives the
437
+ wrong root. This is OpenZeppelin-style sorted-pair ordering but hashed
438
+ with SHA-256, NOT keccak256: stock ``MerkleProof.verify`` hashes with
439
+ keccak256 and will not match these roots. On-chain, verify with a
440
+ SHA-256 sorted-pair verifier (``sha256(abi.encodePacked(a, b))``).
435
441
  """
436
442
  import hashlib
437
- h = leaf
443
+ h = bytes.fromhex(leaf)
438
444
  for sibling in proof:
439
- a, b = (h, sibling) if h < sibling else (sibling, h)
440
- h = hashlib.sha256((a + b).encode("ascii")).hexdigest()
441
- return h == root
445
+ s = bytes.fromhex(sibling)
446
+ a, b = (h, s) if h <= s else (s, h)
447
+ h = hashlib.sha256(a + b).digest()
448
+ return h.hex() == root
442
449
 
443
450
  def get_application(self, application_code: str) -> Dict[str, Any]:
444
451
  """GET /v1/apply/{code} — check application review status."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pax-api
3
- Version: 2.5.0
3
+ Version: 2.5.1
4
4
  Summary: Official Python SDK for the PredictAsiaX Trader Track API — Web3-native prediction markets
5
5
  Author-email: PredictAsiaX <support@predictasiax.com>
6
6
  License: MIT
@@ -9,7 +9,7 @@ Project-URL: Documentation, https://docs.predictasiax.com
9
9
  Project-URL: Repository, https://github.com/predictasiax/pax-python-sdk
10
10
  Project-URL: Issues, https://github.com/predictasiax/pax-python-sdk/issues
11
11
  Project-URL: Changelog, https://docs.predictasiax.com/changelog
12
- Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac
12
+ Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac,polymarket-compatible
13
13
  Classifier: Development Status :: 4 - Beta
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Intended Audience :: Financial and Insurance Industry
@@ -40,9 +40,9 @@ Dynamic: license-file
40
40
 
41
41
  # pax-api — Official Python SDK for PredictAsiaX
42
42
 
43
- Web3-native prediction market REST + WebSocket API client. HMAC-SHA256 signed-request auth for high-security trading bots.
43
+ Web3-native prediction market REST + WebSocket API client. Polymarket-compatible HMAC signing pattern.
44
44
 
45
- **Version 2.5.0** · MIT license · Python 3.8+
45
+ **Version 2.2.1** · MIT license · Python 3.8+
46
46
 
47
47
  - **Docs**: https://docs.predictasiax.com
48
48
  - **Verify**: https://docs.predictasiax.com/verify — public Merkle verifier over the operational ledger
@@ -85,7 +85,7 @@ Same production host either way (`api.predictasiax.com/v1`). Sandbox tier is enf
85
85
 
86
86
  ## Production trading (HMAC-signed)
87
87
 
88
- Machine-to-machine bots use HMAC-SHA256 signing (4 PAX_* headers per request):
88
+ Machine-to-machine bots use HMAC signing (Polymarket-compatible 5-header pattern):
89
89
 
90
90
  ```python
91
91
  from pax_api import PaxClient
@@ -13,6 +13,7 @@ src/pax_api.egg-info/SOURCES.txt
13
13
  src/pax_api.egg-info/dependency_links.txt
14
14
  src/pax_api.egg-info/requires.txt
15
15
  src/pax_api.egg-info/top_level.txt
16
+ tests/test_audit.py
16
17
  tests/test_auth.py
17
18
  tests/test_client.py
18
19
  tests/test_errors.py
@@ -0,0 +1,59 @@
1
+ """Merkle inclusion verifier regression tests.
2
+
3
+ Live-published batch #36937 (4 leaves, seq 1216790..1216793) and its anchored
4
+ merkle_root. The verifier hashes the RAW 32-byte digests (sorted-pair SHA-256),
5
+ matching the publisher. Hashing the hex strings instead yields the wrong root
6
+ (the regression this suite guards against).
7
+ """
8
+
9
+ import hashlib
10
+
11
+ from pax_api import PaxClient
12
+
13
+ ROOT = "d88ec39a9842420a17a3a1eb7b28ba38e0c65addfab659cfb1853a612bd2a81b"
14
+ LEAVES = [
15
+ "d9d7ab1756d6701e32345df160edcd6fde2f391d92f77e80e9f89a848c06d15a",
16
+ "95dbef5fabf638ff9f37bb8b90bfbf62767bad5f4cdd18fb98aaefa1b3d3056d",
17
+ "1dd4ed233edb578e0edf9771ed34aaf66aea8a6c531e32e8aedd5f8a92a62378",
18
+ "263ccaa0884b697a0e4cd5ff6078c92049440c95396a7f8cda538e6490b2b472",
19
+ ]
20
+
21
+
22
+ def _hash_pair(a: str, b: str) -> str:
23
+ A, B = bytes.fromhex(a), bytes.fromhex(b)
24
+ x, y = (A, B) if A <= B else (B, A)
25
+ return hashlib.sha256(x + y).hexdigest()
26
+
27
+
28
+ P01 = _hash_pair(LEAVES[0], LEAVES[1])
29
+ P23 = _hash_pair(LEAVES[2], LEAVES[3])
30
+ # sibling inclusion proof for each leaf index
31
+ PROOFS = [[LEAVES[1], P23], [LEAVES[0], P23], [LEAVES[3], P01], [LEAVES[2], P01]]
32
+
33
+
34
+ def test_raw_byte_sorted_pair_reconstructs_published_root() -> None:
35
+ assert _hash_pair(P01, P23) == ROOT
36
+
37
+
38
+ def test_verify_merkle_proof_accepts_every_valid_leaf() -> None:
39
+ for i, leaf in enumerate(LEAVES):
40
+ assert PaxClient.verify_merkle_proof(leaf, ROOT, PROOFS[i]) is True
41
+
42
+
43
+ def test_rejects_tampered_leaf() -> None:
44
+ bad = "e" + LEAVES[0][1:]
45
+ assert PaxClient.verify_merkle_proof(bad, ROOT, PROOFS[0]) is False
46
+
47
+
48
+ def test_rejects_tampered_proof_path() -> None:
49
+ bad_proof = [LEAVES[2], P23] # wrong sibling
50
+ assert PaxClient.verify_merkle_proof(LEAVES[0], ROOT, bad_proof) is False
51
+
52
+
53
+ def test_old_hex_string_hashing_does_not_match_root() -> None:
54
+ # Pre-fix behaviour: concat hex strings and hash their ASCII bytes.
55
+ h = LEAVES[0]
56
+ for s in PROOFS[0]:
57
+ a, b = (h, s) if h < s else (s, h)
58
+ h = hashlib.sha256((a + b).encode("ascii")).hexdigest()
59
+ assert h != ROOT
@@ -1,4 +1,4 @@
1
- """Unit tests for HMAC signing helpers — verify PAX canonical 5-header protocol."""
1
+ """Unit tests for HMAC signing helpers — verify matches Polymarket-compatible spec."""
2
2
 
3
3
  import base64
4
4
  import hashlib
@@ -21,28 +21,28 @@ def test_signature_matches_reference() -> None:
21
21
  hmac.new(secret.encode(), msg.encode(), hashlib.sha256).digest()
22
22
  ).decode()
23
23
  headers = sign_request("GET", "/v1/health", "", "sk_live_ABC", secret, "pass", timestamp_ms=ts)
24
- assert headers["PAX_ACCESS_KEY"] == "sk_live_ABC"
25
- assert headers["PAX_TIMESTAMP"] == str(ts)
26
- assert headers["PAX_PASSPHRASE"] == "pass"
27
- assert headers["PAX_SIGNATURE"] == expected
24
+ assert headers["POLY_ACCESS_KEY"] == "sk_live_ABC"
25
+ assert headers["POLY_TIMESTAMP"] == str(ts)
26
+ assert headers["POLY_PASSPHRASE"] == "pass"
27
+ assert headers["POLY_SIGNATURE"] == expected
28
28
 
29
29
 
30
30
  def test_signature_differs_when_body_changes() -> None:
31
31
  secret = "s" * 32
32
32
  h1 = sign_request("POST", "/v1/orders", '{"size":"1"}', "k", secret, "p", timestamp_ms=1)
33
33
  h2 = sign_request("POST", "/v1/orders", '{"size":"2"}', "k", secret, "p", timestamp_ms=1)
34
- assert h1["PAX_SIGNATURE"] != h2["PAX_SIGNATURE"]
34
+ assert h1["POLY_SIGNATURE"] != h2["POLY_SIGNATURE"]
35
35
 
36
36
 
37
37
  def test_signature_differs_when_timestamp_changes() -> None:
38
38
  secret = "s" * 32
39
39
  h1 = sign_request("GET", "/v1/health", "", "k", secret, "p", timestamp_ms=1)
40
40
  h2 = sign_request("GET", "/v1/health", "", "k", secret, "p", timestamp_ms=2)
41
- assert h1["PAX_SIGNATURE"] != h2["PAX_SIGNATURE"]
41
+ assert h1["POLY_SIGNATURE"] != h2["POLY_SIGNATURE"]
42
42
 
43
43
 
44
44
  def test_method_is_upcased() -> None:
45
45
  secret = "s" * 32
46
46
  h1 = sign_request("get", "/v1/health", "", "k", secret, "p", timestamp_ms=1)
47
47
  h2 = sign_request("GET", "/v1/health", "", "k", secret, "p", timestamp_ms=1)
48
- assert h1["PAX_SIGNATURE"] == h2["PAX_SIGNATURE"]
48
+ assert h1["POLY_SIGNATURE"] == h2["POLY_SIGNATURE"]
@@ -43,10 +43,10 @@ def test_hmac_headers_sent_when_secret() -> None:
43
43
  responses.add(responses.GET, f"{PROD_BASE}/v1/health", json={"ok": True}, status=200)
44
44
  c.get_health()
45
45
  req = responses.calls[0].request
46
- assert req.headers.get("PAX_ACCESS_KEY") == "sk_live_ABC"
47
- assert req.headers.get("PAX_PASSPHRASE") == "p"
48
- assert req.headers.get("PAX_TIMESTAMP")
49
- assert req.headers.get("PAX_SIGNATURE")
46
+ assert req.headers.get("POLY_ACCESS_KEY") == "sk_live_ABC"
47
+ assert req.headers.get("POLY_PASSPHRASE") == "p"
48
+ assert req.headers.get("POLY_TIMESTAMP")
49
+ assert req.headers.get("POLY_SIGNATURE")
50
50
 
51
51
 
52
52
  @responses.activate
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes