SCORECARDAPISTP1 / hash.py
zombee11's picture
Upload 29 files
bbee61a verified
Raw
History Blame Contribute Delete
426 Bytes
import hashlib
import json
from decimal import Decimal
from typing import Any
def _json_default(value: Any) -> str:
if isinstance(value, Decimal):
return str(value)
return str(value)
def stable_payload_hash(payload: dict[str, Any]) -> str:
serialized = json.dumps(payload, sort_keys=True, default=_json_default, separators=(",", ":"))
return hashlib.sha256(serialized.encode("utf-8")).hexdigest()