Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
♻️ Change cryptoModule to cryptography and childProcesses to child_pr…
Browse files Browse the repository at this point in the history
…ocesses
  • Loading branch information
shuse2 committed Feb 27, 2018
1 parent ade4e9e commit c7cd9a5
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 73 deletions.
6 changes: 3 additions & 3 deletions src/commands/create_account.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import cryptoModule from '../utils/crypto_module';
import cryptography from '../utils/cryptography';
import { createCommand } from '../utils/helpers';
import { createMnemonicPassphrase } from '../utils/mnemonic';

Expand All @@ -24,8 +24,8 @@ const description = `Returns a randomly-generated mnemonic passphrase with its c

export const actionCreator = () => async () => {
const passphrase = createMnemonicPassphrase();
const { publicKey } = cryptoModule.getKeys(passphrase);
const { address } = cryptoModule.getAddressFromPublicKey(publicKey);
const { publicKey } = cryptography.getKeys(passphrase);
const { address } = cryptography.getAddressFromPublicKey(publicKey);

return {
passphrase,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/decrypt_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import cryptoModule from '../utils/crypto_module';
import cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
Expand All @@ -28,7 +28,7 @@ const processInputs = (nonce, senderPublicKey, message) => ({
passphrase,
data,
}) =>
cryptoModule.decryptMessage({
cryptography.decryptMessage({
cipher: message || data,
nonce,
passphrase,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/decrypt_passphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import cryptoModule from '../utils/crypto_module';
import cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources, { getFirstLineFromString } from '../utils/input';
Expand All @@ -34,7 +34,7 @@ const passphraseOptionDescription = `Specifies a source for providing an encrypt
`;

const processInputs = (iv, passphrase) => ({ password, data }) =>
cryptoModule.decryptPassphrase({
cryptography.decryptPassphrase({
cipher: passphrase || getFirstLineFromString(data),
iv,
password,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/encrypt_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import cryptoModule from '../utils/crypto_module';
import cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
Expand All @@ -25,7 +25,7 @@ const description = `Encrypts a message for a given recipient public key using y
`;

const processInputs = (recipient, message) => ({ passphrase, data }) =>
cryptoModule.encryptMessage({
cryptography.encryptMessage({
message: message || data,
passphrase,
recipient,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/encrypt_passphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import cryptoModule from '../utils/crypto_module';
import cryptography from '../utils/cryptography';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
Expand All @@ -29,10 +29,10 @@ const outputPublicKeyOption = [
];

const processInputs = outputPublicKey => ({ passphrase, password }) => {
const cipherAndIv = cryptoModule.encryptPassphrase({ passphrase, password });
const cipherAndIv = cryptography.encryptPassphrase({ passphrase, password });
return outputPublicKey
? Object.assign({}, cipherAndIv, {
publicKey: cryptoModule.getKeys(passphrase).publicKey,
publicKey: cryptography.getKeys(passphrase).publicKey,
})
: cipherAndIv;
};
Expand Down
4 changes: 2 additions & 2 deletions src/commands/sign_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import cryptoModule from '../utils/crypto_module';
import cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
Expand All @@ -25,7 +25,7 @@ const description = `Sign a message using your secret passphrase.
`;

const processInputs = message => ({ passphrase, data }) =>
cryptoModule.signMessage({
cryptography.signMessage({
message: message || data,
passphrase,
});
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/steps/1_given.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/
export * from './api/1_given';
export * from './childProcesses/1_given';
export * from './child_processes/1_given';
export * from './config/1_given';
export * from './crypto/1_given';
export * from './domain/1_given';
Expand Down
2 changes: 1 addition & 1 deletion test/steps/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/
export * from './api/3_then';
export * from './childProcesses/3_then';
export * from './child_processes/3_then';
export * from './config/3_then';
export * from './crypto/3_then';
export * from './domain/3_then';
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions test/steps/crypto/1_given.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/
import lisk from 'lisk-js';
import cryptoInstance from '../../../src/utils/crypto_module';
import cryptography from '../../../src/utils/cryptography';
import * as inputUtils from '../../../src/utils/input/utils';
import { getFirstQuotedString, getQuotedStrings } from '../utils';

Expand All @@ -24,7 +24,7 @@ export function theMessageUnderThePassphraseHasSignature() {
}

export function aCryptoInstance() {
this.test.ctx.cryptoInstance = cryptoInstance;
this.test.ctx.cryptography = cryptography;
}

export function aCryptoInstanceHasBeenInitialised() {
Expand All @@ -40,10 +40,10 @@ export function aCryptoInstanceHasBeenInitialised() {
'getKeys',
'getAddressFromPublicKey',
'signMessage',
].forEach(methodName => cryptoInstance[methodName].returns(cryptoResult));
].forEach(methodName => cryptography[methodName].returns(cryptoResult));

this.test.ctx.cryptoResult = cryptoResult;
this.test.ctx.cryptoInstance = cryptoInstance;
this.test.ctx.cryptography = cryptography;
}

export function aSenderPublicKey() {
Expand Down Expand Up @@ -79,7 +79,7 @@ export function aSecondPassphrase() {

export function aPassphraseWithPublicKey() {
const [passphrase, publicKey] = getQuotedStrings(this.test.parent.title);
cryptoInstance.getKeys.returns({ publicKey });
cryptography.getKeys.returns({ publicKey });

this.test.ctx.passphrase = passphrase;
this.test.ctx.publicKey = publicKey;
Expand All @@ -104,14 +104,14 @@ export function aPassphraseWithPrivateKeyAndPublicKeyAndAddress() {
lisk.crypto.getAddressFromPublicKey.returns(address);
}

if (typeof cryptoInstance.getKeys.returns === 'function') {
cryptoInstance.getKeys.returns(keys);
if (typeof cryptography.getKeys.returns === 'function') {
cryptography.getKeys.returns(keys);
}
if (typeof cryptoInstance.decryptPassphrase.returns === 'function') {
cryptoInstance.decryptPassphrase.returns({ passphrase });
if (typeof cryptography.decryptPassphrase.returns === 'function') {
cryptography.decryptPassphrase.returns({ passphrase });
}
if (typeof cryptoInstance.getAddressFromPublicKey.returns === 'function') {
cryptoInstance.getAddressFromPublicKey.returns({ address });
if (typeof cryptography.getAddressFromPublicKey.returns === 'function') {
cryptography.getAddressFromPublicKey.returns({ address });
}

this.test.ctx.passphrase = passphrase;
Expand Down
64 changes: 28 additions & 36 deletions test/steps/crypto/2_when.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,133 +17,125 @@ import lisk from 'lisk-js';
import { DEFAULT_ERROR_MESSAGE } from '../utils';

export function noErrorOccursAttemptingToSignTheMessageUsingThePassphrase() {
const { cryptoInstance, message, passphrase, signature } = this.test.ctx;
const { cryptography, message, passphrase, signature } = this.test.ctx;

lisk.crypto.signMessageWithPassphrase.returns(signature);

this.test.ctx.returnValue = cryptoInstance.signMessage({
this.test.ctx.returnValue = cryptography.signMessage({
message,
passphrase,
});
}

export function anErrorOccursAttemptingToSignTheMessageUsingThePassphrase() {
const { cryptoInstance, message, passphrase } = this.test.ctx;
const { cryptography, message, passphrase } = this.test.ctx;

lisk.crypto.signMessageWithPassphrase.throws(
new TypeError(DEFAULT_ERROR_MESSAGE),
);

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.signMessage({
this.test.ctx.returnValue = cryptography.signMessage({
message,
passphrase,
});
}

export function anErrorOccursAttemptingToGetTheAddressFromThePublicKey() {
const { cryptoInstance, keys: { publicKey } } = this.test.ctx;
const { cryptography, keys: { publicKey } } = this.test.ctx;

lisk.crypto.getAddressFromPublicKey.throws(
new TypeError(DEFAULT_ERROR_MESSAGE),
);

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.getAddressFromPublicKey(publicKey);
this.test.ctx.returnValue = cryptography.getAddressFromPublicKey(publicKey);
}

export function noErrorOccursAttemptingToGetTheAddressFromThePublicKey() {
const { cryptoInstance, keys: { publicKey }, address } = this.test.ctx;
const { cryptography, keys: { publicKey }, address } = this.test.ctx;
lisk.crypto.getAddressFromPublicKey.returns(address);
this.test.ctx.returnValue = cryptoInstance.getAddressFromPublicKey(publicKey);
this.test.ctx.returnValue = cryptography.getAddressFromPublicKey(publicKey);
}

export function noErrorOccursAttemptingToGetTheKeysForThePassphrase() {
const { cryptoInstance, passphrase } = this.test.ctx;
this.test.ctx.returnValue = cryptoInstance.getKeys(passphrase);
const { cryptography, passphrase } = this.test.ctx;
this.test.ctx.returnValue = cryptography.getKeys(passphrase);
}

export function anErrorOccursAttemptingToGetTheKeysForThePassphrase() {
const { cryptoInstance, passphrase } = this.test.ctx;
const { cryptography, passphrase } = this.test.ctx;

lisk.crypto.getKeys.throws(new TypeError(DEFAULT_ERROR_MESSAGE));

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.getKeys(passphrase);
this.test.ctx.returnValue = cryptography.getKeys(passphrase);
}

export function noErrorOccursAttemptingToEncryptThePassphraseWithThePassword() {
const { cryptoInstance, passphrase, password } = this.test.ctx;
this.test.ctx.returnValue = cryptoInstance.encryptPassphrase({
const { cryptography, passphrase, password } = this.test.ctx;
this.test.ctx.returnValue = cryptography.encryptPassphrase({
passphrase,
password,
});
}

export function anErrorOccursAttemptingToEncryptThePassphraseWithThePassword() {
const { cryptoInstance, passphrase, password } = this.test.ctx;
const { cryptography, passphrase, password } = this.test.ctx;

lisk.crypto.encryptPassphraseWithPassword.throws(
new TypeError(DEFAULT_ERROR_MESSAGE),
);

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.encryptPassphrase({
this.test.ctx.returnValue = cryptography.encryptPassphrase({
passphrase,
password,
});
}

export function noErrorOccursAttemptingToDecryptThePassphraseWithThePassword() {
const {
cryptoInstance,
cipherAndIv: { cipher, iv },
password,
} = this.test.ctx;
this.test.ctx.returnValue = cryptoInstance.decryptPassphrase({
const { cryptography, cipherAndIv: { cipher, iv }, password } = this.test.ctx;
this.test.ctx.returnValue = cryptography.decryptPassphrase({
cipher,
iv,
password,
});
}

export function anErrorOccursAttemptingToDecryptThePassphraseWithThePassword() {
const {
cryptoInstance,
cipherAndIv: { cipher, iv },
password,
} = this.test.ctx;
const { cryptography, cipherAndIv: { cipher, iv }, password } = this.test.ctx;

lisk.crypto.decryptPassphraseWithPassword.throws(
new TypeError(DEFAULT_ERROR_MESSAGE),
);

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.decryptPassphrase({
this.test.ctx.returnValue = cryptography.decryptPassphrase({
cipher,
iv,
password,
});
}

export function noErrorOccursAttemptingToEncryptTheMessageForTheRecipientUsingThePassphrase() {
const { cryptoInstance, message, passphrase, recipientKeys } = this.test.ctx;
this.test.ctx.returnValue = cryptoInstance.encryptMessage({
const { cryptography, message, passphrase, recipientKeys } = this.test.ctx;
this.test.ctx.returnValue = cryptography.encryptMessage({
message,
passphrase,
recipient: recipientKeys.publicKey,
});
}

export function anErrorOccursAttemptingToEncryptTheMessageForTheRecipientUsingThePassphrase() {
const { cryptoInstance, message, passphrase, recipientKeys } = this.test.ctx;
const { cryptography, message, passphrase, recipientKeys } = this.test.ctx;

lisk.crypto.encryptMessageWithPassphrase.throws(
new TypeError(DEFAULT_ERROR_MESSAGE),
);

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.encryptMessage({
this.test.ctx.returnValue = cryptography.encryptMessage({
message,
passphrase,
recipient: recipientKeys.publicKey,
Expand All @@ -152,12 +144,12 @@ export function anErrorOccursAttemptingToEncryptTheMessageForTheRecipientUsingTh

export function noErrorOccursAttemptingToDecryptTheMessageUsingTheRecipientPassphraseAndSenderPublicKey() {
const {
cryptoInstance,
cryptography,
cipherAndNonce: { cipher, nonce },
recipientPassphrase,
keys,
} = this.test.ctx;
this.test.ctx.returnValue = cryptoInstance.decryptMessage({
this.test.ctx.returnValue = cryptography.decryptMessage({
cipher,
nonce,
passphrase: recipientPassphrase,
Expand All @@ -167,7 +159,7 @@ export function noErrorOccursAttemptingToDecryptTheMessageUsingTheRecipientPassp

export function anErrorOccursAttemptingToDecryptTheMessageUsingTheRecipientPassphraseAndSenderPublicKey() {
const {
cryptoInstance,
cryptography,
cipherAndNonce: { cipher, nonce },
recipientPassphrase,
keys,
Expand All @@ -178,7 +170,7 @@ export function anErrorOccursAttemptingToDecryptTheMessageUsingTheRecipientPassp
);

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.decryptMessage({
this.test.ctx.returnValue = cryptography.decryptMessage({
cipher,
nonce,
recipientPassphrase,
Expand Down

0 comments on commit c7cd9a5

Please sign in to comment.