๐Ÿ“˜ SDGE eManual

Complete reference for the Sovereign Document Governance Engine โ€” ingestion, verification, workflows, and API.

๐Ÿ›๏ธ Overview

SDGE (Sovereign Document Governance Engine) is an append-only, hash-chained document ledger designed for Indian Government document governance. It provides tamper-evident storage, ZK receipts, fraud scoring, and a GraphQL-first API for 15 governance domains.

Key properties:

  • Append-only โ€” documents are never modified or deleted once committed
  • SHA-256 chained โ€” each block links to the previous block's hash (like a blockchain)
  • Domain-scoped โ€” all 15 departments have isolated namespaces with domain-specific metadata
  • Actor-authenticated โ€” every ingest is attributed to a verified government actor
  • Fraud-scored โ€” every document receives a fraud risk score (0โ€“100) on ingest
Live system: SDGE runs on port 4103 (Bun + Fastify + Mercurius + PostgreSQL 16). The current ledger has โ€” documents across 19 domains โ€” 15 government + 4 cross-border trade (eBL, LC, Charter Party, Freight).

๐Ÿš€ Quick Start

  1. Go to /login and select your department actor (all demo actors use PIN 1234)
  2. After login, visit /wizard โ€” the 5-step guided document ingest tool
  3. Select your domain, fill document metadata, paste content, review, and confirm
  4. Your document is hashed, assigned a ledger sequence number, and a ZK receipt is issued
  5. Verify any document at any time via the /dashboard โ†’ Document Lookup tab
Note: In the current demo, all actors share PIN 1234. Production deployment uses UIDAI-linked biometric or eSign-based authentication.

๐Ÿ’ก Core Concepts

Document

A sovereign document is any government-issued record: certificate, order, filing, report, or sensor reading. Each document has a unique docId (UUID), a SHA-256 contentHash, a domain, an actorId, and an ingestTime.

Ledger Entry

When a document is ingested, a ledger entry is created with a monotonically increasing ledgerSeq. Each entry stores the hash of its content plus the prevHash of the prior entry, forming an unbreakable chain.

Fraud Score

Every document is scored 0โ€“100 at ingest time by the SDGE fraud engine. Score interpretation:

  • 0โ€“29 โ€” Low risk (green) โ€” routine document
  • 30โ€“59 โ€” Medium risk (yellow) โ€” review recommended
  • 60โ€“79 โ€” High risk (orange) โ€” manual verification required
  • 80โ€“100 โ€” Critical (red) โ€” flagged for fraud investigation

๐Ÿ‘ค Actor Roles

Every SDGE operation is performed by an actor โ€” an authenticated government officer. Actors are scoped to their department's domain.

Actor IDNameDomain
actor-land-reg-01Land RegistryLAND
actor-hospital-01Civil HospitalHEALTH
actor-agri-dept-01Agriculture DeptAGRICULTURE
actor-gem-01GeM ProcurementPROCUREMENT
actor-cbse-01CBSEEDUCATION
actor-gst-01GST / SupplySUPPLY_CHAIN
actor-fcs-01FCS / PDSSUPPLY_CHAIN (PDS)
actor-discom-01DISCOM / IoTIOT
actor-gst-dept-01Tax Dept (GST)TAXATION
actor-uidai-01UIDAI / IdentityIDENTITY
actor-court-01District CourtJUDICIARY
actor-mcd-01Municipal CorpURBAN_LOCAL
actor-sbi-01Bank / FinanceFINANCE
actor-epfo-01EPFO / LabourLABOUR
actor-rto-dl-01RTO / TransportTRANSPORT

๐Ÿ” Authentication

SDGE uses actor-based PIN authentication in this demo. The session is stored in browser localStorage as sdge_actor โ€” a JSON object with id, name, role, domain, and icon.

// Example session object in localStorage { "id": "actor-land-reg-01", "name": "Land Registry", "role": "District Registrar", "domain": "LAND", "icon": "๐Ÿš๏ธ" }

The ingest console on the Dashboard checks for this session. If absent, the ingest form is hidden. The wizard also pre-fills the Actor ID from this session.

Security note: This is a demo system. Production SDGE uses UIDAI-authenticated JWT tokens with 4-hour expiry, signed with the department's DSC (Digital Signature Certificate).

๐Ÿ—๏ธ Sessions

Sessions are browser-local and persist until explicitly cleared. To log out, the session is removed from localStorage. If you clear your browser storage, you will be logged out and redirected to /login.

๐Ÿ—‚๏ธ All 15 Governance Domains

SDGE covers all major Indian government document domains. Each domain has its own namespace, auto-classification patterns, and domain-specific metadata fields.

๐Ÿš๏ธ
LAND
Khasra, mutation certs, e-Nakal, jamabandi
๐Ÿฅ
HEALTH
OPD cards, ABHA records, discharge summaries
๐ŸŒพ
AGRICULTURE
MSP docs, crop insurance, PM-KISAN
๐Ÿ“ฆ
PROCUREMENT
GeM POs, tenders, vendor contracts
๐Ÿ“š
EDUCATION
CBSE marksheets, certificates, admit cards
๐Ÿšข
SUPPLY_CHAIN
GST e-way bills, invoices, logistics
๐Ÿ›’
PDS
Ration cards, FCS registers, PDS allocations
๐Ÿ“ก
IOT
Smart meter data, SCADA logs, sensor reports
๐Ÿงพ
TAXATION
GSTR filings, income tax, PAN records
๐Ÿชช
IDENTITY
Aadhaar docs, voter ID, DigiLocker
โš–๏ธ
JUDICIARY
FIRs, court orders, judgements, summons
๐Ÿ™๏ธ
URBAN_LOCAL
Property tax, building permits, birth/death
๐Ÿฆ
FINANCE
Loan sanction letters, bank statements, KCC
๐Ÿ‘ท
LABOUR
PF passbooks, ESIC, labour contracts
๐Ÿš—
TRANSPORT
Driving licences, vehicle registration, fitness
๐Ÿ“œ
EBL
Electronic Bills of Lading โ€” Mari8X ยท DCSA v3.0 ยท JNPA/Mundra
๐Ÿฆ
LC_TRADE_FINANCE
SWIFT MT700 Letters of Credit ยท DeFi escrow auto-settlement
โš“
CHARTER_PARTY
BIMCO voyage/time/bareboat charters ยท demurrage ยท COA
๐Ÿšš
FREIGHT_SETTLEMENT
FreightBox lorry receipts ยท eWayBill ยท GPS milestone payments

๐Ÿค– Auto-Classification

When you select "Auto-detect domain" in the Wizard or via the GraphQL mutation, SDGE scans the document content for domain-specific signals:

DomainSignals (regex patterns)
LANDkhasra, khatauni, mutation, registry, e-nakal
HEALTHopd, prescription, patient, discharge, abha
AGRICULTUREmsp, kisan, fasal, pm-kisan, crop insurance
PROCUREMENTgem, tender, purchase order, bid, procurement
EDUCATIONcbse, marksheet, result, admit card, roll number
TAXATIONgstin, gstr, tax invoice, pan, income tax
IDENTITYaadhaar, uid, voter id, digilocker
JUDICIARYfir, court order, judgement, summons, case no
TRANSPORTdriving licence, dl no, rc book, vehicle registration

If no patterns match, the document is classified as UNKNOWN. You can always override the auto-detected domain by selecting one manually.

๐Ÿ“ฅ Ingest Guide

There are three ways to ingest a document:

1. Dashboard Ingest Form

On /dashboard, switch to the Ingest Document tab. You must be logged in. Fill the form and submit โ€” the ledger entry is shown inline.

2. Wizard (Recommended)

The /wizard provides a guided 5-step flow with per-domain metadata fields, auto-detect, a review step, and a formatted ZK receipt on completion. Best for manual document entry.

3. GraphQL Mutation

For programmatic ingest (integrations, batch scripts, workflow automations):

mutation { sdgeIngestDocument(input: { filename: "gstr3b-jul-2025.pdf", actorId: "actor-gst-dept-01", domain: TAXATION, content: "GSTIN: 07AAACR0932J1ZT | Period: Jul 2025 | Tax: โ‚น2,47,500" }) { docId ledgerSeq fraudScore fraudLevel zkReceiptId contentHash ingestTime } }

๐Ÿง™ Using the Wizard

The wizard at /wizard walks you through 5 steps:

  1. Select Domain โ€” Choose from 15 domain tiles. Each has an icon, name, and document count badge.
  2. Document Details โ€” Enter filename, verify your actor ID (pre-filled from session), and fill domain-specific fields (e.g., GSTIN for TAXATION, Case No. for JUDICIARY).
  3. Paste Content โ€” Enter the document text. Optionally enable Auto-detect domain to re-classify based on content.
  4. Review โ€” A summary panel shows all fields before commit. Confirm or go back to edit.
  5. Receipt โ€” After successful ingest, a formatted ZK receipt is displayed with docId, ledgerSeq, contentHash, fraud score, and a sharable receipt ID.

๐Ÿ“ฆ Bulk Ingest

For batch ingestion, use the /workflows automation page. Each workflow can ingest multiple documents in a single run. Alternatively, use the GraphQL mutation in a loop from your backend service.

// Node.js / Bun batch example const docs = ["doc1 content", "doc2 content"]; for (const content of docs) { await fetch('https://sdge.ankrlabs.org/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query: `mutation { sdgeIngestDocument(input:{ filename:"batch.dat", actorId:"actor-land-reg-01", domain: LAND, content:"${content}" }) { docId ledgerSeq } }` }) }); }

๐Ÿ”— Sovereign Ledger

The SDGE ledger is an in-memory, append-only chain. Each entry has:

FieldTypeDescription
ledgerSeqnumberMonotonically increasing sequence number
docIdUUIDUnique document identifier
contentHashSHA-256 hexHash of filename+actorId+domain+content
prevHashSHA-256 hexHash of the previous ledger entry
ingestTimeISO timestampUTC timestamp of ingest
fraudScore0โ€“100Fraud risk score at ingest time
zkReceiptIdUUIDZero-knowledge proof receipt identifier
Persistence: SDGE uses PostgreSQL 16 (ankr_sdge, port 5437) as its ledger store. The append-only guarantee is enforced at the DB level โ€” CREATE RULE blocks all UPDATE and DELETE on sdge_ledger. 6 tables: sdge_ledger, sdge_documents, sdge_fraud_signals, sdge_actors, sdge_ebl_registry, sdge_freight_events.

โœ… Chain Verification

Use the Verify Chain tab on the Dashboard to check the integrity of any document or the entire chain:

query { sdgeVerifyChain { chainLength isValid lastHash brokenAt } } // Or verify a single document by docId: query { sdgeLookupDoc(docId: "<uuid>") { docId contentHash ledgerSeq fraudScore fraudLevel ingestTime } }

๐Ÿ” ZK Receipts

Every successful ingest issues a Zero-Knowledge Receipt โ€” a UUID that can be shared publicly to prove a document was committed to the chain at a specific time, without revealing the document content itself.

The ZK receipt ID is derived from the contentHash and ledgerSeq. It can be verified by anyone with access to the SDGE API:

query { sdgeLookupReceipt(receiptId: "<zkReceiptId>") { valid docId domain ingestTime ledgerSeq } }

๐Ÿ“ GraphQL Schema

All SDGE operations are exposed via a single GraphQL endpoint: POST https://sdge.ankrlabs.org/graphql

type SdgeDocument { docId: String! filename: String! actorId: String! domain: DocumentDomain! contentHash: String! ledgerSeq: Int! fraudScore: Int! fraudLevel: String! zkReceiptId: String! ingestTime: String! } enum DocumentDomain { LAND HEALTH AGRICULTURE PROCUREMENT EDUCATION SUPPLY_CHAIN IOT PDS TAXATION IDENTITY EBL LC_TRADE_FINANCE CHARTER_PARTY FREIGHT_SETTLEMENT JUDICIARY URBAN_LOCAL FINANCE LABOUR TRANSPORT UNKNOWN }

๐Ÿ”Ž Queries

QueryAuthDescription
sdgeStatsPublictotalDocs, ledgerSeq, chainHealth, onlineSince
sdgeLookupDoc(docId)PublicFetch document by docId
sdgeListDocs(domain?, limit, offset)ActorList documents, optionally filtered by domain
sdgeVerifyChainPublicVerify full chain integrity
sdgeDomainStatsPublicPer-domain document counts
sdgeLookupReceipt(receiptId)PublicVerify a ZK receipt

โœ๏ธ Mutations

MutationAuthDescription
sdgeIngestDocument(input)ActorIngest a document โ€” returns full ledger entry with ZK receipt

Input fields for sdgeIngestDocument

FieldRequiredDescription
filenameโœ“Original filename of the document
actorIdโœ“Authenticated actor ID (e.g. actor-land-reg-01)
domainโœ“DocumentDomain enum value
contentโœ“Full text content of the document to be hashed and stored

โš™๏ธ Automation Guide

The /workflows page provides 11 pre-built automation workflows across 4 categories:

  • Ingest Automations โ€” Bulk, scheduled pulls from source APIs (LRC, GSTN, NHA, GeM)
  • Verification & Audit โ€” Chain integrity scan, fraud pipeline, identity dedup, IoT sweep
  • Reporting & Export โ€” Daily digest, court approval flow, municipal consolidation

Each workflow can be triggered on-demand, scheduled (hourly/daily/weekly), or chained. Schedule state is stored in the session and persists in localStorage.

Production: In a production deployment, workflows are managed by the @ankr/workflow-engine package โ€” a cron-backed orchestrator with webhook triggers, retry logic, and audit log persistence.

๐Ÿ•ต๏ธ Fraud Detection

The SDGE fraud scoring engine runs on every ingest. It evaluates several signals:

  • Content entropy โ€” random or garbled content scores higher
  • Actor domain mismatch โ€” a HEALTH actor ingesting LAND documents is flagged
  • Duplicate content hash โ€” exact duplicates score 100 (blocked)
  • Known fraud patterns โ€” regex matches for forged Aadhaar numbers, fake GSTINs
  • Temporal anomalies โ€” document dated in the future or >10 years old

To run a full fraud investigation across all high-risk documents, use the Fraud Investigation Pipeline workflow.