This project implements a decentralized identity system using blockchain technology (Ethereum) and Non-Fungible Tokens (NFTs).
The system allows users to create and manage their digital identities as NFTs. It includes features for verification, reputation management, multi-factor authentication, and an appeal process. The system also features an off-chain oracle for identity verification and KYC processes.
blockchain-identity-system/
├── artifacts/ # Compiled contract artifacts (ABI, bytecode)
├── backend/ # Node.js/Express backend API
│ ├── scripts/ # Backend specific utility scripts
│ ├── src/ # Backend source code (server.js, controllers, services)
│ ├── package.json
│ └── ...
├── cache/ # Hardhat cache files
├── contracts/ # Solidity smart contracts
│ ├── DigitalIdentityNFT.sol
│ ├── VerificationRegistry.sol
│ ├── ReputationSystem.sol
│ ├── MultiFactorAuth.sol
│ ├── ModeratorControl.sol
│ ├── AppealSystem.sol
│ └── ...
├── oracle/ # Off-chain oracle service
│ ├── abis/ # Contract ABIs
│ ├── scripts/ # Oracle utility scripts
│ ├── src/ # Oracle source code
│ │ ├── config/ # Configuration files
│ │ ├── controllers/# API controllers
│ │ ├── services/ # Oracle services
│ │ └── utils/ # Utility functions
│ ├── package.json
│ └── ...
├── node_modules/ # Project dependencies
├── scripts/ # Hardhat deployment and interaction scripts
│ ├── deploy.js
│ ├── interact.js
│ ├── test-api-flow.sh # Verification flow test script
│ └── ...
├── test/ # Smart contract tests
├── .gitignore
├── hardhat.config.js # Hardhat configuration
├── KODING.md # Development roadmap
├── VERIFICATION_FLOW.md # Detailed verification process documentation
├── package.json
├── README.md # This file
└── deployed-addresses.json # Addresses of deployed contracts
- DigitalIdentityNFT.sol: The core ERC721 contract representing user identities as NFTs.
- VerificationRegistry.sol: Manages verification statuses for identities.
- ReputationSystem.sol: Tracks and manages user reputation scores.
- MultiFactorAuth.sol: Implements multi-factor authentication logic.
- ModeratorControl.sol: Defines roles and permissions for moderators.
- AppealSystem.sol: Handles the process for users to appeal moderation decisions.
Managed and tested using the Hardhat development environment.
- A Node.js application using the Express framework (
backend/src/server.js). - Provides a RESTful API for interacting with the smart contracts and potentially managing off-chain data.
- Uses
ethers.jsto communicate with the Ethereum blockchain. - Includes routes for identity management, verification, reputation checks, appeals, etc.
- Off-chain service for handling identity verification, KYC processes, and blockchain events.
- Processes verification requests and submits results back to the blockchain.
- Monitors blockchain events for new identity creation, verification requests, and moderation actions.
- Integrates with external KYC providers with a pluggable architecture.
- Provides a RESTful API for verification status checks and callbacks.
- Implements direct contract interaction with a dual-verifier security model.
- Simple example application showing third-party integration with the identity system.
- Implements "Sign in with Blockchain Identity" using MetaMask.
- Demonstrates OAuth flow and session management.
- A real-time messaging application that uses the blockchain identity system for verification.
- Demonstrates how third-party applications can integrate with the identity system.
- Shows user verification status and reputation information.
- Provides examples of reputation-based access control.
- Node.js (>= 16.x)
- npm
- MetaMask extension (for browser testing)
- Install Root Dependencies:
npm i
- Start Local Hardhat Node: (Keep this terminal running)
npx hardhat node
- Deploy Contracts (in a new terminal):
(This will create
npx hardhat run scripts/deploy.js --network localhost
deployed-addresses.json) - Copy Contract ABIs to Oracle:
node oracle/scripts/copy-abis.js
- Install Backend Dependencies:
cd backend npm i - Run Backend Server: (Keep this terminal running)
(The backend server will start, typically on port 3000)
npm run dev
- Install Oracle Dependencies:
cd oracle npm i - Set Up Environment:
# Copy development environment file cp .env.development .env - Run Oracle Service: (Keep this terminal running)
(The oracle service will start, typically on port 3030)
npm run dev
- Install Demo App Dependencies:
cd backend/docs/integration-examples/demo-app npm i - Run Demo App: (Keep this terminal running)
(The demo app will start, typically on port 3050)
npm run dev
- Install Messenger App Dependencies:
cd backend/docs/integration-examples/messenger-app npm i - Run Messenger App: (Keep this terminal running)
(The messenger app will start, typically on port 3060)
npm run dev
-
Hardhat Tasks: Use
npx hardhat [task]for contract compilation, testing, etc.# Compile contracts npx hardhat compile # Run contract tests npx hardhat test # Run a specific test file npx hardhat test test/<test_file_name>.js
-
Run Scripts: Execute custom scripts against the deployed contracts.
# Example: npx hardhat run scripts/interact.js --network localhost -
Hardhat Console: Open an interactive console connected to the network.
npx hardhat console --network localhost
-
Backend API:
- Access API endpoints (defined in
backend/src/server.jsand related files) viahttp://localhost:3000. - Use tools like
curl, Postman, or a frontend application. - Authentication Script: Generate auth headers if needed by backend endpoints.
# Run from the root directory node backend/scripts/generate-auth.js
- Access API endpoints (defined in
-
Oracle API:
- Access Oracle endpoints (defined in
oracle/src/controllers) viahttp://localhost:3030. - Mock verification can be requested via
/api/verifications/mock - Second verifier approval via
/api/verifications/second-approval - Check verification status via
/api/identity/verificationLevel - View health status via
/health - Access API documentation at
/docs
- Access Oracle endpoints (defined in
-
Demo App:
- Access the demo app in your browser at
http://localhost:3050 - Connect your MetaMask wallet to test the "Sign in with Blockchain Identity" flow
- Access the demo app in your browser at
-
Messenger App:
- Access the messenger app in your browser at
http://localhost:3060 - Connect your MetaMask wallet to login with blockchain identity
- Exchange messages with other verified users
- View user verification status and reputation scores
- Access the messenger app in your browser at
The system supports a development mode that allows components to work without requiring all parts to be fully operational:
- Oracle Service: Runs in development mode with mock contracts when actual contracts are not available.
- KYC Verification: Uses a mock provider in development that simulates verification processes.
- Blockchain Connection: Falls back to default development addresses and configurations when needed.
To enable development mode, set NODE_ENV=development in your .env files.
The identity verification system utilizes a multi-step, multi-verifier approach to enhance security:
- UNVERIFIED (0) - Initial state when identity is first created
- BASIC_VERIFIED (1) - Basic verification completed, requires 1 verifier
- KYC_VERIFIED (2) - KYC verification complete, requires 2 different verifiers
- FULL_VERIFIED (3) - Enhanced verification, requires 2 different verifiers
The DigitalIdentityNFT contract includes a security feature that requires at least 2 different verifier addresses to approve before upgrading an identity to KYC_VERIFIED (level 2) or higher. This is a security measure to prevent a single compromised verifier from granting high verification levels.
-
Authentication
curl -X POST http://localhost:3000/api/auth/login \ -H "Content-Type: application/json" \ -d '{ "address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "signature": "0xbdc93f9366702679fc1034a55755d43ca316e07771a483ae18180e38beb29e03102ac67b87524df9f0c621ffaa60f0074209587bb13c0db5bdcd837ccfbbdb301c", "timestamp": "1744747628" }'
Note: The signature is generated by signing the message
Authenticate to Identity System: 1744747628with the admin wallet's private key (0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80). -
Identity Creation
# Using the access token from authentication curl -X POST http://localhost:3000/api/identity/create \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -d '{ "userAddress": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "did": "did:ethr:0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "metadata": { "name": "Test User", "email": "user@example.com" } }'
-
Request Verification via Oracle's Mock Endpoint
curl -X POST http://localhost:3030/api/verifications/mock \ -H "Content-Type: application/json" \ -d '{ "address": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "verificationType": 0, "metadata": { "name": "Test User", "document": "passport", "documentId": "AB123456" } }'
-
Oracle Processes Verification
- Oracle processes verification request
- Uses its VERIFIER_ROLE to call the verify method directly
- Approves identity to BASIC_VERIFIED (level 1) in DigitalIdentityNFT
- This is automatically handled by the oracle service
-
Second Verification in DigitalIdentityNFT
- Required for KYC_VERIFIED (level 2)
- Uses a different verifier address
- Triggered via API endpoint:
curl -X POST http://localhost:3030/api/verifications/second-approval \ -H "Content-Type: application/json" \ -d '{ "tokenId": "1", "targetLevel": 2 }'
-
Check Verification Status
curl http://localhost:3000/api/identity/verificationLevel?address=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
The repository includes a script to test the full verification flow:
# From project root
./scripts/test-api-flow.shThis script demonstrates the complete verification flow including both verifier approvals required to reach KYC_VERIFIED level.
- Smart Contracts: See Hardhat Tasks above (
npx hardhat test). - Backend: Test API endpoints using Postman or curl.
- Oracle: Test verification flows with the mock KYC provider.
- Integration: Use the demo app to test the full authentication flow.
- Verification Flow: Use the test-api-flow.sh script to test the complete verification process.
- Messenger App: Test real-time messaging between verified users.
- VERIFICATION_FLOW.md - Detailed explanation of the verification process
- KODING.md - Development roadmap and feature status
- oracle/docs/kyc-integration-guide.md - Guide for integrating KYC providers with the Oracle
- backend/docs/swagger.json - Backend API documentation in OpenAPI format
- oracle/docs/swagger.json - Oracle API documentation in OpenAPI format
- backend/docs/integration-examples/ - Integration examples for third-party platforms