feat: add address validation to prevent saving invalid Ethereum addresses#50
Merged
scottrepreneur merged 4 commits intoAug 29, 2025
Conversation
Addresses BUILD-1144 where Ethereum addresses (42 chars) caused 400 Bad Request errors when searching users via Neynar API, which requires q param ≤20 chars. Changes: - Add input validation in searchUsersByUsername() before API call - Handle Ethereum addresses (0x + 42 chars) with specific error message - Handle any query >20 chars with generic length error message - Update /search route to return 400 with descriptive errors - Add comprehensive tests for validation edge cases 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
BUILD-1148 Don't save invalid address records, throw instead
|
…sses - Add validateEthereumAddress utility using viem's isAddress function - Validate addresses before database operations in users-service - Add validation to API route address parameters - Throw clear errors instead of saving invalid address records - Addresses must be 0x prefixed, 42 characters, valid hex Fixes BUILD-1148 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
cca252b to
f343f93
Compare
- Replace invalid test addresses containing non-hex characters with valid ones - Use unique FIDs and addresses to avoid test interference - Fix test isolation issues where tests were affecting each other - All 31 tests now pass Co-authored-by: Claude <noreply@anthropic.com>
- Replace invalid test addresses with valid 42-character hex addresses - Update test expectations for proper address validation behavior - Fix non-existent address test to use dynamically generated unique address - Rename 'service error' test to 'invalid address format' with correct expectations - All 24 user route tests now pass with proper address validation Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements BUILD-1148 by adding comprehensive Ethereum address validation using viem's
isAddressfunction to prevent invalid address records from being saved to the database.Changes
✅ Add address validation utility (
src/utils/viem.ts)validateEthereumAddress()function that throws on invalid addressesisValidEthereumAddress()boolean helper functionisAddressfor robust validation (0x prefix, 42 chars, valid hex, EIP-55 checksum)✅ Update Users Service (
src/db/services/users-service.ts)createOrUpdateUser()- validates before adding addressessaveUserAddress()- validates before saving address recordsupdateAddressVerification()- validates before verification updatesgetUserByAddress()- validates lookup addresses✅ Update API Routes (
src/routes/users.ts)GET /address/:addressGET /address/:address/permissionsGET /verifications?address=...Validation Requirements
isAddressfunction as specifiedTest Results
Valid addresses accepted:
0x1234567890123456789012345678901234567890✅0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa✅Invalid addresses rejected:
0xgetuser1234567890123456789012345678901234❌ (non-hex chars)0xnonexistentaddress❌ (wrong length)invalid-address❌ (no 0x prefix)Test plan
🤖 Generated with Claude Code