Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
web3-validator
Advanced tools
This is a sub-package of web3.js.
web3-validator
contains functions for validating objects.
You can install the package either using NPM or using Yarn
npm install web3-validator
yarn add web3-validator
You can use the the validator by importing as and using to validate;
import { validator } from 'web3-validator';
// To validate and throw
validator.validate(['uint8', 'string'], [val1, val2]);
// To validate and return error
const errors = validator.validate(['uint8', 'string'], [val1, val2], { silent: true });
To see more examples of schema you can use to validate check following file.
Following eth types are supported to validate.
Type | Input As | Description |
---|---|---|
uint | number , string , HexString | Unsigned integer, all ethereum compatible variants are also supported e.g. uint8 , uint256 . You can also use array specifiers as uint[] or uint[2] |
int | number , string , HexString | Signed integer, all ethereum compatible variants are also supported e.g. int8 , int256 . You can also use array specifiers as int[] or int[2] |
bytes | HexString , Uint8Array | Raw bytes. You can also use fixed length bytes as bytes[2] |
| string | string
| String values |
| address | string
, HexString
| Ethereum network compatible address |
| bloom | string
, HexString
| Check if a given string is a Eth bloom |
| tuple | array
| You can specify any tuple as nested arrays. e.g. ['uint', 'string']
. For a custom tuple or array tuple you can use syntax e.g. ['tuple[3]', ['uint', 'string']]
|
For the ethereum compatible data values should be passed as arrays e.g. for schema ['uint', 'string']
value should be passed as [2, 'my-string']
.
You can also pass full ABI schema for the validation. e.g.
[{ "name": "owner", "type": "address" }]
The implementation of the validator is extension of JSON-Schema-Draft07 with a custom keyword eth
. So you can use JSON-Schema compatible schema to validate any object based data as well.
Script | Description |
---|---|
clean | Uses rimraf to remove dist/ |
build | Uses tsc to build package and dependent packages |
lint | Uses eslint to lint package |
lint:fix | Uses eslint to check and fix any warnings |
format | Uses prettier to format the code |
test | Uses jest to run unit tests |
test:integration | Uses jest to run tests under /test/integration |
test:unit | Uses jest to run tests under /test/unit |
FAQs
JSON-Schema compatible validator for web3
The npm package web3-validator receives a total of 90,006 weekly downloads. As such, web3-validator popularity was classified as popular.
We found that web3-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.