30 lines
752 B
Python
30 lines
752 B
Python
from __future__ import annotations
|
|
import hmac
|
|
import hashlib
|
|
import time
|
|
from typing import List, Dict, Any
|
|
|
|
class GovernanceLedger:
|
|
def __init__(self, key: bytes = b"secret"):
|
|
self.key = key
|
|
self.entries: List[Dict[str, Any]] = []
|
|
|
|
def sign(self, payload: Dict[str, Any]) -> str:
|
|
m = hashlib.sha256()
|
|
m.update(str(payload).encode())
|
|
m.update(self.key)
|
|
return m.hexdigest()
|
|
|
|
def append_entry(self, action: str, details: Dict[str, Any]) -> Dict[str, Any]:
|
|
entry = {
|
|
"timestamp": time.time(),
|
|
"action": action,
|
|
"details": details,
|
|
}
|
|
entry["signature"] = self.sign(entry)
|
|
self.entries.append(entry)
|
|
return entry
|
|
|
|
def get_entries(self) -> List[Dict[str, Any]]:
|
|
return self.entries
|