How to use the @liskhq/lisk-cryptography.hash 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 LiskArchive / lisk-elements / packages / lisk-dpos / src / delegate.ts View on Github external
delegateList: string[],
): ReadonlyArray => {
	// tslint:disable-next-line no-let
	let hashedRound = hash(round, 'utf8');
	const list = [...delegateList];
	const numberOfDelegates = delegateList.length;
	// tslint:disable-next-line
	for (let i = 0; i < numberOfDelegates; i++) {
		// tslint:disable-next-line
		for (let j = 0; j < 4 && i < numberOfDelegates; i++, j++) {
			const newIndex = hashedRound[j] % numberOfDelegates;
			const temp = list[newIndex];
			list[newIndex] = list[i];
			list[i] = temp;
		}
		hashedRound = hash(hashedRound, 'utf8');
	}

	return list;
};
github LiskArchive / lisk-elements / packages / lisk-dpos / src / delegate.ts View on Github external
export const generateDelegateList = (
	round: string,
	delegateList: string[],
): ReadonlyArray => {
	// tslint:disable-next-line no-let
	let hashedRound = hash(round, 'utf8');
	const list = [...delegateList];
	const numberOfDelegates = delegateList.length;
	// tslint:disable-next-line
	for (let i = 0; i < numberOfDelegates; i++) {
		// tslint:disable-next-line
		for (let j = 0; j < 4 && i < numberOfDelegates; i++, j++) {
			const newIndex = hashedRound[j] % numberOfDelegates;
			const temp = list[newIndex];
			list[newIndex] = list[i];
			list[i] = temp;
		}
		hashedRound = hash(hashedRound, 'utf8');
	}

	return list;
};
github LiskHQ / lisk-sdk / packages / lisk-transactions / src / transactions / helpers / verify_signature.ts View on Github external
signature: string,
	transaction: TransactionJSON,
	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 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-examples / packages / lisk-transactions / src / utils / get_transaction_hash.ts View on Github external
export const getTransactionHash = (transaction: TransactionJSON): Buffer => {
	const bytes = getTransactionBytes(transaction);

	return cryptography.hash(bytes);
};
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 LiskArchive / lisk-elements / packages / lisk-transactions / src / utils / get_transaction_hash.ts View on Github external
export const getTransactionHash = (transaction: BaseTransaction): Buffer => {
	const bytes = getTransactionBytes(transaction);

	return cryptography.hash(bytes);
};
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,
	};
};