feat: add shared Stellar address validation utility#365
Merged
josephchimebuka merged 1 commit intoJun 30, 2026
Merged
Conversation
Centralizes wallet-address format validation that was duplicated and inconsistent across the auth, bet, and user surfaces. New src/utils/stellar-address.util.ts exposes: - isValidStellarAddress(unknown): safe predicate (non-strings/empty → false) - stellarAddressSchema / optionalStellarAddressSchema: reusable Zod schemas - validateStellarAddressParam(paramName): Express route guard that rejects an invalid path param with 400 VALIDATION_ERROR The raw StrKey check stays in services/stellar.service (the single @stellar/stellar-sdk boundary that tests mock); the util delegates to it so the SDK remains mockable and is not imported a second time. Wired in: - auth.schema & bets.schema now source validation from the shared util - user.routes.ts param routes (/:address/stats, /:address/history, /:walletAddress/public-profile) now guard the address → 400 on malformed input - stellar.service.verifySignature and hackathon user.ts reuse the shared helper Adds src/tests/stellar-address.util.spec.ts (11 tests): predicate edge cases, the Zod schema, and the route guard's 400 behavior (stellar.service mocked, as the other suites do, to keep the SDK out of jest). Closes #<address-validation-issue> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 tasks
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.
Closes #267
Summary
Centralizes wallet-address format validation, which was duplicated and inconsistent across the auth, bet, and user surfaces. Adds a single shared utility used by Zod schemas and route guards so every wallet-related endpoint accepts/rejects the exact same set of addresses.
What changed
New
src/utils/stellar-address.util.tsisValidStellarAddress(address: unknown)— safe predicate; non-strings/empty/malformed →false(never throws), so it's usable directly on route params.stellarAddressSchema/optionalStellarAddressSchema— reusable Zod schemas.validateStellarAddressParam(paramName)— Express route guard that rejects an invalid:addresspath param with 400VALIDATION_ERRORvia the centralized error handler.Dependency boundary
StrKey.isValidEd25519PublicKeycheck stays inservices/stellar.service— the single@stellar/stellar-sdkboundary that the test suite already mocks. The util delegates to it rather than importing the SDK a second time, so the SDK stays mockable and out of jest's ESM path.Wired in (major routes)
auth.schemaandbets.schemanow source validation from the shared util (removing their local copies).user.routes.tsparam routes —/:address/stats,/:address/history,/:walletAddress/public-profile— now guard the address and return 400 on malformed input (previously unvalidated; passed straight to Soroban/Prisma).stellar.service.verifySignatureand the hackathonuser.tsreuse the shared helper.Acceptance criteria
Testing
src/tests/stellar-address.util.spec.ts— 11 tests: predicate edge cases (non-string/empty/throwing), the Zod schema (valid/invalid/required/optional), and the route guard's 400 behavior + custom param name.stellar.serviceis mocked (as the other suites do) so the SDK stays out of jest.bets.routes,hackathon-bets,hackathon-endpoints, androute-parityare unrelated environmental issues (jest cannot parse@stellar/stellar-sdk's ESM under pnpm) / stale post-feat: mount production user, bet, and tournament routes in hackathon app #363 route-mounting expectations — they fail identically with and without this change.tscshows no new errors.🤖 Generated with Claude Code