Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

web3-validator

Package Overview
Dependencies
Maintainers
5
Versions
356
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-validator - npm Package Compare versions

Comparing version 2.0.7-dev.2f24244.0 to 2.0.7-dev.32c8cc8.0

lib/commonjs/tsconfig.cjs.tsbuildinfo

24

lib/commonjs/types.d.ts
import { AbiParameter } from 'web3-types';
import { ZodIssueBase } from 'zod';
export declare type ValidInputTypes = Uint8Array | bigint | string | number | boolean;
export declare type EthBaseTypes = 'bool' | 'bytes' | 'string' | 'uint' | 'int' | 'address' | 'tuple';
export declare type 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}]`;
export declare type EthExtendedTypes = 'hex' | 'number' | 'blockNumber' | 'blockNumberOrTag' | 'filter' | 'bloom';
export declare type FullValidationSchema = ReadonlyArray<AbiParameter>;
export declare type ShortValidationSchema = ReadonlyArray<string | EthBaseTypes | EthExtendedTypes | EthBaseTypesWithMeta | ShortValidationSchema>;
export declare type ValidationSchemaInput = FullValidationSchema | ShortValidationSchema;
export declare type Web3ValidationOptions = {
export type ValidInputTypes = Uint8Array | bigint | string | number | boolean;
export type EthBaseTypes = 'bool' | 'bytes' | 'string' | 'uint' | 'int' | 'address' | 'tuple';
export type 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}]`;
export type EthExtendedTypes = 'hex' | 'number' | 'blockNumber' | 'blockNumberOrTag' | 'filter' | 'bloom';
export type FullValidationSchema = ReadonlyArray<AbiParameter>;
export type ShortValidationSchema = ReadonlyArray<string | EthBaseTypes | EthExtendedTypes | EthBaseTypesWithMeta | ShortValidationSchema>;
export type ValidationSchemaInput = FullValidationSchema | ShortValidationSchema;
export type Web3ValidationOptions = {
readonly silent: boolean;
};
export declare type Json = string | number | boolean | Array<Json> | {
export type Json = string | number | boolean | Array<Json> | {
[id: string]: Json;
};
export declare type ValidationError = ZodIssueBase;
export type ValidationError = ZodIssueBase;
export interface Validate {

@@ -21,3 +21,3 @@ (value: Json): boolean;

}
export declare type Schema = {
export type Schema = {
$schema?: string;

@@ -106,2 +106,2 @@ $vocabulary?: string;

};
export declare type JsonSchema = Schema;
export type JsonSchema = Schema;
import { FullValidationSchema, ShortValidationSchema, ValidationSchemaInput, ValidInputTypes } from './types.js';
export declare const parseBaseType: <T = string>(type: string) => {
baseType?: T | undefined;
baseType?: T;
baseTypeSize: number | undefined;

@@ -5,0 +5,0 @@ arraySizes: number[];

@@ -19,3 +19,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureIfUint8Array = exports.hexToUint8Array = exports.uint8ArrayToHexString = exports.padLeft = exports.numberToHex = exports.hexToNumber = exports.codePointToInt = exports.transformJsonDataToAbiFormat = exports.fetchArrayElement = exports.ethAbiToJsonSchema = exports.abiSchemaToJsonSchema = exports.parseBaseType = void 0;
exports.padLeft = exports.numberToHex = exports.hexToNumber = exports.codePointToInt = exports.transformJsonDataToAbiFormat = exports.fetchArrayElement = exports.ethAbiToJsonSchema = exports.abiSchemaToJsonSchema = exports.parseBaseType = void 0;
exports.uint8ArrayToHexString = uint8ArrayToHexString;
exports.hexToUint8Array = hexToUint8Array;
exports.ensureIfUint8Array = ensureIfUint8Array;
const web3_errors_1 = require("web3-errors");

@@ -351,3 +354,2 @@ const constants_js_1 = require("./constants.js");

}
exports.uint8ArrayToHexString = uint8ArrayToHexString;
// for optimized technique for hex to bytes conversion

@@ -393,3 +395,2 @@ const charCodeMap = {

}
exports.hexToUint8Array = hexToUint8Array;
// @TODO: Remove this function and its usages once all sub dependencies uses version 1.3.3 or above of @noble/hashes

@@ -404,3 +405,2 @@ function ensureIfUint8Array(data) {

}
exports.ensureIfUint8Array = ensureIfUint8Array;
//# sourceMappingURL=utils.js.map

@@ -25,3 +25,8 @@ "use strict";

*/
const isUint8Array = (data) => { var _a, _b; return data instanceof Uint8Array || ((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Uint8Array' || ((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === 'Buffer'; };
const isUint8Array = (data) => {
var _a, _b;
return data instanceof Uint8Array ||
((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Uint8Array' ||
((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === 'Buffer';
};
exports.isUint8Array = isUint8Array;

@@ -28,0 +33,0 @@ const isBytes = (value, options = {

@@ -1,2 +0,2 @@

export declare const isNullish: (item: unknown) => item is null | undefined;
export declare const isNullish: (item: unknown) => item is undefined | null;
export declare const isObject: (item: unknown) => item is Record<string, unknown>;

@@ -5,3 +5,3 @@ import { ValidInputTypes } from '../types.js';

*/
export declare const isString: (value: ValidInputTypes) => boolean;
export declare const isString: (value: ValidInputTypes) => value is string;
export declare const isHexStrict: (hex: ValidInputTypes) => boolean;

@@ -8,0 +8,0 @@ /**

@@ -19,3 +19,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.validateNoLeadingZeroes = exports.isHexPrefixed = exports.isHexString32Bytes = exports.isHexString8Bytes = exports.isHex = exports.isHexString = exports.isHexStrict = exports.isString = void 0;
exports.validateNoLeadingZeroes = exports.isHexString32Bytes = exports.isHexString8Bytes = exports.isHex = exports.isHexStrict = exports.isString = void 0;
exports.isHexString = isHexString;
exports.isHexPrefixed = isHexPrefixed;
/**

@@ -42,3 +44,2 @@ * checks input if typeof data is valid string input

}
exports.isHexString = isHexString;
const isHex = (hex) => typeof hex === 'number' ||

@@ -64,3 +65,2 @@ typeof hex === 'bigint' ||

}
exports.isHexPrefixed = isHexPrefixed;
/**

@@ -67,0 +67,0 @@ * Checks provided Uint8Array for leading zeroes and throws if found.

@@ -8,4 +8,4 @@ import { Web3ValidationErrorObject } from 'web3-types';

silent?: boolean;
}): Web3ValidationErrorObject<string, Record<string, any>, unknown>[] | undefined;
}): Web3ValidationErrorObject[] | undefined;
private convertErrors;
}

@@ -45,5 +45,6 @@ "use strict";

if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && (schema === null || schema === void 0 ? void 0 : schema.items)) {
if (Array.isArray(schema.items) && schema.items.length > 1
&& schema.maxItems !== undefined
&& new Set(schema.items.map((item) => item.$id)).size === schema.items.length) {
if (Array.isArray(schema.items) &&
schema.items.length > 1 &&
schema.maxItems !== undefined &&
new Set(schema.items.map((item) => item.$id)).size === schema.items.length) {
const arr = [];

@@ -60,4 +61,6 @@ for (const item of schema.items) {

let zodArraySchema = zod_1.z.array(convertToZod(nextSchema));
zodArraySchema = schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema;
zodArraySchema = schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema;
zodArraySchema =
schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema;
zodArraySchema =
schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema;
return zodArraySchema;

@@ -64,0 +67,0 @@ }

@@ -22,3 +22,8 @@ /*

*/
export const isUint8Array = (data) => { var _a, _b; return data instanceof Uint8Array || ((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Uint8Array' || ((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === 'Buffer'; };
export const isUint8Array = (data) => {
var _a, _b;
return data instanceof Uint8Array ||
((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Uint8Array' ||
((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === 'Buffer';
};
export const isBytes = (value, options = {

@@ -25,0 +30,0 @@ abiType: 'bytes',

@@ -39,5 +39,6 @@ /*

if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && (schema === null || schema === void 0 ? void 0 : schema.items)) {
if (Array.isArray(schema.items) && schema.items.length > 1
&& schema.maxItems !== undefined
&& new Set(schema.items.map((item) => item.$id)).size === schema.items.length) {
if (Array.isArray(schema.items) &&
schema.items.length > 1 &&
schema.maxItems !== undefined &&
new Set(schema.items.map((item) => item.$id)).size === schema.items.length) {
const arr = [];

@@ -54,4 +55,6 @@ for (const item of schema.items) {

let zodArraySchema = z.array(convertToZod(nextSchema));
zodArraySchema = schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema;
zodArraySchema = schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema;
zodArraySchema =
schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema;
zodArraySchema =
schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema;
return zodArraySchema;

@@ -58,0 +61,0 @@ }

import { AbiParameter } from 'web3-types';
import { ZodIssueBase } from 'zod';
export declare type ValidInputTypes = Uint8Array | bigint | string | number | boolean;
export declare type EthBaseTypes = 'bool' | 'bytes' | 'string' | 'uint' | 'int' | 'address' | 'tuple';
export declare type 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}]`;
export declare type EthExtendedTypes = 'hex' | 'number' | 'blockNumber' | 'blockNumberOrTag' | 'filter' | 'bloom';
export declare type FullValidationSchema = ReadonlyArray<AbiParameter>;
export declare type ShortValidationSchema = ReadonlyArray<string | EthBaseTypes | EthExtendedTypes | EthBaseTypesWithMeta | ShortValidationSchema>;
export declare type ValidationSchemaInput = FullValidationSchema | ShortValidationSchema;
export declare type Web3ValidationOptions = {
export type ValidInputTypes = Uint8Array | bigint | string | number | boolean;
export type EthBaseTypes = 'bool' | 'bytes' | 'string' | 'uint' | 'int' | 'address' | 'tuple';
export type 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}]`;
export type EthExtendedTypes = 'hex' | 'number' | 'blockNumber' | 'blockNumberOrTag' | 'filter' | 'bloom';
export type FullValidationSchema = ReadonlyArray<AbiParameter>;
export type ShortValidationSchema = ReadonlyArray<string | EthBaseTypes | EthExtendedTypes | EthBaseTypesWithMeta | ShortValidationSchema>;
export type ValidationSchemaInput = FullValidationSchema | ShortValidationSchema;
export type Web3ValidationOptions = {
readonly silent: boolean;
};
export declare type Json = string | number | boolean | Array<Json> | {
export type Json = string | number | boolean | Array<Json> | {
[id: string]: Json;
};
export declare type ValidationError = ZodIssueBase;
export type ValidationError = ZodIssueBase;
export interface Validate {

@@ -21,3 +21,3 @@ (value: Json): boolean;

}
export declare type Schema = {
export type Schema = {
$schema?: string;

@@ -106,3 +106,3 @@ $vocabulary?: string;

};
export declare type JsonSchema = Schema;
export type JsonSchema = Schema;
//# sourceMappingURL=types.d.ts.map
import { FullValidationSchema, ShortValidationSchema, ValidationSchemaInput, ValidInputTypes } from './types.js';
export declare const parseBaseType: <T = string>(type: string) => {
baseType?: T | undefined;
baseType?: T;
baseTypeSize: number | undefined;

@@ -5,0 +5,0 @@ arraySizes: number[];

@@ -1,3 +0,3 @@

export declare const isNullish: (item: unknown) => item is null | undefined;
export declare const isNullish: (item: unknown) => item is undefined | null;
export declare const isObject: (item: unknown) => item is Record<string, unknown>;
//# sourceMappingURL=object.d.ts.map

@@ -5,3 +5,3 @@ import { ValidInputTypes } from '../types.js';

*/
export declare const isString: (value: ValidInputTypes) => boolean;
export declare const isString: (value: ValidInputTypes) => value is string;
export declare const isHexStrict: (hex: ValidInputTypes) => boolean;

@@ -8,0 +8,0 @@ /**

@@ -8,5 +8,5 @@ import { Web3ValidationErrorObject } from 'web3-types';

silent?: boolean;
}): Web3ValidationErrorObject<string, Record<string, any>, unknown>[] | undefined;
}): Web3ValidationErrorObject[] | undefined;
private convertErrors;
}
//# sourceMappingURL=validator.d.ts.map
{
"name": "web3-validator",
"version": "2.0.7-dev.2f24244.0+2f24244",
"version": "2.0.7-dev.32c8cc8.0+32c8cc8",
"description": "JSON-Schema compatible validator for web3",

@@ -49,4 +49,4 @@ "main": "./lib/commonjs/index.js",

"util": "^0.12.5",
"web3-errors": "1.3.1-dev.2f24244.0+2f24244",
"web3-types": "1.7.1-dev.2f24244.0+2f24244",
"web3-errors": "1.3.1-dev.32c8cc8.0+32c8cc8",
"web3-types": "1.8.1-dev.32c8cc8.0+32c8cc8",
"zod": "^3.21.4"

@@ -66,5 +66,5 @@ },

"ts-jest": "^29.1.1",
"typescript": "^4.7.4"
"typescript": "^5.5.4"
},
"gitHead": "2f2424487a6ba2865b5a381f22f83500a3133cda"
"gitHead": "32c8cc8cc8cdf0dc6c2e331b6463bccef37c3ce6"
}

@@ -209,21 +209,21 @@ /*

} else if (baseType === 'tuple' && isArray) {
const arraySize = arraySizes[0];
const item: JsonSchema = {
type: 'array',
$id: abiName,
items: abiSchemaToJsonSchema(abiComponents, abiName),
...(arraySize >= 0 && { minItems: arraySize, maxItems: arraySize }),
};
const arraySize = arraySizes[0];
const item: JsonSchema = {
type: 'array',
$id: abiName,
items: abiSchemaToJsonSchema(abiComponents, abiName),
...(arraySize >= 0 && { minItems: arraySize, maxItems: arraySize }),
};
(lastSchema.items as JsonSchema[]).push(item);
(lastSchema.items as JsonSchema[]).push(item);
} else if (isArray) {
const arraySize = arraySizes[0];
const item: JsonSchema = {
type: 'array',
$id: abiName,
items: convertEthType(abiType),
...(arraySize >= 0 && { minItems: arraySize, maxItems: arraySize }),
};
const arraySize = arraySizes[0];
const item: JsonSchema = {
type: 'array',
$id: abiName,
items: convertEthType(abiType),
...(arraySize >= 0 && { minItems: arraySize, maxItems: arraySize }),
};
(lastSchema.items as JsonSchema[]).push(item);
(lastSchema.items as JsonSchema[]).push(item);
} else if (Array.isArray(lastSchema.items)) {

@@ -450,13 +450,10 @@ // Array of non-tuple items

f: 102,
} as const
} as const;
function charCodeToBase16(char: number) {
if (char >= charCodeMap.zero && char <= charCodeMap.nine)
return char - charCodeMap.zero
if (char >= charCodeMap.A && char <= charCodeMap.F)
return char - (charCodeMap.A - 10)
if (char >= charCodeMap.a && char <= charCodeMap.f)
return char - (charCodeMap.a - 10)
return undefined
}
function charCodeToBase16(char: number) {
if (char >= charCodeMap.zero && char <= charCodeMap.nine) return char - charCodeMap.zero;
if (char >= charCodeMap.A && char <= charCodeMap.F) return char - (charCodeMap.A - 10);
if (char >= charCodeMap.a && char <= charCodeMap.f) return char - (charCodeMap.a - 10);
return undefined;
}

@@ -473,17 +470,15 @@ export function hexToUint8Array(hex: string): Uint8Array {

const bytes = new Uint8Array(length);
for (let index = 0, j = offset; index < length; index+=1) {
// eslint-disable-next-line no-plusplus
const nibbleLeft = charCodeToBase16(hex.charCodeAt(j++))
// eslint-disable-next-line no-plusplus
const nibbleRight = charCodeToBase16(hex.charCodeAt(j++))
if (nibbleLeft === undefined || nibbleRight === undefined) {
throw new InvalidBytesError(
`Invalid byte sequence ("${hex[j - 2]}${
hex[j - 1]
}" in "${hex}").`,
)
}
bytes[index] = nibbleLeft * 16 + nibbleRight
for (let index = 0, j = offset; index < length; index += 1) {
// eslint-disable-next-line no-plusplus
const nibbleLeft = charCodeToBase16(hex.charCodeAt(j++));
// eslint-disable-next-line no-plusplus
const nibbleRight = charCodeToBase16(hex.charCodeAt(j++));
if (nibbleLeft === undefined || nibbleRight === undefined) {
throw new InvalidBytesError(
`Invalid byte sequence ("${hex[j - 2]}${hex[j - 1]}" in "${hex}").`,
);
}
bytes[index] = nibbleLeft * 16 + nibbleRight;
}
return bytes
return bytes;
}

@@ -490,0 +485,0 @@

@@ -26,3 +26,5 @@ /*

export const isUint8Array = (data: ValidInputTypes): data is Uint8Array =>
data instanceof Uint8Array || data?.constructor?.name === 'Uint8Array' || data?.constructor?.name === 'Buffer';
data instanceof Uint8Array ||
data?.constructor?.name === 'Uint8Array' ||
data?.constructor?.name === 'Buffer';

@@ -29,0 +31,0 @@ export const isBytes = (

@@ -47,5 +47,8 @@ /*

if (schema?.type === 'array' && schema?.items) {
if (Array.isArray(schema.items) && schema.items.length > 1
&& schema.maxItems !== undefined
&& new Set(schema.items.map((item: JsonSchema) => item.$id)).size === schema.items.length) {
if (
Array.isArray(schema.items) &&
schema.items.length > 1 &&
schema.maxItems !== undefined &&
new Set(schema.items.map((item: JsonSchema) => item.$id)).size === schema.items.length
) {
const arr: Partial<[ZodTypeAny, ...ZodTypeAny[]]> = [];

@@ -61,6 +64,8 @@ for (const item of schema.items) {

const nextSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
let zodArraySchema = z.array(convertToZod(nextSchema));
let zodArraySchema = z.array(convertToZod(nextSchema));
zodArraySchema = schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema;
zodArraySchema = schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema;
zodArraySchema =
schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema;
zodArraySchema =
schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema;
return zodArraySchema;

@@ -67,0 +72,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc