Skip to main content

validator

Index

References

Web3Validator

Re-exports Web3Validator

Namespaces

utils

utils:

abiSchemaToJsonSchema

codePointToInt

  • codePointToInt(codePoint: number): number
  • Code points to int


    Parameters

    • codePoint: number

    Returns number

ensureIfUint8Array

  • ensureIfUint8Array<T>(data: T): Uint8Array | T
  • Type parameters

    • T = any

    Parameters

    • data: T

    Returns Uint8Array | T

ethAbiToJsonSchema

fetchArrayElement

  • fetchArrayElement(data: unknown[], level: number): unknown
  • Parameters

    • data: unknown[]
    • level: number

    Returns unknown

hexToNumber

  • hexToNumber(value: string): number | bigint
  • Converts value to it's number representation


    Parameters

    • value: string

    Returns number | bigint

hexToUint8Array

  • hexToUint8Array(hex: string): Uint8Array
  • Parameters

    • hex: string

    Returns Uint8Array

numberToHex

  • Converts value to it's hex representation


    Parameters

    Returns string

padLeft

  • padLeft(value: ValidInputTypes, characterAmount: number, sign?: string): string
  • Adds a padding on the left of a string, if value is a integer or bigInt will be converted to a hex string.


    Parameters

    Returns string

parseBaseType

  • parseBaseType<T>(type: string): { arraySizes: number[]; baseType?: T; baseTypeSize: undefined | number; isArray: boolean }
  • Type parameters

    • T = string

    Parameters

    • type: string

    Returns { arraySizes: number[]; baseType?: T; baseTypeSize: undefined | number; isArray: boolean }

    • arraySizes: number[]
    • optionalbaseType?: T
    • baseTypeSize: undefined | number
    • isArray: boolean

transformJsonDataToAbiFormat

  • transformJsonDataToAbiFormat(abis: FullValidationSchema, data: Record<string, unknown> | readonly unknown[], transformedData?: unknown[]): unknown[]
  • Parameters

    • abis: FullValidationSchema
    • data: Record<string, unknown> | readonly unknown[]
    • optionaltransformedData: unknown[]

    Returns unknown[]

uint8ArrayToHexString

  • uint8ArrayToHexString(uint8Array: Uint8Array): string
  • Parameters

    • uint8Array: Uint8Array

    Returns string

Classes

Web3ValidatorError

Web3ValidatorError:

Base class for Web3 errors.

constructor

cause

cause: undefined | Error

code

code: number

readonlyerrors

errors: Web3ValidationErrorObject<string, Record<string, any>, unknown>[]

readonlyname

name: string

stack

stack: undefined | string

innerError

  • get innerError(): undefined | Error | Error[]
  • set innerError(cause: undefined | Error | Error[]): void
  • @deprecated

    Use the cause property instead.


    Returns undefined | Error | Error[]

  • @deprecated

    Use the cause property instead.


    Parameters

    • cause: undefined | Error | Error[]

    Returns void

toJSON

  • toJSON(): { cause: undefined | Error; code: number; innerError: undefined | Error; message: string; name: string }
  • Returns { cause: undefined | Error; code: number; innerError: undefined | Error; message: string; name: string }

    • cause: undefined | Error
    • code: number
    • innerError: undefined | Error
    • message: string
    • name: string

staticconvertToString

  • convertToString(value: unknown, unquotValue?: boolean): string
  • Parameters

    • value: unknown
    • optionalunquotValue: boolean

    Returns string

Interfaces

Validate

  • Validate(value: Json): boolean
  • Parameters

    Returns boolean

optionalerrors

errors?: ZodIssueBase[]

Type Aliases

EthBaseTypes

EthBaseTypes: bool | bytes | string | uint | int | address | tuple

EthBaseTypesWithMeta

EthBaseTypesWithMeta: `string${string}` | `string${string}[${number}]` | `bytes${string}` | `bytes${string}[${number}]` | `address[${number}]` | `bool[${number}]` | `int${string}` | `int${string}[${number}]` | `uint${string}` | `uint${string}[${number}]` | tuple[] | `tuple[${number}]`

EthExtendedTypes

EthExtendedTypes: hex | number | blockNumber | blockNumberOrTag | filter | bloom

FullValidationSchema

FullValidationSchema: ReadonlyArray<AbiParameter>

Json

Json: string | number | boolean | Json[] | {}

JsonSchema

JsonSchema: Schema

Schema

Schema: { $anchor?: string; $comment?: string; $defs?: {}; $id?: string; $recursiveAnchor?: boolean; $recursiveRef?: string; $ref?: string; $schema?: string; $vocabulary?: string; additionalItems?: Schema; additionalProperties?: Schema; allOf?: Schema[]; anyOf?: Schema[]; const?: Json; contains?: Schema; contentEncoding?: string; contentMediaType?: string; contentSchema?: Schema; default?: Json; definitions?: {}; dependencies?: {}; dependentRequired?: {}; dependentSchemas?: {}; deprecated?: boolean; description?: string; discriminator?: { mapping?: {}; propertyName: string }; divisibleBy?: number; else?: Schema; enum?: Json[]; eth?: string; examples?: Json[]; exclusiveMaximum?: number | boolean; exclusiveMinimum?: number | boolean; format?: string; id?: string; if?: Schema; items?: Schema | Schema[]; maxContains?: number; maxItems?: number; maxLength?: number; maxProperties?: number; maximum?: number; minContains?: number; minItems?: number; minLength?: number; minProperties?: number; minimum?: number; multipleOf?: number; not?: Schema; oneOf?: Schema[]; pattern?: string; patternProperties?: {}; properties?: {}; propertyNames?: Schema; readOnly?: boolean; required?: string[] | boolean; then?: Schema; title?: string; type?: string | string[]; unevaluatedItems?: Schema; unevaluatedProperties?: Schema; uniqueItems?: boolean; writeOnly?: boolean }

Type declaration

  • optional$anchor?: string
  • optional$comment?: string
  • optional$defs?: {}
  • optional$id?: string
  • optional$recursiveAnchor?: boolean
  • optional$recursiveRef?: string
  • optional$ref?: string
  • optional$schema?: string
  • optional$vocabulary?: string
  • optionaladditionalItems?: Schema
  • optionaladditionalProperties?: Schema
  • optionalallOf?: Schema[]
  • optionalanyOf?: Schema[]
  • optionalconst?: Json
  • optionalcontains?: Schema
  • optionalcontentEncoding?: string
  • optionalcontentMediaType?: string
  • optionalcontentSchema?: Schema
  • optionaldefault?: Json
  • optionaldefinitions?: {}
  • optionaldependencies?: {}
    • [id string]: string[] | Schema
  • optionaldependentRequired?: {}
    • [id string]: string[]
  • optionaldependentSchemas?: {}
  • optionaldeprecated?: boolean
  • optionaldescription?: string
  • optionaldiscriminator?: { mapping?: {}; propertyName: string }
    • optionalmapping?: {}
      • [value string]: string
    • propertyName: string
  • optionaldivisibleBy?: number
  • optionalelse?: Schema
  • optionalenum?: Json[]
  • optionalreadonlyeth?: string
  • optionalexamples?: Json[]
  • optionalexclusiveMaximum?: number | boolean
  • optionalexclusiveMinimum?: number | boolean
  • optionalformat?: string
  • optionalid?: string
  • optionalif?: Schema
  • optionalitems?: Schema | Schema[]
  • optionalmaxContains?: number
  • optionalmaxItems?: number
  • optionalmaxLength?: number
  • optionalmaxProperties?: number
  • optionalmaximum?: number
  • optionalminContains?: number
  • optionalminItems?: number
  • optionalminLength?: number
  • optionalminProperties?: number
  • optionalminimum?: number
  • optionalmultipleOf?: number
  • optionalnot?: Schema
  • optionaloneOf?: Schema[]
  • optionalpattern?: string
  • optionalpatternProperties?: {}
  • optionalproperties?: {}
  • optionalpropertyNames?: Schema
  • optionalreadOnly?: boolean
  • optionalrequired?: string[] | boolean
  • optionalthen?: Schema
  • optionaltitle?: string
  • optionaltype?: string | string[]
  • optionalunevaluatedItems?: Schema
  • optionalunevaluatedProperties?: Schema
  • optionaluniqueItems?: boolean
  • optionalwriteOnly?: boolean

ShortValidationSchema

ShortValidationSchema: ReadonlyArray<string | EthBaseTypes | EthExtendedTypes | EthBaseTypesWithMeta | ShortValidationSchema>

ValidInputTypes

ValidInputTypes: Uint8Array | bigint | string | number | boolean

ValidationError

ValidationError: ZodIssueBase

ValidationSchemaInput

Web3ValidationOptions

Web3ValidationOptions: { silent: boolean }

Type declaration

  • readonlysilent: boolean

Variables

constVALID_ETH_BASE_TYPES

VALID_ETH_BASE_TYPES: string[]

constvalidator

validator: Web3Validator

Functions

checkAddressCheckSum

  • checkAddressCheckSum(data: string): boolean
  • Checks the checksum of a given address. Will also return false on non-checksum addresses.


    Parameters

    • data: string

    Returns boolean

isAddress

  • Checks if a given string is a valid Ethereum address. It will also check the checksum, if the address has upper and lowercase letters.


    Parameters

    Returns boolean

isBigInt

  • Checks if a given value is a valid big int


    Parameters

    Returns boolean

isBlockNumber

  • isBlockNumber(value: string | number | bigint): boolean
  • Parameters

    • value: string | number | bigint

    Returns boolean

isBlockNumberOrTag

  • isBlockNumberOrTag(value: string | number | bigint): boolean
  • Returns true if given value is valid hex string and not negative, or is a valid BlockTag


    Parameters

    • value: string | number | bigint

    Returns boolean

isBlockTag

  • isBlockTag(value: string): boolean
  • Returns true if the given blockNumber is 'latest', 'pending', 'earliest, 'safe' or 'finalized'


    Parameters

    • value: string

    Returns boolean

isBloom

isBoolean

isBytes

  • isBytes(value: number[] | ValidInputTypes, options?: { abiType: string; size?: undefined } | { abiType?: undefined; size: number }): boolean
  • Parameters

    • value: number[] | ValidInputTypes
    • optionaloptions: { abiType: string; size?: undefined } | { abiType?: undefined; size: number }
      • abiType: string
      • optionalsize: undefined
      • optionalabiType: undefined
      • size: number

    Returns boolean

isContractAddressInBloom

  • isContractAddressInBloom(bloom: string, contractAddress: string): boolean
  • Returns true if the contract address is part of the given bloom. note: false positives are possible.


    Parameters

    • bloom: string
    • contractAddress: string

    Returns boolean

isFilterObject

  • isFilterObject(value: Filter): boolean
  • First we check if all properties in the provided value are expected, then because all Filter properties are optional, we check if the expected properties are defined. If defined and they're not the expected type, we immediately return false, otherwise we return true after all checks pass.


    Parameters

    Returns boolean

isHex

isHexPrefixed

  • isHexPrefixed(str: string): boolean
  • Returns a Boolean on whether or not the a String starts with '0x'

    @throws

    if the str input is not a string


    Parameters

    • str: string

      the string input value

    Returns boolean

    a boolean if it is or is not hex prefixed

isHexStrict

isHexString

  • isHexString(value: string, length?: number): boolean
  • Is the string a hex string.


    Parameters

    • value: string
    • optionallength: number

    Returns boolean

    output the string is a hex string

isHexString32Bytes

  • isHexString32Bytes(value: string, prefixed?: boolean): boolean
  • Parameters

    • value: string
    • optionalprefixed: boolean

    Returns boolean

isHexString8Bytes

  • isHexString8Bytes(value: string, prefixed?: boolean): boolean
  • Parameters

    • value: string
    • optionalprefixed: boolean

    Returns boolean

isInBloom

  • isInBloom(bloom: string, value: string | Uint8Array): boolean
  • Returns true if the value is part of the given bloom note: false positives are possible.


    Parameters

    • bloom: string
    • value: string | Uint8Array

    Returns boolean

isInt

  • isInt(value: ValidInputTypes, options?: { abiType: string; bitSize?: undefined } | { abiType?: undefined; bitSize: number }): boolean
  • Parameters

    • value: ValidInputTypes
    • optionaloptions: { abiType: string; bitSize?: undefined } | { abiType?: undefined; bitSize: number }
      • abiType: string
      • optionalbitSize: undefined
      • optionalabiType: undefined
      • bitSize: number

    Returns boolean

isNullish

  • isNullish(item: unknown): item is undefined | null
  • Parameters

    • item: unknown

    Returns item is undefined | null

isNumber

isObject

  • isObject(item: unknown): item is Record<string, unknown>
  • Parameters

    • item: unknown

    Returns item is Record<string, unknown>

isString

  • checks input if typeof data is valid string input


    Parameters

    Returns value is string

isTopic

  • isTopic(topic: string): boolean
  • Checks if its a valid topic


    Parameters

    • topic: string

    Returns boolean

isTopicInBloom

  • isTopicInBloom(bloom: string, topic: string): boolean
  • Returns true if the topic is part of the given bloom. note: false positives are possible.


    Parameters

    • bloom: string
    • topic: string

    Returns boolean

isUInt

  • isUInt(value: ValidInputTypes, options?: { abiType: string; bitSize?: undefined } | { abiType?: undefined; bitSize: number }): boolean
  • Parameters

    • value: ValidInputTypes
    • optionaloptions: { abiType: string; bitSize?: undefined } | { abiType?: undefined; bitSize: number }
      • abiType: string
      • optionalbitSize: undefined
      • optionalabiType: undefined
      • bitSize: number

    Returns boolean

isUint8Array

  • checks input if typeof data is valid Uint8Array input


    Parameters

    Returns data is Uint8Array

isUserEthereumAddressInBloom

  • isUserEthereumAddressInBloom(bloom: string, ethereumAddress: string): boolean
  • Returns true if the ethereum users address is part of the given bloom note: false positives are possible.


    Parameters

    • bloom: string
    • ethereumAddress: string

    Returns boolean

isValidEthBaseType

  • isValidEthBaseType(type: string): boolean
  • Parameters

    • type: string

    Returns boolean

validateNoLeadingZeroes

  • validateNoLeadingZeroes(values: {}): void
  • Checks provided Uint8Array for leading zeroes and throws if found.

    Examples:

    Valid values: 0x1, 0x, 0x01, 0x1234 Invalid values: 0x0, 0x00, 0x001, 0x0001

    Note: This method is useful for validating that RLP encoded integers comply with the rule that all integer values encoded to RLP must be in the most compact form and contain no leading zero bytes

    @throws

    if any provided value is found to have leading zero bytes


    Parameters

    • values: {}

      An object containing string keys and Uint8Array values

      Returns void