Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Schema, SchemaValidator } from '@0x/json-schemas';
import { Order, SignedOrder, SignedZeroExTransaction, ZeroExTransaction } from '@0x/types';
import * as ethUtil from 'ethereumjs-util';
import { ValidationError as SchemaValidationError } from 'jsonschema';
import * as _ from 'lodash';
import { ValidationError, ValidationErrorCodes, ValidationErrorItem } from './errors';
import { Configs } from './types';
const schemaValidator = new SchemaValidator();
export const utils = {
log: (...args: any[]) => {
// tslint:disable-next-line:no-console
console.log(...args);
},
validateSchema(instance: any, schema: Schema): void {
const validationResult = schemaValidator.validate(instance, schema);
if (_.isEmpty(validationResult.errors)) {
return;
} else {
const validationErrorItems = _.map(
validationResult.errors,
(schemaValidationError: SchemaValidationError) =>
schemaValidationErrorToValidationErrorItem(schemaValidationError),
);
import { SchemaValidator } from '@0x/json-schemas';
import { orderMetadataSchema } from 'ts/schemas/metadata_schema';
import { portalOrderSchema } from 'ts/schemas/portal_order_schema';
import { portalTokenMetadataSchema } from 'ts/schemas/portal_token_metadata';
const validator = new SchemaValidator();
validator.addSchema(portalTokenMetadataSchema);
validator.addSchema(orderMetadataSchema);
validator.addSchema(portalOrderSchema);
export { validator };
doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void {
if (value === undefined) {
throw new Error(`${variableName} can't be undefined`);
}
const schemaValidator = new SchemaValidator();
if (subSchemas !== undefined) {
_.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator));
}
const validationResult = schemaValidator.validate(value, schema);
const hasValidationErrors = validationResult.errors.length > 0;
const msg = `Expected ${variableName} to conform to schema ${schema.id}
Encountered: ${JSON.stringify(value, null, '\t')}
Validation errors: ${validationResult.errors.join(', ')}`;
assert.assert(!hasValidationErrors, msg);
},
isWebUri(variableName: string, value: any): void {