Skip to content

Fix: Add missing error handling for Keypair.fromSecret() in API #88

@Smartdevs17

Description

@Smartdevs17

Problem

In api/src/services/stellar.service.ts, Keypair.fromSecret(userSecret) is called inside try-catch blocks, but the error message doesn't distinguish between invalid key format vs other errors.

Context

If a user provides an invalid secret key, the error message is generic. Users need to know specifically that their key format is wrong.

Proposed Solution

Catch the specific error from Keypair.fromSecret():

try {
  const keypair = Keypair.fromSecret(userSecret);
} catch (error) {
  if (error instanceof Error && error.message.includes('Invalid')) {
    throw new ApiError(400, 'Invalid secret key format');
  }
  throw error;
}

Acceptance Criteria

  • Invalid secret key returns 400 with specific message
  • Valid but wrong key proceeds normally
  • Error message does NOT echo the key value
  • Tests for invalid key scenarios

Technical Notes

  • File: api/src/services/stellar.service.ts

Constraints

  • Never include the key value in error responses or logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programapiREST API componentbugSomething isn't workingeasyDifficulty: Easy

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions