How to use the lisk-elements.cryptography function in lisk-elements

To help you get started, we’ve selected a few lisk-elements 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-examples / test / unit / modules / delegates.js View on Github external
* Copyright © 2018 Lisk Foundation
 *
 * See the LICENSE file at the top-level directory of this distribution
 * for licensing information.
 *
 * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
 * no part of this software, including this file, may be copied, modified,
 * propagated, or distributed except according to the terms contained in the
 * LICENSE file.
 *
 * Removal or modification of this copyright notice is prohibited.
 */

'use strict';

const lisk = require('lisk-elements').cryptography;
const genesisDelegates = require('../../data/genesis_delegates.json');
const delegatesRoundsList = require('../../data/delegates_rounds_list.json');
const accountFixtures = require('../../fixtures/accounts');
const application = require('../../common/application');
const seeder = require('../../common/storage_seed');

let storage;

const exceptions = global.exceptions;
const { ACTIVE_DELEGATES } = global.constants;

describe('delegates', () => {
	let library;

	before(done => {
		application.init(
github LiskHQ / lisk-sdk / test / steps / crypto / 1_given.js View on Github external
export function anEncryptedPassphrase() {
	const encryptedPassphrase = getFirstQuotedString(this.test.parent.title);
	const encryptedPassphraseObject = {
		iterations: 1,
		salt: 'e8c7dae4c893e458e0ebb8bff9a36d84',
		cipherText:
			'c0fab123d83c386ffacef9a171b6e0e0e9d913e58b7972df8e5ef358afbc65f99c9a2b6fe7716f708166ed72f59f007d2f96a91f48f0428dd51d7c9962e0c6a5fc27ca0722038f1f2cf16333',
		iv: '1a2206e426c714091b7e48f6',
		tag: '3a9d9f9f9a92c9a58296b8df64820c15',
		version: '1',
	};
	if (
		typeof elements.cryptography.parseEncryptedPassphrase.returns === 'function'
	) {
		elements.cryptography.parseEncryptedPassphrase.returns(
			encryptedPassphraseObject,
		);
	}
	if (
		typeof elements.cryptography.stringifyEncryptedPassphrase.returns ===
		'function'
	) {
		elements.cryptography.stringifyEncryptedPassphrase.returns(
			encryptedPassphrase,
		);
	}
	if (
		typeof elements.cryptography.encryptPassphraseWithPassword.returns ===
		'function'
github LiskHQ / lisk-sdk / test / steps / crypto / 2_when.js View on Github external
export function anErrorOccursAttemptingToEncryptTheMessageForTheRecipientUsingThePassphrase() {
	const { cryptography, message, passphrase, recipientKeys } = this.test.ctx;

	elements.cryptography.encryptMessageWithPassphrase.throws(
		new TypeError(DEFAULT_ERROR_MESSAGE),
	);

	this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
	this.test.ctx.returnValue = cryptography.encryptMessage({
		message,
		passphrase,
		recipient: recipientKeys.publicKey,
	});
}
github LiskHQ / lisk-sdk / test / steps / crypto / 3_then.js View on Github external
export function liskElementsCryptoShouldBeUsedToGetTheEncryptedPassphrase() {
	const { passphrase, password } = this.test.ctx;
	return expect(
		elements.cryptography.encryptPassphraseWithPassword,
	).to.be.calledWithExactly(passphrase, password);
}
github LiskHQ / lisk-sdk / test / steps / crypto / 1_given.js View on Github external
iv: '1a2206e426c714091b7e48f6',
		tag: '3a9d9f9f9a92c9a58296b8df64820c15',
		version: '1',
	};
	if (
		typeof elements.cryptography.parseEncryptedPassphrase.returns === 'function'
	) {
		elements.cryptography.parseEncryptedPassphrase.returns(
			encryptedPassphraseObject,
		);
	}
	if (
		typeof elements.cryptography.stringifyEncryptedPassphrase.returns ===
		'function'
	) {
		elements.cryptography.stringifyEncryptedPassphrase.returns(
			encryptedPassphrase,
		);
	}
	if (
		typeof elements.cryptography.encryptPassphraseWithPassword.returns ===
		'function'
	) {
		elements.cryptography.encryptPassphraseWithPassword.returns(
			encryptedPassphraseObject,
		);
	}

	this.test.ctx.encryptedPassphrase = encryptedPassphrase;
	this.test.ctx.encryptedPassphraseObject = encryptedPassphraseObject;
}
github LiskHQ / lisk-sdk / test / steps / setup.js View on Github external
	].forEach(methodName => sandbox.stub(elements.cryptography, methodName));
};
github LiskHQ / lisk-core / qa / support / lisk_util.js View on Github external
createAccount() {
		const passphrase = elements.passphrase.Mnemonic.generateMnemonic();
		const { publicKey } = elements.cryptography.getKeys(passphrase);
		const address = elements.cryptography.getAddressFromPublicKey(publicKey);

		return {
			passphrase,
			publicKey,
			address,
		};
	}
github LiskHQ / lisk-sdk-examples / src / commands_old / set.js View on Github external
const setNethash = (dotNotation, value) => {
	if (
		dotNotation === 'api.network' &&
		!Object.keys(NETHASHES).includes(value)
	) {
		if (value.length !== 64) {
			throw new ValidationError(NETHASH_ERROR_MESSAGE);
		}
		try {
			elements.cryptography.hexToBuffer(value, 'utf8');
		} catch (error) {
			throw new ValidationError(NETHASH_ERROR_MESSAGE);
		}
	}
	return setValue(dotNotation, value);
};
github LiskHQ / lisk-sdk-examples / src / commands / config / set.js View on Github external
const setNethash = (config, dotNotation, value) => {
	if (
		dotNotation === 'api.network' &&
		!Object.keys(NETHASHES).includes(value)
	) {
		if (value.length !== 64) {
			throw new ValidationError(NETHASH_ERROR_MESSAGE);
		}
		try {
			elements.cryptography.hexToBuffer(value, 'utf8');
		} catch (error) {
			throw new ValidationError(NETHASH_ERROR_MESSAGE);
		}
	}
	return setValue(config, dotNotation, value);
};
github LiskHQ / lisk-core / qa / support / lisk_util.js View on Github external
createAccount() {
		const passphrase = elements.passphrase.Mnemonic.generateMnemonic();
		const { publicKey } = elements.cryptography.getKeys(passphrase);
		const address = elements.cryptography.getAddressFromPublicKey(publicKey);

		return {
			passphrase,
			publicKey,
			address,
		};
	}