ethereumjs-util#isValidChecksumAddress TypeScript Examples

The following examples show how to use ethereumjs-util#isValidChecksumAddress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: checksum.ts    From beefy-api with MIT License 5 votes vote down vote up
validateAllAddressesChecksum = (): InvalidAddressInfo[][] => {
  const invalidPlatformAddressList: InvalidAddressInfo[] = [];
  const invalidTokenAddressList: InvalidAddressInfo[] = [];

  const chains = Object.entries(addressBook);
  for (const chain of chains) {
    const chainName = chain[0] as Exclude<keyof typeof addressBook, ChainId>;
    const { platforms, tokens } = chain[1];
    const platformEntries = Object.entries(platforms);

    // validate platforms
    for (const platform of platformEntries) {
      const platformName = platform[0];
      const addresses = platform[1];

      for (const addressEntry of Object.entries(addresses)) {
        const addressName = addressEntry[0];
        const address = addressEntry[1] as string;

        const isValid = isValidChecksumAddress(address);
        const correctAddress = address ? toChecksumAddress(address) : '';
        if (!isValid) {
          invalidPlatformAddressList.push({
            chainName,
            platformName,
            address,
            addressName,
            correctAddress,
          });
        }
      }
    }

    const tokenInfoEntries = Object.entries(tokens);
    // validate token addresses
    for (const tokenInfoEntry of tokenInfoEntries) {
      const tokenName = tokenInfoEntry[0];
      const tokenInfo = tokenInfoEntry[1];
      const address = tokenInfo.address;

      const isValid = isValidChecksumAddress(address);
      const correctAddress = address ? toChecksumAddress(address) : '';
      if (!isValid) {
        invalidTokenAddressList.push({
          chainName,
          addressName: tokenName,
          address,
          correctAddress,
        });
      }
    }
  }

  return [invalidPlatformAddressList, invalidTokenAddressList];
}