How to use the @liskhq/lisk-cryptography.parseEncryptedPassphrase 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 / 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 / test / utils / cryptography.ts View on Github external
it('should call parseEncryptedPassphrase', () => {
			cryptography.decryptPassphrase(input);
			return expect(
				cryptographyModule.parseEncryptedPassphrase,
			).to.be.calledWithExactly(input.encryptedPassphrase);
		});
github LiskHQ / lisk-sdk / commander / src / utils / cryptography.ts View on Github external
export const decryptPassphrase = ({
	encryptedPassphrase,
	password,
}: DecryptPassphraseInput) => {
	const encryptedPassphraseObject = cryptography.parseEncryptedPassphrase(
		encryptedPassphrase,
	);
	const passphrase = cryptography.decryptPassphraseWithPassword(
		encryptedPassphraseObject,
		password,
	);

	return { passphrase };
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / submodules / delegates.js View on Github external
__private.decryptPassphrase = function(encryptedPassphrase, password) {
	return decryptPassphraseWithPassword(
		parseEncryptedPassphrase(encryptedPassphrase),
		password
	);
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / forger.js View on Github external
!this.config.forging.force ||
			!this.config.forging.defaultPassword
		) {
			return;
		}
		this.logger.info(
			`Loading ${
				encryptedList.length
			} delegates using encrypted passphrases from config`,
		);

		for (const encryptedItem of encryptedList) {
			let passphrase;
			try {
				passphrase = decryptPassphraseWithPassword(
					parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
					this.config.forging.defaultPassword,
				);
			} catch (error) {
				const decryptionError = `Invalid encryptedPassphrase for publicKey: ${
					encryptedItem.publicKey
				}. ${error.message}`;
				this.logger.error(decryptionError);
				throw decryptionError;
			}

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

			const keypair = {
github LiskHQ / lisk-sdk / framework / src / modules / chain / forger / forger.js View on Github external
async updateForgingStatus(publicKey, password, forging) {
		const encryptedList = this.config.forging.delegates;
		const encryptedItem = encryptedList.find(
			item => item.publicKey === publicKey,
		);

		let keypair;
		let passphrase;

		if (encryptedItem) {
			try {
				passphrase = decryptPassphraseWithPassword(
					parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
					password,
				);
			} catch (e) {
				throw new Error('Invalid password and public key combination');
			}
			const {
				publicKeyBytes,
				privateKeyBytes,
			} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);

			keypair = {
				publicKey: publicKeyBytes,
				privateKey: privateKeyBytes,
			};
		} else {
			throw new Error(`Delegate with publicKey: ${publicKey} not found`);
github LiskHQ / lisk-sdk / commander / src / commands / passphrase / decrypt.ts View on Github external
const processInputs = (encryptedPassphrase?: string) => ({
	password,
	data,
}: InputFromSourceOutput) => {
	const encryptedPassphraseTarget =
		encryptedPassphrase || getFirstLineFromString(data);
	if (!encryptedPassphraseTarget) {
		throw new ValidationError('No encrypted passphrase was provided');
	}
	if (!password) {
		throw new ValidationError('No password was provided');
	}

	const encryptedPassphraseObject = parseEncryptedPassphrase(
		encryptedPassphraseTarget,
	);
	const passphrase = decryptPassphraseWithPassword(
		encryptedPassphraseObject,
		password,
	);

	return { passphrase };
};
github LiskHQ / lisk-sdk / framework / src / modules / chain / forger / forger.js View on Github external
!encryptedList ||
			!encryptedList.length ||
			!this.config.forging.force ||
			!this.config.forging.defaultPassword
		) {
			return;
		}
		this.logger.info(
			`Loading ${encryptedList.length} delegates using encrypted passphrases from config`,
		);

		for (const encryptedItem of encryptedList) {
			let passphrase;
			try {
				passphrase = decryptPassphraseWithPassword(
					parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
					this.config.forging.defaultPassword,
				);
			} catch (error) {
				const decryptionError = `Invalid encryptedPassphrase for publicKey: ${encryptedItem.publicKey}. ${error.message}`;
				this.logger.error(decryptionError);
				throw decryptionError;
			}

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

			const keypair = {
				publicKey: publicKeyBytes,
				privateKey: privateKeyBytes,