mirror of
https://github.com/langgenius/dify.git
synced 2026-11-24 20:59:04 +08:00
15 lines
469 B
Python
15 lines
469 B
Python
"""Timestamped HMAC query parameters shared by URL producers."""
|
|
|
|
import base64
|
|
import hashlib
|
|
import hmac
|
|
import os
|
|
import time
|
|
|
|
|
|
def sign_query(*, payload: str, key: bytes) -> dict[str, str]:
|
|
timestamp = str(int(time.time()))
|
|
nonce = os.urandom(16).hex()
|
|
signature = hmac.new(key, f"{payload}|{timestamp}|{nonce}".encode(), hashlib.sha256).digest()
|
|
return {"timestamp": timestamp, "nonce": nonce, "sign": base64.urlsafe_b64encode(signature).decode()}
|