Files
common/packages/util-crypto/src/ethereum/isAddress.ts
T
2024-01-08 15:08:27 +02:00

17 lines
501 B
TypeScript

// Copyright 2017-2024 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { isHex } from '@polkadot/util';
import { isEthereumChecksum } from './isChecksum.js';
export function isEthereumAddress (address?: string): boolean {
if (!address || address.length !== 42 || !isHex(address)) {
return false;
} else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
return true;
}
return isEthereumChecksum(address);
}