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

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 / 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 / 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 LiskHQ / lisk-sdk / protocol-specs / generators / block_processing_votes / index.js View on Github external
publicKey:
			'caff2242b740a733daa3f3f96fc1592303b60c1704a8ac626e2704da039f41ee',
		address: '2222471382442610527L',
		balance: '0',
	},
};

// Decrypt all passwords from delegate genesis and add to accounts array
// eslint-disable-next-line no-restricted-syntax
for (const anAccount of genesisDelegateAccounts) {
	const { encryptedPassphrase } = defaultConfig.forging.delegates.find(
		aDelegate => aDelegate.publicKey === anAccount.publicKey,
	);

	const passphrase = decryptPassphraseWithPassword(
		parseEncryptedPassphrase(encryptedPassphrase),
		defaultConfig.forging.defaultPassword,
	);
	const keys = getPrivateAndPublicKeyFromPassphrase(passphrase);
	const address = getAddressFromPrivateKey(keys.privateKey);

	accounts[`${anAccount.username}_delegate`] = {
		passphrase,
		privateKey: keys.privateKey,
		publicKey: keys.publicKey,
		address,
		balance: '0',
	};
}

// Generators
const generateTestCasesValidBlockVotesTx = () => {
github LiskHQ / lisk-sdk / protocol-specs / utils / dpos / rounds.js View on Github external
const decryptKeypairs = config => {
	const encryptedList = config.forging.delegates;
	const password = config.forging.defaultPassword;

	const keypairs = {};

	// eslint-disable-next-line no-restricted-syntax
	for (const encryptedItem of encryptedList) {
		let passphrase;
		try {
			passphrase = decryptPassphraseWithPassword(
				parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
				password,
			);
		} catch (e) {
			throw new Error('Invalid password and public key combination');
		}

		const {
			publicKeyBytes,
			privateKeyBytes,
		} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);

		const keypair = {
			publicKey: publicKeyBytes,
			privateKey: privateKeyBytes,
		};
github LiskHQ / lisk-sdk / protocol-specs / utils / dpos / rounds.js View on Github external
const decryptKeypairs = config => {
	const encryptedList = config.forging.delegates;
	const password = config.forging.defaultPassword;

	const keypairs = {};

	// eslint-disable-next-line no-restricted-syntax
	for (const encryptedItem of encryptedList) {
		let passphrase;
		try {
			passphrase = decryptPassphraseWithPassword(
				parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
				password,
			);
		} catch (e) {
			throw new Error('Invalid password and public key combination');
		}

		const {
			publicKeyBytes,
			privateKeyBytes,
		} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);

		const keypair = {
			publicKey: publicKeyBytes,
			privateKey: privateKeyBytes,
		};
github LiskHQ / lisk-sdk / protocol-specs / generators / block_processing_votes / index.js View on Github external
'b92e223981770c716ee54192a0ad028639d28d41221b72e455447bc4767aeb94caff2242b740a733daa3f3f96fc1592303b60c1704a8ac626e2704da039f41ee',
		publicKey:
			'caff2242b740a733daa3f3f96fc1592303b60c1704a8ac626e2704da039f41ee',
		address: '2222471382442610527L',
		balance: '0',
	},
};

// Decrypt all passwords from delegate genesis and add to accounts array
// eslint-disable-next-line no-restricted-syntax
for (const anAccount of genesisDelegateAccounts) {
	const { encryptedPassphrase } = defaultConfig.forging.delegates.find(
		aDelegate => aDelegate.publicKey === anAccount.publicKey,
	);

	const passphrase = decryptPassphraseWithPassword(
		parseEncryptedPassphrase(encryptedPassphrase),
		defaultConfig.forging.defaultPassword,
	);
	const keys = getPrivateAndPublicKeyFromPassphrase(passphrase);
	const address = getAddressFromPrivateKey(keys.privateKey);

	accounts[`${anAccount.username}_delegate`] = {
		passphrase,
		privateKey: keys.privateKey,
		publicKey: keys.publicKey,
		address,
		balance: '0',
	};
}

// Generators
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / create_signature_object.ts View on Github external
}

	if (!transaction.id) {
		throw new Error('Transaction ID is required to create a signature object.');
	}

	// tslint:disable-next-line variable-name
	const TransactionClass = transactionMap[transaction.type];
	const tx = new TransactionClass(transaction) as BaseTransaction;

	const validStatus = tx.validate();
	if (validStatus.errors.length > 0) {
		throw new Error('Invalid transaction.');
	}

	const { publicKey } = cryptography.getPrivateAndPublicKeyFromPassphrase(
		passphrase,
	);

	// tslint:disable-next-line no-any
	(tx as any)._signature = undefined;
	// tslint:disable-next-line no-any
	(tx as any)._signSignature = undefined;

	const multiSignature = cryptography.signData(
		cryptography.hash(tx.getBytes()),
		passphrase,
	);

	return {
		transactionId: tx.id,
		publicKey,
github LiskHQ / lisk-sdk / protocol-specs / generators / block_processing_votes / index.js View on Github external
balance: '0',
	},
};

// Decrypt all passwords from delegate genesis and add to accounts array
// eslint-disable-next-line no-restricted-syntax
for (const anAccount of genesisDelegateAccounts) {
	const { encryptedPassphrase } = defaultConfig.forging.delegates.find(
		aDelegate => aDelegate.publicKey === anAccount.publicKey,
	);

	const passphrase = decryptPassphraseWithPassword(
		parseEncryptedPassphrase(encryptedPassphrase),
		defaultConfig.forging.defaultPassword,
	);
	const keys = getPrivateAndPublicKeyFromPassphrase(passphrase);
	const address = getAddressFromPrivateKey(keys.privateKey);

	accounts[`${anAccount.username}_delegate`] = {
		passphrase,
		privateKey: keys.privateKey,
		publicKey: keys.publicKey,
		address,
		balance: '0',
	};
}

// Generators
const generateTestCasesValidBlockVotesTx = () => {
	const chainStateBuilder = new ChainStateBuilder(
		genesisBlock,
		initialAccountsState,