Skip to content

feat: migrate wallet validation from StarkNet to Stellar#264

Open
vicajohn wants to merge 1 commit intoStreamFi-x:devfrom
vicajohn:feat/stellar-wallet-validation
Open

feat: migrate wallet validation from StarkNet to Stellar#264
vicajohn wants to merge 1 commit intoStreamFi-x:devfrom
vicajohn:feat/stellar-wallet-validation

Conversation

@vicajohn
Copy link

  • Add Stellar address validation utility using @stellar/stellar-sdk
  • Update 13 API routes to validate Stellar public keys (56-char Base32)
  • Replace LOWER(wallet) SQL queries with exact match for Stellar addresses
  • Remove wallet.toLowerCase() normalization (Stellar keys are uppercase)
  • Return 400 error for invalid Stellar addresses with clear message

Routes updated:

  • /api/users/wallet/[wallet], /api/users/register, /api/users/updates/[wallet]
  • /api/users/follow, /api/streams/[wallet], /api/streams/create
  • /api/streams/start, /api/streams/update, /api/streams/delete
  • /api/streams/delete-get, /api/streams/key, /api/fetch-username
  • /api/debug/user-stream

Description

Closes #issue_number_here

Changes proposed

What were you told to do?

What did you do?

Check List (Check all the applicable boxes)

🚨Please review the contribution guideline for this repository.

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.
  • I am making a pull request against the main branch (left side).
  • My commit messages styles matches our requested structure.
  • My code additions will fail neither code linting checks nor unit test.
  • I am only making changes to files I was requested to.

Screenshots/Videos

- Add Stellar address validation utility using @stellar/stellar-sdk
- Update 13 API routes to validate Stellar public keys (56-char Base32)
- Replace LOWER(wallet) SQL queries with exact match for Stellar addresses
- Remove wallet.toLowerCase() normalization (Stellar keys are uppercase)
- Return 400 error for invalid Stellar addresses with clear message

Routes updated:
- /api/users/wallet/[wallet], /api/users/register, /api/users/updates/[wallet]
- /api/users/follow, /api/streams/[wallet], /api/streams/create
- /api/streams/start, /api/streams/update, /api/streams/delete
- /api/streams/delete-get, /api/streams/key, /api/fetch-username
- /api/debug/user-stream
@vercel
Copy link

vercel bot commented Feb 22, 2026

@vicajohn is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vicajohn
Copy link
Author

please review

@davedumto
Copy link
Contributor

Great work on implementing Stellar address validation across the API routes! 👍

The implementation is clean and consistent across all 13 routes. However, I noticed one important gap:

Issue: Missing Tests for Validation Utility

The utils/stellar.ts file contains critical security validation logic but has no test coverage:

export function isValidStellarAddress(address: string): boolean {
  return StrKey.isValidEd25519PublicKey(address);
}

This function validates user input across all API routes, so it's essential to have comprehensive tests.

Recommended Fix

Please add a test file utils/__tests__/stellar.test.ts with test cases for:

import { isValidStellarAddress } from '../stellar';

describe('isValidStellarAddress', () => {
  it('should validate correct Stellar public keys', () => {
    const validKey = 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H';
    expect(isValidStellarAddress(validKey)).toBe(true);
  });

  it('should reject invalid keys', () => {
    expect(isValidStellarAddress('INVALID_KEY')).toBe(false);
    expect(isValidStellarAddress('')).toBe(false);
    expect(isValidStellarAddress('0x1234...')).toBe(false); // Ethereum address
  });

  it('should reject keys with wrong prefix', () => {
    const wrongPrefix = 'ABRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H';
    expect(isValidStellarAddress(wrongPrefix)).toBe(false);
  });

  it('should reject keys with wrong length', () => {
    expect(isValidStellarAddress('GBSHORT')).toBe(false);
    expect(isValidStellarAddress('G' + 'A'.repeat(100))).toBe(false);
  });
});

Could you add these tests before we merge? Thanks!

@davedumto
Copy link
Contributor

hi @vicajohn please fix conflicts

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