This implementation provides a complete on-chain wallet architecture for CrowdPay campaigns, with secure key management, comprehensive API endpoints, and full documentation for developers and operators.
- AES-256-GCM encryption for campaign wallet private keys
- Encryption key stored in environment variable
WALLET_ENCRYPTION_KEY - Each encrypted secret includes IV, auth tag, and ciphertext for maximum security
- Functions:
encryptSecret(),decryptSecret()
Migration: backend/db/migrations/001_add_campaign_wallet_secrets.sql
- Added
wallet_secret_encryptedcolumn to campaigns table - Added index on
wallet_public_keyfor efficient lookups
Updated Schema: backend/db/schema.sql
- Campaigns table now stores encrypted wallet secrets
- Maintains backward compatibility with existing campaigns
Added three new functions:
recoverWalletFromSecret(secret): Reconstruct keypair from encrypted secretgetWalletTransactionHistory(publicKey, limit): Retrieve transaction history for auditgetWalletPayments(publicKey, limit): Get detailed payment operations
New endpoints for campaign wallet management:
GET /api/wallets/:campaignId/config- View multisig configurationGET /api/wallets/:campaignId/transactions- Transaction historyGET /api/wallets/:campaignId/payments- Payment audit trailPOST /api/wallets/:campaignId/recover- Recover wallet from encrypted secret
All endpoints require authentication and verify campaign creator ownership.
- Campaign creation now encrypts and stores wallet secrets
- Secrets stored securely in database for recovery purposes
- Maintains existing multisig and trustline setup
WALLET_ARCHITECTURE.md (399 lines):
- Complete architecture overview
- Wallet lifecycle phases (creation → contribution → withdrawal → recovery)
- Security considerations and best practices
- API reference with examples
- Troubleshooting guide
- Future enhancement roadmap
OPERATOR_GUIDE.md (556 lines):
- Step-by-step setup instructions
- Daily operations procedures
- Maintenance tasks (weekly, monthly, quarterly)
- Troubleshooting common issues
- Security and incident response procedures
- Monitoring and alerting setup
- Emergency procedures
API.md (updated):
- Added wallet management endpoint documentation
- Request/response examples
- Error codes and handling
✅ AES-256-GCM encryption for wallet secrets
✅ Multisig control (creator + platform signatures required)
✅ Disabled master keys after wallet setup
✅ Access control on all wallet endpoints
✅ Audit trail for all wallet operations
✅ Transaction history retrieval
✅ Payment operations tracking
✅ On-chain verification via Stellar Horizon
✅ Database records for all contributions and withdrawals
✅ Clear API documentation with examples
✅ Step-by-step guides for common operations
✅ Troubleshooting procedures for common issues
✅ Testing instructions for testnet and mainnet
✅ Setup procedures for initial deployment
✅ Daily operations checklists
✅ Maintenance schedules (weekly, monthly, quarterly)
✅ Emergency procedures for incident response
✅ Monitoring recommendations with key metrics
crowdpay/backend/src/services/walletService.js
crowdpay/backend/src/routes/wallets.js
crowdpay/backend/db/migrations/001_add_campaign_wallet_secrets.sql
crowdpay/WALLET_ARCHITECTURE.md
crowdpay/OPERATOR_GUIDE.md
crowdpay/backend/db/schema.sql
crowdpay/backend/src/services/stellarService.js
crowdpay/backend/src/routes/campaigns.js
crowdpay/backend/src/index.js
crowdpay/backend/.env.example
crowdpay/backend/API.md
-
Read the architecture:
cat WALLET_ARCHITECTURE.md
-
Setup environment:
# Generate encryption key node -e "console.log(require('crypto').randomBytes(32).toString('hex'))" # Add to .env echo "WALLET_ENCRYPTION_KEY=<generated_key>" >> backend/.env
-
Run migrations:
psql $DATABASE_URL -f backend/db/migrations/001_add_campaign_wallet_secrets.sql -
Test wallet creation:
curl -X POST http://localhost:3001/api/campaigns \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"title":"Test","target_amount":"100","asset_type":"USDC"}'
-
Read the operator guide:
cat OPERATOR_GUIDE.md
-
Setup platform account:
cd contracts/stellar node campaignWallet.js --setup-platform -
Configure monitoring:
- Set up alerts for platform balance < 50 XLM
- Monitor ledger monitor lag
- Track withdrawal processing time
-
Backup encryption key:
- Store
WALLET_ENCRYPTION_KEYin secure vault - Create offline backup
- Document recovery procedures
- Store
✅ Each new campaign triggers a unique Stellar account setup
- Implemented in
createCampaignWallet()function - Automatic wallet creation on campaign POST
- Encrypted secret storage in database
✅ Developers have step-by-step documentation for wallet creation
- WALLET_ARCHITECTURE.md covers complete lifecycle
- API.md provides endpoint documentation
- Code comments explain each step
✅ Fund flows and account controls are fully auditable
- Transaction history endpoint
- Payment operations endpoint
- On-chain verification via Stellar Horizon
- Database audit trail
- Use testnet for all development and testing
- Never commit encryption keys to version control
- Test recovery procedures regularly
- Use AWS KMS, Google Cloud KMS, or Azure Key Vault for encryption keys
- Implement key rotation every 90 days
- Enable comprehensive audit logging
- Set up monitoring and alerting
- Restrict wallet recovery endpoint to admin users only
- Use separate platform accounts for testnet and mainnet
- Test campaign creation with wallet encryption
- Test wallet configuration retrieval
- Test transaction history endpoint
- Test payment history endpoint
- Test wallet recovery endpoint
- Test encryption/decryption with sample keys
- Test multisig withdrawal flow
- Verify on-chain wallet configuration
- Test error handling for missing encryption key
- Test access control (non-creator cannot access wallet)
- Run the test suite to verify all functionality
- Deploy to testnet and create test campaigns
- Verify wallet creation on Stellar testnet
- Test complete contribution flow with encrypted wallets
- Test withdrawal flow with multisig
- Review security with security team
- Setup monitoring and alerting
- Train operators on procedures
- Document mainnet deployment plan
- Plan key rotation schedule
- Architecture Questions: See WALLET_ARCHITECTURE.md
- Operational Issues: See OPERATOR_GUIDE.md
- API Usage: See backend/API.md
- Stellar Network: https://developers.stellar.org/
- Implementation Date: 2026-04-24
- Version: 1.0
- Status: Ready for testing
All acceptance criteria met. Implementation complete and documented.