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

Refactory cryptography util - closes #516 #589

Merged
merged 7 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 73 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
"@oclif/plugin-help"
],
"topics": {
"config": { "description": "Manages Lisk Commander configuration." }
"config": {
"description": "Manages Lisk Commander configuration."
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettify seems to have some random behavior.
anyone know why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willclarktech @shuse2 I realized when you run npm install it formats package.json. I upgraded lisk-elements with npm command thus it introduced this change. I say we should keep this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, with npm v5 it preserves indentation as well I think. OK!

}
},
"files": [
Expand All @@ -76,7 +78,7 @@
"chalk": "2.3.0",
"cli-table2": "LiskHQ/cli-table2#187c6ae80b9d963c598d0cb3379153387bfb15c4",
"inquirer": "6.0.0",
"lisk-elements": "1.0.0-beta.3",
"lisk-elements": "1.0.0-rc.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rc.1 is already out, so i think we can use the latest one

"lockfile": "1.0.3",
"semver": "5.5.0",
"strip-ansi": "4.0.0"
Expand Down
26 changes: 11 additions & 15 deletions src/utils/cryptography.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import elements from 'lisk-elements';
import { cryptography } from 'lisk-elements';

export const encryptMessage = ({ message, passphrase, recipient }) =>
elements.cryptography.encryptMessageWithPassphrase(
message,
passphrase,
recipient,
);
cryptography.encryptMessageWithPassphrase(message, passphrase, recipient);

export const decryptMessage = ({
cipher,
nonce,
passphrase,
senderPublicKey,
}) => ({
message: elements.cryptography.decryptMessageWithPassphrase(
message: cryptography.decryptMessageWithPassphrase(
cipher,
nonce,
passphrase,
Expand All @@ -37,38 +33,38 @@ export const decryptMessage = ({
});

export const encryptPassphrase = ({ passphrase, password }) => {
const encryptedPassphraseObject = elements.cryptography.encryptPassphraseWithPassword(
const encryptedPassphraseObject = cryptography.encryptPassphraseWithPassword(
passphrase,
password,
);
const encryptedPassphrase = elements.cryptography.stringifyEncryptedPassphrase(
const encryptedPassphrase = cryptography.stringifyEncryptedPassphrase(
encryptedPassphraseObject,
);
return { encryptedPassphrase };
};

export const decryptPassphrase = ({ encryptedPassphrase, password }) => {
const encryptedPassphraseObject = elements.cryptography.parseEncryptedPassphrase(
const encryptedPassphraseObject = cryptography.parseEncryptedPassphrase(
encryptedPassphrase,
);
const passphrase = elements.cryptography.decryptPassphraseWithPassword(
const passphrase = cryptography.decryptPassphraseWithPassword(
encryptedPassphraseObject,
password,
);
return { passphrase };
};

export const getKeys = passphrase => elements.cryptography.getKeys(passphrase);
export const { getKeys } = cryptography;

export const getAddressFromPublicKey = publicKey => ({
address: elements.cryptography.getAddressFromPublicKey(publicKey),
address: cryptography.getAddressFromPublicKey(publicKey),
});

export const signMessage = ({ message, passphrase }) =>
elements.cryptography.signMessageWithPassphrase(message, passphrase);
cryptography.signMessageWithPassphrase(message, passphrase);

export const verifyMessage = ({ publicKey, signature, message }) => ({
verified: elements.cryptography.verifyMessageWithPublicKey({
verified: cryptography.verifyMessageWithPublicKey({
publicKey,
signature,
message,
Expand Down
2 changes: 1 addition & 1 deletion test/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('api utils', () => {
'https://node07.lisk.io:443',
'https://node08.lisk.io:443',
];
const testnetNode = 'http://testnet.lisk.io:7000';
const testnetNode = 'https://testnet.lisk.io:443';

let apiClient;
let apiConfig;
Expand Down
Loading