Spaces:
Sleeping
Sleeping
Commit Β·
b773f5c
1
Parent(s): 646fc8e
Integrate real BSV blockchain attestation
Browse files- Add SimpleBSV API integration for on-chain attestation
- Results are published to BSV mainnet with txid
- Include WhatsOnChain verification link
- No trade secrets exposed - only result summaries
- Fallback to offline mode if API unavailable
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Files changed (2)
- app.py+88-8
- requirements.txt+1
14 unmodified lines151617181920212223327 unmodified lines35135235335435535635735835936036136213 unmodified lines37637737837938038138238338438538638714 unmodified linesimport hashlibimport randomimport timefrom datetime import datetimefrom typing import Optional, Dict, List, Tuple# =============================================================================# Demo Configuration - Pre-computed results (no trade secrets exposed)# =============================================================================327 unmodified linesdef generate_bsv_attestation(variant_id: str, classification: str, confidence: float) -> str:"""Generate BSV blockchain attestation."""timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S UTC")# Create deterministic hashdata_str = f"{variant_id}|{classification}|{confidence}|{timestamp}"query_hash = hashlib.sha256(data_str.encode()).hexdigest()[:16]return f"""```13 unmodified linesβ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Status: β DEMO ATTESTATION ββ Network: BSV Testnet ββ ββ This certificate demonstrates TopoGrammar's blockchain ββ verification capability. Production attestations are ββ recorded on BSV mainnet. ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ```14 unmodified lines15161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869327 unmodified lines39739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044113 unmodified lines45545645745845946046146246346446546646714 unmodified linesimport hashlibimport randomimport timeimport httpximport jsonimport osfrom datetime import datetimefrom typing import Optional, Dict, List, Tuple# =============================================================================# BSV Blockchain Configuration# =============================================================================BSV_API_URL = "https://simplebsv.codenlighten.org"BSV_API_KEY = os.getenv("BSV_API_KEY", "REDACTED_BSV_KEY")def publish_to_bsv(data: Dict) -> Optional[str]:"""Publish attestation data to BSV blockchain via SimpleBSV API.Args:data: Dictionary containing attestation data (no trade secrets)Returns:Transaction ID if successful, None otherwise"""try:headers = {"Content-Type": "application/json","x-api-key": BSV_API_KEY}# Use ?wait=true for synchronous response with txidresponse = httpx.post(f"{BSV_API_URL}/publish/json?wait=true",headers=headers,json={"data": data},timeout=30.0)if response.status_code == 200:result = response.json()return result.get("txid")else:print(f"BSV API error: {response.status_code} - {response.text}")return Noneexcept Exception as e:print(f"BSV publish error: {e}")return None# =============================================================================# Demo Configuration - Pre-computed results (no trade secrets exposed)# =============================================================================327 unmodified linesdef generate_bsv_attestation(variant_id: str, classification: str, confidence: float) -> str:"""Generate and publish BSV blockchain attestation."""timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S UTC")# Create attestation data (no trade secrets - only results summary)attestation_data = {"platform": "TopoGrammar","version": "v2.1.0","timestamp": timestamp,"analysis_type": "VUS_Resolution","variant_id": variant_id,"classification": classification,"confidence": round(confidence, 2),"attestation_type": "demo"}# Create hash of the attestation datadata_str = json.dumps(attestation_data, sort_keys=True)query_hash = hashlib.sha256(data_str.encode()).hexdigest()[:16]full_hash = hashlib.sha256(data_str.encode()).hexdigest()# Publish to BSV blockchaintxid = publish_to_bsv(attestation_data)if txid:# Real blockchain attestationwhatsonchain_url = f"https://whatsonchain.com/tx/{txid}"status_line = f"Status: β RECORDED ON BSV MAINNET"txid_display = txid[:20] + "..." if len(txid) > 20 else txidverify_section = f"""β Transaction ID: {txid_display}β ββ π Verify on WhatsOnChain: ββ {whatsonchain_url[:54]}"""else:# Fallback if API failsstatus_line = "Status: β OFFLINE MODE (BSV API unavailable)"verify_section = f"""β Data Hash: {full_hash[:32]}...β ββ βΉ Blockchain recording temporarily unavailable. ββ Result hash preserved for later attestation."""return f"""```13 unmodified linesβ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ {status_line}β Network: BSV Mainnet ββ β{verify_section}β ββ This attestation is immutably recorded on BSV blockchain. ββ No proprietary algorithms or trade secrets are published. ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ```
1gradio>=4.0.012gradio>=4.0.0httpx>=0.25.0
app.py+88-8
requirements.txt+1