All files / abi/base Address.js

47.06% Statements 8/17
26.67% Branches 4/15
33.33% Functions 1/3
50% Lines 8/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34      15x 9x   6x 6x                                         1x 1x 1x 1x    
import { keccak256 } from "../../utils/ethersUtils";
class Address {
    static isHexAddress(address) {
        if (!/^(0x)?[0-9a-f]{42}$/i.test(address)) {
            return false;
        }
        else Eif (/^(0x)?[0-9a-f]{42}$/.test(address) || /^(0x)?[0-9A-F]{42}$/.test(address)) {
            return true;
        }
        else {
            return this.isChecksumHexAddress(address);
        }
    }
    static isChecksumHexAddress(address) {
        address = address.replace("0x", "");
        const addressHash = Address.sha3(address.toLowerCase());
        for (let i = 0; i < 40; i++) {
            if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i])
                || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
                return false;
            }
        }
        return true;
    }
    static sha3(stringf, prefix = true) {
        return (prefix ? '0x' : '') + keccak256(Buffer.from(stringf, 'utf-8')).toString().substring(2);
    }
}
const ADDRESS_SIZE = 34;
const ADDRESS_PREFIX = "41";
const ADDRESS_PREFIX_BYTE = 0x41;
const ADDRESS_PREFIX_REGEX = /^(41)/;
export { ADDRESS_SIZE, ADDRESS_PREFIX, ADDRESS_PREFIX_BYTE, ADDRESS_PREFIX_REGEX, Address };