Technical Details

Enterprise and Military Grade Identity Verification Platform

Hash algorithms, fraud detection mechanics, MAR protocol, and development guidelines

Hash Algorithms & Duplicate Detection

Core Principle: Never hash raw images. Hash normalized, deterministic data only.
Mobile Number Hash

Method: SHA-256 of E.164 normalized string

Accuracy: ~100%

Raw:        (11) 99999-8888
Normalized: +5511999998888
Hash:       SHA-256(normalized)
Why It Works:
  • Mobile numbers are deterministic text
  • E.164 normalization ensures consistency
  • Same number = same hash always
Document Text Hash

Method: SHA-256 of normalized Textract fields

Accuracy: ~95%

Fields: nome + cpf + rg + ...
Normalize: lowercase, trim, 
           remove accents/punctuation
Hash: SHA-256(concatenated)
The 5% Gap:
  • Textract OCR errors on poor scans
  • Misread characters in CPF/name
  • Human review for borderline cases
Face Hash (pHash)

Method: Perceptual hash + Rekognition

Accuracy: ~99%

pHash: Pre-filter (~90%)
       Hamming distance < 10
Rekognition: Confirmation
       CompareFaces > 85%
Two-Stage Process:
  • pHash: Fast GSI index lookup
  • Rekognition: Accurate confirmation
  • Never run Rekognition on all profiles
Why Raw Image Hashing Fails
❌ Naive Approach (Broken)
Original photo → SHA-256 → abc123...
Same person, rescanned → xyz789...
Result: DIFFERENT HASH ❌

Tiny differences cause total hash change:
• Different lighting
• Slight rotation
• Compression artifacts
• Different camera
✅ Correct Approach (Works)
Photo → Rekognition → Face Vector
[0.234, -0.891, 0.445, ...]

Same person → Similar vector
Cosine similarity > 0.85 = MATCH ✅

Perceptual hash for fast pre-filter:
pHash distance < 10 = candidate
Then confirm with Rekognition

Fraud Detection Mechanics

Async Detection Flow (Never Blocks Verification)
Verification completes → Profile written with hashes
        ↓
   EventBridge fires VERIFICATION_COMPLETED
        ↓
      SQS Queue (buffer — absorbs load spikes)
        ↓
  Fraud Lambda (max 10 concurrent)
        ↓
  Query hash indexes for duplicates:
    • DocumentHashIndex (SHA-256)
    • MobileHashIndex (SHA-256)
    • FaceHashIndex (pHash)
        ↓
  If match found:
    → Rekognition CompareFaces (faces only)
    → profile.fraud.flagged = true
    → FraudCase created with profileId reference
    → Fraud reviewer notified
        ↓
  If Lambda fails → SQS retries (max 3)
        ↓
  If still fails → Dead Letter Queue (DLQ)
        ↓
  DLQ → Manual inspection by System Admin
Key Benefit: Verification never blocked. Fraud detection completely invisible to end user. Nothing is ever lost.
What Gets Stored
interface ProfileHashes {
  documentHash: string;
  // SHA-256 of normalized fields
  
  mobileHash: string;
  // SHA-256 of E.164 mobile
  
  faceHash: string;
  // pHash for index lookup
  
  faceVector: number[];
  // Rekognition 128-dim embedding
}

Written atomically when each factor completes. Fraud Lambda reads from profile — never re-processes images.

GSI Indexes

Fast lookup without table scan:

  • DocumentHashIndex → hashKey: documentHash
  • MobileHashIndex → hashKey: mobileHash
  • FaceHashIndex → hashKey: faceHash

Fraud Lambda queries indexes directly. No throttling. ~10-50ms per query.

MAR Protocol (More Analysis Required)

MANDATORY: All code modifications must follow MAR protocol. No exceptions.
1
Targeted Search
  • Use fileSearch with keywords
  • Read ALL relevant files
  • Map existing functionality
2
Recycling Assessment
  • Can components be reused?
  • Can functions be extended?
  • What patterns to maintain?
3
Consultation
  • STOP and explain analysis
  • Present recycling options
  • Get explicit approval
4
Documentation
  • Add MAR header to files
  • Create/update .md in mar-analysis/
  • Document all changes
MAR Header Format
/* MAR: /mar-analysis/FileName.md | Last: YYYY-MM-DD */

Every modified file must include this header at the top. Links to corresponding analysis document.

Design System

Glassmorphism + Neumorphism + MUI Enterprise

Color Palette (Monochromatic)
#000000
Pure Black
#333333
Dark Grey
#666666
Mid Grey
#FFFFFF
Pure White

Philosophy: Clean, serious, trustworthy. Perfect for security products.

Glassmorphism Tokens
Night Mode Glass:
background: rgba(255,255,255,0.05);
backdrop-filter: blur(12px);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 16px;
Day Mode Glass:
background: rgba(0,0,0,0.03);
backdrop-filter: blur(12px);
border: 1px solid rgba(0,0,0,0.06);
border-radius: 16px;
Typography Scale
Element Size Weight Usage
h1 32px 700 Page titles
h2 24px 600 Section headers
h3 20px 600 Card titles
h4 18px 500 Subsection titles
body1 16px 400 Primary content
body2 14px 400 Secondary content
caption 12px 400 Labels, timestamps

Font: Inter (primary), Geist (fallback), system-ui, sans-serif

Production Rules

🚫 PROHIBITED
  • No bypass or demo modes
  • No mock or fake data
  • No hardcoded values (ARNs, pool IDs, table names)
  • No hardcoded API keys
  • No localStorage for auth (sessionStorage only)
  • No setTimeout simulations (real API calls only)
  • No multiple Cognito pools (single pool only)
  • No manual AWS Console changes (SST only)
  • No circular imports
  • No removal: "remove" on any stage
  • No copying biometric data to fraud tables
  • No fraud detection inside verification flow
✅ REQUIRED
  • Node 22 — all Lambda runtimes
  • TypeScript strict mode — no any
  • removal: "retain" on ALL stages
  • Single Cognito pool — defined in AuthStack
  • All S3 buckets private — signed URLs only (15 min)
  • JWT with tenantId on every request
  • Tenant isolation — 403 if mismatch
  • SECURITY_RULES.ts enforcement ON
  • Audit log every security event
  • MAR protocol — analysis before modifications
  • SST resource linking — never hardcode names

Development Tools & Scripts

Testing Scripts
# Delete all external users
./scripts/nuke-external-users.sh

# Delete specific tenant's users
./scripts/nuke-external-users.sh 

# Delete entire tenant
./scripts/delete-tenant.sh 
Backup Commands
# Local project backup
pnpm backup

# AWS infrastructure backup
pnpm backup:aws

# Full disaster recovery
./scripts/disaster-recovery-backup.sh
Deployment
# Deploy to dev
pnpm sst deploy --stage dev

# Deploy with logging
./scripts/deploy-with-logging.sh

# Remove deployment
pnpm sst remove --stage dev