Skip to content

feat: add shared Stellar address validation utility#365

Merged
josephchimebuka merged 1 commit into
TevaLabs:mainfrom
ebubechi-ihediwa:feat/shared-stellar-address-util
Jun 30, 2026
Merged

feat: add shared Stellar address validation utility#365
josephchimebuka merged 1 commit into
TevaLabs:mainfrom
ebubechi-ihediwa:feat/shared-stellar-address-util

Conversation

@ebubechi-ihediwa

@ebubechi-ihediwa ebubechi-ihediwa commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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.ts

  • isValidStellarAddress(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 :address path param with 400 VALIDATION_ERROR via the centralized error handler.

Dependency boundary

  • The raw StrKey.isValidEd25519PublicKey check stays in services/stellar.service — the single @stellar/stellar-sdk boundary 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.schema and bets.schema now source validation from the shared util (removing their local copies).
  • user.routes.ts param 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.verifySignature and the hackathon user.ts reuse the shared helper.

Acceptance criteria

  • ✅ Invalid addresses rejected with 400 (route guards + schema refinements).
  • ✅ Shared helper used in the major auth/bet/user routes.
  • ✅ Wallet-related endpoints behave consistently (one validator).

Testing

  • New src/tests/stellar-address.util.spec.ts11 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.service is mocked (as the other suites do) so the SDK stays out of jest.
  • Verified against a measured baseline: zero new test failures. The pre-existing failures in bets.routes, hackathon-bets, hackathon-endpoints, and route-parity are 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. tsc shows no new errors.

🤖 Generated with Claude Code

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>
@josephchimebuka josephchimebuka merged commit e964a9f into TevaLabs:main Jun 30, 2026
1 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add shared Stellar address validation utility

2 participants