import streamlit as st import requests from PIL import Image import numpy as np from pryvx import SMPC import uuid import os smpc1 = SMPC() total_servers = 3 smpc_server1 = os.getenv("smpc_server1") smpc_server2 = os.getenv("smpc_server2") smpc_server3 = os.getenv("smpc_server3") def submit_identity_ui(BASE_URL, identity, index_id): try: SUBMIT_URL = f"{BASE_URL}/submit_identity" payload = {"identity": identity, "index": index_id} response = requests.post(SUBMIT_URL, json=payload) return response.json().get("message", "Submission failed.") except Exception as e: return f"Error: {e}" def check_identity_ui(BASE_URL, identity): try: CHECK_URL = f"{BASE_URL}/check_identity/{identity}" response = requests.get(CHECK_URL) subtracted = response.json().get("subtracted_results", []) return subtracted except Exception as e: return f"Error: {e}" st.set_page_config(page_title="SMPC Identity Match Demo", layout="centered") st.title("🔐 Secure Multi-Party Computation (SMPC) Identity Match Demo") image = Image.open("src/smpc-architecture.png") st.image(image, caption="SMPC Architecture Diagram", use_container_width=True) st.markdown(""" ### 🛡️ Benefits of SMPC - 🔒 **Privacy Preserving**: Your data stays encrypted during processing. - 🤝 **Collaborative**: Enables institutions to securely collaborate without sharing raw data. - ✅ **Accurate**: Maintains correctness even when data is split across parties. - 🧩 **Flexible**: Can be applied to fraud detection, identity matching, and more. - 🌍 **Scalable**: Easily extends to multiple organizations or datasets. """) tab1, tab2 = st.tabs(["Submit Identity", "Check Identity"]) with tab1: st.subheader("Submit Suspected Identity") identity_input = st.text_input("Enter Identity", key="submit") if st.button("Submit"): shares = smpc1.get_secret_shares(smpc1.hash_to_bigint(identity_input), total_servers) index_id = str(uuid.uuid4()) st.info(f"Spliting [{identity_input}] into shares => {shares}") for i, (_share, _server) in enumerate(zip(shares, [smpc_server1, smpc_server2, smpc_server3])): st.write(f"Sending share {i+1} to server {i+1}") result = submit_identity_ui(_server, _share, index_id) st.success(result) with tab2: st.subheader("Check Identity") check_input = st.text_input("Enter Identity", key="check") if st.button("Check"): shares = smpc1.get_secret_shares(smpc1.hash_to_bigint(check_input), total_servers) st.info(f"Spliting [{check_input}] into shares => {shares}") x = np.array(check_identity_ui(smpc_server1, shares[0])) y = np.array(check_identity_ui(smpc_server2, shares[1])) z = np.array(check_identity_ui(smpc_server3, shares[2])) result = x+y+z count = 0 for x in result: if smpc1.reconstruct(x) == 0: count += 1 if count: st.info(f"✅ {count} Match Found") else: st.info("❌ No Match")