How to use the @liskhq/lisk-cryptography.hexToBuffer 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 / protocol-specs / generators / multisignature / index.js View on Github external
const createSignatureObject = (txBuffer, account) => ({
	// publicKey: account.publicKey,
	signature: signData(
		hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
		account.passphrase,
	),
});
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / 9_second_signature_transaction.ts View on Github external
public sign(passphrase: string): void {
		this._signature = undefined;
		this._signSignature = undefined;
		const networkIdentifierBytes = hexToBuffer(this._networkIdentifier);
		const transactionWithNetworkIdentifierBytes = Buffer.concat([
			networkIdentifierBytes,
			this.getBytes(),
		]);
		this._signature = signData(
			hash(transactionWithNetworkIdentifierBytes),
			passphrase,
		);
		this._id = getId(this.getBytes());
	}
}
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / utils / validation / validation.ts View on Github external
export const validateNetworkIdentifier = (networkIdentifier: string) => {
	if (!networkIdentifier) {
		throw new Error(`Network identifier can not be empty.`);
	}
	const networkIdentifierBuffer = cryptography.hexToBuffer(networkIdentifier);
	if (networkIdentifierBuffer.length !== NETWORK_IDENTIFIER_LENGTH) {
		throw new Error(`Invalid network identifier length: ${networkIdentifier}`);
	}

	return true;
};
github LiskHQ / lisk-sdk / protocol-specs / generators / multisignature / index.js View on Github external
const serializeBasicProperties = tx => {
	const transactionTimestamp = Buffer.alloc(4);
	transactionTimestamp.writeIntBE(tx.timestamp, 0, 4);
	return Buffer.concat([
		Buffer.alloc(1, tx.type),
		transactionTimestamp,
		hexToBuffer(tx.senderPublicKey),
		intToBuffer(tx.asset.numberOfSignatures, 1),
		assetToBytes(tx),
	]);
};
github LiskArchive / lisk-elements / packages / lisk-blockchain / src / block.ts View on Github external
const totalAmountBuffer = new BigNum(this.totalAmount).toBuffer({
			endian: 'little',
			size: SIZE_INT64,
		});
		const totalFeeBuffer = new BigNum(this.totalFee).toBuffer({
			endian: 'little',
			size: SIZE_INT64,
		});
		const rewardBuffer = new BigNum(this.reward).toBuffer({
			endian: 'little',
			size: SIZE_INT64,
		});
		const payloadLengthBuffer = Buffer.alloc(SIZE_INT32);
		payloadLengthBuffer.writeInt32LE(this.payloadLength, 0);
		const payloadHashBuffer = hexToBuffer(this.payloadHash);
		const generatorPublicKeyBuffer = hexToBuffer(this.generatorPublicKey);

		return Buffer.concat([
			versionBuffer,
			timestampBuffer,
			prevBlockBuffer,
			numTxBuffer,
			totalAmountBuffer,
			totalFeeBuffer,
			rewardBuffer,
			payloadLengthBuffer,
			payloadHashBuffer,
			generatorPublicKeyBuffer,
		]);
	}
}
github LiskHQ / lisk-sdk / framework / src / modules / chain / block_processor_v0.js View on Github external
LITTLE_ENDIAN,
	);

	const rewardBuffer = intToBuffer(
		block.reward.toString(),
		SIZE_INT64,
		LITTLE_ENDIAN,
	);

	const payloadLengthBuffer = intToBuffer(
		block.payloadLength,
		SIZE_INT32,
		LITTLE_ENDIAN,
	);

	const payloadHashBuffer = hexToBuffer(block.payloadHash);

	const generatorPublicKeyBuffer = hexToBuffer(block.generatorPublicKey);

	const blockSignatureBuffer = block.blockSignature
		? hexToBuffer(block.blockSignature)
		: Buffer.alloc(0);

	return Buffer.concat([
		blockVersionBuffer,
		timestampBuffer,
		previousBlockBuffer,
		numTransactionsBuffer,
		totalAmountBuffer,
		totalFeeBuffer,
		rewardBuffer,
		payloadLengthBuffer,
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / utils / get_transaction_bytes.ts View on Github external
if (amountBigNum.gt(new BigNum(MAX_TRANSACTION_AMOUNT))) {
		throw new Error('Transaction amount is too large.');
	}
	const transactionAmount = amountBigNum.toBuffer({
		endian: 'little',
		size: BYTESIZES.AMOUNT,
	});

	const transactionAssetData = getAssetBytes(transaction);

	const transactionSignature = signature
		? cryptography.hexToBuffer(signature)
		: Buffer.alloc(0);

	const transactionSecondSignature = signSignature
		? cryptography.hexToBuffer(signSignature)
		: Buffer.alloc(0);

	return Buffer.concat([
		transactionType,
		transactionTimestamp,
		transactionSenderPublicKey,
		transactionRecipientID,
		transactionAmount,
		transactionAssetData,
		transactionSignature,
		transactionSecondSignature,
	]);
};
github LiskHQ / lisk-sdk / protocol-specs / generators / multisignature / index.js View on Github external
tx.signatures.forEach(aSignature => {
		const signatureBuffer = Buffer.concat([
			Buffer.alloc(1, aSignature.index),
			hexToBuffer(aSignature.signature),
		]);
		txBufferCopy = Buffer.concat([txBufferCopy, signatureBuffer]);
	});
	return txBufferCopy;
github LiskHQ / lisk-sdk / framework / src / modules / chain / block_processor_v2.js View on Github external
LITTLE_ENDIAN,
	);

	const rewardBuffer = intToBuffer(
		block.reward.toString(),
		SIZE_INT64,
		LITTLE_ENDIAN,
	);

	const payloadLengthBuffer = intToBuffer(
		block.payloadLength,
		SIZE_INT32,
		LITTLE_ENDIAN,
	);

	const payloadHashBuffer = hexToBuffer(block.payloadHash);

	const generatorPublicKeyBuffer = hexToBuffer(block.generatorPublicKey);

	const blockSignatureBuffer = block.blockSignature
		? hexToBuffer(block.blockSignature)
		: Buffer.alloc(0);

	return Buffer.concat([
		blockVersionBuffer,
		timestampBuffer,
		previousBlockBuffer,
		heightBuffer,
		maxHeightPreviouslyForgedBuffer,
		maxHeightPrevotedBuffer,
		numTransactionsBuffer,
		totalAmountBuffer,
github LiskHQ / lisk-sdk / framework / src / modules / chain / blocks / block.js View on Github external
}
	}

	byteBuffer.writeInt(block.numberOfTransactions);
	byteBuffer.writeLong(block.totalAmount.toString());
	byteBuffer.writeLong(block.totalFee.toString());
	byteBuffer.writeLong(block.reward.toString());

	byteBuffer.writeInt(block.payloadLength);

	const payloadHashBuffer = hexToBuffer(block.payloadHash);
	for (let i = 0; i < payloadHashBuffer.length; i++) {
		byteBuffer.writeByte(payloadHashBuffer[i]);
	}

	const generatorPublicKeyBuffer = hexToBuffer(block.generatorPublicKey);
	for (let i = 0; i < generatorPublicKeyBuffer.length; i++) {
		byteBuffer.writeByte(generatorPublicKeyBuffer[i]);
	}

	if (block.blockSignature) {
		const blockSignatureBuffer = hexToBuffer(block.blockSignature);
		for (let i = 0; i < blockSignatureBuffer.length; i++) {
			byteBuffer.writeByte(blockSignatureBuffer[i]);
		}
	}

	byteBuffer.flip();
	return byteBuffer.toBuffer();
};