Skip to content

feat: Add Stellar address validation utility - #114

Merged
Jaydbrown merged 4 commits into
Nodus-protocol:mainfrom
AbelOsaretin:feat/stellar-address-validation
Jun 24, 2026
Merged

feat: Add Stellar address validation utility#114
Jaydbrown merged 4 commits into
Nodus-protocol:mainfrom
AbelOsaretin:feat/stellar-address-validation

Conversation

@AbelOsaretin

Copy link
Copy Markdown
Contributor

Closes #82

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional or behavioral changes)
  • Performance improvement
  • Documentation update
  • Build / CI configuration change
  • Dependency update
  • Other:

Summary

The wallet connection flow accepted any non-empty string as a secret key, deferring validation to the Stellar SDK deep in the SEP-10 flow. This caused cryptic errors ("Invalid seed") instead of clear user-facing messages. This PR adds a Validation utility class that validates Stellar secret and public key format at the UI boundary, showing immediate feedback for invalid inputs.

Motivation / Context

Fixes #82

Users who mistype their secret key receive cryptic errors from the Stellar SDK instead of clear validation messages. The issue identifies that:

  • No validation utility exists (lib/utils/validation.dart returns 404)
  • The wallet screen only checks for empty strings
  • Invalid keys cause confusing errors during the async SEP-10 flow

Detailed Changes

  • New file: lib/utils/validation.dart — Added Validation class with:

    • stellarSecretKey(String key) — validates prefix 'S', length 56, base32 character set
    • stellarPublicKey(String key) — validates prefix 'G', length 56
    • Returns null for valid keys, error message string for invalid ones
  • Modified: lib/screens/wallet_screen.dart — Updated _onConnect method to:

    • Call Validation.stellarSecretKey() before passing key to provider
    • Show SnackBar with error message when validation fails
    • Prevent invalid keys from reaching WalletProvider.connect()
  • New file: test/utils/validation_test.dart — Comprehensive unit tests covering:

    • Valid format keys (prefix, length, base32 characters)
    • Empty input rejection
    • Wrong prefix detection
    • Wrong length detection
    • Invalid base32 character detection
    • Whitespace trimming behavior

Current Behavior vs. New Behavior

Before: Enter any non-empty string → key passed to SDK → cryptic "Invalid seed" error deep in SEP-10 flow

After: Enter invalid key → immediate SnackBar with clear error message (e.g., "Secret key must start with 'S'", "Secret key must be exactly 56 characters (got 55)")

Testing

  • Unit tests: 9 test cases covering all validation paths (valid keys, empty input, wrong prefix, wrong length, invalid base32 chars, whitespace trimming)
  • All existing tests pass locally
  • Manual verification: entering invalid keys now shows clear error messages instead of cryptic SDK errors

Screenshots / Recordings

N/A (CLI input validation)

Breaking Changes

No

Risks and Rollback

Low risk — validation is additive and non-breaking. Rollback: revert commits on the feature branch.

Checklist

Self-Review

  • I have read the entire diff line by line as if a stranger wrote it
  • No debug code remains (console.log, print, debugger, commented-out blocks)
  • No hardcoded secrets, tokens, API keys, or internal URLs
  • Naming is consistent with the existing codebase
  • Error handling is present and produces meaningful messages
  • Edge cases are addressed (null/undefined, empty collections, boundary values)
  • No unused imports, dead code, or unnecessary dependencies

Testing

  • All existing tests pass locally
  • New tests added for new logic (functions, methods, branches)
  • Edge cases and failure paths are tested, not just the happy path
  • Manual testing steps documented above (if applicable)
  • Screenshots / recordings attached (for UI changes)

CI / Pipeline

  • All CI checks are passing (build, lint, test, type-check)
  • No new compiler warnings or linting errors introduced

Documentation

  • README updated if setup, usage, or installation changed
  • API documentation updated for any public interface changes
  • Inline comments added for non-obvious logic (explain "why", not "what")
  • Configuration / env var documentation updated (if applicable)

Changelog

  • Changelog entry added (if the project maintains one)
  • Entry uses user-facing language, not implementation details
  • Breaking changes are flagged with migration instructions

Security

  • User input is validated and sanitized at trust boundaries
  • No SQL injection, XSS, or injection vulnerabilities introduced
  • Authentication / authorization checks are in place for new endpoints
  • Dependencies have no known critical vulnerabilities

Performance

  • No N+1 database query patterns introduced
  • New queries use appropriate indexes
  • No memory leaks (event listeners cleaned up, connections closed)
  • Large data sets are paginated or streamed, not loaded entirely into memory

Reviewer Notes

  • The validation utility follows the pattern specified in the issue (#82)
  • Unit tests cover all validation paths specified in the issue
  • The wallet screen now shows clear error messages via SnackBar

Additional References

@AbelOsaretin
AbelOsaretin requested a review from Jaydbrown as a code owner June 24, 2026 12:26

@AbelOsaretin AbelOsaretin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. CI Status ⚠️

  • Analyze step fails — This is a pre-existing issue caused by --fatal-infos flag in CI workflow
  • PR #104 already addresses this by changing to --fatal-warnings
  • My code changes do not introduce new analysis errors

2. Merge Conflicts ✅

  • No merge conflicts detected

- Add Validation class with stellarSecretKey and stellarPublicKey methods
- Validate key format: prefix, length, and base32 character set
- Return null for valid keys, error message string for invalid ones
- Integrate Validation.stellarSecretKey in _onConnect method
- Show SnackBar with error message for invalid keys
- Prevent invalid keys from being passed to WalletProvider.connect()
@AbelOsaretin
AbelOsaretin force-pushed the feat/stellar-address-validation branch from fe4a22e to 64d1105 Compare June 24, 2026 13:09
- Test valid secret key format (prefix, length, base32 chars)
- Test valid public key format
- Test edge cases: empty string, wrong prefix, wrong length, invalid chars
- Test trimming of whitespace in input
@AbelOsaretin
AbelOsaretin force-pushed the feat/stellar-address-validation branch from 9584778 to d297e4c Compare June 24, 2026 13:17
- S-key test fixture was 55 chars, now 56 chars
- G-key test fixture was 59 chars, now 56 chars
- Both test keys now match the 56-character requirement for Stellar keys
@Jaydbrown
Jaydbrown merged commit 7d265ba into Nodus-protocol:main Jun 24, 2026
1 check 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.

2 participants