validator
Index
References
Namespaces
Classes
Interfaces
Type Aliases
Variables
Functions
- checkAddressCheckSum
- isAddress
- isBigInt
- isBlockNumber
- isBlockNumberOrTag
- isBlockTag
- isBloom
- isBoolean
- isBytes
- isContractAddressInBloom
- isFilterObject
- isHex
- isHexPrefixed
- isHexStrict
- isHexString
- isHexString32Bytes
- isHexString8Bytes
- isInBloom
- isInt
- isNullish
- isNumber
- isObject
- isString
- isTopic
- isTopicInBloom
- isUInt
- isUint8Array
- isUserEthereumAddressInBloom
- isValidEthBaseType
- validateNoLeadingZeroes
References
Web3Validator
Namespaces
utils
abiSchemaToJsonSchema
Parameters
abis: FullValidationSchema | ShortValidationSchema
optionallevel: string
Returns Schema
codePointToInt
Parameters
codePoint: number
Returns number
ensureIfUint8Array
Type parameters
- T = any
Parameters
data: T
Returns Uint8Array | T
ethAbiToJsonSchema
Parameters
abis: ValidationSchemaInput
Returns Schema
fetchArrayElement
Parameters
data: unknown[]
level: number
Returns unknown
hexToNumber
Converts value to it's number representation
Parameters
value: string
Returns number | bigint
hexToUint8Array
Parameters
hex: string
Returns Uint8Array
numberToHex
Converts value to it's hex representation
Parameters
value: ValidInputTypes
Returns string
padLeft
Adds a padding on the left of a string, if value is a integer or bigInt will be converted to a hex string.
Parameters
value: ValidInputTypes
characterAmount: number
optionalsign: string
Returns string
parseBaseType
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
Parameters
abis: FullValidationSchema
data: Record<string, unknown> | readonly unknown[]
optionaltransformedData: unknown[]
Returns unknown[]
uint8ArrayToHexString
Parameters
uint8Array: Uint8Array
Returns string
Classes
Web3ValidatorError
Base class for Web3 errors.
constructor
Parameters
errors: Web3ValidationErrorObject<string, Record<string, any>, unknown>[]
Returns Web3ValidatorError
cause
code
readonlyerrors
readonlyname
stack
innerError
Returns undefined | Error | Error[]
Parameters
cause: undefined | Error | Error[]
Returns void
toJSON
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
Parameters
value: unknown
optionalunquotValue: boolean
Returns string
Interfaces
Validate
Parameters
value: Json
Returns boolean
optionalerrors
Type Aliases
EthBaseTypes
EthBaseTypesWithMeta
EthExtendedTypes
FullValidationSchema
Json
JsonSchema
Schema
Type declaration
optional$anchor?: string
optional$comment?: string
optional$defs?: {}
[id string]: Schema
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?: {}
[id string]: Schema
optionaldependencies?: {}
[id string]: string[] | Schema
optionaldependentRequired?: {}
[id string]: string[]
optionaldependentSchemas?: {}
[id string]: Schema
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?: {}
[pattern string]: Schema
optionalproperties?: {}
[id string]: Schema
optionalpropertyNames?: Schema
optionalreadOnly?: boolean
optionalrequired?: string[] | boolean
optionalthen?: Schema
optionaltitle?: string
optionaltype?: string | string[]
optionalunevaluatedItems?: Schema
optionalunevaluatedProperties?: Schema
optionaluniqueItems?: boolean
optionalwriteOnly?: boolean
ShortValidationSchema
ValidInputTypes
ValidationError
ValidationSchemaInput
Web3ValidationOptions
Type declaration
readonlysilent: boolean
Variables
constVALID_ETH_BASE_TYPES
constvalidator
Functions
checkAddressCheckSum
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
value: ValidInputTypes
optionalcheckChecksum: boolean
Returns boolean
isBigInt
Checks if a given value is a valid big int
Parameters
value: ValidInputTypes
Returns boolean
isBlockNumber
Parameters
value: string | number | bigint
Returns boolean
isBlockNumberOrTag
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
Returns true if the given blockNumber is 'latest', 'pending', 'earliest, 'safe' or 'finalized'
Parameters
value: string
Returns boolean
isBloom
Returns true if the bloom is a valid bloom https://github.com/joshstevens19/ethereum-bloom-filters/blob/fbeb47b70b46243c3963fe1c2988d7461ef17236/src/index.ts#L7
Parameters
bloom: ValidInputTypes
Returns boolean
isBoolean
Parameters
value: ValidInputTypes
Returns boolean
isBytes
Parameters
value: number[] | ValidInputTypes
optionaloptions: { abiType: string; size?: undefined } | { abiType?: undefined; size: number }
abiType: string
optionalsize: undefined
optionalabiType: undefined
size: number
Returns boolean
isContractAddressInBloom
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
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
value: Filter
Returns boolean
isHex
Parameters
hex: ValidInputTypes
Returns boolean
isHexPrefixed
Returns a
Boolean
on whether or not the aString
starts with '0x'Parameters
str: string
the string input value
Returns boolean
a boolean if it is or is not hex prefixed
isHexStrict
Parameters
hex: ValidInputTypes
Returns boolean
isHexString
Is the string a hex string.
Parameters
value: string
optionallength: number
Returns boolean
output the string is a hex string
isHexString32Bytes
Parameters
value: string
optionalprefixed: boolean
Returns boolean
isHexString8Bytes
Parameters
value: string
optionalprefixed: boolean
Returns boolean
isInBloom
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
Parameters
value: ValidInputTypes
optionaloptions: { abiType: string; bitSize?: undefined } | { abiType?: undefined; bitSize: number }
abiType: string
optionalbitSize: undefined
optionalabiType: undefined
bitSize: number
Returns boolean
isNullish
Parameters
item: unknown
Returns item is undefined | null
isNumber
Parameters
value: ValidInputTypes
Returns boolean
isObject
Parameters
item: unknown
Returns item is Record<string, unknown>
isString
checks input if typeof data is valid string input
Parameters
value: ValidInputTypes
Returns value is string
isTopic
Checks if its a valid topic
Parameters
topic: string
Returns boolean
isTopicInBloom
Returns true if the topic is part of the given bloom. note: false positives are possible.
Parameters
bloom: string
topic: string
Returns boolean
isUInt
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
data: ValidInputTypes
Returns data is Uint8Array
isUserEthereumAddressInBloom
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
Parameters
type: string
Returns boolean
validateNoLeadingZeroes
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
Parameters
values: {}
An object containing string keys and Uint8Array values
Returns void
Code points to int