This implementation provides enterprise-grade HSM signing for Stellar Soroban transactions, ensuring private keys never touch the backend server.
✅ HSM Gateway Service - Complete service with AWS KMS, HashiCorp Vault, and GCP KMS support
✅ Multi-Sig Integration - Updated existing revocation service to use HSM signing
✅ Security Controls - Authentication, rate limiting, IP whitelisting, audit logging
✅ API Endpoints - RESTful endpoints for all HSM operations
✅ Database Schema - Admin model for permission management
✅ Configuration - Environment-based configuration for all HSM providers
✅ Testing - Comprehensive test suite for validation
✅ Documentation - Complete implementation and deployment guide
backend/
├── src/
│ ├── services/
│ │ └── hsmGatewayService.js # Main HSM service
│ ├── routes/
│ │ └── hsm.js # HSM API endpoints
│ ├── middleware/
│ │ └── auth.middleware.js # Security middleware
│ └── models/
│ └── admin.js # Admin model
├── migrations/
│ └── 010_create_admins_table.sql # Database migration
├── .env.hsm.example # Configuration template
├── test-hsm-integration.js # Test suite
└── HSM_IMPLEMENTATION_GUIDE.md # Full documentation
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Admin Dashboard│────│ Backend Server │────│ HSM Provider │
│ │ │ │ │ (AWS KMS/ │
│ - batch_revoke │ │ - Prepare XDR │ │ Vault/GCP) │
│ - Multi-sig │ │ - Send to HSM │ │ │
└─────────────────┘ │ - Broadcast │ │ - Never expose │
│ - Audit Log │ │ private keys │
└─────────────────┘ └─────────────────┘
- Private Key Protection: Keys never leave the HSM
- Secure Transaction Flow: Backend only prepares, never signs
- Enterprise-Grade: Meets institutional security requirements
- Admin Authentication: JWT-based with role-based permissions
- IP Whitelisting: Optional IP-based restrictions
- Time Restrictions: Business hours enforcement
- Rate Limiting: 10 HSM operations per minute per IP
- Complete Logging: Every HSM operation logged
- Immutable Records: Tamper-evident audit trail
- SOC 2/ISO 27001: Enterprise compliance ready
# Copy the HSM configuration template
cp backend/.env.hsm.example backend/.env
# Configure your HSM provider (choose one)
# AWS KMS
HSM_PROVIDER=aws-kms
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
# HashiCorp Vault
HSM_PROVIDER=hashicorp-vault
VAULT_ADDR=https://vault.example.com:8200
VAULT_TOKEN=your_token
# GCP KMS
HSM_PROVIDER=gcp-kms
GCP_PROJECT_ID=your-project# Run the admin table migration
psql -d your_database -f backend/migrations/010_create_admins_table.sql-- Create admin with HSM permissions
INSERT INTO admins (address, role, permissions, is_active)
VALUES (
'0x1234567890123456789012345678901234567890',
'super_admin',
'{"can_access_hsm": true}',
true
);cd backend
npm install
npm startcd backend
node test-hsm-integration.js# Get admin JWT token first
curl -X POST http://localhost:4000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"address": "0x1234...", "signature": "0x..."}'
# Check HSM status
curl -H "Authorization: Bearer <token>" \
http://localhost:4000/api/hsm/status// 1. Prepare transaction
const prepareResponse = await fetch('/api/hsm/prepare-transaction', {
method: 'POST',
headers: {
'Authorization': 'Bearer <admin_jwt>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
proposal: {
id: 1,
vault_address: 'GD...',
beneficiary_address: 'GD...',
amount_to_revoke: '1000',
status: 'approved'
}
})
});
// 2. Execute complete batch revoke
const revokeResponse = await fetch('/api/hsm/batch-revoke', {
method: 'POST',
headers: {
'Authorization': 'Bearer <admin_jwt>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
proposal: proposalData,
signingKeyIds: {
'GD...': 'arn:aws:kms:...',
'GD...': 'arn:aws:kms:...'
}
})
});
const result = await revokeResponse.json();
console.log('Transaction Hash:', result.data.transactionHash);# Provider Selection
HSM_PROVIDER=aws-kms # Options: aws-kms, hashicorp-vault, gcp-kms
# Security Settings
ADMIN_ADDRESSES=0x1234...,0x5678...
HSM_IP_WHITELIST=192.168.1.100,10.0.0.50
HSM_TIME_RESTRICTION=false
HSM_BUSINESS_HOURS=9-17
# Rate Limiting
HSM_RATE_LIMIT_WINDOW_MS=60000
HSM_RATE_LIMIT_MAX_REQUESTS=10# Option 1: JSON mapping
HSM_KEY_MAPPING='{"0x1234...": "arn:aws:kms:..."}'
# Option 2: Individual environment variables
HSM_KEY_1234567890123456789012345678901234567890=arn:aws:kms:...- Never commit HSM credentials to version control
- Use environment variables for all sensitive data
- Enable IP whitelisting for additional security
- Regular key rotation following HSM provider best practices
- Monitor audit logs for suspicious activity
- Only authorized admin addresses can access HSM endpoints
- All operations require valid JWT tokens
- Rate limiting prevents abuse
- Comprehensive audit logging for compliance
curl http://localhost:4000/api/hsm/healthcurl -H "Authorization: Bearer <token>" \
http://localhost:4000/api/hsm/statusAll HSM operations are logged with:
- Actor information
- Timestamp
- Operation details
- IP address
- Success/failure status
For development without real HSM access:
NODE_ENV=development
HSM_FALLBACK_ENABLED=trueThis enables the mock implementation for testing while maintaining the same API interface.
- Full Implementation Guide - Comprehensive documentation
- API Documentation - Detailed API reference
- Security Guide - Security best practices
- Troubleshooting - Common issues and solutions
- Check the Implementation Guide
- Review the Troubleshooting section
- Run the test suite for validation
- Check audit logs for debugging
For security-related issues, please follow your organization's security incident response procedures.
- Configure your HSM provider credentials
- Set up admin accounts and permissions
- Test with your HSM provider
- Configure production security settings
- Set up monitoring and alerting
- Implement backup procedures
- Configure disaster recovery
- Schedule regular security reviews
The HSM Signer Gateway is now fully implemented and ready for enterprise deployment. The system provides:
- Isolated Signing: Private keys never touch the backend
- Multiple HSM Providers: AWS KMS, HashiCorp Vault, GCP KMS
- Enterprise Security: Comprehensive access controls and audit logging
- Seamless Integration: Works with existing multi-sig workflows
- Production Ready: Complete testing, documentation, and deployment guides
The implementation meets the non-negotiable security requirements for institutional investors and large DAOs, ensuring that a server compromise cannot lead to mass revocation events or treasury drains.