-
Notifications
You must be signed in to change notification settings - Fork 35
feat: add blockchain integrity fields to ResolutionProofToken #753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,6 +323,10 @@ class ResolutionProofToken(Base): | |
| valid_from = Column(DateTime, nullable=True) | ||
| valid_until = Column(DateTime, nullable=True) | ||
|
|
||
| # Blockchain integrity fields | ||
| integrity_hash = Column(String, nullable=True) | ||
| previous_integrity_hash = Column(String, nullable=True, index=True) | ||
|
Comment on lines
+326
to
+328
Comment on lines
+326
to
+328
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C2 'resolution_proof_tokens|integrity_hash|previous_integrity_hash|create_index|add_column' .Repository: RohanExploit/VishwaGuru Length of output: 45382 🏁 Script executed: find . -type d -name alembic -o -name migrations -o -name migrate | head -20Repository: RohanExploit/VishwaGuru Length of output: 49 🏁 Script executed: ls -la backend/init_db.py && wc -l backend/init_db.pyRepository: RohanExploit/VishwaGuru Length of output: 159 🏁 Script executed: sed -n '260,280p' backend/init_db.pyRepository: RohanExploit/VishwaGuru Length of output: 1262 Add migration for The model defines these columns and 🤖 Prompt for AI Agents |
||
|
|
||
| # Relationship | ||
| grievance = relationship("Grievance", back_populates="resolution_tokens") | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ | |
| EvidenceAuditLog, VerificationStatus, GrievanceStatus | ||
| ) | ||
| from backend.config import get_config, get_auth_config | ||
| from backend.cache import resolution_last_hash_cache, evidence_audit_last_hash_cache | ||
| from backend.cache import resolution_last_hash_cache, evidence_audit_last_hash_cache, token_last_hash_cache | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -189,6 +189,22 @@ def generate_proof_token( | |
|
|
||
| signature = ResolutionProofService._sign_payload(payload) | ||
|
|
||
| # Generate Integrity Hash | ||
| prev_hash = token_last_hash_cache.get("last_hash") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Reading Prompt for AI agents |
||
| if prev_hash is None: | ||
| # Cache miss: Fetch only the last hash from DB | ||
| last_record = db.query(ResolutionProofToken.integrity_hash).order_by(ResolutionProofToken.id.desc()).first() | ||
| prev_hash = last_record[0] if last_record and last_record[0] else "" | ||
| token_last_hash_cache.set(data=prev_hash, key="last_hash") | ||
|
|
||
|
Comment on lines
+192
to
+199
|
||
| hash_content = f"{token_uuid}|{grievance_id}|{authority_email}|{now.isoformat()}|{prev_hash}" | ||
| secret_key = get_auth_config().secret_key | ||
| integrity_hash = hmac.new( | ||
| secret_key.encode('utf-8'), | ||
| hash_content.encode('utf-8'), | ||
| hashlib.sha256 | ||
| ).hexdigest() | ||
|
|
||
| # Create token record | ||
| token = ResolutionProofToken( | ||
| token_id=token_uuid, | ||
|
|
@@ -203,12 +219,16 @@ def generate_proof_token( | |
| nonce=nonce, | ||
| token_signature=signature, | ||
| is_used=False, | ||
| integrity_hash=integrity_hash, | ||
| previous_integrity_hash=prev_hash, | ||
| ) | ||
|
Comment on lines
192
to
224
|
||
|
|
||
| db.add(token) | ||
| db.commit() | ||
| db.refresh(token) | ||
|
|
||
| token_last_hash_cache.set(data=integrity_hash, key="last_hash") | ||
|
|
||
| logger.info( | ||
| f"Generated RPT {token_uuid} for grievance {grievance_id} " | ||
| f"by {authority_email}, expires {valid_until.isoformat()}" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Missing database migration for the new
integrity_hashandprevious_integrity_hashcolumns (and the index onprevious_integrity_hash).init_db.pyhandles migrations forresolution_proof_tokensbut only coversnonce,valid_from, andvalid_until. On existing deployments the ORM will try to read/write columns that don't exist, causing runtime errors. Add the correspondingadd_column/create_indexstatements to the migration block ininit_db.py.Prompt for AI agents