Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* 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(
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'
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,
});
}
export function liskElementsCryptoShouldBeUsedToGetTheEncryptedPassphrase() {
const { passphrase, password } = this.test.ctx;
return expect(
elements.cryptography.encryptPassphraseWithPassword,
).to.be.calledWithExactly(passphrase, password);
}
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;
}
].forEach(methodName => sandbox.stub(elements.cryptography, methodName));
};
createAccount() {
const passphrase = elements.passphrase.Mnemonic.generateMnemonic();
const { publicKey } = elements.cryptography.getKeys(passphrase);
const address = elements.cryptography.getAddressFromPublicKey(publicKey);
return {
passphrase,
publicKey,
address,
};
}
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);
};
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);
};
createAccount() {
const passphrase = elements.passphrase.Mnemonic.generateMnemonic();
const { publicKey } = elements.cryptography.getKeys(passphrase);
const address = elements.cryptography.getAddressFromPublicKey(publicKey);
return {
passphrase,
publicKey,
address,
};
}