How to use the @liskhq/lisk-cryptography.getKeys 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 / utils / bft / index.js View on Github external
const generateBlockHeader = ({
	delegateName,
	height,
	maxHeightPreviouslyForged,
	maxHeightPrevoted,
	delegateMinHeightActive,
}) => {
	const delegatePublicKey = getKeys(delegateName).publicKey;

	// Generate a deterministic block id from a block height
	const blockId = BigNum.fromBuffer(
		hash(height.toString(), 'utf8').slice(0, 8),
	).toString();

	return {
		blockId,
		height,
		maxHeightPreviouslyForged,
		delegatePublicKey,
		delegateMinHeightActive,
		maxHeightPrevoted,
	};
};
github LiskArchive / lisk-elements / packages / lisk-blockchain / src / block.ts View on Github external
txMap,
	version,
	epochTime,
	lastBlock,
	rewards,
	transactions,
	passphrase,
}: CreateBlockInput): Block => {
	const sortedTransactions = sortTransactions(
		transactions as TransactionJSON[],
	);
	const height = lastBlock.height + 1;
	const txs = rawTransactionToInstance(txMap, sortedTransactions);
	const reward = calculateRewawrd(rewards, height);
	const timestamp = getTimeFromBlockchainEpoch(epochTime);
	const { publicKey } = getKeys(passphrase);
	const rawBlock = {
		version,
		height,
		previousBlock: lastBlock.id,
		timestamp,
		reward,
		// Calculate tx related property
		...calculateTransactionsData(txs),
		transactions: sortedTransactions,
		generatorPublicKey: publicKey,
	};
	// Get reward
	const block = new Block(rawBlock, txs);
	block.sign(passphrase);

	return block;
github LiskHQ / lisk-sdk / commander / src / commands / account / create.ts View on Github external
const createAccount = (): AccountInfo => {
	const passphrase = createMnemonicPassphrase();
	const { privateKey, publicKey } = getKeys(passphrase);
	const address = getAddressFromPublicKey(publicKey);

	return {
		passphrase,
		privateKey,
		publicKey,
		address,
	};
};
github LiskHQ / lisk-sdk / protocol-specs / generators / block_processing_second_signature / index.js View on Github external
).balance = parseInt(
		new BigNum(senderBalance.toString()).sub(amount).toString(),
		10,
	);

	resultingAccountState.find(
		account => account.address === accounts.existingDelegate.address,
	).balance = parseInt(
		new BigNum(recipientBalance.toString()).plus(amount).toString(),
		10,
	);

	const secondSignature =
		'erupt sponsor rude supreme vacant delay salute allow laundry swamp curve brain';

	const { publicKey } = getKeys(secondSignature);
	const secondPassphraseObject = {
		timestamp,
		senderPublicKey: accounts.existingDelegate.publicKey,
		asset: {
			signature: {
				publicKey,
			},
		},
	};

	const secondPassphraseTx = new SecondSignatureTransaction(
		secondPassphraseObject,
	);
	secondPassphraseTx.sign(accounts.existingDelegate.passphrase);

	const blockWithSecondSignatureRegistered = createBlock(
github LiskHQ / lisk-sdk / commander / src / commands / account / show.ts View on Github external
const processInput = ({ passphrase }: { readonly passphrase?: string }) => {
	if (!passphrase) {
		throw new ValidationError('Passphrase cannot be empty');
	}

	const { privateKey, publicKey } = getKeys(passphrase);
	const address = getAddressFromPublicKey(publicKey);

	return {
		privateKey,
		publicKey,
		address,
	};
};
github LiskHQ / lisk-sdk / commander / src / commands / passphrase / encrypt.ts View on Github external
if (!password) {
		throw new ValidationError('No password was provided');
	}

	const encryptedPassphraseObject = encryptPassphraseWithPassword(
		passphrase,
		password,
	);
	const encryptedPassphrase = stringifyEncryptedPassphrase(
		encryptedPassphraseObject,
	);

	return outputPublicKey
		? {
				encryptedPassphrase,
				publicKey: getKeys(passphrase).publicKey,
		  }
		: { encryptedPassphrase };
};
github LiskHQ / lisk-sdk / elements / lisk-transactions / src / register_second_passphrase.ts View on Github external
export const registerSecondPassphrase = (
	inputs: SecondPassphraseInputs,
): Partial => {
	validateInputs(inputs);
	const { passphrase, secondPassphrase, networkIdentifier } = inputs;
	const { publicKey } = getKeys(secondPassphrase);

	const transaction = {
		...createBaseTransaction(inputs),
		type: 9,
		asset: { publicKey },
		networkIdentifier,
	};

	if (!passphrase) {
		return transaction;
	}

	const secondSignatureTransaction = new SecondSignatureTransaction(
		transaction as TransactionJSON,
	);
	secondSignatureTransaction.sign(passphrase);
github LiskArchive / lisk-elements / packages / lisk-transactions / src / utils / prepare_transaction.ts View on Github external
export const prepareTransaction = (
	partialTransaction: PartialTransaction,
	passphrase?: string,
	secondPassphrase?: string,
	timeOffset?: number,
): TransactionJSON => {
	const senderPublicKey = passphrase
		? cryptography.getKeys(passphrase).publicKey
		: undefined;
	const timestamp = getTimeWithOffset(timeOffset);

	const transaction = {
		amount: '0',
		recipientId: '',
		senderPublicKey,
		timestamp,
		...partialTransaction,
	};

	if (!validTransaction(transaction)) {
		throw new Error('Invalid transaction to process');
	}

	if (!passphrase) {