How to use @liskhq/lisk-validator - 10 common examples

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 / elements / lisk-transactions / src / 8_transfer_transaction.ts View on Github external
public constructor(rawTransaction: unknown) {
		super(rawTransaction);
		const tx = (typeof rawTransaction === 'object' && rawTransaction !== null
			? rawTransaction
			: {}) as Partial;
		// Initializes to empty object if it doesn't exist
		if (tx.asset) {
			const rawAsset = tx.asset as RawAsset;
			this.asset = {
				data: rawAsset.data,
				recipientId: rawAsset.recipientId,
				amount: new BigNum(
					isPositiveNumberString(rawAsset.amount) ? rawAsset.amount : '0',
				),
			};
		} else {
			// tslint:disable-next-line no-object-literal-type-assertion
			this.asset = {
				amount: new BigNum('0'),
				recipientId: '',
			} as TransferAsset;
		}
	}
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 / commander / src / commands / transaction / create / multisignature.ts View on Github external
async run(): Promise {
		const {
			args,
			flags: {
				networkIdentifier: networkIdentifierSource,
				passphrase: passphraseSource,
				'second-passphrase': secondPassphraseSource,
				'no-signature': noSignature,
			},
		} = this.parse(MultisignatureCommand);

		const { lifetime, minimum, keysgroup: keysgroupStr }: Args = args;
		const keysgroup = keysgroupStr.split(',');

		validatePublicKeys(keysgroup);

		validateLifetime(lifetime);
		validateMinimum(minimum);

		const transactionLifetime = parseInt(lifetime, 10);
		const transactionMinimumConfirmations = parseInt(minimum, 10);
		const networkIdentifier = getNetworkIdentifierWithInput(
			networkIdentifierSource,
			this.userConfig.api.network,
		);
		const processFunction = processInputs(
			networkIdentifier,
			transactionLifetime,
			transactionMinimumConfirmations,
			keysgroup,
		);
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;
};