Blockchain Services

Blockchain services connecting your institutional users and lab access control system to the blockchain

Build & Test Security Scan Release

Comprehensive Spring Boot service for the DecentraLabs ecosystem that combines authentication, authorization, and institutional treasury management with full Ethereum wallet capabilities. While it is designed so that it can be deployed as an independent container, it is recommended to use it with the Lab Gateway.

This service provides two main components:

  1. Authentication & Authorization Service: Web3-based JWT authentication with wallet challenges and SAML2 SSO integration

  2. Institutional Wallet & Treasury: Complete Ethereum wallet management and treasury operations for institutional lab providers and consumers

Together, they offer a bridge between institutional access control systems (like the Lab Gateway in the figure above) and blockchain-based smart contracts.

πŸ“š Documentation Structure

This documentation is organized into specialized sections:

πŸ—οΈ Architecture Overview

πŸ› οΈ Technology Stack

Core Framework

  • Spring Boot - Application framework with embedded Tomcat

  • Java - LTS version with modern language features

  • Maven - Build automation and dependency management

Security & Authentication

  • Spring Security - Authentication and authorization

  • JJWT - JWT generation and validation

  • Bouncy Castle - Cryptographic operations (AES-256-GCM, PBKDF2)

Blockchain Integration

  • Web3j - Ethereum client library for smart contract interactions

  • Netty - Async I/O for RPC communication

  • OkHttp - HTTP client with connection pooling

Data Processing

  • Jackson - JSON serialization/deserialization

  • Lombok - Boilerplate code reduction

  • Bucket4j - Rate limiting for API endpoints

Deployment & Operations

  • Docker - Containerized deployment with multi-stage builds

  • Tomcat Embedded - Servlet container (via Spring Boot)

  • GitHub Actions - CI/CD for build, test, security scanning, and releases

πŸš€ Key Features

Authentication & Authorization Service

  • Wallet Challenges: Web3 signature-based authentication with blockchain verification

  • SAML2 Integration: Dual-path SSO (auth-only and booking-aware flows)

  • JWT Management: JWKS discovery, dynamic key rotation, and claim-based authorization

  • Smart Contract Validation: Direct on-chain reservation and booking queries

Institutional Wallet & Treasury

  • Wallet Management: Create/import encrypted institutional wallets (AES-256-GCM + PBKDF2)

  • Multi-Network Support: Mainnet/Sepolia/Goerli with automatic RPC failover

  • Treasury Operations: Deposits, withdrawals, spending limits, and user financial stats

  • Reservation Engine: Metadata-driven auto-approval/denial based on lab availability

  • Event Monitoring: Real-time blockchain event listening and status reporting

πŸ”§ API Overview

Authentication Endpoints (/auth)

Endpoint
Method
Description

/auth/.well-known/openid-configuration

GET

OIDC discovery metadata

/auth/jwks

GET

JSON Web Keys for token validation

/auth/message

GET

Get wallet challenge message

/auth/wallet-auth

POST

Wallet authentication (no booking)

/auth/wallet-auth2

POST

Wallet authentication + authorization

/auth/saml-auth

POST

SAML2 authentication

/auth/saml-auth2

POST

SAML2 authentication + authorization

Wallet Endpoints (/wallet) πŸ”’ localhost only

Endpoint
Method
Description

/wallet/create

POST

Create new encrypted wallet

/wallet/import

POST

Import existing wallet

/wallet/{address}/balance

GET

Get ETH and LAB token balance

/wallet/{address}/transactions

GET

Get transaction history

/wallet/listen-events

GET

Event listener status

/wallet/networks

GET

List available networks

/wallet/switch-network

POST

Switch active network

/wallet/reveal

POST

Reveal institutional private key (localhost + password)

Treasury Endpoints (/treasury) πŸ”’ localhost only

Endpoint
Method
Description

/treasury/reservations

POST

Create reservation (auto-approved/denied)

/treasury/admin/execute

POST

Execute treasury admin operations

πŸ”’ Wallet and Treasury endpoints are protected by LocalhostOnlyFilter and only accept requests from 127.0.0.1 / ::1

πŸ› οΈ Quick Start

Prerequisites

  • Java 21+

  • Maven 3.6+

  • Docker (optional, for containerized deployment)

Local Development

  1. Build the project:

  2. Run locally:

  3. Access the service:

    • Health check: http://localhost:8080/health

    • OIDC discovery: http://localhost:8080/auth/.well-known/openid-configuration

    • JWKS endpoint: http://localhost:8080/auth/jwks

Docker Deployment (Development)

⚠️ IMPORTANT: Docker deployment requires RSA keys and wallet configuration that are NOT included in the repository.

  1. Generate RSA keys for JWT signing:

  2. Start services (local dev uses the bundled docker-compose.override.yml to expose port 8080):

  3. Configure institutional wallet:

    Open http://localhost:8080/wallet-dashboard in your browser

    • Create new wallet: Click "Create Wallet" β†’ Set password β†’ Save credentials

    • Import existing: Click "Import Wallet" β†’ Provide private key + password

    • The backend automatically encrypts the private key into /app/data/wallets.json, stores the address and an AES-GCM–encrypted password in /app/data/wallet-config.properties (institutional.wallet.password.encrypted), and hot-reloads the institutional wallet.

    πŸ’‘ Nothing else to configure unless you want to override the wallet via environment variables (see below).

πŸ’‘ Testing APIs: For manual testing, use test-wallet-local.sh / test-wallet-local.ps1

πŸ’‘ Reverse Proxy: When this project is consumed as a submodule behind OpenResty, reference only docker-compose.yml (omit docker-compose.override.yml) so the container stays on the internal network without publishing 8080.

πŸ“¦ CI/CD & Production Deployment

This project uses a security-first deployment approach:

GitHub Actions Workflows

Pipeline
Purpose
Output
Trigger

Build & Test

Validates code quality

Test results

Every PR/push

Security Scan

Detects vulnerabilities

Security alerts

Weekly + PR

Release

Creates versioned artifacts

WAR + checksums

Git tag v*.*.*

Docker Image

Builds container

Docker image

Manual dispatch

Secrets Management

  • βœ… .env.example tracked (public template). Copy it to .env locally (gitignored) before running anything.

  • πŸ” keys/*.pem gitignored (generate per environment)

  • πŸ” Wallet address/password captured through /wallet-dashboard β†’ private key encrypted into /app/data/wallets.json, password stored as institutional.wallet.password.encrypted inside wallet-config.properties. Persist wallet.config.encryption-key separately (env/secrets manager) or let the service auto-generate it into /app/data/.wallet-encryption-key (configurable via wallet.config.encryption-key-file). Just ensure that /app/data is a persistent volume so restarts can decrypt the password; provide env overrides only if you need full external secret management.

Production Deployment Steps

  1. Download release artifacts:

  2. Prepare environment:

  3. Deploy:

  4. Configure institutional wallet:

    Access http://your-domain/wallet-dashboard and create/import the wallet.

⚠️ CRITICAL: Never commit secrets. Use AWS Secrets Manager / Azure Key Vault for production.

βš™οΈ Configuration

Critical Environment Variables

Variable
Required
Description
Default

CONTRACT_ADDRESS

πŸ”΄ Yes

DecentraLabs contract address

-

WALLET_ADDRESS

πŸ”΄ Yes

Institutional wallet address

-

BLOCKCHAIN_NETWORK_ACTIVE

🟑 Recommended

Initial network (mainnet/sepolia)

sepolia

ETHEREUM_MAINNET_RPC_URL

🟑 Recommended

Mainnet RPC endpoints (comma-separated)

Public RPCs

ETHEREUM_SEPOLIA_RPC_URL

🟑 Recommended

Sepolia RPC endpoints (comma-separated)

Public RPCs

Optional Environment Variables

Variable
Description
Default

SPRING_PROFILES_ACTIVE

Active Spring profile

default

JAVA_OPTS

JVM options

-

ALLOWED_ORIGINS

CORS allowed origins

-

PRIVATE_KEY_PATH

Path to JWT private key

config/keys/private_key.pem

PUBLIC_KEY_PATH

Path to JWT public key

config/keys/public_key.pem

ADMIN_DASHBOARD_LOCAL_ONLY

true blocks /treasury/admin/** to localhost, false keeps it open (dev default)

true

Configuration Files

Repository structure:

Docker container structure:

πŸ’‘ Configuration priority: Environment variables > .env (local file) > application.properties. For the institutional wallet specifically: env vars / secrets manager > wallet-config.properties (auto-generated institutional.wallet.address + encrypted password) > persisted wallet metadata.

Example Docker Run

πŸ” Security

CRITICAL: This service handles sensitive cryptographic keys and blockchain transactions.

Security Checklist

  • βœ… Private keys provided via environment variables (never hardcoded)

  • βœ… RSA keys mounted with proper permissions (chmod 400)

  • βœ… RPC URLs configured with authenticated endpoints

  • βœ… Localhost-only filters enabled for sensitive operations

  • βœ… CORS origins restricted to trusted domains

Reservation Notifications (email + ICS)

  • Enable with NOTIFICATIONS_MAIL_ENABLED=true and choose driver NOTIFICATIONS_MAIL_DRIVER=smtp|graph|noop (default: noop).

  • Common settings: NOTIFICATIONS_MAIL_FROM, NOTIFICATIONS_MAIL_DEFAULT_TO (comma-separated), and NOTIFICATIONS_MAIL_TIMEZONE (IANA zone, e.g., Europe/Madrid).

  • SMTP driver: configure NOTIFICATIONS_MAIL_SMTP_HOST, PORT, USERNAME, PASSWORD, plus NOTIFICATIONS_MAIL_SMTP_STARTTLS when required.

  • Microsoft Graph driver: NOTIFICATIONS_MAIL_GRAPH_TENANT_ID, CLIENT_ID, CLIENT_SECRET, GRAPH_FROM (UPN/mailbox with Mail.Send app permission).

  • ICS invite attached when start/end are available; subject Reserva aprobada: <lab> and body includes lab, window, renter, payer, and tx hash.

  • Runtime config (localhost): GET/POST /treasury/admin/notifications to view/update settings; persisted at ./data/notifications-config.json.

πŸ“Š Monitoring & Health Checks

Health endpoint available at /health:

🀝 Contributing

  1. Fork the project

  2. Create feature branch (git checkout -b feature/AmazingFeature)

  3. Commit changes (git commit -m 'Add AmazingFeature')

  4. Push to branch (git push origin feature/AmazingFeature)

  5. Open Pull Request

πŸ“„ License

See LICENSE file for details.

Last updated