zhschain / utils.py
clove1002's picture
Create utils.py
fb86ab9 verified
Raw
History Blame Contribute Delete
414 Bytes
import hashlib
import time
import uuid
def get_timestamp() -> float:
"""Return current timestamp."""
return time.time()
def generate_id() -> str:
"""Generate a unique ID."""
return str(uuid.uuid4())
def calculate_hash(data: dict) -> str:
"""Calculate SHA-256 hash of given dictionary."""
json_data = str(sorted(data.items())).encode()
return hashlib.sha256(json_data).hexdigest()