-
walletService.ts - Enhanced with placeholder detection and validation
isPlaceholderAddress()function to detect common patternsensureWalletForUser()validates before persistingassertUserWalletAddress()validates on read (defense in depth)setStellarAddressForUser()new safe entry point for external addresses
-
Database Migration -
20260426000000_add_stellar_address_validation- Pre-flight validation (fails if invalid data exists)
- CHECK constraint enforcing valid format
- Performance index on stellar_address
-
Validation Script -
scripts/validate_stellar_addresses.sql- SQL script to check existing data
- Can be run before applying migration
-
Schema Documentation - Added comments to schema.prisma
-
Documentation - B-013_FIX_SUMMARY.md with complete details
-
Run validation script against your database:
psql -U your_user -d your_db -f scripts/validate_stellar_addresses.sql
- Should return 0 invalid addresses
- If invalid addresses found, fix them before deploying
-
Test wallet creation flow:
- Create new user account
- Sign in (triggers wallet creation)
- Verify stellar address is valid 56-char G-address
- Verify address is NOT a placeholder pattern
-
Test signin with existing user:
- Sign in with existing user
- Verify stellar_address is returned correctly
- No validation errors should occur
-
Test transfer operations:
- Initiate transfer
- Verify
assertUserWalletAddress()validates correctly - No false positives or negatives
# Run this against your production/staging database
psql -U your_user -d your_db -f scripts/validate_stellar_addresses.sqlExpected Output:
invalid_address_count = 0- List of invalid addresses should be EMPTY
If Invalid Addresses Found:
-- Option 1: Clear invalid addresses
UPDATE users SET stellar_address = NULL WHERE id = 'user-id';
-- Option 2: Replace with valid address (if user has real wallet)
UPDATE users SET stellar_address = 'GVALID...' WHERE id = 'user-id';# Ensure database is running
npx prisma migrate deploy
# Should succeed without errorsnpm run build
# or
pnpm run buildShould compile without TypeScript errors.
- Run validation script on production database
- Fix any invalid addresses found
- Confirm
invalid_address_count = 0
npx prisma migrate deploynpm run build
npm start
# or your deployment method- Monitor logs for: "Invalid stellar address format in database"
- Watch for wallet creation failures
- Check transfer operations work correctly
## B-013: Fix Placeholder/Invalid Stellar Address Prevention
### Problem
Non-G placeholder addresses could break downstream Stellar validation and UX. No database constraint prevented invalid addresses from being stored.
### Solution
**Defense in Depth Strategy:**
1. Application-level validation with placeholder detection
2. Database CHECK constraint enforcing valid format
3. Validation on read to catch any corrupted data
4. Comprehensive logging for debugging
### Changes
- `src/services/wallet/walletService.ts` - Enhanced validation
- `prisma/migrations/20260426000000_add_stellar_address_validation/migration.sql` - DB constraint
- `scripts/validate_stellar_addresses.sql` - Pre-deployment validation
- `prisma/schema.prisma` - Documentation
### Acceptance Criteria
✅ No user row ships with invalid stellarAddress format in prod
✅ Placeholder addresses rejected at app and DB levels
✅ Existing data validated before constraint application
✅ Proper error logging for debugging
### Testing
- [ ] Validation script run on target database (0 invalid addresses)
- [ ] Wallet creation flow tested
- [ ] Signin flow tested
- [ ] Transfer operations tested
### Deployment Notes
⚠️ MUST run `scripts/validate_stellar_addresses.sql` before applying migration
⚠️ Fix any invalid addresses before deploymentYES, the implementation is complete and ready for PR submission!
- ✅ MUST run validation script on your database
- ✅ MUST fix any invalid addresses found
- ✅ SHOULD test locally with your database
- ✅ SHOULD run test suite (if available)
- ✅ Code implementation complete
- ✅ Database migration created
- ✅ Validation scripts provided
- ✅ Documentation comprehensive
- ✅ Defense in depth implemented
⚠️ Validate your existing database has no invalid addresses⚠️ Test the changes with your specific setup⚠️ Run your test suite to ensure no regressions
Implementation Status: ✅ COMPLETE
Ready for PR: ✅ YES
Ready for Production:
The code is production-ready and follows best practices. Just ensure your existing data is clean before deploying the migration!