Socket
Socket
Sign inDemoInstall

web3-validator

Package Overview
Dependencies
Maintainers
5
Versions
306
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.cbcfc18.0 to 2.0.7-dev.d6baee6.0

7

lib/commonjs/validation/bytes.js

@@ -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 = {

13

lib/commonjs/validator.js

@@ -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 @@ }

{
"name": "web3-validator",
"version": "2.0.7-dev.cbcfc18.0+cbcfc18",
"version": "2.0.7-dev.d6baee6.0+d6baee6",
"description": "JSON-Schema compatible validator for web3",

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

"util": "^0.12.5",
"web3-errors": "1.2.1-dev.cbcfc18.0+cbcfc18",
"web3-types": "1.7.1-dev.cbcfc18.0+cbcfc18",
"web3-errors": "1.3.1-dev.d6baee6.0+d6baee6",
"web3-types": "1.8.1-dev.d6baee6.0+d6baee6",
"zod": "^3.21.4"

@@ -68,3 +68,3 @@ },

},
"gitHead": "cbcfc1878502008349f805a2e82e9263a02b717e"
"gitHead": "d6baee6ca3b729d06cb262211a572fbe2361bf68"
}

@@ -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

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