Blockchain Services
Blockchain services connecting your institutional users and lab access control system to the blockchain
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:
Authentication & Authorization Service: Web3-based JWT authentication with wallet challenges and SAML2 SSO integration
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:
Authentication Service - Wallet challenges, SAML2 SSO, JWT generation and validation
Institutional Wallet & Treasury - Ethereum wallet management, treasury operations, and smart contract interactions
ποΈ 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)
/auth)/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
/wallet) π localhost only/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
/treasury) π localhost only/treasury/reservations
POST
Create reservation (auto-approved/denied)
/treasury/admin/execute
POST
Execute treasury admin operations
π Wallet and Treasury endpoints are protected by
LocalhostOnlyFilterand only accept requests from127.0.0.1/::1
π οΈ Quick Start
Prerequisites
Java 21+
Maven 3.6+
Docker (optional, for containerized deployment)
Local Development
Build the project:
Run locally:
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.
Generate RSA keys for JWT signing:
Start services (local dev uses the bundled
docker-compose.override.ymlto expose port 8080):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(omitdocker-compose.override.yml) so the container stays on the internal network without publishing8080.
π¦ CI/CD & Production Deployment
This project uses a security-first deployment approach:
GitHub Actions Workflows
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.exampletracked (public template). Copy it to.envlocally (gitignored) before running anything.π
keys/*.pemgitignored (generate per environment)π Wallet address/password captured through
/wallet-dashboardβ private key encrypted into/app/data/wallets.json, password stored asinstitutional.wallet.password.encryptedinsidewallet-config.properties. Persistwallet.config.encryption-keyseparately (env/secrets manager) or let the service auto-generate it into/app/data/.wallet-encryption-key(configurable viawallet.config.encryption-key-file). Just ensure that/app/datais a persistent volume so restarts can decrypt the password; provide env overrides only if you need full external secret management.
Production Deployment Steps
Download release artifacts:
Prepare environment:
Deploy:
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
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
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-generatedinstitutional.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=trueand choose driverNOTIFICATIONS_MAIL_DRIVER=smtp|graph|noop(default: noop).Common settings:
NOTIFICATIONS_MAIL_FROM,NOTIFICATIONS_MAIL_DEFAULT_TO(comma-separated), andNOTIFICATIONS_MAIL_TIMEZONE(IANA zone, e.g.,Europe/Madrid).SMTP driver: configure
NOTIFICATIONS_MAIL_SMTP_HOST,PORT,USERNAME,PASSWORD, plusNOTIFICATIONS_MAIL_SMTP_STARTTLSwhen 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/notificationsto view/update settings; persisted at./data/notifications-config.json.
π Monitoring & Health Checks
Health endpoint available at /health:
π€ Contributing
Fork the project
Create feature branch (
git checkout -b feature/AmazingFeature)Commit changes (
git commit -m 'Add AmazingFeature')Push to branch (
git push origin feature/AmazingFeature)Open Pull Request
π License
See LICENSE file for details.
Last updated