Skip to content

Commit

Permalink
fix: handle non-checksummed EVM addresses in validateAddress (shapesh…
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored May 9, 2023
1 parent 600784e commit a7ebe39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 2 additions & 9 deletions packages/chain-adapters/src/evm/EvmBaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { BIP44Params } from '@shapeshiftoss/types'
import { KnownChainIds } from '@shapeshiftoss/types'
import type * as unchained from '@shapeshiftoss/unchained-client'
import { utils } from 'ethers'
import WAValidator from 'multicoin-address-validator'
import { numberToHex } from 'web3-utils'

import type { ChainAdapter as IChainAdapter } from '../api'
Expand All @@ -35,12 +34,7 @@ import type {
ValidAddressResult,
} from '../types'
import { ValidAddressResultType } from '../types'
import {
chainIdToChainLabel,
getAssetNamespace,
toAddressNList,
toRootDerivationPath,
} from '../utils'
import { getAssetNamespace, toAddressNList, toRootDerivationPath } from '../utils'
import { bnOrZero } from '../utils/bignumber'
import type { avalanche, bnbsmartchain, ethereum, optimism, polygon } from '.'
import type { BuildCustomTxInput, EstimateGasRequest, Fees, GasFeeDataEstimate } from './types'
Expand Down Expand Up @@ -461,8 +455,7 @@ export abstract class EvmBaseAdapter<T extends EvmChainId> implements IChainAdap

// eslint-disable-next-line require-await
async validateAddress(address: string): Promise<ValidAddressResult> {
const chainLabel = chainIdToChainLabel(this.chainId)
const isValidAddress = WAValidator.validate(address, chainLabel)
const isValidAddress = utils.isAddress(address)
if (isValidAddress) return { valid: true, result: ValidAddressResultType.Valid }
return { valid: false, result: ValidAddressResultType.Invalid }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,18 @@ describe('EthereumChainAdapter', () => {
const invalidAddressTuple = { valid: false, result: ValidAddressResultType.Invalid }

describe('validateAddress', () => {
it('should return true for a valid address', async () => {
it('should return true for a valid checksummed address', async () => {
const adapter = new ethereum.ChainAdapter(makeChainAdapterArgs())
const res = await adapter.validateAddress('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
expect(res).toMatchObject(validAddressTuple)
})

it('should return true for a valid lowercased address', async () => {
const adapter = new ethereum.ChainAdapter(makeChainAdapterArgs())
const res = await adapter.validateAddress('0xd8da6bf26964af9d7eed9e03e53415d37aa96045')
expect(res).toMatchObject(validAddressTuple)
})

it('should return false for an empty address', async () => {
const adapter = new ethereum.ChainAdapter(makeChainAdapterArgs())
const res = await adapter.validateAddress('')
Expand Down

0 comments on commit a7ebe39

Please sign in to comment.