Skip to content

fix(stellar): consolidate address validation and truncate helpers (#18, #3) - #93

Open
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/consolidate-stellar-helpers-18-3
Open

fix(stellar): consolidate address validation and truncate helpers (#18, #3)#93
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/consolidate-stellar-helpers-18-3

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Consolidates duplicated Stellar utility functions across src/utils/stellar.ts and src/lib/stellar.ts and fixes weak address validation in src/utils/validation.ts.

Closes #18, Closes #3.

Changes

  1. Consolidated isValidStellarAddress:
    • Switched to StrKey.isValidEd25519PublicKey(address) in src/lib/stellar.ts to strictly validate Base32 Ed25519 checksums instead of weaker format or error-prone constructors.
    • Updated validateRecipient in src/utils/validation.ts to use isValidStellarAddress instead of naive string length / prefix checks.
  2. Short-string guard for truncateAddress:
    • Added guard (if (address.length <= chars * 2) return address) in src/lib/stellar.ts to prevent overlapping substring duplication when inputs are shorter than 2 * chars.
  3. Re-export & Backward Compatibility:
    • Re-exported consolidated helpers (isValidStellarAddress, truncateAddress, formatAmount, formatXLM, formatUSD) from src/utils/stellar.ts to avoid breaking changes across existing consumer components.
    • Migrated AddContact.tsx import to canonical @/lib/stellar.
  4. Test Coverage:
    • Updated and added unit tests in stellar.test.ts and validation.test.ts for invalid checksum public keys and short-string truncation edge cases.

Verification

  • Ran Vitest suite across all 27 test files: 116 passed (100% green).

…ellarSend#18, StellarSend#3)

- Use StrKey.isValidEd25519PublicKey in lib/stellar.ts for rigorous checksum validation
- Guard truncateAddress against short strings to prevent overlapping substring duplication
- Re-export consolidated helpers from utils/stellar.ts for backward compatibility
- Use isValidStellarAddress in utils/validation.ts validateRecipient
- Update tests for invalid checksum validation and short-string truncation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant