Skip to content

Commit

Permalink
change schema check to only character limit and alphanumeric
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
  • Loading branch information
shrenujb committed Jan 16, 2025
1 parent 1099fdf commit d49bf25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,16 +406,13 @@ describe('addresses-controller#V4', () => {
const response: request.Response = await sendRequest({
type: RequestMethod.GET,
path: `/v4/addresses/${invalidAddress}`,
expectedStatus: 400,
expectedStatus: 404,
});

expect(response.body).toEqual({
errors: [
{
msg: 'address must be a valid dydx address',
location: 'params',
param: 'address',
value: 'invalidAddress',
msg: 'No subaccounts found for address invalidAddress',
},
],
});
Expand Down Expand Up @@ -736,10 +733,7 @@ describe('addresses-controller#V4', () => {
expect(response.body).toEqual({
errors: [
{
msg: 'address must be a valid dydx address',
location: 'params',
param: 'address',
value: 'invalidAddress',
msg: 'Address invalidAddress is not a valid dYdX V4 address',
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { complianceProvider } from '../../../helpers/compliance/compliance-clien
import { create4xxResponse, handleControllerError } from '../../../lib/helpers';
import { rateLimiterMiddleware } from '../../../lib/rate-limit';
import { getIpAddr } from '../../../lib/utils';
import { CheckAddressSchema } from '../../../lib/validation/schemas';
import { handleValidationErrors } from '../../../request-helpers/error-handler';
import ExportResponseCodeStats from '../../../request-helpers/export-response-code-stats';
import { ComplianceRequest, ComplianceResponse } from '../../../types';
Expand Down
11 changes: 7 additions & 4 deletions indexer/services/comlink/src/lib/validation/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@ function verifyIsBech32(address: string): Error | undefined {
return undefined;
}

export function isValidAddress(address: string): boolean {
export function isValidDydxAddress(address: string): boolean {
// An address is valid if it starts with `dydx1` and is Bech32 format.
const ret: boolean = address.startsWith('dydx1') && (verifyIsBech32(address) === undefined);
console.log('is valid address: ', ret);
return ret;
return address.startsWith('dydx1') && (verifyIsBech32(address) === undefined);
}

export function isValidAddress(address: string): boolean {
// Address is valid if its under 90 characters and alphanumeric
return address.length <= 90 && /^[a-zA-Z0-9]*$/.test(address);
}

0 comments on commit d49bf25

Please sign in to comment.