Skip to content

lugondev/gnark-selective-disclosure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—οΈ BBS+ Credential System

A privacy-preserving credential system built with BBS+ signatures, enabling selective disclosure and zero-knowledge proofs.

πŸš€ Quick Start

Prerequisites

  • Go: Version 1.23.0 or later (tested with 1.23.8)
  • Node.js: Version 18 or later (tested with v22.14.0)
  • npm: Version 10 or later (tested with 10.9.2)

Backend (Issuer Service)

  1. Build and run the issuer service:
cd ./gnark-bbs-example
go build ./cmd/issuer
./issuer

The service will start on http://localhost:8080

  1. Test using the provided script:
chmod +x ./scripts/simple-university-test.sh
./scripts/simple-university-test.sh

Frontend (Holder App)

  1. Install dependencies:
cd web
npm install
  1. Start the development server:
npm run dev

The app will be available at http://localhost:3000

πŸ“‹ API Endpoints

Issuer Endpoints

  • POST /api/v1/issuers - Create a new issuer
  • GET /api/v1/issuers/:did - Get issuer information
  • GET /api/v1/credentials - List all credentials
  • POST /api/v1/credentials - Issue a new credential
  • GET /api/v1/credentials/:id - Get credential details
  • POST /api/v1/credentials/:id/revoke - Revoke a credential
  • GET /api/v1/schemas - List available schemas
  • POST /api/v1/schemas - Create a new schema
  • GET /api/v1/schemas/:id - Get schema details
  • GET /api/v1/schemas/:id/selective-fields - Get schema selective disclosure fields
  • GET /api/v1/public-keys/:issuer-did - Get issuer public key

Presentation Endpoints

  • POST /api/v1/presentations - Create a selective disclosure presentation
  • POST /api/v1/presentations/verify - Verify a presentation
  • POST /api/v1/presentations/bbs - Create BBS+ presentation

Proof Endpoints

  • GET /api/v1/proofs/data/:credentialId - Get proof creation data
  • POST /api/v1/proofs/create - Create proof
  • POST /api/v1/proofs/verify-client - Verify client proof
  • POST /api/v1/proofs/verify-bbs - Verify BBS+ proof

πŸ§ͺ Testing the System

1. Create an Issuer

curl -X POST http://localhost:8080/api/v1/issuers \
  -H "Content-Type: application/json" \
  -d '{
    "did": "did:example:issuer123",
    "name": "Demo University",
    "description": "A demo university issuing BBS+ credentials",
    "website": "https://demo-university.edu"
  }'

2. Issue a Credential

curl -X POST http://localhost:8080/api/v1/credentials \
  -H "Content-Type: application/json" \
  -d '{
    "issuer_did": "did:example:issuer123",
    "subject_did": "did:example:student456",
    "schema_id": "identity-card-v1",
    "attributes": {
      "name": "Alice Johnson",
      "age": 25,
      "university": "Demo University",
      "degree": "Computer Science",
      "graduation_year": 2023
    }
  }'

3. Create a Selective Disclosure Presentation

curl -X POST http://localhost:8080/api/v1/presentations \
  -H "Content-Type: application/json" \
  -d '{
    "credential_id": "cred_12345",
    "revealed_attributes": ["name", "degree"],
    "verifier_did": "did:example:verifier789"
  }'

πŸ—οΈ Architecture

graph TB
    subgraph "Frontend Layer"
        A[Next.js App Router 15.4.6]
        B[React 19.1.0]
        C[TypeScript 5.x]
        D[Tailwind CSS 4.x]
    end
    
    subgraph "Backend Layer"
        E[Gin HTTP Server]
        F[Go 1.23.8]
        G[REST API]
    end
    
    subgraph "Cryptographic Layer"
        H[BBS+ Signatures]
        I[gnark-crypto v0.18.0]
        J[BLS12-381 Curve]
        K[Selective Disclosure]
    end
    
    subgraph "Storage Layer"
        L[In-Memory Storage]
        M[Credential Repository]
        N[Schema Repository]
    end
    
    A --> E
    B --> G
    E --> H
    H --> I
    I --> J
    G --> L
    L --> M
    L --> N
Loading

πŸ” Core Features

βœ… Implemented

  • BBS+ Key Generation: Cryptographically secure key pairs using BLS12-381
  • Credential Issuance: Sign credentials with multiple attributes
  • Selective Disclosure: Reveal only chosen attributes in presentations
  • Zero-Knowledge Proofs: Prove possession without revealing hidden attributes
  • Unlinkability: Randomized signatures prevent correlation
  • REST API: Complete HTTP interface for issuers and holders
  • Next.js Frontend: Modern React-based UI with App Router
  • Schema Management: Dynamic credential schema creation and validation
  • Client-side Proofs: Browser-based proof generation and verification

🚧 In Progress

  • Enhanced UI/UX: Improved credential management interface
  • QR Code Integration: Easy credential exchange via QR codes
  • Mobile Responsiveness: Optimized mobile experience

πŸ“‹ TODO

βœ… Completed

  • DID Resolution: βœ… W3C DID standard support implemented
    • DID Document implementation with W3C compliance
    • Support for key, web, and bbs DID methods
    • DID resolver and universal resolver functionality
  • Verifier Interface: βœ… Complete verification workflow implemented
    • Verifier registration and management
    • Policy creation and enforcement
    • Verification request handling and processing

🚧 In Progress / Pending

  • Database Integration: πŸ”΄ Persistent storage with PostgreSQL
    • Currently using in-memory storage only
    • Database configuration prepared in .env.example
    • Need to implement repository layer with PostgreSQL
  • Unit Testing: πŸ”΄ Comprehensive test coverage
    • Only integration test script available
    • Need unit tests for all modules and handlers
    • Test coverage reporting
  • Production Deployment: πŸ”΄ Docker containers and CI/CD
    • Missing Dockerfile and docker-compose.yml
    • No CI/CD pipeline (GitHub Actions)
    • Production environment configuration
  • Performance Optimization: πŸ”΄ Caching and batch processing
    • No caching layer (Redis/Memcached)
    • No batch processing for bulk operations
    • Need performance monitoring and optimization
  • Security Audit: πŸ”΄ Third-party security review
    • Code security analysis needed
    • Vulnerability assessment
    • Penetration testing

🎯 Priority Recommendations

  1. Database Integration (High Priority)
  2. Unit Testing (High Priority)
  3. Docker & CI/CD (Medium Priority)
  4. Performance Optimization (Medium Priority)
  5. Security Audit (Low Priority)

πŸ”§ Development

Project Structure

gnark-bbs-example/
β”œβ”€β”€ cmd/                     # Application entry points
β”‚   β”œβ”€β”€ issuer/             # Issuer service main
β”‚   └── holder-api/         # Holder backend API (future)
β”œβ”€β”€ internal/               # Private application code
β”‚   β”œβ”€β”€ domain/            # Business entities
β”‚   β”‚   β”œβ”€β”€ credential/    # Credential domain logic
β”‚   β”‚   β”œβ”€β”€ did/          # DID-related entities
β”‚   β”‚   └── signature/    # Signature domain
β”‚   β”œβ”€β”€ application/       # Use cases
β”‚   β”‚   β”œβ”€β”€ credential/   # Credential services
β”‚   β”‚   β”œβ”€β”€ holder/       # Holder services
β”‚   β”‚   └── issuer/       # Issuer services
β”‚   β”œβ”€β”€ infrastructure/    # External adapters
β”‚   β”‚   β”œβ”€β”€ crypto/       # Cryptographic implementations
β”‚   β”‚   β”œβ”€β”€ http/         # HTTP server setup
β”‚   β”‚   └── storage/      # Storage implementations
β”‚   └── interfaces/        # API handlers
β”‚       β”œβ”€β”€ rest/         # REST API handlers
β”‚       └── websocket/    # WebSocket handlers (future)
β”œβ”€β”€ pkg/                   # Shared libraries
β”‚   β”œβ”€β”€ bbs/              # BBS+ implementation
β”‚   β”œβ”€β”€ did/              # DID utilities
β”‚   └── zkproof/          # Zero-knowledge proofs
β”œβ”€β”€ web/                  # Next.js frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/          # App Router pages
β”‚   β”‚   β”œβ”€β”€ components/   # React components
β”‚   β”‚   β”œβ”€β”€ hooks/        # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ lib/          # Utility libraries
β”‚   β”‚   β”œβ”€β”€ services/     # API services
β”‚   β”‚   β”œβ”€β”€ stores/       # State management (Zustand)
β”‚   β”‚   └── types/        # TypeScript type definitions
β”‚   └── public/           # Static assets
β”œβ”€β”€ scripts/              # Development and test scripts
└── docs/                 # Documentation

Key Components

  1. BBS+ Core (pkg/bbs/)

    • types.go - Core data structures and interfaces
    • keygen.go - Key generation and management
    • signer.go - Signing and verification logic
    • prover.go - Selective disclosure proof generation
  2. HTTP Server (internal/infrastructure/http/)

    • server.go - Gin HTTP server setup with CORS
    • Middleware stack for logging and security
  3. REST Handlers (internal/interfaces/rest/handlers/)

    • issuer_handler.go - Issuer operations (create, list, manage)
    • holder_handler.go - Holder operations (presentations)
    • proof_handler.go - Client-side proof operations
  4. Frontend (web/src/)

    • App Router: Next.js 15.4.6 with React 19.1.0
    • Components: Modular UI components with Tailwind CSS
    • Services: API client services for backend communication
    • Stores: Zustand state management for credentials and presentations
    • Hooks: Custom React hooks for selective disclosure

Technology Stack

Backend:

  • Language: Go 1.23.8
  • Framework: Gin HTTP framework
  • Cryptography: gnark-crypto v0.18.0 (BLS12-381)
  • Storage: In-memory (temporary)

Frontend:

  • Framework: Next.js 15.4.6 with App Router
  • Language: TypeScript 5.x
  • UI Library: React 19.1.0
  • Styling: Tailwind CSS 4.x
  • State Management: Zustand 5.0.7
  • HTTP Client: Axios 1.11.0
  • Cryptography: @noble/curves, crypto-js

πŸ›‘οΈ Security Features

  • Cryptographic Unlinkability: Each presentation uses fresh randomness
  • Zero-Knowledge Proofs: Hidden attributes remain private
  • Signature Randomization: Prevents tracking across verifiers
  • Selective Disclosure: Minimal information disclosure principle
  • BLS12-381 Security: Industry-standard elliptic curve

πŸ“Š Performance

  • Credential Issuance: < 500ms typical response time
  • Proof Generation: < 200ms for 5 attributes
  • Verification: < 100ms typical response time
  • Frontend Loading: < 2s initial page load
  • API Response: < 50ms for cached data

πŸ§ͺ Testing

Automated Testing Script

The project includes a comprehensive test script that demonstrates the full workflow:

# Make the script executable
chmod +x ./scripts/simple-university-test.sh

# Run the complete test suite
./scripts/simple-university-test.sh

This script will:

  1. Create a university credential schema
  2. Generate an issuer with BBS+ keys
  3. Issue a sample credential
  4. Create selective disclosure presentations
  5. Verify the presentations

Manual API Testing

You can also test individual endpoints manually. See the API examples in the original documentation above.

🀝 Contributing

  1. Fork the repository and create a feature branch
  2. Follow the coding standards outlined in the general instructions
  3. Keep files under 500 lines for maintainability
  4. Add tests for new features and bug fixes
  5. Update documentation for API changes
  6. Ensure security best practices are followed
  7. Run the test script before submitting PRs

Development Workflow

# Clone your fork
git clone https://github.com/your-username/gnark-bbs-example.git
cd gnark-bbs-example

# Install dependencies
go mod download
cd web && npm install

# Run tests
./scripts/simple-university-test.sh

# Start development servers
go run cmd/issuer/main.go &  # Backend on :8080
cd web && npm run dev        # Frontend on :3000

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License Summary

  • βœ… Commercial use
  • βœ… Modification
  • βœ… Distribution
  • βœ… Private use
  • ❌ No liability
  • ❌ No warranty

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages