Skip to content

Commit

Permalink
Merge branch '4.x' into release/4.0.1-alpha.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevcs committed Nov 3, 2022
2 parents 2320850 + ca536a4 commit a754e3a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/web3-validator/src/web3_validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import Ajv from 'ajv';
import { blake2b } from 'ethereum-cryptography/blake2b';
import { utf8ToBytes, toHex } from 'ethereum-cryptography/utils';
import { ethAbiToJsonSchema } from './utils';
import { ValidationSchemaInput, Web3ValidationErrorObject, Web3ValidationOptions } from './types';
import { ethKeyword } from './keywords/eth';
Expand Down Expand Up @@ -98,7 +100,11 @@ export class Web3Validator {
]);
}

if (!this._validator.validate(jsonSchema, data)) {
const schemaKey = toHex(blake2b(utf8ToBytes(JSON.stringify(jsonSchema))));
if (!this._validator.getSchema(schemaKey)) {
this._validator.addSchema(jsonSchema, schemaKey);
}
if (!this._validator.validate(schemaKey, data)) {
const errors = this._validator.errors as Web3ValidationErrorObject[];

if (options?.silent) {
Expand Down

0 comments on commit a754e3a

Please sign in to comment.