Spaces:
Paused
Paused
Update proxy_handler.py
Browse files- proxy_handler.py +11 -14
proxy_handler.py
CHANGED
|
@@ -48,8 +48,8 @@ class ProxyHandler:
|
|
| 48 |
|
| 49 |
def _generate_signature(self, e_payload: str, t_payload: str) -> Dict[str, Any]:
|
| 50 |
"""
|
| 51 |
-
Generates the signature based on the logic from the reference JS code.
|
| 52 |
-
This is a two-level HMAC-SHA256 process.
|
| 53 |
|
| 54 |
Args:
|
| 55 |
e_payload (str): The simplified payload string (e.g., "requestId,...,timestamp,...").
|
|
@@ -58,20 +58,17 @@ class ProxyHandler:
|
|
| 58 |
Returns:
|
| 59 |
A dictionary with 'signature' and 'timestamp'.
|
| 60 |
"""
|
| 61 |
-
# The provided reference code uses a different logic for the key derivation.
|
| 62 |
-
# It's based on a timestamp bucket. Let's re-implement that one.
|
| 63 |
-
# However, the OTHER reference code `signature_generator.py` uses a different method.
|
| 64 |
-
# Let's stick to the one from the new `utils.py` and `signature_generator.py` for now.
|
| 65 |
-
# The provided python snippet in the prompt is actually different from the JS.
|
| 66 |
-
# The python snippet is: `n = timestamp_ms // (5 * 60 * 1000)`
|
| 67 |
-
# The JS snippet is: `minuteBucket = Math.floor(timestampMs / 60000)`
|
| 68 |
-
# Let's trust the JS one as it's more complete. Let's try the python one first as it's provided.
|
| 69 |
-
|
| 70 |
-
# --- Let's use the Python snippet logic from the prompt first ---
|
| 71 |
timestamp_ms = self._get_timestamp_millis()
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
# Per the Python snippet: n is a 5-minute bucket
|
| 75 |
n = timestamp_ms // (5 * 60 * 1000)
|
| 76 |
|
| 77 |
# Intermediate key derivation
|
|
|
|
| 48 |
|
| 49 |
def _generate_signature(self, e_payload: str, t_payload: str) -> Dict[str, Any]:
|
| 50 |
"""
|
| 51 |
+
Generates the signature based on the logic from the reference JS code (work.js).
|
| 52 |
+
This is a two-level HMAC-SHA256 process with Base64 encoding for the content.
|
| 53 |
|
| 54 |
Args:
|
| 55 |
e_payload (str): The simplified payload string (e.g., "requestId,...,timestamp,...").
|
|
|
|
| 58 |
Returns:
|
| 59 |
A dictionary with 'signature' and 'timestamp'.
|
| 60 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
timestamp_ms = self._get_timestamp_millis()
|
| 62 |
+
|
| 63 |
+
# --- MODIFICATION START ---
|
| 64 |
+
# As per work.js, the last message content (t_payload) must be Base64 encoded.
|
| 65 |
+
content_base64 = base64.b64encode(t_payload.encode('utf-8')).decode('utf-8')
|
| 66 |
+
|
| 67 |
+
# Concatenate with the Base64 encoded content
|
| 68 |
+
message_string = f"{e_payload}|{content_base64}|{timestamp_ms}"
|
| 69 |
+
# --- MODIFICATION END ---
|
| 70 |
|
| 71 |
+
# Per the Python snippet and JS reference: n is a 5-minute bucket
|
| 72 |
n = timestamp_ms // (5 * 60 * 1000)
|
| 73 |
|
| 74 |
# Intermediate key derivation
|