How to use the @ethersproject/bytes.isBytes function in @ethersproject/bytes

To help you get started, we’ve selected a few @ethersproject/bytes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethers-io / ethers.js / packages / bignumber / fixednumber.js View on Github external
FixedNumber.from = function (value, format) {
        if (typeof (value) === "string") {
            return FixedNumber.fromString(value, format);
        }
        if (bytes_1.isBytes(value)) {
            return FixedNumber.fromBytes(value, format);
        }
        try {
            return FixedNumber.fromValue(value, 0, format);
        }
        catch (error) {
            // Allow NUMERIC_FAULT to bubble up
            if (error.code !== logger_1.Logger.errors.INVALID_ARGUMENT) {
                throw error;
            }
        }
        return logger.throwArgumentError("invalid FixedNumber value", "value", value);
    };
    FixedNumber.isFixedNumber = function (value) {
github ethers-io / ethers.js / packages / contracts / lib / index.js View on Github external
function ContractFactory(contractInterface, bytecode, signer) {
        var _newTarget = this.constructor;
        var bytecodeHex = null;
        if (typeof (bytecode) === "string") {
            bytecodeHex = bytecode;
        }
        else if (bytes_1.isBytes(bytecode)) {
            bytecodeHex = bytes_1.hexlify(bytecode);
        }
        else if (bytecode && typeof (bytecode.object) === "string") {
            // Allow the bytecode object from the Solidity compiler
            bytecodeHex = bytecode.object;
        }
        else {
            // Crash in the next verification step
            bytecodeHex = "!";
        }
        // Make sure it is 0x prefixed
        if (bytecodeHex.substring(0, 2) !== "0x") {
            bytecodeHex = "0x" + bytecodeHex;
        }
        // Make sure the final result is valid bytecode
        if (!bytes_1.isHexString(bytecodeHex) || (bytecodeHex.length % 2)) {
github ethers-io / ethers.js / packages / bignumber / lib.esm / fixednumber.js View on Github external
static from(value, format) {
        if (typeof (value) === "string") {
            return FixedNumber.fromString(value, format);
        }
        if (isBytes(value)) {
            return FixedNumber.fromBytes(value, format);
        }
        try {
            return FixedNumber.fromValue(value, 0, format);
        }
        catch (error) {
            // Allow NUMERIC_FAULT to bubble up
            if (error.code !== Logger.errors.INVALID_ARGUMENT) {
                throw error;
            }
        }
        return logger.throwArgumentError("invalid FixedNumber value", "value", value);
    }
    static isFixedNumber(value) {
github ethers-io / ethers.js / packages / contracts / lib.esm / index.js View on Github external
constructor(contractInterface, bytecode, signer) {
        let bytecodeHex = null;
        if (typeof (bytecode) === "string") {
            bytecodeHex = bytecode;
        }
        else if (isBytes(bytecode)) {
            bytecodeHex = hexlify(bytecode);
        }
        else if (bytecode && typeof (bytecode.object) === "string") {
            // Allow the bytecode object from the Solidity compiler
            bytecodeHex = bytecode.object;
        }
        else {
            // Crash in the next verification step
            bytecodeHex = "!";
        }
        // Make sure it is 0x prefixed
        if (bytecodeHex.substring(0, 2) !== "0x") {
            bytecodeHex = "0x" + bytecodeHex;
        }
        // Make sure the final result is valid bytecode
        if (!isHexString(bytecodeHex) || (bytecodeHex.length % 2)) {
github ethers-io / ethers.js / packages / bignumber / src.ts / fixednumber.ts View on Github external
static from(value: any, format?: FixedFormat | string) {
        if (typeof(value) === "string") {
            return FixedNumber.fromString(value, format);
        }

        if (isBytes(value)) {
            return FixedNumber.fromBytes(value, format);
        }

        try {
            return FixedNumber.fromValue(value, 0, format);
        } catch (error) {
            // Allow NUMERIC_FAULT to bubble up
            if (error.code !== Logger.errors.INVALID_ARGUMENT) {
                throw error;
            }
        }

        return logger.throwArgumentError("invalid FixedNumber value", "value", value);
    }
github ethers-io / ethers.js / packages / bignumber / lib.esm / bignumber.js View on Github external
}
            return logger.throwArgumentError("invalid BigNumber string", "value", value);
        }
        if (typeof (value) === "number") {
            if (value % 1) {
                throwFault("underflow", "BigNumber.from", value);
            }
            if (value >= MAX_SAFE || value <= -MAX_SAFE) {
                throwFault("overflow", "BigNumber.from", value);
            }
            return BigNumber.from(String(value));
        }
        if (typeof (value) === "bigint") {
            return BigNumber.from(value.toString());
        }
        if (isBytes(value)) {
            return BigNumber.from(hexlify(value));
        }
        if (value._hex && isHexString(value._hex)) {
            return BigNumber.from(value._hex);
        }
        if (value.toHexString) {
            value = value.toHexString();
            if (typeof (value) === "string") {
                return BigNumber.from(value);
            }
        }
        return logger.throwArgumentError("invalid BigNumber value", "value", value);
    }
    static isBigNumber(value) {
github ethers-io / ethers.js / packages / bignumber / lib / bignumber.js View on Github external
function isBigNumberish(value) {
    return (value != null) && (BigNumber.isBigNumber(value) ||
        (typeof (value) === "number" && (value % 1) === 0) ||
        (typeof (value) === "string" && !!value.match(/^-?[0-9]+$/)) ||
        bytes_1.isHexString(value) ||
        (typeof (value) === "bigint") ||
        bytes_1.isBytes(value));
}
exports.isBigNumberish = isBigNumberish;
github ethers-io / ethers.js / packages / bignumber / lib / bignumber.js View on Github external
}
            return logger.throwArgumentError("invalid BigNumber string", "value", value);
        }
        if (typeof (value) === "number") {
            if (value % 1) {
                throwFault("underflow", "BigNumber.from", value);
            }
            if (value >= MAX_SAFE || value <= -MAX_SAFE) {
                throwFault("overflow", "BigNumber.from", value);
            }
            return BigNumber.from(String(value));
        }
        if (typeof (value) === "bigint") {
            return BigNumber.from(value.toString());
        }
        if (bytes_1.isBytes(value)) {
            return BigNumber.from(bytes_1.hexlify(value));
        }
        if (value._hex && bytes_1.isHexString(value._hex)) {
            return BigNumber.from(value._hex);
        }
        if (value.toHexString) {
            value = value.toHexString();
            if (typeof (value) === "string") {
                return BigNumber.from(value);
            }
        }
        return logger.throwArgumentError("invalid BigNumber value", "value", value);
    };
    BigNumber.isBigNumber = function (value) {
github ethers-io / ethers.js / packages / bignumber / lib.esm / bignumber.js View on Github external
export function isBigNumberish(value) {
    return (value != null) && (BigNumber.isBigNumber(value) ||
        (typeof (value) === "number" && (value % 1) === 0) ||
        (typeof (value) === "string" && !!value.match(/^-?[0-9]+$/)) ||
        isHexString(value) ||
        (typeof (value) === "bigint") ||
        isBytes(value));
}
export class BigNumber {