Skip to content

Commit

Permalink
🏠 fix commit conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
bmaggi-lisk committed Nov 2, 2018
2 parents 9926bde + 0f5fc31 commit 5b9149f
Show file tree
Hide file tree
Showing 31 changed files with 11,824 additions and 12,149 deletions.
5 changes: 4 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"env": {
"test": {
"presets": [["env"], "react", "stage-3"],
"plugins": ["transform-es2015-modules-commonjs"]
"plugins": ["transform-es2015-modules-commonjs", ["transform-runtime", {
"polyfill": false,
"regenerator": true
}]]
}
}
}
124 changes: 124 additions & 0 deletions app/src/ledger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { app, ipcMain } from 'electron'; // eslint-disable-line import/no-extraneous-dependencies
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; // eslint-disable-line import/no-extraneous-dependencies
import Lisk from 'lisk-elements'; // eslint-disable-line import/no-extraneous-dependencies
import { LedgerAccount, SupportedCoin, DposLedger } from 'dpos-ledger-api'; // eslint-disable-line import/no-extraneous-dependencies
import win from './modules/win';

TransportNodeHid.setListenDevicesDebounce(200);
/*
TransportNodeHid.setListenDevicesDebug((msg, ...args) => {
console.log(msg);
console.log({
type: 'listenDevices',
args,
});
});
*/
let busy = false;
TransportNodeHid.setListenDevicesPollingSkip(() => busy);
let ledgerPath = null;
const getLedgerAccount = (index = 0) => {
const ledgerAccount = new LedgerAccount();
ledgerAccount.coinIndex(SupportedCoin.LISK);
ledgerAccount.account(index);
return ledgerAccount;
};

const isValidAddress = address => address.length > 2 && address.length < 22 && address[address.length - 1] === 'L';
const isInsideLedgerApp = async (path) => {
try {
const transport = await TransportNodeHid.open(path);
const liskLedger = new DposLedger(transport);
const ledgerAccount = getLedgerAccount(0);
const liskAccount = await liskLedger.getPubKey(ledgerAccount);
transport.close();
return isValidAddress(liskAccount.address);
} catch (e) {
return false;
}
};
const ledgerObserver = {
next: async ({ device, type }) => {
if (device) {
if (type === 'add') {
if (process.platform === 'darwin' || await isInsideLedgerApp(device.path)) {
ledgerPath = device.path;
win.send({ event: 'ledgerConnected', value: null });
}
} else if (type === 'remove') {
if (ledgerPath) {
ledgerPath = null;
win.send({ event: 'ledgerDisconnected', value: null });
}
}
}
},
};

let observableListen = null;
const syncDevices = () => {
try {
observableListen = TransportNodeHid.listen(ledgerObserver);
} catch (e) {
ledgerPath = null;
syncDevices();
}
};
syncDevices();
app.on('will-quit', () => {
if (observableListen) {
observableListen.unsubscribe();
observableListen = null;
}
});

const getBufferToHex = buffer => Lisk.cryptography.bufferToHex(buffer);
const createCommand = (k, fn) => {
ipcMain.on(`${k}.request`, (event, ...args) => {
fn(...args)
.then(r => ({ success: true, data: r }))
.catch(e => ({ success: false, errorKey: e }))
.then(r => event.sender.send(`${k}.result`, r));
});
};
// eslint-disable-next-line arrow-body-style
createCommand('ledgerCommand', (command) => {
if (ledgerPath) {
return TransportNodeHid.open(ledgerPath)
.then(async (transport) => {
busy = true;
try {
const liskLedger = new DposLedger(transport);
const ledgerAccount = getLedgerAccount(command.data.index);
let commandResult;
if (command.action === 'GET_ACCOUNT') {
commandResult = await liskLedger.getPubKey(ledgerAccount);
}
if (command.action === 'SIGN_MSG') {
const signature = await liskLedger.signMSG(ledgerAccount, command.data.message);
commandResult = getBufferToHex(signature.slice(0, 64));
}
if (command.action === 'SIGN_TX') {
commandResult = await liskLedger.signTX(ledgerAccount, command.data.tx, false);
}
transport.close();
busy = false;
return Promise.resolve(commandResult);
} catch (err) {
transport.close();
busy = false;
if (err.statusText && err.statusText === 'CONDITIONS_OF_USE_NOT_SATISFIED') {
return Promise.reject(new Error('LEDGER_ACTION_DENIED_BY_USER'));
}
return Promise.reject(new Error('LEDGER_ERR_DURING_CONNECTION'));
}
})
.catch((e) => {
if (typeof e === 'string') {
return Promise.reject(e);
}
return Promise.reject(new Error('LEDGER_ERR_DURING_CONNECTION'));
});
}
return Promise.reject(new Error('LEDGER_IS_NOT_CONNECTED'));
});
3 changes: 3 additions & 0 deletions app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import './styles.dialog.css';
// import localeHandler from './modules/localeHandler';
import updateChecker from './modules/autoUpdater';

require('babel-polyfill'); // eslint-disable-line import/no-extraneous-dependencies
require('./ledger');

const checkForUpdates = updateChecker({
autoUpdater,
dialog: electron.dialog,
Expand Down
4 changes: 4 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module.exports = {
fs: 'empty',
child_process: 'empty',
},
externals: {
'node-hid': 'commonjs node-hid',
usb: 'commonjs usb',
},
module: {
rules: [
{
Expand Down
22 changes: 22 additions & 0 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
"Access extra features": "Access extra features",
"Account Info": "Account Info",
"Account initialization": "Account initialization",
"Accounts on Ledger": "Accounts on Ledger",
"Action Denied by User": "Action Denied by User",
"Active": "Active",
"Activity": "Activity",
"Add a Lisk ID": "Add a Lisk ID",
"Add new": "Add new",
"Add this account to your dashboard to keep track of its balance, and use it as a bookmark in the future.": "Add this account to your dashboard to keep track of its balance, and use it as a bookmark in the future.",
"Add to dashboard": "Add to dashboard",
"Add to followed accounts": "Add to followed accounts",
Expand Down Expand Up @@ -110,6 +113,9 @@
"Enter your second passphrase to confirm": "Enter your second passphrase to confirm",
"Entered passphrase does not belong to the active account": "Entered passphrase does not belong to the active account",
"Error": "Error",
"Error during login with Ledger.": "Error during login with Ledger.",
"Error on Ledger Connection. Be sure your device is connected properly": "Error on Ledger Connection. Be sure your device is connected properly",
"Error while retrievieng addresses information.": "Error while retrievieng addresses information.",
"Explain Blockchain Like I'm 5": "Explain Blockchain Like I'm 5",
"Explore the network": "Explore the network",
"Failed to connect to node": "Failed to connect to node",
Expand Down Expand Up @@ -168,6 +174,8 @@
"Learn more": "Learn more",
"Learn more about Lisk ID initialization": "Learn more about Lisk ID initialization",
"Learn more about Lisk sidechains": "Learn more about Lisk sidechains",
"Ledger Nano S Connected.": "Ledger Nano S Connected.",
"Ledger Nano S Disconnected.": "Ledger Nano S Disconnected.",
"Like almost all blockchains Lisk has transparency at it’s core. This means that anyone can view everything that happens on the Lisk network, including the holdings of each account.": "Like almost all blockchains Lisk has transparency at it’s core. This means that anyone can view everything that happens on the Lisk network, including the holdings of each account.",
"Lisk Academy": "Lisk Academy",
"Lisk Chat": "Lisk Chat",
Expand All @@ -178,9 +186,14 @@
"Lisk ID": "Lisk ID",
"Lisk Website": "Lisk Website",
"Lisk.Chat": "Lisk.Chat",
"Loading accounts": "Loading accounts",
"Local": "Local",
"Log in": "Log in",
"Log in with Ledger": "Log in with Ledger",
"Login Type not recognized.": "Login Type not recognized.",
"Logout": "Logout",
"Look at your Ledger for confirmation": "Look at your Ledger for confirmation",
"Look at your Ledger for confirmation of second signature": "Look at your Ledger for confirmation of second signature",
"Mainnet": "Mainnet",
"Manage your application": "Manage your application",
"Max 20 characters, a-z and 0-1, no special characters except for “!@$&.”": "Max 20 characters, a-z and 0-1, no special characters except for “!@$&.”",
Expand All @@ -206,6 +219,7 @@
"No results": "No results",
"No results found": "No results found",
"No, thanks": "No, thanks",
"Not Yet Implemented. Sorry.": "Not Yet Implemented. Sorry.",
"Not enough LSK": "Not enough LSK",
"Not voted": "Not voted",
"Note: After registration completes,": "Note: After registration completes,",
Expand All @@ -214,6 +228,8 @@
"Okay": "Okay",
"Okay, I'm done": "Okay, I'm done",
"Onboarding whenever you need": "Onboarding whenever you need",
"Open the Lisk App": "Open the Lisk App",
"Open the Lisk App with your Ledger Nano S": "Open the Lisk App with your Ledger Nano S",
"Out": "Out",
"Outgoing": "Outgoing",
"Page not found.": "Page not found.",
Expand All @@ -230,6 +246,7 @@
"Please sign in with your first passphrase": "Please sign in with your first passphrase",
"Please sign in with your passphrase": "Please sign in with your passphrase",
"Please sign in with your second passphrase": "Please sign in with your second passphrase",
"Please use the last not-initialized account before creating a new one!": "Please use the last not-initialized account before creating a new one!",
"Previous": "Previous",
"Price data currently not available": "Price data currently not available",
"Productivity": "Productivity",
Expand Down Expand Up @@ -337,10 +354,15 @@
"Transaction not found": "Transaction not found",
"Transactions can’t be reversed": "Transactions can’t be reversed",
"Transfer": "Transfer",
"Try Again": "Try Again",
"Try again": "Try again",
"Try using menu for navigation.": "Try using menu for navigation.",
"URL is invalid": "URL is invalid",
"Unable to connect to the node": "Unable to connect to the node",
"Unable to connect to the node, no response from the server.": "Unable to connect to the node, no response from the server.",
"Unable to detect the communication layer with your Ledger Nano S": "Unable to detect the communication layer with your Ledger Nano S",
"Unable to detect the communication layer. Is ledger connected? Is Fido U2F Extension Installed?": "Unable to detect the communication layer. Is ledger connected? Is Fido U2F Extension Installed?",
"Unable to detect your Ledger Nano S. Be sure your device is connected and inside the Lisk App": "Unable to detect your Ledger Nano S. Be sure your device is connected and inside the Lisk App",
"Undo": "Undo",
"Unfollow": "Unfollow",
"Unlock account": "Unlock account",
Expand Down
12 changes: 12 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ module.exports = function (config) {
'src/components/register/register.js',
'src/components/voteUrlProcessor/index.js',
'src/utils/api/liskService.js',
'src/utils/ledger.js',
'src/utils/api/ledger.js',
'src/components/login/index.js',
'src/components/login/login.js',
'src/utils/rawTransactionWrapper.js',
'src/store/middlewares/login.js',
'src/utils/to.js',
'src/components/ledger/index.js',
'src/components/ledger/unlockWallet.js',
'src/components/ledger/ledgerLogin.js',
'src/components/ledger/addAccountCard.js',
'src/components/ledger/accountCard.js',
'src/store/reducers/liskService.js',
'src/actions/transactions.js',
'src/components/errorBoundary/index.js',
Expand Down
Loading

0 comments on commit 5b9149f

Please sign in to comment.