web3-validator
Advanced tools
Comparing version 2.0.7-dev.973ee80.0 to 2.0.7-dev.984cb7c.0
@@ -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 = { |
@@ -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.973ee80.0+973ee80", | ||
"version": "2.0.7-dev.984cb7c.0+984cb7c", | ||
"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.973ee80.0+973ee80", | ||
"web3-types": "1.7.1-dev.973ee80.0+973ee80", | ||
"web3-errors": "1.3.1-dev.984cb7c.0+984cb7c", | ||
"web3-types": "1.9.1-dev.984cb7c.0+984cb7c", | ||
"zod": "^3.21.4" | ||
@@ -68,3 +68,3 @@ }, | ||
}, | ||
"gitHead": "973ee809d48a96441cbfd502f12915dcc0cb5dad" | ||
"gitHead": "984cb7cc3649f5aaca498921f4a40f20efde7c08" | ||
} |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
959365
5652