How to use the @liskhq/lisk-validator.validator.validate function in @liskhq/lisk-validator

To help you get started, we’ve selected a few @liskhq/lisk-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LiskHQ / lisk-sdk / framework / src / controller / application.js View on Github external
constructor(genesisBlock, config = {}) {
		const errors = liskValidator.validate(genesisBlockSchema, genesisBlock);
		if (errors.length) {
			throw errors;
		}

		// Don't change the object parameters provided
		let appConfig = _.cloneDeep(config);

		if (!_.has(appConfig, 'app.label')) {
			_.set(
				appConfig,
				'app.label',
				`lisk-${genesisBlock.payloadHash.slice(0, 7)}`,
			);
		}

		if (!_.has(appConfig, 'components.logger.logFileName')) {
github LiskHQ / lisk-sdk / framework / src / modules / chain / transport / transport.js View on Github external
async handleRPCGetTransactions(data = {}, peerId) {
		await this._addRateLimit(
			'getTransactions',
			peerId,
			DEFAULT_RATE_LIMIT_FREQUENCY,
		);
		const errors = validator.validate(schemas.getTransactionsRequest, data);
		if (errors.length) {
			this.logger.warn(
				{ err: errors, peerId },
				'Received invalid transactions body',
			);
			await this.channel.invoke('network:applyPenalty', {
				peerId,
				penalty: 100,
			});
			throw errors;
		}

		const { transactionIds } = data;
		if (!transactionIds) {
			return {
				transactions: this.transactionPoolModule.getMergedTransactionList(
github LiskHQ / lisk-sdk / framework / src / modules / chain / transport / transport.js View on Github external
async handleEventPostSignatures(data, peerId) {
		await this._addRateLimit(
			'postSignatures',
			peerId,
			DEFAULT_RATE_LIMIT_FREQUENCY,
		);
		const errors = validator.validate(schemas.postSignatureEvent, data);

		if (errors.length) {
			this.logger.warn({ err: errors }, 'Invalid signatures body');
			await this.channel.invoke('network:applyPenalty', {
				peerId,
				penalty: 100,
			});
			throw errors;
		}

		for (const signature of data.signatures) {
			const signatureObjectErrors = validator.validate(
				schemas.signatureObject,
				signature,
			);
github LiskHQ / lisk-sdk / framework / src / modules / chain / block_processor_v2.js View on Github external
const validateSchema = ({ block }) => {
	const errors = validator.validate(blockSchema, block);
	if (errors.length) {
		throw errors;
	}
};
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / 9_second_signature_transaction.ts View on Github external
protected validateAsset(): ReadonlyArray {
		const schemaErrors = validator.validate(
			secondSignatureAssetFormatSchema,
			this.asset,
		);
		const errors = convertToAssetError(
			this.id,
			schemaErrors,
		) as TransactionError[];

		return errors;
	}
github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / block_v1.js View on Github external
const objectNormalize = (block, exceptions = {}) => {
	Object.keys(block).forEach(key => {
		if (block[key] === null || typeof block[key] === 'undefined') {
			delete block[key];
		}
	});

	const errors = validator.validate(blockSchema, block);
	if (errors.length) {
		throw errors;
	}

	const { transactionsResponses } = validateTransactions(exceptions)(
		block.transactions
	);
	const invalidTransactionResponse = transactionsResponses.find(
		transactionResponse => transactionResponse.status !== TransactionStatus.OK
	);
	if (invalidTransactionResponse) {
		throw invalidTransactionResponse.errors;
	}
	return block;
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / block_processor_v0.js View on Github external
const validateSchema = ({ block }) => {
	const errors = validator.validate(baseBlockSchema, block);
	if (errors.length) {
		throw errors;
	}
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / block_v2.js View on Github external
const objectNormalize = (block, exceptions = {}) => {
	Object.keys(block).forEach(key => {
		if (block[key] === null || typeof block[key] === 'undefined') {
			delete block[key];
		}
	});

	const errors = validator.validate(blockSchema, block);
	if (errors.length) {
		throw errors;
	}

	const { transactionsResponses } = validateTransactions(exceptions)(
		block.transactions
	);
	const invalidTransactionResponse = transactionsResponses.find(
		transactionResponse => transactionResponse.status !== TransactionStatus.OK
	);
	if (invalidTransactionResponse) {
		throw invalidTransactionResponse.errors;
	}
	return block;
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / transport / transport.js View on Github external
async handleRPCGetBlocksFromId(data, peerId) {
		const errors = validator.validate(schemas.getBlocksFromIdRequest, data);

		if (errors.length) {
			const error = `${errors[0].message}`;

			this.logger.warn(
				{
					err: error,
					req: data,
				},
				'getBlocksFromID request validation failed',
			);
			await this.channel.invoke('network:applyPenalty', {
				peerId,
				penalty: 100,
			});
			throw new Error(error);
github LiskHQ / lisk-sdk / framework / src / modules / chain / transport / transport.js View on Github external
async handleEventPostSignature(data) {
		const errors = validator.validate(schemas.signatureObject, data.signature);

		if (errors.length) {
			const error = new TransactionError(errors[0].message);
			return {
				code: 400,
				errors: [error],
			};
		}

		try {
			await this.transactionPoolModule.getTransactionAndProcessSignature(
				data.signature,
			);
			return {};
		} catch (err) {
			return {