How to use the @liskhq/lisk-cryptography.verifyData function in @liskhq/lisk-cryptography

To help you get started, we’ve selected a few @liskhq/lisk-cryptography 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 / packages / lisk-transactions / src / transactions / helpers / verify_signature.ts View on Github external
isSecondSignature: boolean = false,
): VerifyReturn => {
	const {
		signature: removedSignature,
		signSignature,
		...strippedTransaction
	} = transaction;

	// If transaction includes asset data, include those bytes
	const transactionBytes =
		transaction.asset && Object.keys(transaction.asset).length
			? getTransactionBytes(strippedTransaction as TransactionJSON)
			: getBytes(transaction, !isSecondSignature);
	const transactionHash = cryptography.hash(transactionBytes);

	const verified = cryptography.verifyData(
		transactionHash,
		signature,
		publicKey,
	);

	return {
		verified,
		error: !verified
			? new TransactionError(
					`Failed to verify signature ${signature}`,
					transaction.id,
					'.signature',
			  )
			: undefined,
	};
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / block_v1.js View on Github external
const verifySignature = block => {
	const signatureLength = 64;
	const data = getBytes(block);
	const dataWithoutSignature = Buffer.alloc(data.length - signatureLength);

	for (let i = 0; i < dataWithoutSignature.length; i++) {
		dataWithoutSignature[i] = data[i];
	}
	const hashedBlock = hash(dataWithoutSignature);
	return verifyData(
		hashedBlock,
		block.blockSignature,
		block.generatorPublicKey
	);
};
github jondubois / lisk-dex / index.js View on Github external
_verifySignature(targetChain, publicKey, transaction, signatureToVerify) {
    let isValidMemberSignature = this.multisigWalletInfo[targetChain].members[publicKey];
    if (!isValidMemberSignature) {
      return false;
    }
    let {signature, signSignature, ...transactionToHash} = transaction;
    let txnHash = liskCryptography.hash(liskTransactions.utils.getTransactionBytes(transactionToHash));
    return liskCryptography.verifyData(txnHash, signatureToVerify, publicKey);
  }
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / utils / sign_and_validate.ts View on Github external
export const validateSignature = (
	publicKey: string,
	signature: string,
	transactionBytes: Buffer,
	id?: string,
): IsValidResponseWithError => {
	const transactionHash = cryptography.hash(transactionBytes);

	const valid = cryptography.verifyData(transactionHash, signature, publicKey);

	return {
		valid,
		error: !valid
			? new TransactionError(
					`Failed to validate signature ${signature}`,
					id,
					'.signature',
			  )
			: undefined,
	};
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / validate.js View on Github external
const validateSignature = (block, blockBytes) => {
	const signatureLength = 64;
	const dataWithoutSignature = blockBytes.slice(
		0,
		blockBytes.length - signatureLength,
	);
	const hashedBlock = hash(dataWithoutSignature);

	const verified = verifyData(
		hashedBlock,
		block.blockSignature,
		block.generatorPublicKey,
	);

	if (!verified) {
		throw new Error('Invalid block signature');
	}
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / block_v2.js View on Github external
const verifySignature = block => {
	const signatureLength = 64;
	const data = getBytes(block);
	const dataWithoutSignature = Buffer.alloc(data.length - signatureLength);

	for (let i = 0; i < dataWithoutSignature.length; i++) {
		dataWithoutSignature[i] = data[i];
	}
	const hashedBlock = hash(dataWithoutSignature);
	return verifyData(
		hashedBlock,
		block.blockSignature,
		block.generatorPublicKey
	);
};
github LiskHQ / lisk-sdk / packages / lisk-transactions / src / utils / validate_multisignatures.ts View on Github external
(
						collectedSignatures: ReadonlyArray,
						signature: string,
					): ReadonlyArray => {
						if (
							cryptography.verifyData(transactionHash, signature, publicKey)
						) {
							checkedPublicKeys = [publicKey, ...checkedPublicKeys];
							validatedSignaturesCount++;

							return collectedSignatures;
						}

						return [signature, ...collectedSignatures];
					},
					[],
github LiskHQ / lisk-sdk / commander / src / commands / transaction / verify.ts View on Github external
);

		const secondPublicKey = secondPublicKeySource
			? await processSecondPublicKey(secondPublicKeySource)
			: undefined;

		if (!secondPublicKey) {
			const { errors } = txInstance.validate();
			this.print({
				verified: errors.length === 0,
			});

			return;
		}

		const verified = cryptography.verifyData(
			txInstance.getBytes(),
			signSignature,
			secondPublicKey,
		);

		this.print({ verified });
	}
}
github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / block.js View on Github external
const verifySignature = block => {
	const signatureLength = 64;
	const data = getBytes(block);
	const dataWithoutSignature = Buffer.alloc(data.length - signatureLength);

	for (let i = 0; i < dataWithoutSignature.length; i++) {
		dataWithoutSignature[i] = data[i];
	}
	const hashedBlock = hash(dataWithoutSignature);
	return verifyData(
		hashedBlock,
		block.blockSignature,
		block.generatorPublicKey
	);
};